diff options
| author | Adam Soltys <[email protected]> | 2025-11-26 14:53:20 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-11 15:33:08 -0800 |
| commit | 68e7fe9655f94efc573f3aab7acf60d03c4162a0 (patch) | |
| tree | 48f35ea51823ac1cd0d74afc453628f5e128bf71 /src/routes/(app)/ark | |
| parent | 5f1c31b6618f0b895fb98c8f2a841989625eaf16 (diff) | |
| download | coinos-ui-68e7fe9655f94efc573f3aab7acf60d03c4162a0.tar.gz coinos-ui-68e7fe9655f94efc573f3aab7acf60d03c4162a0.zip | |
ark balance
Diffstat (limited to 'src/routes/(app)/ark')
| -rw-r--r-- | src/routes/(app)/ark/+page.server.ts | 11 | ||||
| -rw-r--r-- | src/routes/(app)/ark/+page.svelte | 115 |
2 files changed, 103 insertions, 23 deletions
diff --git a/src/routes/(app)/ark/+page.server.ts b/src/routes/(app)/ark/+page.server.ts new file mode 100644 index 00000000..bac0a02a --- /dev/null +++ b/src/routes/(app)/ark/+page.server.ts @@ -0,0 +1,11 @@ +import getRates from "$lib/rates"; + +export async function load({ depends, parent }) { + depends("app:payments"); + depends("app:items"); + + const { user } = await parent(); + + const rates = await getRates(); + return { rate: rates[user.currency] }; +} diff --git a/src/routes/(app)/ark/+page.svelte b/src/routes/(app)/ark/+page.svelte index 09d4d9a3..3089d887 100644 --- a/src/routes/(app)/ark/+page.svelte +++ b/src/routes/(app)/ark/+page.svelte @@ -1,44 +1,113 @@ <script> - import { onMount, tick } from "svelte"; - import { HDKey } from "@scure/bip32"; - import { wallet } from "$lib/ark"; + import { onMount } from "svelte"; + import { getBalance, getAddress, keyToNsec } from "$lib/ark"; + import Amount from "$comp/Amount.svelte"; + import { s, copy } from "$lib/utils"; + import { t } from "$lib/translations"; - let loading = $state(); - let balance = $state(); + let { data } = $props(); + let { user, rate } = $derived(data); + + let loading = $state(true); + let balance = $state({ available: 0, pending: 0 }); + let address = $state(""); + let showNsec = $state(false); + let nsec = $state(""); onMount(async () => { - setTimeout(checkBalance, 1000); + await refresh(); }); - let checkBalance = async (e) => { - e?.preventDefault(); + let refresh = async () => { loading = true; + try { + [balance, address] = await Promise.all([getBalance(), getAddress()]); + } catch (e) { + console.error("Failed to load ARK wallet:", e); + } + loading = false; + }; - balance = await wallet().getBalance(); + let revealNsec = () => { + nsec = keyToNsec(); + showNsec = true; + }; - loading = false; + let copyNsec = () => { + copy(nsec); }; </script> <div class="space-y-5"> - <h1 class="text-center text-3xl font-semibold">Ark</h1> + <div class="flex items-center justify-center gap-2"> + <iconify-icon noobserver icon="ph:vault-bold" width="32"></iconify-icon> + <h1 class="text-3xl font-semibold">Ark Wallet</h1> + </div> - <div class="container w-full mx-auto text-lg px-4 max-w-xl space-y-5"> + <div class="container w-full mx-auto px-4 max-w-xl space-y-5"> {#if loading} - <div> - <div class="loading loading-spinner"></div> + <div class="flex justify-center py-8"> + <div class="loading loading-spinner loading-lg"></div> </div> - {:else if typeof balance !== "undefined"} - <div class="flex items-center gap-2"> - <div> - {balance.available} sats + {:else} + <div class="text-center space-y-2"> + <Amount + amount={balance.available} + {rate} + currency={user?.currency || "USD"} + /> + {#if balance.pending > 0} + <div class="text-sm text-warning"> + +{s(balance.pending)} pending + </div> + {/if} + </div> + + <div class="flex gap-2 justify-center w-full text-xl"> + <a href="/invoice" class="btn flex-grow"> + <iconify-icon noobserver icon="ph:hand-coins-bold" width="24" flip="horizontal"></iconify-icon> + Receive + </a> + <a href="/send" class="btn flex-grow"> + <iconify-icon noobserver icon="ph:paper-plane-right-bold" width="24"></iconify-icon> + Send + </a> + </div> + + <button class="btn btn-ghost btn-sm w-full" onclick={refresh}> + <iconify-icon noobserver icon="ph:arrows-clockwise-bold" width="20"></iconify-icon> + Refresh + </button> + + <div class="divider"></div> + + <div class="space-y-2"> + <div class="text-sm text-secondary">Your ARK Address</div> + <div + class="text-xs break-all bg-base-200 p-3 rounded-lg cursor-pointer hover:bg-base-300" + onclick={() => copy(address)} + > + {address} </div> </div> - {/if} - <div class="flex gap-2 justify-center w-full"> - <a href="/receive" class="btn grow">Receive</a> - <a href="/send" class="btn grow">Send</a> - </div> + <div class="space-y-2"> + <div class="text-sm text-secondary">Backup Key</div> + {#if showNsec} + <div + class="text-xs break-all bg-warning/20 p-3 rounded-lg cursor-pointer border border-warning" + onclick={copyNsec} + > + {nsec} + </div> + <div class="text-xs text-warning">⚠️ Keep this secret! Anyone with this key can spend your funds.</div> + {:else} + <button class="btn btn-warning btn-sm" onclick={revealNsec}> + <iconify-icon noobserver icon="ph:eye-bold" width="20"></iconify-icon> + Reveal nsec + </button> + {/if} + </div> + {/if} </div> </div> |
