aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-11-21 22:56:09 -0800
committerAdam Soltys <[email protected]>2024-11-21 22:56:35 -0800
commitff3bbbe6a1814ab5b17386eb630b5dd3111578eb (patch)
tree468233f260d41d08685212729cc94b5dc661a570 /src
parent38660e024c055952180bfa3f9067274cf2e0d6ed (diff)
downloadcoinos-ui-ff3bbbe6a1814ab5b17386eb630b5dd3111578eb.tar.gz
coinos-ui-ff3bbbe6a1814ab5b17386eb630b5dd3111578eb.zip
ecash requests
Diffstat (limited to 'src')
-rw-r--r--src/components/InvoiceTypes.svelte48
-rw-r--r--src/routes/(app)/ecash/[id]/[...version]/+page.svelte18
-rw-r--r--src/routes/(app)/send/ecash/+page.svelte6
-rw-r--r--src/routes/(app)/send/ecash/[request]/+page.svelte51
-rw-r--r--src/routes/(app)/sent/[id]/+page.server.ts2
5 files changed, 58 insertions, 67 deletions
diff --git a/src/components/InvoiceTypes.svelte b/src/components/InvoiceTypes.svelte
index 4e1e5b20..e6c3478d 100644
--- a/src/components/InvoiceTypes.svelte
+++ b/src/components/InvoiceTypes.svelte
@@ -6,33 +6,17 @@
<div class="grid grid-cols-2 gap-2 justify-around text-secondary">
<button
class="btn flex-nowrap"
- class:bg-base-300={type === types.bitcoin}
- class:text-secondary={type === types.bitcoin}
- onclick={() => setType(types.bitcoin)}
- >
- <img src="/images/bitcoin.svg" class="w-8" alt="Bitcoin" />
- <div class="my-auto text-lg">Bitcoin</div>
- </button>
-
- <button
- class="btn flex-nowrap"
- class:bg-base-300={type === types.liquid}
- class:text-secondary={type === types.liquid}
- onclick={() => setType(types.liquid)}
- >
- <img src="/images/liquid.svg" class="w-8" alt="Liquid" />
- <div class="my-auto text-lg">Liquid</div>
- </button>
-
- <button
- class="btn flex-nowrap"
class:bg-base-300={type === types.lightning}
class:text-secondary={type === types.lightning}
onclick={() => setType(types.lightning)}
>
- <div class="bg-base-100 rounded-full w-8 h-8 items-center justify-center flex">
+ <div
+ class="bg-base-100 rounded-full w-8 h-8 items-center justify-center flex"
+ >
<div class="m-auto">
- <iconify-icon icon="ph:lightning-fill" class="text-yellow-300 text-3xl"
+ <iconify-icon
+ icon="ph:lightning-fill"
+ class="text-yellow-300 text-3xl"
></iconify-icon>
</div>
</div>
@@ -45,6 +29,26 @@
<div class="my-auto text-lg">Ecash</div>
</button>
</a>
+
+ <button
+ class="btn flex-nowrap"
+ class:bg-base-300={type === types.bitcoin}
+ class:text-secondary={type === types.bitcoin}
+ onclick={() => setType(types.bitcoin)}
+ >
+ <img src="/images/bitcoin.svg" class="w-8" alt="Bitcoin" />
+ <div class="my-auto text-lg">Bitcoin</div>
+ </button>
+
+ <button
+ class="btn flex-nowrap"
+ class:bg-base-300={type === types.liquid}
+ class:text-secondary={type === types.liquid}
+ onclick={() => setType(types.liquid)}
+ >
+ <img src="/images/liquid.svg" class="w-8" alt="Liquid" />
+ <div class="my-auto text-lg">Liquid</div>
+ </button>
</div>
{#if type === types.liquid}
diff --git a/src/routes/(app)/ecash/[id]/[...version]/+page.svelte b/src/routes/(app)/ecash/[id]/[...version]/+page.svelte
index 47126c78..7cc93455 100644
--- a/src/routes/(app)/ecash/[id]/[...version]/+page.svelte
+++ b/src/routes/(app)/ecash/[id]/[...version]/+page.svelte
@@ -7,7 +7,7 @@
let { data, form } = $props();
let link = $page.url.href;
- let { id, total, version, token, external, spent } = $state(data);
+ let { id, total, token, external, spent } = $state(data);
</script>
{#if form?.error}
@@ -57,20 +57,4 @@
>
{token}
</button>
-
- {#if version === 4}
- <a data-sveltekit-reload href={`/ecash/${id}/3`} class="contents">
- <button type="button" class="btn">
- <iconify-icon icon="ph:gear-bold" width="32"></iconify-icon>
- <div class="my-auto">{$t("payments.legacyVersion")}</div>
- </button>
- </a>
- {:else}
- <a data-sveltekit-reload href={`/ecash/${id}`} class="contents">
- <button type="button" class="btn">
- <iconify-icon icon="ph:gear-bold" width="32"></iconify-icon>
- <div class="my-auto">{$t("payments.newVersion")}</div>
- </button>
- </a>
- {/if}
</div>
diff --git a/src/routes/(app)/send/ecash/+page.svelte b/src/routes/(app)/send/ecash/+page.svelte
index 88239c1a..5de8bee1 100644
--- a/src/routes/(app)/send/ecash/+page.svelte
+++ b/src/routes/(app)/send/ecash/+page.svelte
@@ -34,12 +34,6 @@
</script>
<div class="container px-4 max-w-xl mx-auto space-y-5 text-center">
- <div class="card text-left rounded-2xl shadow shadow-primary p-4 bg-base-200">
- <div class="text-secondary">
- {$t("payments.ecashDesc")}
- <a href="https://cashu.space/" class="font-bold">cashu.space</a>
- </div>
- </div>
<form use:enhance={handler(toggle)} method="POST" class="space-y-5">
<h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
{$t("payments.fundingAmount")}
diff --git a/src/routes/(app)/send/ecash/[request]/+page.svelte b/src/routes/(app)/send/ecash/[request]/+page.svelte
index 7f2ac7ba..bed8c0ae 100644
--- a/src/routes/(app)/send/ecash/[request]/+page.svelte
+++ b/src/routes/(app)/send/ecash/[request]/+page.svelte
@@ -1,5 +1,6 @@
<script lang="ts">
- import { post } from "$lib/utils";
+ import { goto } from "$app/navigation";
+ import { fail, post } from "$lib/utils";
import { applyAction, deserialize } from "$app/forms";
import { t } from "$lib/translations";
import { enhance } from "$app/forms";
@@ -8,7 +9,7 @@
import Spinner from "$comp/Spinner.svelte";
import { rate, pin } from "$lib/store";
import { wrapEvent } from "nostr-tools/nip17";
- import { getPrivateKey, sign } from "$lib/nostr";
+ import { getPrivateKey, sign, send } from "$lib/nostr";
import { getDecodedToken } from "@cashu/cashu-ts";
import type { PaymentRequestPayload } from "@cashu/cashu-ts";
@@ -20,27 +21,35 @@
e.preventDefault();
submitting = true;
- let { token } = await post("/ecash/mint", { amount });
- const dec = (token) => getDecodedToken(token).token[0];
- let { proofs } = dec(token);
- let { id, mints, unit = "" } = req;
- // let mint = mints[0];
- let mint = "http://mint:3338";
- const paymentPayload: PaymentRequestPayload = {
- id,
- mint,
- unit,
- proofs,
- };
+ try {
+ let { pid, token } = await post("/ecash/mint", { amount });
+ const dec = (token) => getDecodedToken(token).token[0];
+ let { proofs } = dec(token);
+ let { id, mints, unit = "" } = req;
+ let mint = mints[0];
+ const paymentPayload: PaymentRequestPayload = {
+ id,
+ mint,
+ unit,
+ proofs,
+ };
- const paymentPayloadString = JSON.stringify(paymentPayload);
- let event = wrapEvent(
- await getPrivateKey(user),
- { publicKey: recipient.pubkey },
- JSON.stringify(paymentPayload),
- );
+ const paymentPayloadString = JSON.stringify(paymentPayload);
+ let event = wrapEvent(
+ await getPrivateKey(user),
+ { publicKey: recipient.pubkey },
+ JSON.stringify(paymentPayload),
+ );
+
+ await sign({ event, user });
+ await send(event);
+
+ goto(`/sent/${pid}`);
+ } catch (e) {
+ console.log(e);
+ fail(e.message);
+ }
- await sign({ event, user });
submitting = false;
};
diff --git a/src/routes/(app)/sent/[id]/+page.server.ts b/src/routes/(app)/sent/[id]/+page.server.ts
index d3d98ea5..31bf4dd1 100644
--- a/src/routes/(app)/sent/[id]/+page.server.ts
+++ b/src/routes/(app)/sent/[id]/+page.server.ts
@@ -1,4 +1,4 @@
-import { get, auth } from "$lib/utils";
+import { auth, get } from "$lib/utils";
export const load = async ({ cookies, params }) => {
const { id } = params;