From 3c0489e1cca4f6a211215b700489d256695c3ce1 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 24 Dec 2024 00:41:51 -0800 Subject: create fund --- src/components/Lnurlw.svelte | 6 +- src/components/Payments.svelte | 120 ++++++++++++++++++ src/locales/en.json | 23 ++-- src/routes/(app)/fund/[id]/+page.server.ts | 7 +- src/routes/(app)/fund/[id]/+page.svelte | 137 ++++++--------------- .../(app)/fund/[id]/withdraw/+page.server.ts | 15 ++- src/routes/(app)/fund/[id]/withdraw/+page.svelte | 59 +++++---- src/routes/(app)/ln/[lnurl]/+page.server.ts | 9 +- src/routes/(app)/payment/[id]/+page.svelte | 6 +- src/routes/(app)/payments/[...page]/+page.svelte | 110 ++--------------- src/routes/(app)/qr/[text]/+page.svelte | 2 +- src/routes/(app)/send/[...text]/+page.svelte | 8 ++ .../fund/[...name]/[...amount]/+page.server.ts | 28 +++++ .../send/fund/[...name]/[...amount]/+page.svelte | 70 +++++++++++ .../send/fund/[name]/[...amount]/+page.server.ts | 17 --- .../send/fund/[name]/[...amount]/+page.svelte | 66 ---------- 16 files changed, 350 insertions(+), 333 deletions(-) create mode 100644 src/components/Payments.svelte create mode 100644 src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts create mode 100644 src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte delete mode 100644 src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts delete mode 100644 src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte (limited to 'src') diff --git a/src/components/Lnurlw.svelte b/src/components/Lnurlw.svelte index e3345d31..8793d3b4 100644 --- a/src/components/Lnurlw.svelte +++ b/src/components/Lnurlw.svelte @@ -55,7 +55,7 @@ {/if} -
+ @@ -65,11 +65,11 @@
-
diff --git a/src/components/Payments.svelte b/src/components/Payments.svelte new file mode 100644 index 00000000..2d38513e --- /dev/null +++ b/src/components/Payments.svelte @@ -0,0 +1,120 @@ + + +
+ {#each payments as p, i} + {@const amount = fund ? -p.amount : p.amount} +
goto(`/payment/${p.id}`)} + > +
+
+
+ +
{s(Math.abs(amount), locale)}
+
+
+ +
+ {f(Math.abs(amount) * (p.rate / sats), p.currency, locale)} + + {#if p.tip} + +  +{Math.round((p.tip / Math.abs(amount)) * 100)}% + + {/if} +
+
+ +
+ {#if p.type === types.fund} + {#if fund} +
+
+ +
+
+ {p.user.username} +
+
+ {:else} + +
+ + +
{$t("payments.fund")}
+
+
+ {/if} + {:else if p.with} +
+
+ +
+
+ {p.with.username} +
+
+ {:else} +
+ {#if p.type === types.lightning} + + {:else if p.type === types.ecash} + + {:else if p.type === types.reconcile} + + {:else if p.type === types.bitcoin} + + {:else if p.type === types.liquid} +
+ Liquid +
+ {/if} + +
+ {amount > 0 ? (p.confirmed ? "Received" : "Pending") : "Sent"} +
+
+ {/if} +
+ +
+
+ {format(new Date(p.created), "h:mm aaa", { locale })} +
+
+ {format(new Date(p.created), "MMM d, yy", { locale })} +
+
+
+ {:else} +

{$t("payments.empty")}

+ {/each} +
diff --git a/src/locales/en.json b/src/locales/en.json index 26f9779b..a0d0f855 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -111,7 +111,7 @@ "addTipq": "Add a tip?", "addMemo": "Add memo", "setMemo": "Set memo", - "memo": "Memo", + "memo": "Memo", "done": "Done", "paymentSuccessful": "Payment received!", "invoice": "Invoice", @@ -193,7 +193,7 @@ "subheader": "Latest Updates" }, "user": { - "loadMore": "Load more", + "loadMore": "Load more", "url": "Public URL", "install": "Install app", "moreDetails": "Profile details", @@ -250,8 +250,8 @@ "placeholder": "Enter an address, invoice or username" }, "settings": { - "integrations": "Integrations", - "connectNostr": "Nostr Wallet Connect", + "integrations": "Integrations", + "connectNostr": "Nostr Wallet Connect", "pleaseEnterYourPassword": "Please enter your password", "memoPrompt": "Checkout instructions", "memoPromptPlaceholder": "e.g. Please enter your name for the order", @@ -262,7 +262,7 @@ "destinationPlaceholder": "Enter a Bitcoin, Liquid or Lightning address", "reserve": "Reserve amount", "reserveDesc": "The amount to be left in your account after the withdrawal is complete", - "nostr": "Nostr", + "nostr": "Nostr", "shopify": "Shopify", "threshold": "Autowithdrawal threshold", "thresholdDesc": "When your balance exceeds this amount, a withdrawal will be triggered", @@ -276,8 +276,8 @@ "seedPhrase": "Seed phrase", "nostrKeys": "Nostr secret key", "nostrDescription": "Your nostr secret key is used to sign and decrypt messages, keep it safe or someone may be able to impersonate you.", - "nwc": "Nostr wallet connect", - "nwcDescription": "Enable your nostr app to send payments from your account", + "nwc": "Nostr wallet connect", + "nwcDescription": "Enable your nostr app to send payments from your account", "seedDescription": "This 12 word seed phrase is used to derive your nostr private key and your self-custodial wallet keys which determine your auto-withdrawal addresses. Back it up and don't let anyone see it.", "emailDescription": "For password resets and payment notifications only", "hideNsec": "Hide nostr secret key", @@ -361,6 +361,7 @@ "memo": "Notes", "voucherText": "Enter an ecash token or lnurlw code", "createEcash": "Mint ecash", + "lnurlw": "LNURLw", "tips": "Tips", "options": "options", "bump": "Bump fee", @@ -368,6 +369,8 @@ "platformFee": "Platform fee", "fastest": "Fastest", "fundingAmount": "Funding amount", + "createFund": "Create a fund", + "withdraw": "Withdraw", "fast": "Fast", "ecashDesc": "Ecash tokens are funded with bitcoin. They may be redeemed in exchange for a lightning payment equal to their value or loaded back into a coinos account at any time. They can also be transferred to other ecash wallets either wholly or partially. You might use them to give bitcoin to someone who doesn't have a wallet by texting the token to them or sharing a link to it. Learn more at", "ecashToken": "Ecash token", @@ -376,8 +379,8 @@ "slow": "Slow", "create": "Create", "fund": "Fund", - "addFunds": "Add Funds", - "takeFunds": "Take Funds", + "addFunds": "Add funds", + "takeFunds": "Take funds", "show": "Show", "showText": "Show text", "showQr": "Show QR", @@ -386,7 +389,7 @@ "qr": "QR", "copy": "Copy", "amountPrompt": "Prompt for amount", - "shareLink": "Share link", + "shareLink": "Share", "copyLink": "Copy link", "copyText": "Copy text", "openLink": "Open wallet", diff --git a/src/routes/(app)/fund/[id]/+page.server.ts b/src/routes/(app)/fund/[id]/+page.server.ts index 668ea3af..9ea33627 100644 --- a/src/routes/(app)/fund/[id]/+page.server.ts +++ b/src/routes/(app)/fund/[id]/+page.server.ts @@ -2,9 +2,12 @@ import getRates from "$lib/rates"; import { auth, get, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export const load = async ({ params: { id } }) => { +export const load = async ({ depends, params: { id }, parent }) => { + depends("app:payments"); const data = await get(`/fund/${id}`); - data.rate = await getRates(); + const rates = await getRates(); + const { user } = await parent(); + data.rate = rates[user?.currency || "USD"]; return data; }; diff --git a/src/routes/(app)/fund/[id]/+page.svelte b/src/routes/(app)/fund/[id]/+page.svelte index 23dce871..f99b17d7 100644 --- a/src/routes/(app)/fund/[id]/+page.svelte +++ b/src/routes/(app)/fund/[id]/+page.svelte @@ -1,28 +1,33 @@
@@ -30,117 +35,55 @@
-
- - {#if id.split("-").length === 4} -

Card {id}

- {:else} - Fund -
-

- {$t("payments.fund")} -

-

{id}

-
- {/if} -
{#if show} - {id} +
+ URL +
{/if}
-
-

- {f(amountFiat, currency)} -

-

- {sat(amount)} -

-
+
- - -
- +
diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts index 1e477918..696c52ff 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.server.ts +++ b/src/routes/(app)/fund/[id]/withdraw/+page.server.ts @@ -1,9 +1,15 @@ +import getRates from "$lib/rates"; +import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -import { fd, auth, post } from "$lib/utils"; -export async function load({ parent }) { +export async function load({ params, parent }) { const { user } = await parent(); if (!user) redirect(307, "/register"); + const rates = await getRates(); + const rate = rates[user.currency]; + const fund = await get(`/fund/${params.id}`); + const { amount: balance } = fund; + return { ...params, balance, rate }; } export const actions = { @@ -11,8 +17,9 @@ export const actions = { const body = await fd(request); try { await post("/take", body, auth(cookies)); - } catch (e: any) { - return fail(400, { message: e.message }); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); } redirect(307, `/fund/${body.id}`); diff --git a/src/routes/(app)/fund/[id]/withdraw/+page.svelte b/src/routes/(app)/fund/[id]/withdraw/+page.svelte index 89654d23..f6f12b1a 100644 --- a/src/routes/(app)/fund/[id]/withdraw/+page.svelte +++ b/src/routes/(app)/fund/[id]/withdraw/+page.svelte @@ -1,40 +1,35 @@ - + let setMax = (e) => { + e.preventDefault(); + fiat = false; + amount = balance; + }; + {#if form?.message}
@@ -43,22 +38,32 @@ {/if}
- + - + -
+
+ +
diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts index 681137ad..53445461 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.ts +++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts @@ -7,10 +7,12 @@ export async function load({ params, parent }) { if (!user) redirect(307, "/register"); const rates = await getRates(); + console.log("YO"); let data; try { const { lnurl } = params; data = await get(`/decode?text=${lnurl}`); + console.log("DATA", data); } catch (e) { const { message } = e as Error; error(500, message); @@ -76,8 +78,11 @@ export const actions = { auth(cookies), ); - const c = callback.includes("?") ? "&" : "?"; - await fetch(`${callback}${c}k1=${k1}&pr=${pr}`).then((r) => r.json()); + const url = new URL(callback); + url.searchParams.append("k1", k1); + url.searchParams.append("pr", pr); + + await fetch(url.toString()); redirect(307, "/payments"); }, diff --git a/src/routes/(app)/payment/[id]/+page.svelte b/src/routes/(app)/payment/[id]/+page.svelte index 279b87e7..63b8ccca 100644 --- a/src/routes/(app)/payment/[id]/+page.svelte +++ b/src/routes/(app)/payment/[id]/+page.svelte @@ -112,7 +112,11 @@
- Pot +
{p.memo}
diff --git a/src/routes/(app)/payments/[...page]/+page.svelte b/src/routes/(app)/payments/[...page]/+page.svelte index d53c13c0..09bdf4c7 100644 --- a/src/routes/(app)/payments/[...page]/+page.svelte +++ b/src/routes/(app)/payments/[...page]/+page.svelte @@ -1,6 +1,6 @@
diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index ebc705b5..261a1784 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -94,6 +94,14 @@
{$t("payments.createEcash")}
+ + + + {#if contacts.length} diff --git a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts new file mode 100644 index 00000000..428d8d78 --- /dev/null +++ b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.server.ts @@ -0,0 +1,28 @@ +import getRates from "$lib/rates"; +import { auth, fd, post } from "$lib/utils"; +import { fail, redirect } from "@sveltejs/kit"; + +export async function load({ parent, params }) { + let { name, amount } = params; + if (!name) name = crypto.randomUUID(); + const { user } = await parent(); + const rates = await getRates(); + const rate = rates[user.currency]; + return { name, amount, rate }; +} + +export const actions = { + default: async ({ cookies, request }) => { + const body = await fd(request); + let p; + + try { + p = await post("/payments", body, auth(cookies)); + } catch (e) { + const { message } = e as Error; + return fail(400, { message }); + } + + if (p) redirect(307, `/fund/${body.fund}`); + }, +}; diff --git a/src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte new file mode 100644 index 00000000..314be3ef --- /dev/null +++ b/src/routes/(app)/send/fund/[...name]/[...amount]/+page.svelte @@ -0,0 +1,70 @@ + + +{#if form?.message} +
+ {form.message} +
+{/if} + +
+ + +
+ + + + +
+ + + +
+
+
diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts b/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts deleted file mode 100644 index ed39f96b..00000000 --- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.server.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { fail, redirect } from "@sveltejs/kit"; -import { auth, fd, post } from "$lib/utils"; - -export const actions = { - default: async ({ cookies, request }) => { - const body = await fd(request); - let p; - - try { - p = await post("/payments", body, auth(cookies)); - } catch (e: any) { - return fail(400, { message: e.message }); - } - - if (p) redirect(307, `/fund/${body.name}`); - }, -}; diff --git a/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte b/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte deleted file mode 100644 index d1c3b204..00000000 --- a/src/routes/(app)/send/fund/[name]/[...amount]/+page.svelte +++ /dev/null @@ -1,66 +0,0 @@ - - - - -{#if form?.message} -
- {form.message} -
-{/if} - -
- - -
- - - - -
- -
-
-
-- cgit v1.2.3