diff options
| author | Adam Soltys <[email protected]> | 2025-06-23 08:49:49 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-06-23 08:49:49 -0700 |
| commit | 1e8567796d1f28fa8c47664c7d1e34a57d820aca (patch) | |
| tree | 1458e3e115cb6c1667c757223184163603992b3f /src/routes/(app) | |
| parent | 759e6a0530a7092ae8f2294f1ec1a6fb5e77a7de (diff) | |
| download | coinos-ui-1e8567796d1f28fa8c47664c7d1e34a57d820aca.tar.gz coinos-ui-1e8567796d1f28fa8c47664c7d1e34a57d820aca.zip | |
user lnurl
Diffstat (limited to 'src/routes/(app)')
4 files changed, 59 insertions, 29 deletions
diff --git a/src/routes/(app)/[username]/(profile)/+layout.svelte b/src/routes/(app)/[username]/(profile)/+layout.svelte index afd94ab0..f3e018ee 100644 --- a/src/routes/(app)/[username]/(profile)/+layout.svelte +++ b/src/routes/(app)/[username]/(profile)/+layout.svelte @@ -16,12 +16,13 @@ } from "$lib/utils"; import { t } from "$lib/translations"; import { sign, send } from "$lib/nostr"; - import { bech32m } from "@scure/base"; + import { bech32 } from "@scure/base"; import { page } from "$app/stores"; + import { PUBLIC_DOMAIN } from "$env/static/public"; let { data, children } = $props(); - let { encode, toWords } = bech32m; + let { encode, toWords } = bech32; let { events, @@ -107,6 +108,17 @@ : `${stripped}@${$page.url.host}`, ); let profile = $derived(`${$page.url.host}/${subject.anon ? npub : stripped}`); + let lnurl = $derived( + encode( + "lnurl", + toWords( + new TextEncoder().encode( + `https://${PUBLIC_DOMAIN}/p/${subject.anon ? npub : stripped}`, + ), + ), + 20000, + ), + ); $effect(() => followList.then((l) => (list = l))); let following = $derived(list.some((t) => t.includes(subject.pubkey))); </script> @@ -214,18 +226,20 @@ </div> </div> <div> - <div class="text-secondary">{$t("user.nostrPubkey")}</div> + <div class="text-secondary">{$t("user.lnurl")}</div> <div class="flex gap-4"> <div class="break-all grow text-xl"> - {subject.pubkey} + {lnurl} </div> - <div class="flex my-auto gap-1"> - <button class="my-auto" onclick={() => copy(subject.pubkey)} + <div class="flex mb-auto gap-1"> + <button class="my-auto" onclick={() => copy(lnurl)} ><iconify-icon noobserver icon="ph:copy-bold" width="32" ></iconify-icon></button > <a - href={`/qr/${encodeURIComponent(subject.pubkey)}`} + href={`/qr/${encodeURIComponent( + `${$page.url.protocol}//${lnurl}`, + )}`} class="my-auto" > <iconify-icon noobserver icon="ph:qr-code-bold" width="32" diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts index 405dc4b3..1ee182b1 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.ts +++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts @@ -1,6 +1,9 @@ +import { PUBLIC_DOMAIN } from "$env/static/public"; import getRates from "$lib/rates"; -import { auth, fd, get, post } from "$lib/utils"; +import { auth, fd, get, post, types } from "$lib/utils"; +import { bech32 } from "@scure/base"; import { error, fail, redirect } from "@sveltejs/kit"; +const { decode, fromWords } = bech32; export async function load({ params, parent }) { const { user } = await parent(); @@ -8,28 +11,44 @@ export async function load({ params, parent }) { const rates = await getRates(); let data; - try { - const { lnurl } = params; - data = await get(`/decode?text=${lnurl}`); - let { callback, minSendable, maxSendable, comment, tag } = data; - if (tag === "payRequest" && minSendable === maxSendable) { - minSendable = Math.round(minSendable / 1000); - maxSendable = Math.round(maxSendable / 1000); - const amount = minSendable; + const { lnurl } = params; - let url = `${callback}?amount=${amount * 1000}`; - if (comment) url += `&comment=${comment}`; + const url = Buffer.from(fromWords(decode(lnurl, 20000).words)).toString(); - const { pr } = await fetch(url).then((r) => r.json()); - let path = `/send/lightning/${pr}`; - if (comment) path += `/${encodeURIComponent(comment)}`; - redirect(307, path); - } + try { + data = await get(`/decode?text=${lnurl}`); } catch (e) { const { message } = e as Error; error(500, message); } + 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 (tag === "payRequest" && minSendable === maxSendable) { + minSendable = Math.round(minSendable / 1000); + maxSendable = Math.round(maxSendable / 1000); + const amount = minSendable; + + let url = `${callback}?amount=${amount * 1000}`; + if (comment) url += `&comment=${comment}`; + + const { pr } = await fetch(url).then((r) => (r as Response).json()); + console.log("PR", pr); + let path = `/send/lightning/${pr}`; + if (comment) path += `/${encodeURIComponent(comment)}`; + redirect(307, path); + } + if (!["payRequest", "withdrawRequest"].includes(data.tag)) error(500, "We only support LNURLp and LNURLw at this time"); diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts index b0f824ed..9c2b1e3b 100644 --- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts +++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts @@ -13,7 +13,7 @@ export async function load({ cookies, params, parent }) { let [amount, currency] = params.amount.split("/"); const rate = rates[currency ? currency.toUpperCase() : subject.currency]; - if (!rate) error(500, "Invalid currency symbol"); + if (currency && !rate) error(500, "Invalid currency symbol"); if (amount) { if (currency) amount = (amount * sats) / rate; @@ -33,8 +33,6 @@ export async function load({ cookies, params, parent }) { auth(cookies), ); - const { balance } = await get(`/account/${user.id}`, auth(cookies)); - redirect(307, `/invoice/${id}`); } @@ -66,8 +64,8 @@ export const actions = { return fail(400, { message }); } - if (parseInt(amount) > 0 && prompt) redirect(307, `/invoice/${id}/tip`); - else if (parseInt(amount) <= 0 ) redirect(307, `/${username}/receive`); + if (parseInt(amount) > 0 && prompt) redirect(307, `/invoice/${id}/tip`); + else if (parseInt(amount) <= 0) redirect(307, `/${username}/receive`); redirect(307, `/invoice/${id}`); }, }; diff --git a/src/routes/(app)/send/bitcoin/[address]/+page.svelte b/src/routes/(app)/send/bitcoin/[address]/+page.svelte index 154534a7..671de954 100644 --- a/src/routes/(app)/send/bitcoin/[address]/+page.svelte +++ b/src/routes/(app)/send/bitcoin/[address]/+page.svelte @@ -34,7 +34,6 @@ <div class="text-xl text-secondary break-all">{address}</div> - <div>{amount}</div> <Numpad bind:amount={a} bind:fiat {currency} {submit} bind:rate={$rate} /> <div class="flex justify-center gap-2"> |
