aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-06 09:32:53 -0700
committerAdam Soltys <[email protected]>2024-09-17 09:18:36 -0700
commit1b7cc6d64fb2ee3340a18d0924c4b64afabbc1e1 (patch)
tree4498405ef5555a6680b36e9628806f497ec0f561
parentc5ef18aec5de023732eb6b86f768f206462fea93 (diff)
downloadcoinos-ui-1b7cc6d64fb2ee3340a18d0924c4b64afabbc1e1.tar.gz
coinos-ui-1b7cc6d64fb2ee3340a18d0924c4b64afabbc1e1.zip
per account payment pages
-rw-r--r--src/components/Account.svelte87
-rw-r--r--src/components/Numpad.svelte2
-rw-r--r--src/lib/types.ts1
-rw-r--r--src/routes/(app)/[username]/(profile)/+page.svelte4
-rw-r--r--src/routes/(app)/[username]/[...account]/payments/[...page]/+page.server.ts (renamed from src/routes/(app)/[username]/payments/[...page]/+page.server.ts)0
-rw-r--r--src/routes/(app)/[username]/[...account]/payments/[...page]/+page.svelte (renamed from src/routes/(app)/[username]/payments/[...page]/+page.svelte)0
-rw-r--r--src/routes/(app)/[username]/[...account]/payments/[...page]/+server.ts (renamed from src/routes/(app)/[username]/payments/[...page]/+server.ts)0
-rw-r--r--src/routes/(app)/[username]/[...account]/receive/[...param]/+page.server.ts (renamed from src/routes/(app)/[username]/receive/[...param]/+page.server.ts)8
-rw-r--r--src/routes/(app)/[username]/[...account]/receive/[...param]/+page.svelte (renamed from src/routes/(app)/[username]/receive/[...param]/+page.svelte)0
-rw-r--r--src/routes/(app)/[username]/account/setup/+page.svelte4
-rw-r--r--src/routes/(app)/[username]/account/setup/step2/+page.svelte15
-rw-r--r--src/routes/(app)/[username]/invoice/[id]/+page.svelte89
12 files changed, 102 insertions, 108 deletions
diff --git a/src/components/Account.svelte b/src/components/Account.svelte
index 5286c4d3..a781e809 100644
--- a/src/components/Account.svelte
+++ b/src/components/Account.svelte
@@ -4,50 +4,55 @@
import { t } from "$lib/translations";
export let user, rate, account;
- let { balance, setup, type } = account;
+ let { balance, setup, type, id } = account;
</script>
-<div class="border rounded-xl shadow p-4 space-y-5">
- <div class="flex justify-center lg:justify-start">
- <Balance {balance} {user} {rate} />
- <div class="ml-auto text-secondary">{type}</div>
- </div>
+<a href={`/${user.username}/${id}/payments`.replace(/undefined\//, "")}>
+ <div class="border rounded-xl shadow p-4 space-y-5">
+ <div class="flex justify-center lg:justify-start">
+ <Balance {balance} {user} {rate} />
+ <div class="ml-auto text-secondary">{type}</div>
+ </div>
- <div class="flex flex-wrap gap-3 justify-center w-full text-xl">
- {#if setup}
- <a href={`/send`} class="contents grow">
- <button
- type="button"
- class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
- >
- <div class="mx-auto flex gap-2">
- <Icon icon="send" style="w-8" />
- <div class="my-auto">{$t("user.dashboard.send")}</div>
- </div>
- </button>
- </a>
+ <div class="flex flex-wrap gap-3 justify-center w-full text-xl">
+ {#if setup}
+ <a href={`/send`} class="contents grow">
+ <button
+ type="button"
+ class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
+ >
+ <div class="mx-auto flex gap-2">
+ <Icon icon="send" style="w-8" />
+ <div class="my-auto">{$t("user.dashboard.send")}</div>
+ </div>
+ </button>
+ </a>
- <a href={`/${user.username}/receive`} class="contents">
- <button
- class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
- >
- <div class="mx-auto flex gap-2">
- <Icon icon="receive" style="w-8" />
- <div class="my-auto">{$t("user.dashboard.receive")}</div>
- </div>
- </button>
- </a>
- {:else}
- <a href={`/${user.username}/account/setup`} class="contents">
- <button
- class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
+ <a
+ href={`/${user.username}/${id}/receive`.replace(/undefined\//, "")}
+ class="contents"
>
- <div class="mx-auto flex gap-2">
- <Icon icon="settings" style="w-8" />
- <div class="my-auto">{$t("user.dashboard.setup")}</div>
- </div>
- </button>
- </a>
- {/if}
+ <button
+ class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
+ >
+ <div class="mx-auto flex gap-2">
+ <Icon icon="receive" style="w-8" />
+ <div class="my-auto">{$t("user.dashboard.receive")}</div>
+ </div>
+ </button>
+ </a>
+ {:else}
+ <a href={`/${user.username}/account/setup`} class="contents">
+ <button
+ class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
+ >
+ <div class="mx-auto flex gap-2">
+ <Icon icon="settings" style="w-8" />
+ <div class="my-auto">{$t("user.dashboard.setup")}</div>
+ </div>
+ </button>
+ </a>
+ {/if}
+ </div>
</div>
-</div>
+</a>
diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte
index 88b5b899..78322ff5 100644
--- a/src/components/Numpad.svelte
+++ b/src/components/Numpad.svelte
@@ -1,7 +1,7 @@
<script>
import Left from "$comp/Left.svelte";
import Icon from "$comp/Icon.svelte";
- import { f, s, focus, post, warning, sat, sats } from "$lib/utils";
+ import { f, s, focus, warning, sat, sats } from "$lib/utils";
import { t } from "$lib/translations";
export let amount,
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 33f78c85..666ea1fb 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -14,6 +14,7 @@ export interface User {
}
export interface Invoice {
+ account: string;
id?: string;
memoPrompt?: boolean;
memo?: string;
diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte
index afb4e58c..7c0de9d8 100644
--- a/src/routes/(app)/[username]/(profile)/+page.svelte
+++ b/src/routes/(app)/[username]/(profile)/+page.svelte
@@ -23,11 +23,11 @@
$installPrompt = null;
};
- user.savings = 0;
+ if (user) user.savings = 0;
let accounts = [
{ balance: user.balance, setup: true, type: "Cash" },
- { balance: user.savings, setup: false, type: "Savings" },
+ { id: "pubtest", balance: user.savings, setup: !!user.seed, type: "Savings" },
];
</script>
diff --git a/src/routes/(app)/[username]/payments/[...page]/+page.server.ts b/src/routes/(app)/[username]/[...account]/payments/[...page]/+page.server.ts
index 070349f8..070349f8 100644
--- a/src/routes/(app)/[username]/payments/[...page]/+page.server.ts
+++ b/src/routes/(app)/[username]/[...account]/payments/[...page]/+page.server.ts
diff --git a/src/routes/(app)/[username]/payments/[...page]/+page.svelte b/src/routes/(app)/[username]/[...account]/payments/[...page]/+page.svelte
index 1efdc2ec..1efdc2ec 100644
--- a/src/routes/(app)/[username]/payments/[...page]/+page.svelte
+++ b/src/routes/(app)/[username]/[...account]/payments/[...page]/+page.svelte
diff --git a/src/routes/(app)/[username]/payments/[...page]/+server.ts b/src/routes/(app)/[username]/[...account]/payments/[...page]/+server.ts
index a81faaf3..a81faaf3 100644
--- a/src/routes/(app)/[username]/payments/[...page]/+server.ts
+++ b/src/routes/(app)/[username]/[...account]/payments/[...page]/+server.ts
diff --git a/src/routes/(app)/[username]/receive/[...param]/+page.server.ts b/src/routes/(app)/[username]/[...account]/receive/[...param]/+page.server.ts
index 502678a9..13eb1381 100644
--- a/src/routes/(app)/[username]/receive/[...param]/+page.server.ts
+++ b/src/routes/(app)/[username]/[...account]/receive/[...param]/+page.server.ts
@@ -2,16 +2,18 @@ import { redirect } from "@sveltejs/kit";
import { auth, post } from "$lib/utils";
import type { Invoice } from "$lib/types";
-export let load = async ({ cookies, parent }) => {
+export let load = async ({ cookies, params, parent }) => {
+ let { account } = params;
let {subject, user, rates } = await parent();
let invoice: Invoice = {
- type: "lightning",
+ account,
+ type: account ? "bitcoin": "lightning",
rate: rates[user?.currency || subject?.currency],
};
if(!user) user = subject;
- invoice = await post("/invoice", { invoice, user }, auth(cookies));
+ invoice = await post("/invoice", { invoice, account, user }, auth(cookies));
let { id } = invoice;
if (invoice.memoPrompt && !invoice.memo) {
diff --git a/src/routes/(app)/[username]/receive/[...param]/+page.svelte b/src/routes/(app)/[username]/[...account]/receive/[...param]/+page.svelte
index f9267105..f9267105 100644
--- a/src/routes/(app)/[username]/receive/[...param]/+page.svelte
+++ b/src/routes/(app)/[username]/[...account]/receive/[...param]/+page.svelte
diff --git a/src/routes/(app)/[username]/account/setup/+page.svelte b/src/routes/(app)/[username]/account/setup/+page.svelte
index 5c2102c7..9636ff2a 100644
--- a/src/routes/(app)/[username]/account/setup/+page.svelte
+++ b/src/routes/(app)/[username]/account/setup/+page.svelte
@@ -32,8 +32,8 @@
</p>
<p class="text-secondary mb-1">
- Whoever knows these words can withdraw funds from the account. We can't
- help you recover them if you lose them.
+ Whoever knows these words in the correct order can withdraw funds from the account. We can't
+ recover them if you lose them.
</p>
{#if reveal}
diff --git a/src/routes/(app)/[username]/account/setup/step2/+page.svelte b/src/routes/(app)/[username]/account/setup/step2/+page.svelte
index 3b403295..d8f44e16 100644
--- a/src/routes/(app)/[username]/account/setup/step2/+page.svelte
+++ b/src/routes/(app)/[username]/account/setup/step2/+page.svelte
@@ -5,6 +5,8 @@
import { encrypt, decrypt } from "nostr-tools/nip49";
import { mnemonicToEntropy, entropyToMnemonic } from "@scure/bip39";
import { wordlist } from "@scure/bip39/wordlists/english";
+ import { fail, post } from "$lib/utils";
+ import { goto } from "$app/navigation";
export let data;
let { user } = data;
@@ -12,11 +14,14 @@
let password;
let submit = async () => {
- console.log($mnemonic);
- let t = await encrypt(mnemonicToEntropy($mnemonic, wordlist), password);
-
- let m = await decrypt(t, password);
- console.log(entropyToMnemonic(m, wordlist));
+ user.seed = await encrypt(mnemonicToEntropy($mnemonic, wordlist), password);
+ try {
+ await post("/api/user", user);
+ goto(`/${user.username}`);
+ } catch (e) {
+ console.log(e);
+ fail("Something went wrong");
+ }
};
</script>
diff --git a/src/routes/(app)/[username]/invoice/[id]/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/+page.svelte
index 28bfe27b..24e75fa5 100644
--- a/src/routes/(app)/[username]/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/[username]/invoice/[id]/+page.svelte
@@ -28,7 +28,6 @@
export let data;
- let ndef;
let showOptions;
let reading = async ({ message, serialNumber }) => {
@@ -41,6 +40,7 @@
$: refresh(data);
let { invoice, id, subject, user, src } = data;
let {
+ account,
amount,
hash,
type,
@@ -56,6 +56,7 @@
let refresh = async (data) => {
({ invoice, id, user, src } = data);
({
+ account,
amount,
hash,
type,
@@ -66,21 +67,6 @@
} = invoice);
tipPercent = (tip / amount) * 100;
-
- // if (browser && window.NDEFReader) {
- // try {
- // ndef = new NDEFReader();
- // await ndef.scan();
- //
- // ndef.removeEventListener('readingerror', readingerror);
- // ndef.removeEventListener('reading', reading);
- //
- // ndef.addEventListener('readingerror', readingerror);
- // ndef.addEventListener('reading', reading);
- // } catch (e) {
- // console.log(e);
- // }
- // }
};
$: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2));
@@ -100,13 +86,6 @@
}
});
- onDestroy(() => {
- if (ndef) {
- ndef.removeEventListener("readingerror", readingerror);
- ndef.removeEventListener("reading", reading);
- }
- });
-
$: link = [types.bitcoin, types.liquid].includes(type)
? text
: `lightning:${text}`;
@@ -257,39 +236,41 @@
</div>
</div>
- <div class="flex justify-around text-secondary">
- <button
- class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
- class:bg-primary={type === types.bitcoin}
- class:text-black={type === types.bitcoin}
- on:click={() => setType(types.bitcoin)}
- >
- <img src="/images/bitcoin.svg" class="w-8" alt="Bitcoin" />
- <div class="my-auto text-lg">Bitcoin</div>
- </button>
+ {#if !account}
+ <div class="flex justify-around text-secondary">
+ <button
+ class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
+ class:bg-primary={type === types.bitcoin}
+ class:text-black={type === types.bitcoin}
+ on:click={() => setType(types.bitcoin)}
+ >
+ <img src="/images/bitcoin.svg" class="w-8" alt="Bitcoin" />
+ <div class="my-auto text-lg">Bitcoin</div>
+ </button>
- <button
- class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
- class:bg-primary={type === types.liquid}
- class:text-black={type === types.liquid}
- on:click={() => setType(types.liquid)}
- >
- <img src="/images/liquid.svg" class="w-8" alt="Liquid" />
- <div class="my-auto text-lg">Liquid</div>
- </button>
+ <button
+ class="hover:bg-primary my-auto flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
+ class:bg-primary={type === types.liquid}
+ class:text-black={type === types.liquid}
+ on:click={() => setType(types.liquid)}
+ >
+ <img src="/images/liquid.svg" class="w-8" alt="Liquid" />
+ <div class="my-auto text-lg">Liquid</div>
+ </button>
- <button
- class="hover:bg-primary flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
- class:bg-primary={type === types.lightning}
- class:text-black={type === types.lightning}
- on:click={() => setType(types.lightning)}
- >
- <div class="bg-white rounded-full w-8 h-8 text-center flex">
- <div class="m-auto">⚡️</div>
- </div>
- <div class="my-auto text-lg">Lightning</div>
- </button>
- </div>
+ <button
+ class="hover:bg-primary flex gap-1 sm:gap-2 py-3 px-2 sm:px-5 w-full justify-center"
+ class:bg-primary={type === types.lightning}
+ class:text-black={type === types.lightning}
+ on:click={() => setType(types.lightning)}
+ >
+ <div class="bg-white rounded-full w-8 h-8 text-center flex">
+ <div class="m-auto">⚡️</div>
+ </div>
+ <div class="my-auto text-lg">Lightning</div>
+ </button>
+ </div>
+ {/if}
{#if type === types.liquid}
<div class="flex justify-center">