From 67e26efeb6f0c7cc2d4dfbd91f30ff0a158991e6 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 28 Nov 2024 14:02:31 -0800 Subject: number formatting --- src/components/Amount.svelte | 4 +-- src/components/Balance.svelte | 5 ++-- src/components/Numpad.svelte | 67 ++++--------------------------------------- 3 files changed, 11 insertions(+), 65 deletions(-) (limited to 'src/components') diff --git a/src/components/Amount.svelte b/src/components/Amount.svelte index 46aa2d1b..035152d1 100644 --- a/src/components/Amount.svelte +++ b/src/components/Amount.svelte @@ -11,7 +11,7 @@ >
{s(amount)} + >{s(amount, locale)}
{#if tip} @@ -19,7 +19,7 @@
+
-
{s(tip)}
+
{s(tip, locale)}
{/if} diff --git a/src/components/Balance.svelte b/src/components/Balance.svelte index 33597c18..28bd69b3 100644 --- a/src/components/Balance.svelte +++ b/src/components/Balance.svelte @@ -6,6 +6,7 @@ let show = $state(); let { user, rate, balance } = $props(); + let locale = loc(user); let toggleShow = (e) => { e.preventDefault(); e.stopPropagation(); @@ -27,14 +28,14 @@
- {s(balance)} + {s(balance, locale)}
{#if isNaN(rate)}
—
{:else} - {f(toFiat(balance, rate), user.currency, loc(user))} + {f(toFiat(balance, rate), user.currency, locale)} {/if}
{/if} diff --git a/src/components/Numpad.svelte b/src/components/Numpad.svelte index e813a24b..f694679a 100644 --- a/src/components/Numpad.svelte +++ b/src/components/Numpad.svelte @@ -72,65 +72,9 @@ ]; const handleInput = (value) => { - if (selecting) amount = 0; - selecting = false; - - if ($fiat) { - if ( - amountFiat === 0 && - value !== decimal && - value !== "<" && - value !== "0" - ) { - amountFiat = value; - } else if ((amountFiat === 0 || amountFiat === "0") && value === "0") { - return; - } else if (amountFiat === 0 && value === decimal) { - amountFiat = `0${decimal}`; - } else if ( - amountFiat !== 0 && - amountFiat.includes(decimal) && - value === decimal - ) { - return; - } else if (value === "<") { - if (amountFiat !== 0) { - amountFiat = amountFiat.slice(0, amountFiat.length - 1); - if (amountFiat.length === 0) { - amountFiat = 0; - amount = 0; - } - } - } else if ( - value !== decimal && - value !== "<" && - parseInt(amountFiat + value) > rate - ) { - warning($t("user.receive.lessThan1BTCWarning")); - } else if (amountFiat !== 0 && amountFiat.match(/\.../)) { - return; - } else { - amountFiat = amountFiat + value; - } - } else { - if (value === decimal) { - return; - } else if (!amount && value !== "<" && value !== "0") { - amount = parseInt(value); - } else if (value === "<") { - if (amount !== 0) { - amount = Math.floor(amount / 10); - if (amount.length === 0) { - amount = 0; - amountFiat = 0; - } - } - } else if (value !== "<" && parseInt(amount + value) > sats) { - warning($t("user.receive.lessThan1BTCWarning")); - } else { - amount = parseInt(amount.toString() + value); - } - } + if (value === "<") html = html.substr(0, html.length - 1); + else html += value; + input(); }; $: html = $fiat ? amountFiat : s(amount); @@ -196,10 +140,11 @@ if (html.length < prev.length && p === 1 && i > 1) i--; } - let node = e.target.childNodes[0]; + let node = element.childNodes[0]; let range = document.createRange(); if (node) { + if (i > node.length) i = node.length; range.setStart(node, i); range.setEnd(node, i); @@ -280,7 +225,7 @@ {#if $fiat} - {s(amount)} + {s(amount, locale)} {:else} {f(amountFiat, currency, locale)} {/if} -- cgit v1.2.3