From cf1d8029efc1f9497bcef71b5c959c42794f3566 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Feb 2026 16:44:55 -0800 Subject: payment forwarding --- .../lightning/[payreq]/[...memo]/+page.server.ts | 13 +++++- .../send/lightning/[payreq]/[...memo]/+page.svelte | 52 ++++++++++++++++++---- 2 files changed, 55 insertions(+), 10 deletions(-) (limited to 'src/routes/(app)/send/lightning') diff --git a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts index 5c3e297c..e6cd0e76 100644 --- a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts +++ b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.server.ts @@ -1,5 +1,5 @@ import getRates from "$lib/rates"; -import { auth, fd, post } from "$lib/utils"; +import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { @@ -11,6 +11,16 @@ export async function load({ cookies, params, parent }) { } data.rate = rates[user.currency]; + + const aid = cookies.get("aid") || user.id; + if (aid !== user.id) { + const account = await get(`/account/${aid}`, auth(cookies)); + if (account.type === "ark") { + data.account = account; + data.serverArkAddress = await get("/ark/address"); + } + } + return data; } @@ -36,6 +46,7 @@ export const actions = { let p; try { const body = await fd(request); + body.aid = cookies.get("aid"); console.log("BODY", body); diff --git a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte index 4dfaabc2..02ff06ae 100644 --- a/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/[...memo]/+page.svelte @@ -2,12 +2,14 @@ import { untrack } from "svelte"; import { t } from "$lib/translations"; import { enhance } from "$app/forms"; + import { goto } from "$app/navigation"; import Amount from "$comp/Amount.svelte"; import Numpad from "$comp/Numpad.svelte"; import Spinner from "$comp/Spinner.svelte"; import { page } from "$app/stores"; - import { loc, back, toFiat, f, s, focus } from "$lib/utils"; + import { loc, back, toFiat, f, s, post, focus } from "$lib/utils"; import { fiat, rate, pin } from "$lib/store"; + import { sendArk } from "$lib/ark"; let { data, form } = $props(); @@ -20,9 +22,9 @@ $effect(() => form && (loading = false)); let showMax = $state(); + let error = $state(""); let loading = $state(); - let submit = () => (loading = true); let next = $state(); let toggle = () => (show = !show); @@ -31,16 +33,49 @@ Math.max(5, Math.round(untrack(() => amount) * 0.02 || 0)), ); $effect(() => (maxfee = Math.max(5, Math.round(amount * 0.02) || 0))); + + let handler = ({ cancel }) => { + loading = true; + error = ""; + + if (data.account?.type === "ark") { + cancel(); + + (async () => { + try { + const txid = await sendArk(data.serverArkAddress, parseInt(amount)); + + const inv = await post("/post/invoice", { + invoice: { type: "ark", amount: parseInt(amount), forward: payreq, aid: data.account.id }, + 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 form?.message} + {#if form?.message || error}
- {#if form.message.includes($t("payments.insufficientFunds"))} -
{form.message}
-
{$t("payments.lockedBalance")}: {locked}
+ {#if (form?.message || error).includes($t("payments.insufficientFunds"))} +
{form?.message || error}
+
{$t("payments.lockedBalance")}: {locked}
{:else} - {$t("payments.failedToRoute")} + {form?.message || error} {/if}
{/if} @@ -78,8 +113,7 @@
-- cgit v1.2.3