diff options
| author | Adam Soltys <[email protected]> | 2025-07-19 08:41:49 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-07-19 08:41:49 -0700 |
| commit | fea147df07046f240e77075e7c743959d85b1271 (patch) | |
| tree | aeb578df4777ea0b74c06b3141ffd4ba0b5b4a1c | |
| parent | f063e6a88999f1fe4d9ed2900b90efba1bcf1ac5 (diff) | |
| download | coinos-ui-fea147df07046f240e77075e7c743959d85b1271.tar.gz coinos-ui-fea147df07046f240e77075e7c743959d85b1271.zip | |
handle tipping for lnurls, sweep fixes
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts | 11 | ||||
| -rw-r--r-- | src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte | 3 | ||||
| -rw-r--r-- | src/routes/(app)/ln/[lnurl]/+page.server.ts | 28 |
3 files changed, 25 insertions, 17 deletions
diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts index 61a66fd2..8a8e71ee 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.server.ts @@ -8,8 +8,9 @@ export async function load({ cookies, request, params, parent }) { const { id } = params; let [amount, currency] = params.amount.split("/"); + if (!currency) currency = user?.currency; const rates = await getRates(); - const rate = rates[user?.currency || "USD"]; + const rate = rates[currency?.toUpperCase() || "USD"]; if (currency && !rate) error(500, "Invalid currency symbol"); if (!amount) { @@ -35,6 +36,10 @@ export async function load({ cookies, request, params, parent }) { await register(user, ip, cookies, `/fund/${id}/sweep`); } - await post("/take", { amount, id }, auth(cookies)); - return { amount, id, rate, rates, password }; + try { + await post("/take", { amount, id }, auth(cookies)); + } catch (e) { + redirect(307, `/fund/${id}`); + } + return { amount, currency, id, rate, rates, password }; } diff --git a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte index adba77ae..7a7d5402 100644 --- a/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte +++ b/src/routes/(app)/fund/[id]/sweep/[...amount]/+page.svelte @@ -11,8 +11,7 @@ let { data } = $props(); - let { amount, id, user, rate, rates, password: pw } = data; - let { currency } = user; + let { amount, currency, id, user, rate, rates, password: pw } = data; let locale = $derived(loc(user)); onMount(() => ($password = pw)); diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts index 1ee182b1..b77a84e7 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.ts +++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts @@ -23,17 +23,17 @@ export async function load({ params, parent }) { } let { callback, minSendable, maxSendable, comment, tag } = data; - if (callback.includes(PUBLIC_DOMAIN)) { - const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1]; - // const inv = await post("/invoice", { - // invoice: { type: types.lightning, amount: minSendable / 1000 }, - // user: { username }, - // }); - // const { id: iid } = inv; - let redir = `/pay/${username}`; - if (minSendable === maxSendable && minSendable > 0) redir += `/${minSendable / 1000}`; - redirect(307, redir); - } + // if (callback.includes(PUBLIC_DOMAIN)) { + // const username = url.split(`https://${PUBLIC_DOMAIN}/p/`)[1]; + // // const inv = await post("/invoice", { + // // invoice: { type: types.lightning, amount: minSendable / 1000 }, + // // user: { username }, + // // }); + // // const { id: iid } = inv; + // let redir = `/pay/${username}`; + // if (minSendable === maxSendable && minSendable > 0) redir += `/${minSendable / 1000}`; + // redirect(307, redir); + // } if (tag === "payRequest" && minSendable === maxSendable) { minSendable = Math.round(minSendable / 1000); maxSendable = Math.round(maxSendable / 1000); @@ -43,7 +43,10 @@ export async function load({ params, parent }) { if (comment) url += `&comment=${comment}`; const { pr } = await fetch(url).then((r) => (r as Response).json()); - console.log("PR", pr); + + const invoice = await get(`/invoice/${pr}`); + if (invoice) redirect(307, `/invoice/${invoice.id}`); + let path = `/send/lightning/${pr}`; if (comment) path += `/${encodeURIComponent(comment)}`; redirect(307, path); @@ -75,6 +78,7 @@ export const actions = { if (comment) url += `&comment=${comment}`; const { pr } = await fetch(url).then((r) => r.json()); + let path = `/send/lightning/${pr}`; if (comment) path += `/${encodeURIComponent(comment)}`; redirect(307, path); |
