From 80cf7e9b77dcc4cbcf7711eb63a218c3aec07ec6 Mon Sep 17 00:00:00 2001
From: secondl1ght <85003930+secondl1ght@users.noreply.github.com>
Date: Wed, 27 Jul 2022 00:00:43 -0600
Subject: hook up receive page and more adjustments
---
src/components/AppHeader.svelte | 4 +-
src/lib/socket.js | 3 +-
src/lib/store.js | 1 +
src/routes/invoice.js | 3 +-
src/routes/invoice.svelte | 23 +++--
src/routes/receive.svelte | 194 +++++++++++++++++++++++++++++-----------
6 files changed, 157 insertions(+), 71 deletions(-)
(limited to 'src')
diff --git a/src/components/AppHeader.svelte b/src/components/AppHeader.svelte
index 9998a4f6..bbe2e05e 100644
--- a/src/components/AppHeader.svelte
+++ b/src/components/AppHeader.svelte
@@ -14,10 +14,10 @@
>
- import { rate, user } from '$lib/store';
- import { onMount } from 'svelte';
+ import { rate, user, invoiceAmount } from '$lib/store';
export let text;
-QR code
-
-{text}
-
-{$rate}
-
-{$user?.username}
-
-{#each $user.payments as p}
- {p.amount}
-{/each}
+{#if $user}
+ {text}
+ {$invoiceAmount}
+ {$rate}
+ {$user.username}
+ {#each $user.payments as p}
+ {p.amount}
+ {/each}
+{/if}
diff --git a/src/routes/receive.svelte b/src/routes/receive.svelte
index 73d3cc06..8cc49de2 100644
--- a/src/routes/receive.svelte
+++ b/src/routes/receive.svelte
@@ -2,74 +2,162 @@
// 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';
let useFiat = true;
let amountFiat = 0;
let amountSats = 0;
+ let message = '';
+
+ $: $invoiceAmount = parseInt(amountSats === 0 ? amountFiat / ($rate / 100000000) : amountSats);
+ $: amountSatsFormatted = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format(
+ amountSats
+ );
+
+ $: amountFiatConverted = new Intl.NumberFormat('en-US', {
+ style: 'currency',
+ currency: 'USD'
+ }).format(amountSats * ($rate / 100000000));
+
+ $: amountSatsConverted = new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format(
+ amountFiat / ($rate / 100000000)
+ );
const numPad = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0', '<'];
+
+ const handleInput = (value) => {
+ if (message) {
+ message = '';
+ }
+ if (useFiat) {
+ if (amountFiat === 0 && value !== '.' && value !== '<' && value !== '0') {
+ amountFiat = value;
+ } else if (amountFiat === 0 && value === '.') {
+ amountFiat = '0.';
+ } else if (amountFiat !== 0 && amountFiat.includes('.') && value === '.') {
+ return;
+ } else if (value === '<') {
+ if (amountFiat !== 0) {
+ amountFiat = amountFiat.slice(0, amountFiat.length - 1);
+ if (amountFiat.length === 0) {
+ amountFiat = 0;
+ }
+ }
+ } else if (value !== '.' && value !== '<' && parseInt(amountFiat + value) > $rate) {
+ message = 'Please enter an amount less than 1 bitcoin.';
+ } else if (amountFiat !== 0 && amountFiat.match(/\.../)) {
+ return;
+ } else {
+ amountFiat = amountFiat + value;
+ }
+ } else {
+ if (value === '.') {
+ return;
+ } else if (amountSats === 0 && value !== '<' && value !== '0') {
+ amountSats = value;
+ } else if (value === '<') {
+ if (amountSats !== 0) {
+ amountSats = amountSats.slice(0, amountSats.length - 1);
+ if (amountSats.length === 0) {
+ amountSats = 0;
+ }
+ }
+ } else if (value !== '<' && parseInt(amountSats + value) > 100000000) {
+ message = 'Please enter an amount less than 1 bitcoin.';
+ } else {
+ amountSats = amountSats + value;
+ }
+ }
+ };
-
-
-
-
-
- {useFiat ? `$${amountFiat}` : amountSats}
{useFiat ? 'CAD' : 'SATS'}
+
+
+
+
+ {useFiat ? `$${amountFiat}` : amountSatsFormatted}{useFiat ? 'USD' : 'SATS'}
+
+
{useFiat ? `${amountSatsConverted} SATS` : `${amountFiatConverted} USD`}
+
-
{useFiat ? `${amountSats} SATS` : `$${amountFiat} CAD`}
-
-
-
- {#each numPad as value}
- {#if value === '<'}
-
+ {:else}
+
+ {/if}
+ {/each}
+
-
-
-
-
+
+
+
+
+
-
+{/if}
--
cgit v1.2.3