aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-20 09:50:42 -0700
committerAdam Soltys <[email protected]>2024-08-20 09:50:42 -0700
commit7064846be383ae352329377f21304d0cfdc5040c (patch)
tree091c308eeaf69a4a4aafdbc83b183e19f52c26a3
parentaec0d4a219d26bc7d09b149ca45ef5f723f929a4 (diff)
downloadcoinos-ui-7064846be383ae352329377f21304d0cfdc5040c.tar.gz
coinos-ui-7064846be383ae352329377f21304d0cfdc5040c.zip
use id's for cash links
-rw-r--r--src/components/Avatar.svelte2
-rw-r--r--src/lib/parse.js1
-rw-r--r--src/locales/en.json4
-rw-r--r--src/routes/(app)/[username]/ecash/[...token]/+page.svelte13
-rw-r--r--src/routes/(app)/ecash/[id]/+page.server.js9
-rw-r--r--src/routes/(app)/ecash/[id]/+page.svelte79
-rw-r--r--src/routes/(app)/register/+page.server.js2
-rw-r--r--src/routes/(app)/send/ecash/+page.server.js11
-rw-r--r--src/routes/(app)/voucher/[...token]/+page.server.js14
-rw-r--r--src/routes/(app)/voucher/[...token]/+page.svelte3
-rw-r--r--static/icons/link.svg5
11 files changed, 119 insertions, 24 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>
diff --git a/static/icons/link.svg b/static/icons/link.svg
index 7b3654be..0fad4e49 100644
--- a/static/icons/link.svg
+++ b/static/icons/link.svg
@@ -1 +1,4 @@
-<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M14.851 11.923c-.179-.641-.521-1.246-1.025-1.749-1.562-1.562-4.095-1.563-5.657 0l-4.998 4.998c-1.562 1.563-1.563 4.095 0 5.657 1.562 1.563 4.096 1.561 5.656 0l3.842-3.841.333.009c.404 0 .802-.04 1.189-.117l-4.657 4.656c-.975.976-2.255 1.464-3.535 1.464-1.28 0-2.56-.488-3.535-1.464-1.952-1.951-1.952-5.12 0-7.071l4.998-4.998c.975-.976 2.256-1.464 3.536-1.464 1.279 0 2.56.488 3.535 1.464.493.493.861 1.063 1.105 1.672l-.787.784zm-5.703.147c.178.643.521 1.25 1.026 1.756 1.562 1.563 4.096 1.561 5.656 0l4.999-4.998c1.563-1.562 1.563-4.095 0-5.657-1.562-1.562-4.095-1.563-5.657 0l-3.841 3.841-.333-.009c-.404 0-.802.04-1.189.117l4.656-4.656c.975-.976 2.256-1.464 3.536-1.464 1.279 0 2.56.488 3.535 1.464 1.951 1.951 1.951 5.119 0 7.071l-4.999 4.998c-.975.976-2.255 1.464-3.535 1.464-1.28 0-2.56-.488-3.535-1.464-.494-.495-.863-1.067-1.107-1.678l.788-.785z"/></svg> \ No newline at end of file
+<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
+<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M9.16488 17.6505C8.92513 17.8743 8.73958 18.0241 8.54996 18.1336C7.62175 18.6695 6.47816 18.6695 5.54996 18.1336C5.20791 17.9361 4.87912 17.6073 4.22153 16.9498C3.56394 16.2922 3.23514 15.9634 3.03767 15.6213C2.50177 14.6931 2.50177 13.5495 3.03767 12.6213C3.23514 12.2793 3.56394 11.9505 4.22153 11.2929L7.04996 8.46448C7.70755 7.80689 8.03634 7.47809 8.37838 7.28062C9.30659 6.74472 10.4502 6.74472 11.3784 7.28061C11.7204 7.47809 12.0492 7.80689 12.7068 8.46448C13.3644 9.12207 13.6932 9.45086 13.8907 9.7929C14.4266 10.7211 14.4266 11.8647 13.8907 12.7929C13.7812 12.9825 13.6314 13.1681 13.4075 13.4078M10.5919 10.5922C10.368 10.8319 10.2182 11.0175 10.1087 11.2071C9.57284 12.1353 9.57284 13.2789 10.1087 14.2071C10.3062 14.5492 10.635 14.878 11.2926 15.5355C11.9502 16.1931 12.279 16.5219 12.621 16.7194C13.5492 17.2553 14.6928 17.2553 15.621 16.7194C15.9631 16.5219 16.2919 16.1931 16.9495 15.5355L19.7779 12.7071C20.4355 12.0495 20.7643 11.7207 20.9617 11.3787C21.4976 10.4505 21.4976 9.30689 20.9617 8.37869C20.7643 8.03665 20.4355 7.70785 19.7779 7.05026C19.1203 6.39267 18.7915 6.06388 18.4495 5.8664C17.5212 5.3305 16.3777 5.3305 15.4495 5.8664C15.2598 5.97588 15.0743 6.12571 14.8345 6.34955" stroke="#000000" stroke-width="2" stroke-linecap="round"/>
+</svg> \ No newline at end of file