From 1f63848ca9fb01336f04b41434de1cc06a5b3d93 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 10 Sep 2024 20:39:47 -0700 Subject: move routes --- src/lib/invoice.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib/invoice.ts') diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts index 7897dadc..3c885346 100644 --- a/src/lib/invoice.ts +++ b/src/lib/invoice.ts @@ -25,9 +25,9 @@ export default async ({ cookies, request }) => { let { id } = invoice; if (invoice.prompt && invoice.tip === null) - redirect(307, `/${user.username}/invoice/${id}/tip`); + redirect(307, `/invoice/${id}/tip`); if (invoice.memoPrompt && !invoice.memo) { - redirect(307, `/${user.username}/invoice/${id}/memo`); - } else redirect(307, `/${user.username}/invoice/${id}`); + redirect(307, `/invoice/${id}/memo`); + } else redirect(307, `/invoice/${id}`); }; -- cgit v1.2.3 From 2114156be3f89a2ef4c5bd13fd6d7a51d8fbc135 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 12 Sep 2024 15:23:45 -0700 Subject: self custodial send --- .env.production | 1 + bun.lockb | Bin 158882 -> 161519 bytes package.json | 3 +- src/components/Account.svelte | 17 ++- src/components/LandingHeader.svelte | 16 +-- src/components/Request.svelte | 39 ------ src/lib/invoice.ts | 7 +- src/lib/store.ts | 1 + src/lib/utils.ts | 41 ++++++- src/locales/en.json | 1 + src/routes/(app)/+error.svelte | 38 ++++++ src/routes/(app)/+layout.svelte | 6 - src/routes/(app)/[username]/(profile)/+page.svelte | 42 ++++--- src/routes/(app)/[username]/+layout.server.ts | 1 - src/routes/(app)/account/setup/step2/+page.svelte | 28 ++++- src/routes/(app)/invoice/+page.server.ts | 4 +- src/routes/(app)/invoice/[id]/+layout.server.ts | 7 +- src/routes/(app)/invoice/[id]/+page.svelte | 4 +- src/routes/(app)/logout/+page.server.ts | 1 + .../(app)/payments/[...page]/+page.server.ts | 3 +- src/routes/(app)/qr/[text]/+page.svelte | 4 - .../(app)/send/bitcoin/[address]/+page.server.ts | 7 ++ .../(app)/send/bitcoin/[address]/+page.svelte | 4 +- .../[amount]/[...feeRate]/+page.server.ts | 27 +++- .../[address]/[amount]/[...feeRate]/+page.svelte | 136 ++++++++++++++++++++- src/routes/(app)/send/ecash/+page.svelte | 6 - src/routes/(app)/sent/+page.server.ts | 3 +- src/routes/(app)/settings/[...tab]/+page.svelte | 2 +- src/routes/(static)/+layout.svelte | 2 +- src/routes/(static)/login/+page.svelte | 2 +- src/routes/(static)/register/+page.svelte | 2 +- src/routes/(static)/support/+page.svelte | 9 +- src/routes/+error.svelte | 1 - 33 files changed, 325 insertions(+), 140 deletions(-) delete mode 100644 src/components/Request.svelte create mode 100644 src/routes/(app)/+error.svelte create mode 100644 src/routes/(app)/send/bitcoin/[address]/+page.server.ts (limited to 'src/lib/invoice.ts') diff --git a/.env.production b/.env.production index 1ae57c17..8b72abf4 100644 --- a/.env.production +++ b/.env.production @@ -6,3 +6,4 @@ PUBLIC_LIQUID_EXPLORER=https://liquid.network PUBLIC_DOMAIN=coinos.io PUBLIC_COINOS_PUBKEY=ba80990666ef0b6f4ba5059347beb13242921e54669e680064ca755256a1e3a6 PUBLIC_COINOS_RELAY=wss://relay.coinos.io +PUBLIC_COINOS_NETWORK=regtest diff --git a/bun.lockb b/bun.lockb index df7d1899..97e0841d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 848db710..2ed4c699 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,9 @@ "@capacitor/cli": "^6.0.0", "@capacitor/core": "^6.0.0", "@capacitor/ios": "^6.1.2", - "@scure/base": "^1.1.1", + "@scure/base": "^1.1.8", "@scure/bip39": "^1.2.1", + "@scure/btc-signer": "^1.3.2", "@sveltejs/adapter-node": "^2.0.0", "@sveltejs/kit": "^2.5.22", "@sveltejs/vite-plugin-svelte": "^3.0.0", diff --git a/src/components/Account.svelte b/src/components/Account.svelte index eb1b0bac..f83068b5 100644 --- a/src/components/Account.svelte +++ b/src/components/Account.svelte @@ -1,4 +1,5 @@ - +
-
- -
-
{type} account
-
-
+
- +
diff --git a/src/components/Request.svelte b/src/components/Request.svelte deleted file mode 100644 index 297b7438..00000000 --- a/src/components/Request.svelte +++ /dev/null @@ -1,39 +0,0 @@ - - -{#if $request} -
-
-
-
- -

- {$request.requester.username} - {$t("payments.readyToPay")} -

-
-
- -
-
-{/if} diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts index 3c885346..0ab0a9af 100644 --- a/src/lib/invoice.ts +++ b/src/lib/invoice.ts @@ -1,13 +1,14 @@ -import { auth, get, post } from "$lib/utils"; +import { auth, get, post, setAccount } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export default async ({ cookies, request }) => { +export default async ({ cookies, request, url }) => { let form = await request.formData(); let rates = await get("/rates"); let amount = parseInt(form.get("amount")); let invoice = { + account, amount, items: JSON.parse(form.get("items")), memo: form.get("memo"), @@ -16,7 +17,7 @@ export default async ({ cookies, request }) => { type: form.get("type"), prompt: form.get("prompt") === "true", rate: parseFloat(form.get("rate")) || rates[form.get("currency")], - id: undefined + id: undefined, }; let user = { username: form.get("username"), currency: form.get("currency") }; diff --git a/src/lib/store.ts b/src/lib/store.ts index 3c1ff321..42b41127 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -38,6 +38,7 @@ let persistLocal = (key, defaultValue: any = undefined) => { return s; }; +export let account = writable(); export let amountPrompt = persistLocal("amountPrompt"); export let avatar = writable(); export let banner = writable(); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 69e0f949..c20a7d29 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,7 +1,7 @@ import { browser } from "$app/environment"; import { toast } from "@zerodevx/svelte-toast"; import { goto } from "$app/navigation"; -import { PUBLIC_COINOS_URL } from "$env/static/public"; +import { PUBLIC_COINOS_NETWORK, PUBLIC_COINOS_URL } from "$env/static/public"; import { page } from "$app/stores"; import { get as getStore } from "svelte/store"; @@ -41,7 +41,11 @@ export let get = (url: string, headers = {}) => { }); }; -export let post = async (url: string, body: object, headers: HeadersInit | undefined = undefined) => { +export let post = async ( + url: string, + body: object, + headers: HeadersInit | undefined = undefined +) => { headers = { "content-type": "application/json", accept: "application/json", @@ -242,7 +246,11 @@ export let select = (el: HTMLInputElement): any => export let sleep = (n: number): Promise => new Promise((r) => setTimeout(r, n)); -export let wait = async (f: () => boolean | Promise, n: number = 100, s: number = 300): Promise => { +export let wait = async ( + f: () => boolean | Promise, + n: number = 100, + s: number = 300 +): Promise => { let i = 0; while (!(await f()) && i < s) { await sleep(n); @@ -327,3 +335,30 @@ export function setCookie(name: string, value: string, seconds: number): void { const expires = "expires=" + now.toUTCString(); document.cookie = name + "=" + value + ";" + expires + ";path=/"; } + +export let network = { + bitcoin: { + bech32: "bc", + pubKeyHash: 0x00, + scriptHash: 0x05, + wif: 0x80, + }, + regtest: { + bech32: "bcrt", + pubKeyHash: 0x6f, + scriptHash: 0xc4, + wif: 0xef, + }, +}[PUBLIC_COINOS_NETWORK]; + +export let versions = { + bitcoin: { + private: 0x0488ade4, + public: 0x0488b21e, + }, + regtest: { + private: 0x04358394, + public: 0x043587cf, + }, +}[PUBLIC_COINOS_NETWORK]; + diff --git a/src/locales/en.json b/src/locales/en.json index b1bbe1c4..fd2807b4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -299,6 +299,7 @@ } }, "payments": { + "enterWalletPass": "Please enter your wallet password", "legacyVersion": "Legacy version", "newVersion": "New version", "income": "Income", diff --git a/src/routes/(app)/+error.svelte b/src/routes/(app)/+error.svelte new file mode 100644 index 00000000..6ce7979c --- /dev/null +++ b/src/routes/(app)/+error.svelte @@ -0,0 +1,38 @@ + + +
+
+ + + +
+ +
+
+
+

Error

+
+

Something went wrong

+

{$page.error.message}

+ + +
+
+
diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 0ff4816d..05ca0d0c 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -17,7 +17,6 @@ import AppHeader from "$comp/AppHeader.svelte"; import Invoice from "$comp/Invoice.svelte"; import Password from "$comp/Password.svelte"; - import Request from "$comp/Request.svelte"; import { getCookie, warning, protectedRoutes } from "$lib/utils"; import { t, locale, loading } from "$lib/translations"; import { goto, onNavigate } from "$app/navigation"; @@ -36,7 +35,6 @@ }); let { generate, rate, user, subject, token, rates } = data; - console.log("SUB", subject) $: update(data); let update = (data) => { @@ -127,10 +125,6 @@ {/if} -{#if $request} - -{/if} - diff --git a/src/routes/(app)/account/pass/+page.svelte b/src/routes/(app)/account/pass/+page.svelte index ee29d2c3..0eb16072 100644 --- a/src/routes/(app)/account/pass/+page.svelte +++ b/src/routes/(app)/account/pass/+page.svelte @@ -18,7 +18,7 @@ let { user } = data; - let confirm, password; + let confirm, password, revealPassword, revealConfirm; onMount(() => { if (!$mnemonic) goto("/account/savings"); @@ -65,13 +65,66 @@ class="container w-full mx-auto text-lg px-4 max-w-xl space-y-5" >

- Please add a password to the account. It should be different than your - login password. We won't be able to reset it. You'll - need it to make withdrawals. + Careful! If you lose this password you won't be able to use the account. + We can't recover it for you.

- - +
+ {#if revealPassword} + + {:else} + + {/if} + +
+ +
+ {#if revealConfirm} + + {:else} + + {/if} + +
Lightning
-
- {/if} - {#if type === types.liquid} - - {/if} - {#if user?.id === invoice?.user?.id} - - - + {#if type === types.liquid} +
+
+ {$t("payments.onlyLbtc")} + L-BTC, + {$t("payments.dontDeposit")} +
+
+ {/if} {/if}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 8417de91..48ebf970 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,7 +1,7 @@ import invoice from "$lib/invoice"; import { redirect } from "@sveltejs/kit"; -export async function load({ parent, params }) { +export async function load({ parent }) { let { invoice } = await parent(); if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index 35b24bf1..e4510693 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -59,6 +59,7 @@ $: refresh(data); let { invoice, id, user, rates } = data; let { + account_id, amount, hash, items, @@ -81,6 +82,7 @@ ({ invoice, id } = data); ({ + account_id, amount, hash, items, @@ -111,6 +113,7 @@
+ diff --git a/src/routes/(app)/logout/+page.server.ts b/src/routes/(app)/logout/+page.server.ts index 9c2a029c..03dff6a8 100644 --- a/src/routes/(app)/logout/+page.server.ts +++ b/src/routes/(app)/logout/+page.server.ts @@ -7,7 +7,7 @@ const opts = { export async function load({ cookies }) { let lang = cookies.get("lang"); - cookies.set("account", "", opts); + cookies.set("account_id", "", opts); cookies.set("lang", "", opts); cookies.set("username", "", opts); cookies.set("token", "", opts); diff --git a/src/routes/(app)/send/[...text]/+page.svelte b/src/routes/(app)/send/[...text]/+page.svelte index d1b6cc23..be7fc664 100644 --- a/src/routes/(app)/send/[...text]/+page.svelte +++ b/src/routes/(app)/send/[...text]/+page.svelte @@ -18,7 +18,7 @@ let el, text, pasted, w; - let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click()); + let keypress = (e) => e.key === "Enter" ? (e.preventDefault() || el.click()) : (pasted = false); let paste = async () => { text = await navigator.clipboard.readText(); @@ -52,7 +52,7 @@ name="text" placeholder={$t("user.send.placeholder")} on:keypress={keypress} - class="w-full p-4 border rounded-xl h-48 text-xl" + class="w-full p-4 border rounded-xl h-32 text-xl" bind:value={text} on:paste={() => (pasted = true)} autocapitalize="none" @@ -95,7 +95,7 @@ type="button" class="flex border rounded-2xl px-6 py-5 w-full font-bold gap-2 justify-center text-xl bg-primary" > - +
{$t("payments.createEcash")}
diff --git a/src/routes/(app)/send/ecash/+page.svelte b/src/routes/(app)/send/ecash/+page.svelte index 615c068a..ef8e368c 100644 --- a/src/routes/(app)/send/ecash/+page.svelte +++ b/src/routes/(app)/send/ecash/+page.svelte @@ -30,18 +30,14 @@
-

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

- -
+
{#if submitting} {:else} - {$t("payments.mint")} + +
{$t("payments.mint")}
{/if}
diff --git a/src/routes/(app)/send/lightning/[payreq]/+page.svelte b/src/routes/(app)/send/lightning/[payreq]/+page.svelte index 57a17e01..74c100f8 100644 --- a/src/routes/(app)/send/lightning/[payreq]/+page.svelte +++ b/src/routes/(app)/send/lightning/[payreq]/+page.svelte @@ -58,11 +58,7 @@ let toggle = () => (show = !show); - - -
+
{#if amount} {#if form?.message}
@@ -81,12 +77,9 @@

⚡️{s(amount)}

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

{alias}

+
+ {$t("payments.to")} + {alias}
{#if ourfee} @@ -109,7 +102,7 @@ use:enhance on:submit={submit} action="?/send" - class="space-y-5" + class="space-y-2" > diff --git a/static/icons/cash.svg b/static/icons/cash.svg new file mode 100644 index 00000000..966c00a5 --- /dev/null +++ b/static/icons/cash.svg @@ -0,0 +1,12 @@ + + \ No newline at end of file diff --git a/static/icons/text.svg b/static/icons/text.svg index 2bf9998f..a8fe6e04 100644 --- a/static/icons/text.svg +++ b/static/icons/text.svg @@ -1,17 +1,4 @@ - - - - - align-left - Created with Sketch Beta. - - - - - - - - - - + + + \ No newline at end of file -- cgit v1.2.3 From fb8510db273f78317a02ca151f7f24a9b8de29ab Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 20 Sep 2024 10:03:30 -0700 Subject: rename account_id --- src/components/Account.svelte | 2 +- src/lib/invoice.ts | 4 ++-- src/lib/types.ts | 2 +- src/routes/(app)/[username]/receive/+page.svelte | 6 +++--- src/routes/(app)/invoice/+page.server.ts | 6 +++--- src/routes/(app)/invoice/[id]/+page.svelte | 6 +++--- src/routes/(app)/invoice/[id]/tip/+page.svelte | 6 +++--- src/routes/(app)/logout/+page.server.ts | 2 +- src/routes/(app)/payments/[...page]/+page.server.ts | 4 ++-- src/routes/(app)/send/bitcoin/[address]/+page.server.ts | 4 ++-- .../send/bitcoin/[address]/[amount]/[...feeRate]/+page.server.ts | 6 +++--- src/routes/(app)/sent/+page.server.ts | 4 ++-- 12 files changed, 26 insertions(+), 26 deletions(-) (limited to 'src/lib/invoice.ts') diff --git a/src/components/Account.svelte b/src/components/Account.svelte index 0baeb9a0..47deadcd 100644 --- a/src/components/Account.svelte +++ b/src/components/Account.svelte @@ -12,7 +12,7 @@ let refresh = (a) => ({ seed, balance, id } = a); let setAccount = () => - (document.cookie = `account_id=${id}; path=/; max-age=86400`); + (document.cookie = `aid=${id}; path=/; max-age=86400`); diff --git a/src/lib/invoice.ts b/src/lib/invoice.ts index 0a50b876..fa2f7786 100644 --- a/src/lib/invoice.ts +++ b/src/lib/invoice.ts @@ -2,14 +2,14 @@ import { auth, get, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; export default async ({ cookies, request }) => { - let account_id = cookies.get("account_id"); + let aid = cookies.get("aid"); let form = await request.formData(); let rates = await get("/rates"); let amount = parseInt(form.get("amount")); let invoice = { - account_id, + aid, amount, items: JSON.parse(form.get("items")), memo: form.get("memo"), diff --git a/src/lib/types.ts b/src/lib/types.ts index 67a51f62..827f96aa 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -14,7 +14,7 @@ export interface User { } export interface Invoice { - account_id: string; + aid: string; id?: string; memoPrompt?: boolean; memo?: string; diff --git a/src/routes/(app)/[username]/receive/+page.svelte b/src/routes/(app)/[username]/receive/+page.svelte index 7d7958f1..9977cc76 100644 --- a/src/routes/(app)/[username]/receive/+page.svelte +++ b/src/routes/(app)/[username]/receive/+page.svelte @@ -39,7 +39,7 @@ $: refresh(data); let { invoice, id, subject, user, src } = data; let { - account_id, + aid, amount, hash, type, @@ -55,7 +55,7 @@ let refresh = async (data) => { ({ invoice, id, user, src } = data); ({ - account_id, + aid, amount, hash, type, @@ -235,7 +235,7 @@
- {#if account_id === user.id} + {#if aid === user.id}
- {#if account_id === user.id} + {#if aid === user.id}