diff options
| author | Adam Soltys <[email protected]> | 2024-08-20 09:50:42 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-08-20 09:50:42 -0700 |
| commit | 7064846be383ae352329377f21304d0cfdc5040c (patch) | |
| tree | 091c308eeaf69a4a4aafdbc83b183e19f52c26a3 /src | |
| parent | aec0d4a219d26bc7d09b149ca45ef5f723f929a4 (diff) | |
| download | coinos-ui-7064846be383ae352329377f21304d0cfdc5040c.tar.gz coinos-ui-7064846be383ae352329377f21304d0cfdc5040c.zip | |
use id's for cash links
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Avatar.svelte | 2 | ||||
| -rw-r--r-- | src/lib/parse.js | 1 | ||||
| -rw-r--r-- | src/locales/en.json | 4 | ||||
| -rw-r--r-- | src/routes/(app)/[username]/ecash/[...token]/+page.svelte | 13 | ||||
| -rw-r--r-- | src/routes/(app)/ecash/[id]/+page.server.js | 9 | ||||
| -rw-r--r-- | src/routes/(app)/ecash/[id]/+page.svelte | 79 | ||||
| -rw-r--r-- | src/routes/(app)/register/+page.server.js | 2 | ||||
| -rw-r--r-- | src/routes/(app)/send/ecash/+page.server.js | 11 | ||||
| -rw-r--r-- | src/routes/(app)/voucher/[...token]/+page.server.js | 14 | ||||
| -rw-r--r-- | src/routes/(app)/voucher/[...token]/+page.svelte | 3 |
10 files changed, 115 insertions, 23 deletions
diff --git a/src/components/Avatar.svelte b/src/components/Avatar.svelte index 227200d7..4922c065 100644 --- a/src/components/Avatar.svelte +++ b/src/components/Avatar.svelte @@ -8,7 +8,7 @@ export let disabled = false; $: s = size.toString(); - $: link = user.anon ? `/${user.pubkey}` : `/${user.username}`; + $: link = user?.anon ? `/${user.pubkey}` : `/${user.username}`; $: src = ($avatar?.id && $avatar.id === user.id && $avatar.src) || diff --git a/src/lib/parse.js b/src/lib/parse.js index fa4cb002..3470fb52 100644 --- a/src/lib/parse.js +++ b/src/lib/parse.js @@ -63,6 +63,7 @@ export default async (t, host, cookies) => { claimed = await post(`/claim`, { token: t }, auth(cookies)); claimed = { ok: true }; } catch (e) { + console.log(e); return e.message; } if (claimed.ok) { diff --git a/src/locales/en.json b/src/locales/en.json index 20dac0c5..20160b0d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -316,8 +316,8 @@ "voucher": "Redeem voucher", "qr": "QR", "copy": "Copy", - "copyLink": "Copy Link", - "copyText": "Copy Text", + "copyLink": "Copy link", + "copyText": "Copy text", "openLink": "Open wallet", "setAmount": "Set amount", "moreOptions": "More options", diff --git a/src/routes/(app)/[username]/ecash/[...token]/+page.svelte b/src/routes/(app)/[username]/ecash/[...token]/+page.svelte index e920c6d2..21fa979b 100644 --- a/src/routes/(app)/[username]/ecash/[...token]/+page.svelte +++ b/src/routes/(app)/[username]/ecash/[...token]/+page.svelte @@ -51,12 +51,11 @@ </button> </a> - - <button - class="border rounded-2xl px-6 py-5 w-full break-all text-xl hover:bg-slate-100" - on:click={() => copy(token)} - > - {token} - </button> + <button + class="border rounded-2xl px-6 py-5 w-full break-all text-xl hover:bg-slate-100" + on:click={() => copy(token)} + > + {token} + </button> </div> </div> diff --git a/src/routes/(app)/ecash/[id]/+page.server.js b/src/routes/(app)/ecash/[id]/+page.server.js new file mode 100644 index 00000000..c5f24e82 --- /dev/null +++ b/src/routes/(app)/ecash/[id]/+page.server.js @@ -0,0 +1,9 @@ +import { auth, get } from "$lib/utils"; +import { fail, redirect } from "@sveltejs/kit"; +import parse from "$lib/parse"; + +export async function load({ cookies, params, request, url }) { + let { id } = params; + let token = await get(`/cash/${id}`); + return { id, token }; +} diff --git a/src/routes/(app)/ecash/[id]/+page.svelte b/src/routes/(app)/ecash/[id]/+page.svelte new file mode 100644 index 00000000..023276ee --- /dev/null +++ b/src/routes/(app)/ecash/[id]/+page.svelte @@ -0,0 +1,79 @@ +<script> + import AppHeader from "$comp/AppHeader.svelte"; + import { getDecodedToken } from "@cashu/cashu-ts"; + import { copy, sats, f, s } from "$lib/utils"; + import { t } from "$lib/translations"; + import Icon from "$comp/Icon.svelte"; + import { page } from "$app/stores"; + + export let data; + + let { id, rates, user, token } = data; + let currency = user?.currency || "USD" + let rate = rates[currency]; + + let { proofs } = getDecodedToken(token).token[0]; + let amount = proofs.reduce((a, b) => a + b.amount, 0); + + let link = $page.url.href; + + $: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2)); +</script> + +<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20"> + <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold"> + {$t("payments.ecash")} + </h1> + + {#if amount > 0} + <div class="text-center font-bold text-2xl"> + <div> + {f(amountFiat, currency)} + </div> + <div> + <span class="text-secondary font-normal text-xl" + >⚡️{`${s(amount)}`}</span + > + </div> + </div> + {/if} + + <div class="flex flex-wrap gap-2 text-xl"> + <button + type="button" + class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2" + on:click={() => copy(link)} + > + <Icon icon="link" style="w-8 my-auto" /> + <div class="my-auto">{$t("payments.copyLink")}</div> + </button> + + <!-- TODO we need animated QR's --> + <!-- <a href={`/qr/${encodeURIComponent(token)}`} class="contents"> --> + <!-- <button --> + <!-- type="button" --> + <!-- class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2" --> + <!-- > --> + <!-- <Icon icon="qr" style="w-8 my-auto invert" /> --> + <!-- <div class="my-auto">{$t("payments.qr")}</div> --> + <!-- </button> --> + <!-- </a> --> + + <a href={`/voucher/${id}`} class="contents"> + <button + type="button" + class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2" + > + <Icon icon="receive" style="w-8 my-auto" /> + <div class="my-auto">{$t("payments.redeem")}</div> + </button> + </a> + + <button + class="border rounded-2xl px-6 py-5 w-full break-all text-xl hover:bg-slate-100" + on:click={() => copy(token)} + > + {token} + </button> + </div> +</div> diff --git a/src/routes/(app)/register/+page.server.js b/src/routes/(app)/register/+page.server.js index 806eda1f..f2288d9c 100644 --- a/src/routes/(app)/register/+page.server.js +++ b/src/routes/(app)/register/+page.server.js @@ -21,6 +21,8 @@ export const actions = { let error; if (loginRedirect === "undefined") loginRedirect = undefined; + + console.log("LOGIN REDIRECT", loginRedirect) try { await post("/register", { user }, { "cf-connecting-ip": ip }); diff --git a/src/routes/(app)/send/ecash/+page.server.js b/src/routes/(app)/send/ecash/+page.server.js index 8541a3f8..422e5a30 100644 --- a/src/routes/(app)/send/ecash/+page.server.js +++ b/src/routes/(app)/send/ecash/+page.server.js @@ -3,20 +3,15 @@ import { auth, post, fd } from "$lib/utils"; export const actions = { default: async ({ cookies, request }) => { - let token; + let id; try { let body = await fd(request); - ({ token } = await post("/mint", body, auth(cookies))); - console.log("token", token) + ({ id } = await post("/mint", body, auth(cookies))); } catch (e) { - console.log(e) console.log("problem creating ecash", e); return fail(400, { message: e.message }); } - cookies.set("ecash", token, { path: "/" }); - - console.log("redirecting") - redirect(307, `/${cookies.get("username")}/ecash`); + redirect(307, `/ecash/${id}`); }, }; diff --git a/src/routes/(app)/voucher/[...token]/+page.server.js b/src/routes/(app)/voucher/[...token]/+page.server.js index dfcbb5f5..5f90ba64 100644 --- a/src/routes/(app)/voucher/[...token]/+page.server.js +++ b/src/routes/(app)/voucher/[...token]/+page.server.js @@ -1,14 +1,20 @@ import { validate } from "bitcoin-address-validation"; import bip21 from "bip21"; import { auth, get, isLiquid, post } from "$lib/utils"; -import { fail, redirect } from "@sveltejs/kit"; +import { error, fail, redirect } from "@sveltejs/kit"; import { PUBLIC_DOMAIN } from "$env/static/public"; import parse from "$lib/parse"; import { test } from "$lib/parse"; -export async function load({ cookies, params, request, url }) { - console.log(params.token); - await parse(params.token, url.host, cookies); +export async function load({ cookies, params, parent, request, url }) { + let { user } = await parent(); + if (!user) redirect(307, `/register?redirect=${url.pathname}`); + + let { token } = params; + if (!token.startsWith("cashu")) token = await get(`/cash/${token}`); + await parse(token, url.host, cookies); + + if (token) error(409, "Token could not be redeemed. Was it already spent?"); } export const actions = { diff --git a/src/routes/(app)/voucher/[...token]/+page.svelte b/src/routes/(app)/voucher/[...token]/+page.svelte index f5b7b882..2fd4b879 100644 --- a/src/routes/(app)/voucher/[...token]/+page.svelte +++ b/src/routes/(app)/voucher/[...token]/+page.svelte @@ -13,6 +13,8 @@ export let data; export let form; + + let { token } = data; data.subject = data.user; let el, text, pasted, w; @@ -23,7 +25,6 @@ text = await navigator.clipboard.readText(); }; - $: if (browser && pasted && text) el.click() && (pasted = false); </script> |
