aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/voucher
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-18 13:09:41 -0700
committerAdam Soltys <[email protected]>2024-08-18 22:15:05 -0700
commit250c7f9e9621d9eae1a3b364dd7d0716e7c49e31 (patch)
tree5cf0250363d11fb33414d8cae4f583e186247123 /src/routes/(app)/voucher
parente1cdf7d3c4c7b737d779efdf4236fb55fc0e4229 (diff)
downloadcoinos-ui-250c7f9e9621d9eae1a3b364dd7d0716e7c49e31.tar.gz
coinos-ui-250c7f9e9621d9eae1a3b364dd7d0716e7c49e31.zip
ecash
Diffstat (limited to 'src/routes/(app)/voucher')
-rw-r--r--src/routes/(app)/voucher/+page.svelte90
-rw-r--r--src/routes/(app)/voucher/[...token]/+page.server.js20
-rw-r--r--src/routes/(app)/voucher/[...token]/+page.svelte91
3 files changed, 201 insertions, 0 deletions
diff --git a/src/routes/(app)/voucher/+page.svelte b/src/routes/(app)/voucher/+page.svelte
new file mode 100644
index 00000000..5e21b3be
--- /dev/null
+++ b/src/routes/(app)/voucher/+page.svelte
@@ -0,0 +1,90 @@
+<script>
+ import { page } from "$app/stores";
+ import { fly } from "svelte/transition";
+ import { enhance } from "$app/forms";
+ import { tick } from "svelte";
+ import { browser } from "$app/environment";
+ import { t } from "$lib/translations";
+ import AppHeader from "$comp/AppHeader.svelte";
+ import Avatar from "$comp/Avatar.svelte";
+ import Icon from "$comp/Icon.svelte";
+ import Spinner from "$comp/Spinner.svelte";
+ import { back, fail, focus } from "$lib/utils";
+
+ export let data;
+ export let form;
+ data.subject = data.user;
+
+ let el, text, pasted, w;
+
+ let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click());
+
+ let paste = async () => {
+ text = await navigator.clipboard.readText();
+ };
+
+ $: if (browser && pasted && text) el.click() && (pasted = false);
+</script>
+
+<svelte:window bind:innerWidth={w} />
+
+<AppHeader {data} />
+<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
+ <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
+ {$t("payments.voucher")}
+ </h1>
+
+ <form method="POST" use:enhance class="space-y-2 text-xl">
+ {#if form?.error}
+ <div class="mb-5">
+ <div class="text-red-600">
+ {form.error === "default"
+ ? $t("error.unrecognizedInput")
+ : form.error}
+ </div>
+ </div>
+ {/if}
+
+ <div class="mb-2">
+ <textarea
+ use:focus
+ name="text"
+ placeholder={$t("payments.voucherText")}
+ on:keypress={keypress}
+ class="w-full p-4 border rounded-xl h-48 text-xl"
+ bind:value={text}
+ on:paste={() => (pasted = true)}
+ autocapitalize="none"
+ />
+ </div>
+
+ <div class="flex gap-2">
+ <a href="/scan" class="w-full">
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
+ >
+ <Icon icon="camera" style="mr-2 w-6 my-auto" />
+ <div class="my-auto">{$t("user.send.scan")}</div>
+ </button>
+ </a>
+
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
+ on:click={paste}
+ >
+ <Icon icon="paste" style="mr-2 w-6 my-auto" />
+ <div class="my-auto">{$t("user.send.paste")}</div>
+ </button>
+ </div>
+
+ <button
+ bind:this={el}
+ type="submit"
+ class="bg-black text-white border rounded-2xl px-6 py-5 w-full font-bold"
+ >
+ {$t("user.send.next")}
+ </button>
+ </form>
+</div>
diff --git a/src/routes/(app)/voucher/[...token]/+page.server.js b/src/routes/(app)/voucher/[...token]/+page.server.js
new file mode 100644
index 00000000..dcfb046e
--- /dev/null
+++ b/src/routes/(app)/voucher/[...token]/+page.server.js
@@ -0,0 +1,20 @@
+import { validate } from "bitcoin-address-validation";
+import bip21 from "bip21";
+import { auth, get, isLiquid, post } from "$lib/utils";
+import { fail, redirect } from "@sveltejs/kit";
+import { PUBLIC_DOMAIN } from "$env/static/public";
+import parse from "$lib/parse";
+import { test } from "$lib/parse";
+
+export async function load({ cookies, params, request, url }) {
+ await parse(params.token, url.host, cookies);
+}
+
+export const actions = {
+ default: async ({ cookies, request, url }) => {
+ const form = await request.formData();
+ let t = form.get("text");
+ let msg = await parse(t, url.host, cookies);
+ return fail(400, { error: msg || "default" });
+ },
+};
diff --git a/src/routes/(app)/voucher/[...token]/+page.svelte b/src/routes/(app)/voucher/[...token]/+page.svelte
new file mode 100644
index 00000000..f5b7b882
--- /dev/null
+++ b/src/routes/(app)/voucher/[...token]/+page.svelte
@@ -0,0 +1,91 @@
+<script>
+ import { page } from "$app/stores";
+ import { fly } from "svelte/transition";
+ import { enhance } from "$app/forms";
+ import { tick } from "svelte";
+ import { browser } from "$app/environment";
+ import { t } from "$lib/translations";
+ import AppHeader from "$comp/AppHeader.svelte";
+ import Avatar from "$comp/Avatar.svelte";
+ import Icon from "$comp/Icon.svelte";
+ import Spinner from "$comp/Spinner.svelte";
+ import { back, fail, focus } from "$lib/utils";
+
+ export let data;
+ export let form;
+ data.subject = data.user;
+
+ let el, text, pasted, w;
+
+ let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click());
+
+ let paste = async () => {
+ text = await navigator.clipboard.readText();
+ };
+
+
+ $: if (browser && pasted && text) el.click() && (pasted = false);
+</script>
+
+<svelte:window bind:innerWidth={w} />
+
+<AppHeader {data} />
+<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
+ <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
+ {$t("payments.voucher")}
+ </h1>
+
+ <form method="POST" use:enhance class="space-y-2 text-xl">
+ {#if form?.error}
+ <div class="mb-5">
+ <div class="text-red-600">
+ {form.error === "default"
+ ? $t("error.unrecognizedInput")
+ : form.error}
+ </div>
+ </div>
+ {/if}
+
+ <div class="mb-2">
+ <textarea
+ use:focus
+ name="text"
+ placeholder={$t("payments.voucherText")}
+ on:keypress={keypress}
+ class="w-full p-4 border rounded-xl h-48 text-xl"
+ bind:value={text}
+ on:paste={() => (pasted = true)}
+ autocapitalize="none"
+ />
+ </div>
+
+ <div class="flex gap-2">
+ <a href="/scan" class="w-full">
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
+ >
+ <Icon icon="camera" style="mr-2 w-6 my-auto" />
+ <div class="my-auto">{$t("user.send.scan")}</div>
+ </button>
+ </a>
+
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
+ on:click={paste}
+ >
+ <Icon icon="paste" style="mr-2 w-6 my-auto" />
+ <div class="my-auto">{$t("user.send.paste")}</div>
+ </button>
+ </div>
+
+ <button
+ bind:this={el}
+ type="submit"
+ class="bg-black text-white border rounded-2xl px-6 py-5 w-full font-bold"
+ >
+ {$t("user.send.next")}
+ </button>
+ </form>
+</div>