From 806baacb2f126191068a4a7e3fccf9684a339d07 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Feb 2026 19:29:31 -0800 Subject: ark fees --- .../[amount]/[...feeRate]/+page.server.ts | 11 ++- .../[amount]/[...feeRate]/+page.server.ts | 14 +++- .../[address]/[amount]/[...feeRate]/+page.svelte | 91 +++++++++++++++------- 3 files changed, 86 insertions(+), 30 deletions(-) (limited to 'src') 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 02cda48a..acdd77a4 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 @@ -8,8 +8,17 @@ export async function load({ params: { address, amount }, cookies, parent }) { const aid = cookies.get("aid") || user.id; const account = await get(`/account/${aid}`, auth(cookies)); + + if (account.seed) { + const inv = await post( + "/invoice", + { invoice: { type: "bitcoin", amount: parseInt(amount), forward: address }, user }, + auth(cookies), + ); + redirect(307, `/send/bitcoin/${inv.hash}/${amount}`); + } + const rate = rates[user.currency]; - console.log("rate", rate); return { account, diff --git a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts index ddee9c1c..9695247b 100644 --- a/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts +++ b/src/routes/(app)/send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts @@ -10,6 +10,18 @@ export async function load({ const rates = await getRates(); const { user } = await parent(); const aid = cookies.get("aid") || user.id; + const account = await get(`/account/${aid}`, auth(cookies)); + + if (account.type === "ark") { + const serverArkAddress = await get("/ark/address"); + return { + account, + amount, + address, + rate: rates[user.currency], + serverArkAddress, + }; + } try { const { fee, fees, inputs, ourfee, hex, subtract } = await post( @@ -18,8 +30,6 @@ export async function load({ auth(cookies), ); - const account = await get(`/account/${aid}`, auth(cookies)); - return { account, amount, 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 c31ce60d..acbaf3f9 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, s, sat, closest, network, post } from "$lib/utils"; import { pin } from "$lib/store"; import { goto, invalidate } from "$app/navigation"; import { rate } from "$lib/store"; @@ -21,6 +21,7 @@ getRememberedWalletPassword, forgetWalletPassword, } from "$lib/passwordCache"; + import { sendArk } from "$lib/ark"; import Amount from "$comp/Amount.svelte"; @@ -31,6 +32,8 @@ let password = $state(); let cancel = $state(() => (passwordPrompt = false)); let signed = $state(); + let loading = $state(false); + let error = $state(""); let trySignWithCachedPassword = async () => { const cached = getRememberedWalletPassword(); @@ -54,6 +57,36 @@ passwordPrompt = true; }; let handler = ({ cancel }) => { + if (account.type === "ark") { + cancel(); + + (async () => { + loading = true; + error = ""; + try { + const txid = await sendArk(data.serverArkAddress, parseInt(amount)); + + const inv = await post("/post/invoice", { + invoice: { type: "ark", amount: parseInt(amount), forward: address, aid: account.id }, + user: data.user, + }); + + const p = await post("/post/ark/receive", { + amount: parseInt(amount), + hash: txid, + iid: inv.id, + }); + + goto(`/sent/${p.id}`, { invalidateAll: true }); + } catch (e) { + loading = false; + error = e.message || "Failed to send"; + } + })(); + + return; + } + if (account.seed && !signed) cancel(), void togglePassword(); return async ({ result }) => { if (result.type === "redirect") { @@ -124,10 +157,12 @@ let { feeRate } = $state(data); $effect(() => { - delete fees.minimumFee; - feeRate = feeRate - ? closest(Object.values(fees), feeRate) - : fees.halfHourFee; + if (fees) { + delete fees.minimumFee; + feeRate = feeRate + ? closest(Object.values(fees), feeRate) + : fees.halfHourFee; + } }); $effect(() => { @@ -156,9 +191,9 @@ >

{$t("payments.send")}

- {#if form?.message || message} + {#if form?.message || message || error}
-
{form?.message || message}
+
{form?.message || message || error}
{:else}
{address}
@@ -169,27 +204,29 @@ {currency} /> -
-

{$t("payments.networkFee")}

- -
- - -
-
- - {#if ourfee} + {#if fees}
-

{$t("payments.platformFee")}

+

{$t("payments.networkFee")}

- +
+ + +
+ + {#if ourfee} +
+

{$t("payments.platformFee")}

+ + +
+ {/if} {/if}
@@ -205,9 +242,9 @@ bind:this={submit} type="submit" class="btn btn-accent" - disabled={submitting} + disabled={submitting || loading} > - {#if submitting} + {#if submitting || loading} {:else} {$t("payments.send")} -- cgit v1.2.3