aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-26 13:36:28 -0800
committerAdam Soltys <[email protected]>2026-02-26 13:36:28 -0800
commita5faa64ba470f935ea3e7932feece3cd9fbadb90 (patch)
tree79ec7d6cb2038b5920d5cca977a244fbb189923c /src/routes
parentb137cdfca84cf68a2b8a620ba1c55337e88a0050 (diff)
downloadcoinos-ui-a5faa64ba470f935ea3e7932feece3cd9fbadb90.tar.gz
coinos-ui-a5faa64ba470f935ea3e7932feece3cd9fbadb90.zip
ark tests
Diffstat (limited to 'src/routes')
-rw-r--r--src/routes/(app)/+layout.svelte31
-rw-r--r--src/routes/(app)/account/[id]/+page.svelte5
-rw-r--r--src/routes/(app)/pay/[username]/[...amount]/+page.server.ts21
-rw-r--r--src/routes/(app)/payment/[id]/+page.svelte2
-rw-r--r--src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts6
-rw-r--r--src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.svelte30
-rw-r--r--src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte9
7 files changed, 86 insertions, 18 deletions
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte
index 0c88ff19..3fc8f9cf 100644
--- a/src/routes/(app)/+layout.svelte
+++ b/src/routes/(app)/+layout.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
- import { getWallet, syncTransactions, settle, refresh, arkkey, arkaid, sendArk, arkSending } from "$lib/ark";
+ import { getWallet, subscribeToAsp, syncTransactions, settle, refresh, arkkey, arkaid, sendArk, arkSending } from "$lib/ark";
import { SvelteToast } from "@zerodevx/svelte-toast";
import { onDestroy, onMount } from "svelte";
import { close, connect, send, socket } from "$lib/socket";
@@ -102,6 +102,7 @@
let arkInitializedKey: string | undefined;
let arkRefreshTimer: ReturnType<typeof setInterval> | undefined;
+ let aspStopFunc: (() => void) | undefined;
const initArk = async () => {
const key = $arkkey;
@@ -111,7 +112,32 @@
const wallet = await getWallet();
if (wallet) {
localStorage.setItem("arkkey:uid", user.id);
- wallet.notifyIncomingFunds(() => arkSync("notifyIncomingFunds"));
+
+ // Subscribe directly to ASP event stream (bypasses SDK's fragile wrapper)
+ aspStopFunc?.();
+ aspStopFunc = subscribeToAsp(async () => {
+ // Retry arkSync with backoff — indexer needs time to process the new VTXO
+ for (const delay of [1000, 3000, 8000]) {
+ await new Promise((r) => setTimeout(r, delay));
+ const aid = $arkaid || getCookie("aid") || user.id;
+ const result = await syncTransactions(aid);
+ console.log(`[arkSync] SSE retry (delay: ${delay}ms, received: ${result?.received || 0})`);
+ if (result?.received > 0) {
+ const paidPayment = result.payments?.find((p: any) => p.iid && p.amount > 0);
+ if (paidPayment) {
+ goto(`/invoice/${paidPayment.iid}`);
+ } else if ($fiat && $rateStore && user?.currency) {
+ success(`Received ${f(toFiat(result.received, $rateStore as number), user.currency)}!`);
+ } else {
+ success(`Received ${s(result.received)}!`);
+ }
+ invalidate("app:payments");
+ return;
+ }
+ }
+ invalidate("app:payments");
+ });
+
arkSync("initArk");
refresh().catch((e) => console.error("Ark refresh failed:", e));
settle().catch((e) => console.error("Ark settle failed:", e));
@@ -200,6 +226,7 @@
close();
clearTimeout(checkTimer);
if (arkRefreshTimer) clearInterval(arkRefreshTimer);
+ aspStopFunc?.();
}
});
</script>
diff --git a/src/routes/(app)/account/[id]/+page.svelte b/src/routes/(app)/account/[id]/+page.svelte
index 065b85c6..62c4beea 100644
--- a/src/routes/(app)/account/[id]/+page.svelte
+++ b/src/routes/(app)/account/[id]/+page.svelte
@@ -5,7 +5,7 @@
import Toggle from "$comp/Toggle.svelte";
import WalletPass from "$comp/WalletPass.svelte";
import { goto } from "$app/navigation";
- import { copy, fail, focus, post } from "$lib/utils";
+ import { copy, fail, focus, loc, post } from "$lib/utils";
import { importing } from "$lib/store";
import { enhance } from "$app/forms";
import { t } from "$lib/translations";
@@ -33,6 +33,7 @@
let name = $state(data.account.name || displayType);
let currency = $state(data.account.currency || data.user.currency);
let userCurrency = $derived(data.user.currency);
+ let locale = $derived(loc(data.user));
let currencyChanged = $derived(currency !== userCurrency);
let updateUserCurrency = $state(false);
@@ -325,6 +326,7 @@
<Numpad
bind:amount={threshold}
{currency}
+ {locale}
bind:rate
bind:submit={doneReserve}
bind:element={thresholdEl}
@@ -341,6 +343,7 @@
<Numpad
bind:amount={reserve}
{currency}
+ {locale}
bind:rate
bind:submit={doneReserve}
bind:element={reserveEl}
diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
index f1e5a073..ca0f382d 100644
--- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
+++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts
@@ -7,7 +7,26 @@ export async function load({ cookies, params, parent }) {
const { user } = await parent();
const rates = await getRates();
- if (user?.username === username) redirect(307, `/${username}/receive`);
+ if (user?.username === username) {
+ // Allow vault→custodial self-payment: redirect to send/ark with server address
+ const aid = cookies.get("aid");
+ if (aid && aid !== user.id) {
+ const account = await get(`/account/${aid}`, auth(cookies));
+ if (account?.type === "ark") {
+ const serverAddr = await get("/ark/address");
+ let [amt, cur] = params.amount.split("/");
+ if (amt) {
+ if (cur) {
+ const r = rates[cur.toUpperCase()];
+ if (r) amt = String(Math.round((Number(amt) * sats) / r));
+ }
+ redirect(307, `/send/ark/${serverAddr}/${amt}`);
+ }
+ redirect(307, `/send/ark/${serverAddr}`);
+ }
+ }
+ redirect(307, `/${username}/receive`);
+ }
const subject = await get(`/users/${username}`);
let [amount, currency] = params.amount.split("/");
diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte
index 84a728a0..af729233 100644
--- a/src/routes/(app)/payment/[id]/+page.svelte
+++ b/src/routes/(app)/payment/[id]/+page.svelte
@@ -144,7 +144,7 @@
<div>
<span class="text-lg text-secondary">{$t("payments.date")}</span>
<div>
- {format(new Date(created), "MMM d, yyyy", { locale })}{format(new Date(created), "h:mmaaa", { locale })}
+ {format(new Date(created), "MMM d, yyyy", { locale })} {format(new Date(created), "h:mmaaa", { locale })}
</div>
</div>
diff --git a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts
index 10a6a737..9fa754d6 100644
--- a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts
+++ b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.server.ts
@@ -26,12 +26,18 @@ export async function load({ params: { address, amount }, cookies, parent }) {
}
const rate = rates[user.currency];
+ const serverArkAddress = account.type === "ark" ? await get("/ark/address") : null;
+
+ // Check if destination is the user's own vault address (custodial ark invoice)
+ const isCustodialForward = account.type === "ark" && address === account.arkAddress;
return {
account,
amount,
address,
rate,
+ serverArkAddress,
+ isCustodialForward,
};
}
diff --git a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.svelte b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.svelte
index 02f1c4fb..744886ae 100644
--- a/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.svelte
+++ b/src/routes/(app)/send/ark/[address]/[amount]/[...feeRate]/+page.svelte
@@ -2,12 +2,12 @@
import { t } from "$lib/translations";
import { enhance } from "$app/forms";
import Spinner from "$comp/Spinner.svelte";
- import { focus, s, post } from "$lib/utils";
+ import { focus, loc, s, post } from "$lib/utils";
import { pin } from "$lib/store";
import { goto, invalidate } from "$app/navigation";
import { rate } from "$lib/store";
import { applyAction } from "$app/forms";
- import { sendArk } from "$lib/ark";
+ import { sendArk, sendArkViaForward } from "$lib/ark";
import Amount from "$comp/Amount.svelte";
@@ -23,13 +23,24 @@
submitting = true;
error = "";
try {
- const txid = await sendArk(address, parseInt(amount));
+ let p;
- const p = await post("/post/ark/vault-send", {
- hash: txid,
- amount: parseInt(amount),
- aid: account.id,
- });
+ if (data.serverArkAddress && (address === data.serverArkAddress || data.isCustodialForward)) {
+ // Vault→custodial: send to server and credit custodial account
+ p = await sendArkViaForward({
+ serverArkAddress: data.serverArkAddress,
+ amount: parseInt(amount),
+ aid: account.id,
+ user: data.user,
+ });
+ } else {
+ const txid = await sendArk(address, parseInt(amount));
+ p = await post("/post/ark/vault-send", {
+ hash: txid,
+ amount: parseInt(amount),
+ aid: account.id,
+ });
+ }
goto(`/sent/${p.id}`, { invalidateAll: true });
} catch (e: any) {
@@ -65,6 +76,7 @@
let balance = $derived(data.user.balance);
let currency = $derived(data.user.currency);
+ let locale = $derived(loc(data.user));
let submitting = $state(false),
submit = $state();
</script>
@@ -81,7 +93,7 @@
{#if !error}
<div class="text-xl text-secondary break-all">{address}</div>
- <Amount {amount} rate={$rate} {currency} />
+ <Amount {amount} rate={$rate} {currency} {locale} />
<form method="POST" use:enhance={handler}>
<input name="pin" value={$pin} type="hidden" />
diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte
index 967c47af..4cb22155 100644
--- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte
+++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.svelte
@@ -6,7 +6,7 @@
import Spinner from "$comp/Spinner.svelte";
import WalletPass from "$comp/WalletPass.svelte";
import { page } from "$app/stores";
- import { toFiat, f, focus, s, sat, closest, network } from "$lib/utils";
+ import { toFiat, f, focus, loc, s, sat, closest, network } from "$lib/utils";
import { pin } from "$lib/store";
import { goto, invalidate } from "$app/navigation";
import { rate } from "$lib/store";
@@ -198,6 +198,7 @@
let balance = $derived(data.user.balance);
let currency = $derived(data.user.currency);
+ let locale = $derived(loc(data.user));
let submitting = $state(),
submit: any = $state(),
showSettings = $state();
@@ -231,7 +232,7 @@
<div class="text-xl text-secondary break-all">{address}</div>
{/if}
- <Amount amount={subtract ? amount - fee - ourfee : amount} rate={$rate} {currency} />
+ <Amount amount={subtract ? amount - fee - ourfee : amount} rate={$rate} {currency} {locale} />
{#if fees}
<div class="text-center">
@@ -245,7 +246,7 @@
</option>
{/each}
</select>
- <Amount amount={fee} rate={$rate} {currency} />
+ <Amount amount={fee} rate={$rate} {currency} {locale} />
</div>
</div>
@@ -253,7 +254,7 @@
<div class="text-center">
<h2 class="text-secondary text-lg">{$t("payments.platformFee")}</h2>
- <Amount amount={ourfee} rate={$rate} {currency} />
+ <Amount amount={ourfee} rate={$rate} {currency} {locale} />
</div>
{/if}
{/if}