diff options
| author | Adam Soltys <[email protected]> | 2025-01-03 15:24:31 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-03 15:24:31 -0800 |
| commit | 50296ccde06dc7892b0c6bd1546030f495564b28 (patch) | |
| tree | 444e26008235c9a57ec2756d8b8fa60133d4e4a9 /src/routes | |
| parent | 1bfdc18184fd57b741f5ebdfb0e323747f4d06b0 (diff) | |
| download | coinos-ui-50296ccde06dc7892b0c6bd1546030f495564b28.tar.gz coinos-ui-50296ccde06dc7892b0c6bd1546030f495564b28.zip | |
nostr sign in
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/(app)/[username]/(profile)/+page.svelte | 15 | ||||
| -rw-r--r-- | src/routes/(app)/events/+server.ts | 8 | ||||
| -rw-r--r-- | src/routes/(app)/invoice/[id]/paid/+page.svelte | 11 | ||||
| -rw-r--r-- | src/routes/(app)/ln/[lnurl]/+page.server.ts | 2 | ||||
| -rw-r--r-- | src/routes/(app)/pay/[username]/[...amount]/+page.server.ts | 6 | ||||
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.ts | 4 | ||||
| -rw-r--r-- | src/routes/(static)/login/+page.server.ts | 2 | ||||
| -rw-r--r-- | src/routes/(static)/login/+page.svelte | 62 | ||||
| -rw-r--r-- | src/routes/amber/[id]/[pubkey]/+server.ts | 6 |
9 files changed, 51 insertions, 65 deletions
diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte index a498f0f7..6530f149 100644 --- a/src/routes/(app)/[username]/(profile)/+page.svelte +++ b/src/routes/(app)/[username]/(profile)/+page.svelte @@ -8,6 +8,7 @@ import { t } from "$lib/translations"; import { installPrompt } from "$lib/store"; import { afterNavigate, preloadData } from "$app/navigation"; + import { page } from "$app/stores"; let { data } = $props(); @@ -24,7 +25,9 @@ $installPrompt = null; }; + let pubkey = $state(); if (user) user.savings = 0; + let { host } = $derived($page.url); </script> <div class="space-y-2"> @@ -37,14 +40,16 @@ <a href={`/account/savings`} class="contents"> <button class="btn btn-lg w-full rounded-2xl whitespace-nowrap"> - <iconify-icon noobserver icon="ph:plus-circle-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:plus-circle-bold" width="32" + ></iconify-icon> {$t("accounts.addAccount")} </button> </a> {#if $installPrompt} <button class="btn btn-accent lg:hidden" onclick={install}> - <iconify-icon noobserver icon="ph:floppy-disk-bold" width="32"></iconify-icon> + <iconify-icon noobserver icon="ph:floppy-disk-bold" width="32" + ></iconify-icon> {$t("user.install")} </button> {/if} @@ -62,7 +67,10 @@ <button class="btn btn-accent !text-2xl items-center !w-full sm:!max-w-[400px] mx-auto" > - <iconify-icon noobserver icon="ph:lightning-fill" class="text-yellow-300" + <iconify-icon + noobserver + icon="ph:lightning-fill" + class="text-yellow-300" ></iconify-icon> <div> {$t("user.pay")} @@ -72,3 +80,4 @@ </a> {/if} </div> + diff --git a/src/routes/(app)/events/+server.ts b/src/routes/(app)/events/+server.ts index 42b9f3dd..59fc472e 100644 --- a/src/routes/(app)/events/+server.ts +++ b/src/routes/(app)/events/+server.ts @@ -1,5 +1,11 @@ import { auth, post } from "$lib/utils"; -import { json, error } from "@sveltejs/kit"; +import { error, json } from "@sveltejs/kit"; + +export async function GET({ url }) { + console.log(url.searchParams.get("event")); + console.log(url.searchParams.get("uid")); + return json({}); +} export async function POST({ cookies, request }) { const body = await request.json(); diff --git a/src/routes/(app)/invoice/[id]/paid/+page.svelte b/src/routes/(app)/invoice/[id]/paid/+page.svelte index a13692d7..bc61d7fe 100644 --- a/src/routes/(app)/invoice/[id]/paid/+page.svelte +++ b/src/routes/(app)/invoice/[id]/paid/+page.svelte @@ -2,29 +2,36 @@ import Amount from "$comp/Amount.svelte"; import Success from "$comp/Success.svelte"; import { t } from "$lib/translations"; + import { loc } from "$lib/utils"; let { data } = $props(); let { amount, currency, rate, received, pending, tip, user, id } = $derived( data.invoice, ); + let locale = $derived(loc(user)); // toast.pop(0); </script> <div class="container px-4 text-center mx-auto"> {#if pending} - <iconify-icon noobserver icon="ph:clock-bold" class="text-warning" width="160" + <iconify-icon + noobserver + icon="ph:clock-bold" + class="text-warning" + width="160" ></iconify-icon> <h1 class="text-3xl md:text-4xl font-bold mb-6">Payment detected</h1> - <Amount amount={pending - tip} {tip} {rate} {currency} /> + <Amount amount={pending - tip} {tip} {rate} {currency} {locale} /> {:else} <Success amount={received - tip} {rate} {tip} {currency} + {locale} title={$t("invoice.paymentSuccessful")} /> {/if} diff --git a/src/routes/(app)/ln/[lnurl]/+page.server.ts b/src/routes/(app)/ln/[lnurl]/+page.server.ts index 53445461..7b63e6f5 100644 --- a/src/routes/(app)/ln/[lnurl]/+page.server.ts +++ b/src/routes/(app)/ln/[lnurl]/+page.server.ts @@ -7,12 +7,10 @@ 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); diff --git a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts index 812b97ec..b0f824ed 100644 --- a/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts +++ b/src/routes/(app)/pay/[username]/[...amount]/+page.server.ts @@ -45,11 +45,8 @@ export const actions = { default: async ({ cookies, request }) => { let id; const body = await fd(request); - console.log("BODY", body); const { amount, rate, prompt, type, username } = body; - console.log("AMT", amount); - try { ({ id } = await post( "/invoice", @@ -69,7 +66,8 @@ export const actions = { return fail(400, { message }); } - if (prompt) redirect(307, `/invoice/${id}/tip`); + if (parseInt(amount) > 0 && prompt) redirect(307, `/invoice/${id}/tip`); + else if (parseInt(amount) <= 0 ) redirect(307, `/${username}/receive`); redirect(307, `/invoice/${id}`); }, }; diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 9b971f2f..658629ef 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -8,7 +8,7 @@ export async function load({ cookies, params: { id }, parent }) { const invoice = await get(`/invoice/${id}`); - if (invoice.prompt && invoice.tip === null) + if (invoice.amount && invoice.prompt && invoice.tip === null) redirect(307, `/invoice/${id}/tip`); if (invoice.memoPrompt && invoice.memo === null) @@ -17,7 +17,7 @@ export async function load({ cookies, params: { id }, parent }) { if (user && invoice.aid === aid) error(500, { message: "Cannot send to self" }); else if (user && ![types.lightning, types.bolt12].includes(invoice.type)) - redirect(307, `/send/${invoice.type}/${invoice.hash}`); + redirect(307, `/send/${invoice.type === types.ecash ? "ecash" : "bitcoin"}/${invoice.hash}`); if (!user) redirect(307, `/invoice/${id}`); diff --git a/src/routes/(static)/login/+page.server.ts b/src/routes/(static)/login/+page.server.ts index 975dab5d..6bf06ad2 100644 --- a/src/routes/(static)/login/+page.server.ts +++ b/src/routes/(static)/login/+page.server.ts @@ -1,6 +1,6 @@ +import { PUBLIC_COINOS_URL } from "$env/static/public"; import { fd, get, login } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -import { PUBLIC_COINOS_URL } from "$env/static/public"; export const load = async ({ parent }) => { const { user } = await parent(); diff --git a/src/routes/(static)/login/+page.svelte b/src/routes/(static)/login/+page.svelte index bfd30fe2..dec02b17 100644 --- a/src/routes/(static)/login/+page.svelte +++ b/src/routes/(static)/login/+page.svelte @@ -3,21 +3,22 @@ import handler from "$lib/handler"; import { onMount } from "svelte"; - import { applyAction, deserialize } from "$app/forms"; + import { deserialize } from "$app/forms"; import { tick } from "svelte"; import { fly } from "svelte/transition"; import { enhance } from "$app/forms"; + import Nostr from "$comp/Nostr.svelte"; import Pinpad from "$comp/Pinpad.svelte"; import PasswordInput from "$comp/PasswordInput.svelte"; - import { focus, fail } from "$lib/utils"; + import { wait, copy, focus, fail } from "$lib/utils"; import { password, pin, loginRedirect } from "$lib/store"; import { t } from "$lib/translations"; import { page } from "$app/stores"; import { invalidateAll } from "$app/navigation"; - let nostr = $state(); + let { data, form } = $props(); + onMount(() => { - if (browser && window.nostr) nostr = true; $pin = undefined; localStorage.clear(); sessionStorage.clear(); @@ -26,11 +27,10 @@ if (lang) document.cookie = `lang=${lang} ;`; }); - let { data, form } = $props(); let { id } = $derived(data); + let nostrSignin = $state(); let token = $state(""); - let code = []; $password = undefined; @@ -78,43 +78,6 @@ }); }); - let nostrLogin = async () => { - let pubkey = await window.nostr.getPublicKey(); - const formData = new FormData(); - - let ev = { - kind: 1, - pubkey, - created_at: Date.now(), - content: id, - tags: [], - }; - - try { - let signedEvent = await window.nostr.signEvent(ev); - - formData.append("loginRedirect", redirect); - formData.append("token", token); - formData.append("event", JSON.stringify(signedEvent)); - formData.append("id", id); - - let response = await fetch("?/nostr", { - method: "POST", - body: formData, - }); - - const result = deserialize(await response.text()); - - if (result.type === "success") { - await invalidateAll(); - } - - applyAction(result); - } catch (e) { - fail(e.message); - } - }; - let redirect = $derived( $loginRedirect || $page.url.searchParams.get("redirect"), ); @@ -163,13 +126,10 @@ {$t("login.signIn")} </button> - {#if nostr} - <button type="button" class="btn" onclick={nostrLogin}> - <img src="/images/nostr.png" class="w-8" /> - <div class="my-auto">{$t("login.nostr")}</div> - </button> - {/if} - + <button type="button" class="btn" onclick={() => (nostrSignin = true)}> + <img src="/images/nostr.png" class="w-8" /> + <div class="my-auto">{$t("login.nostr")}</div> + </button> <p class="text-secondary text-center font-medium"> {$t("login.noAccount")} <a @@ -203,3 +163,5 @@ </div> </div> {/if} + +<Nostr {id} {nostrSignin} {redirect} {token} /> diff --git a/src/routes/amber/[id]/[pubkey]/+server.ts b/src/routes/amber/[id]/[pubkey]/+server.ts new file mode 100644 index 00000000..6a6f69cf --- /dev/null +++ b/src/routes/amber/[id]/[pubkey]/+server.ts @@ -0,0 +1,6 @@ +import { json } from "@sveltejs/kit"; + +export async function GET({ params }) { + console.log(params); + return json({}); +} |
