From a038ce9711f8ae5945eba073c82aa2aeb2bcf5c3 Mon Sep 17 00:00:00 2001 From: secondl1ght <85003930+secondl1ght@users.noreply.github.com> Date: Fri, 29 Jul 2022 21:29:18 -0600 Subject: start hooking up invoice screen --- src/components/RegisterOrLogin.svelte | 7 +- src/hooks/index.js | 18 +-- src/lib/store.js | 4 +- src/routes/__layout.svelte | 8 +- src/routes/invoice.svelte | 253 ++++++++++++++++++++++++++++++++-- src/routes/receive.svelte | 22 +-- 6 files changed, 273 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/components/RegisterOrLogin.svelte b/src/components/RegisterOrLogin.svelte index 2334741d..15be60cf 100644 --- a/src/components/RegisterOrLogin.svelte +++ b/src/components/RegisterOrLogin.svelte @@ -7,7 +7,8 @@ export let page; - let username = "bob", password = "pw"; + let username = 'bob', + password = 'pw'; let revealPassword = false; @@ -20,7 +21,7 @@ let r = await post(url, { username, password }); if (!r.token) r = await post('/login', { username, password }); $token = r.token; - console.log("new token", r.token) + console.log('new token', r.token); auth(); goto('/receive'); }; @@ -43,7 +44,7 @@ required class="bg-primary p-4 rounded-2xl w-full" bind:value={username} - autofocus + autofocus /> diff --git a/src/hooks/index.js b/src/hooks/index.js index 21e56052..6a9c8ec5 100644 --- a/src/hooks/index.js +++ b/src/hooks/index.js @@ -1,16 +1,16 @@ -import cookie from "cookie"; +import cookie from 'cookie'; export async function handle({ event, resolve }) { - let { request: { headers }, - } = event; + let { + request: { headers } + } = event; - const cookies = cookie.parse(headers.get("cookie") || ""); - let { token } = cookies; - event.locals = { token }; + const cookies = cookie.parse(headers.get('cookie') || ''); + let { token } = cookies; + event.locals = { token }; - return resolve(event); + return resolve(event); } - export const getSession = ({ locals: { token } }) => { - return { token }; + return { token }; }; diff --git a/src/lib/store.js b/src/lib/store.js index 62232f9d..6f4a9515 100644 --- a/src/lib/store.js +++ b/src/lib/store.js @@ -8,8 +8,7 @@ const persisted = (k, i) => { : i ); - s.subscribe((v) => browser && sessionStorage.setItem(k, JSON.stringify(v)) - ); + s.subscribe((v) => browser && sessionStorage.setItem(k, JSON.stringify(v))); return s; }; @@ -17,4 +16,5 @@ const persisted = (k, i) => { export const rate = writable(); export const user = writable(); export const invoiceAmount = writable(); +export const invoiceAmountFiat = writable(); export const token = persisted('token'); diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 1af9679a..6562db18 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -2,11 +2,11 @@ import '../app.css'; import { onMount } from 'svelte'; import { connect } from '$lib/socket'; - import { token } from "$lib/store"; - import { session } from "$app/stores"; - import { browser } from "$app/env"; + import { token } from '$lib/store'; + import { session } from '$app/stores'; + import { browser } from '$app/env'; - browser && ($token ||= $session.token); + browser && ($token ||= $session.token); onMount(connect); diff --git a/src/routes/invoice.svelte b/src/routes/invoice.svelte index 567aefbb..6dce84fe 100644 --- a/src/routes/invoice.svelte +++ b/src/routes/invoice.svelte @@ -1,15 +1,248 @@ -{#if $user} - {text} - {$invoiceAmount} - {$rate} - {$user.username} - {#each $user.payments as p} - {p.amount}
- {/each} -{/if} + + +
+
+ {#if $invoiceAmount && $invoiceAmountFiat && $rate && text} + +
+

Add a tip?

+ +
+ {tipAmountFormatted}{`(${tipAmountSats} SATS)`} + {tipPercent}% +
+ + { + customTipAmount = ''; + tipPercent = e.target.value; + }} + /> + +
+ {#each tipAmounts as amount} + + {/each} + +
+ $ + handleCustomTipAmount(e)} + class="bg-primary rounded-2xl py-3 px-10 font-semibold mt-2 mr-1 w-full md:w-auto" + placeholder="Other" + /> + +
+
+
+ +
+ + +
+ Scan to pay insert name here + +
+ +
+
+ Invoice + {invoiceAmountFiatFormatted} + {`(${invoiceAmountFormatted} SATS)`} +
+ +
+ Tip + {tipAmountFormatted} + {`(${tipAmountSats} SATS)`} +
+ +
+ Total + {totalAmountFormatted} + {`(${totalAmountSats} SATS)`} +
+
+
+ {:else} +
+
+
+ {/if} +
+
+ + diff --git a/src/routes/receive.svelte b/src/routes/receive.svelte index 338bc06c..095a2ba3 100644 --- a/src/routes/receive.svelte +++ b/src/routes/receive.svelte @@ -2,7 +2,7 @@ // in the future we will want to allow users to set their fiat currency in the settings import { AppHeader, Icon } from '$comp'; import { goto } from '$app/navigation'; - import { invoiceAmount, rate } from '$lib/store'; + import { invoiceAmount, invoiceAmountFiat, rate } from '$lib/store'; let useFiat = true; let amountFiat = 0; @@ -10,6 +10,9 @@ let message = ''; $: $invoiceAmount = parseInt(amountSats === 0 ? amountFiat / ($rate / 100000000) : amountSats); + $: $invoiceAmountFiat = parseInt( + amountFiat === 0 ? amountSats * ($rate / 100000000) : amountFiat + ); $: amountSatsFormatted = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format( amountSats ); @@ -63,6 +66,7 @@ amountSats = amountSats.slice(0, amountSats.length - 1); if (amountSats.length === 0) { amountSats = 0; + amountFiat = 0; } } } else if (value !== '<' && parseInt(amountSats + value) > 100000000) { @@ -77,8 +81,8 @@ -{#if $rate} -
+
+ {#if $rate}
@@ -165,11 +169,7 @@ >
-
-{:else} -
-
-
-{/if} + {:else} +
+ {/if} +
-- cgit v1.2.3