flotilla/src/routes/settings/wallet/+page.svelte

122 lines
4.8 KiB
Svelte
Raw Normal View History

2025-07-04 13:22:19 +00:00
<script lang="ts">
import {nwc} from "@getalby/sdk"
import {LOCALE} from "@welshman/lib"
import {displayRelayUrl, isNWCWallet, fromMsats} from "@welshman/util"
import {session, pubkey, profilesByPubkey} from "@welshman/app"
2025-07-04 13:22:19 +00:00
import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte"
import WalletConnect from "@app/components/WalletConnect.svelte"
import WalletDisconnect from "@app/components/WalletDisconnect.svelte"
import WalletUpdateReceivingAddress from "@app/components/WalletUpdateReceivingAddress.svelte"
import {pushModal} from "@app/util/modal"
import {getWebLn} from "@app/core/commands"
2025-09-10 22:26:39 +00:00
import Wallet2 from "@assets/icons/wallet.svg?dataurl"
import CheckCircle from "@assets/icons/check-circle.svg?dataurl"
import AddCircle from "@assets/icons/add-circle.svg?dataurl"
import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
import InfoCircle from "@assets/icons/info-circle.svg?dataurl"
2025-07-04 13:22:19 +00:00
const connect = () => pushModal(WalletConnect)
const disconnect = () => pushModal(WalletDisconnect)
const updateReceivingAddress = () => pushModal(WalletUpdateReceivingAddress)
const profile = $derived($profilesByPubkey.get($pubkey || ""))
const profileLightningAddress = $derived(profile?.lud16)
const walletLud16 = $derived(
$session?.wallet && isNWCWallet($session.wallet) ? $session.wallet.info.lud16 : undefined,
)
2025-07-04 13:22:19 +00:00
</script>
<div class="content column gap-4">
2025-11-05 23:32:55 +00:00
<div class="card2 bg-alt flex flex-col gap-6 shadow-md">
2025-07-04 13:22:19 +00:00
<div class="flex items-center justify-between">
<strong class="flex items-center gap-3">
2025-09-10 22:26:39 +00:00
<Icon icon={Wallet2} />
2025-07-04 13:22:19 +00:00
Wallet
</strong>
{#if $session?.wallet}
2025-07-07 20:58:43 +00:00
<div class="flex items-center gap-2 text-sm text-success">
2025-09-10 22:26:39 +00:00
<Icon icon={CheckCircle} size={4} />
2025-07-04 13:22:19 +00:00
Connected
</div>
{:else}
<Button class="btn btn-primary btn-sm" onclick={connect}>
2025-09-10 22:26:39 +00:00
<Icon icon={AddCircle} />
2025-07-04 13:22:19 +00:00
Connect Wallet
</Button>
{/if}
</div>
<div class="col-4">
{#if $session?.wallet}
{#if $session.wallet.type === "webln"}
{@const {node, version} = $session.wallet.info}
2025-07-04 13:22:19 +00:00
<div class="flex flex-col justify-between gap-2 lg:flex-row">
<p>
Connected to <strong>{node?.alias || version || "unknown wallet"}</strong>
via <strong>{$session.wallet.type}</strong>
2025-07-04 13:22:19 +00:00
</p>
2025-07-07 20:58:43 +00:00
<p class="flex gap-2 whitespace-nowrap">
2025-07-04 13:22:19 +00:00
Balance:
{#await getWebLn()
?.enable()
.then(() => getWebLn().getBalance())}
<span class="loading loading-spinner loading-sm"></span>
{:then res}
2025-07-09 20:19:33 +00:00
{new Intl.NumberFormat(LOCALE).format(res?.balance || 0)}
2025-07-04 13:22:19 +00:00
{:catch}
[unknown]
{/await}
sats
</p>
</div>
{:else if $session.wallet.type === "nwc"}
{@const {lud16, relayUrl, nostrWalletConnectUrl} = $session.wallet.info}
2025-07-04 13:22:19 +00:00
<div class="flex flex-col justify-between gap-2 lg:flex-row">
<p>
Connected to <strong>{lud16}</strong> via <strong>{displayRelayUrl(relayUrl)}</strong>
</p>
2025-07-07 20:58:43 +00:00
<p class="flex gap-2 whitespace-nowrap">
2025-07-04 13:22:19 +00:00
Balance:
{#await new nwc.NWCClient({nostrWalletConnectUrl}).getBalance()}
<span class="loading loading-spinner loading-sm"></span>
{:then res}
2025-07-07 20:58:43 +00:00
{new Intl.NumberFormat(LOCALE).format(fromMsats(res?.balance || 0))}
2025-07-04 13:22:19 +00:00
{:catch}
[unknown]
{/await}
sats
</p>
</div>
{/if}
<Button class="btn btn-neutral btn-sm" onclick={disconnect}>
2025-09-10 22:26:39 +00:00
<Icon icon={CloseCircle} />
2025-07-04 13:22:19 +00:00
Disconnect Wallet
</Button>
{:else}
<p class="py-12 text-center opacity-75">No wallet connected</p>
{/if}
</div>
</div>
<div
2025-11-05 23:32:55 +00:00
class="card2 bg-alt flex flex-col shadow-md"
class:gap-6={profileLightningAddress && walletLud16 && profile?.lud16 !== walletLud16}>
<div class="flex items-center justify-between">
<strong>Lightning Address</strong>
<div class="flex items-center gap-2">
<span class={profileLightningAddress ? "" : "text-warning"}>
{profileLightningAddress ? profileLightningAddress : "Not set"}
</span>
<Button class="btn btn-neutral btn-xs ml-3" onclick={updateReceivingAddress}>Update</Button>
</div>
</div>
{#if profileLightningAddress && walletLud16 && profile?.lud16 !== walletLud16}
<div class="card2 bg-alt flex items-center gap-2 text-xs">
<Icon icon={InfoCircle} size={4} />
Your profile has a different lightning address than your connected wallet.
</div>
{/if}
</div>
2025-07-04 13:22:19 +00:00
</div>