diff --git a/src/Create.tsx b/src/Create.tsx index 903a968c..c7b61168 100644 --- a/src/Create.tsx +++ b/src/Create.tsx @@ -61,8 +61,8 @@ const Create = () => { const changeReceiveAmount = (evt: InputEvent) => { const target = evt.currentTarget as HTMLInputElement; const amount = target.value.trim(); - const satAmount = convertAmount(Number(amount), denomination()); - const sendAmount = calculateSendAmount(satAmount); + const satAmount = convertAmount(BigNumber(amount), denomination()); + const sendAmount = calculateSendAmount(satAmount.toNumber()); setAmountChanged(sideReceive); setReceiveAmount(BigNumber(satAmount)); setSendAmount(BigNumber(sendAmount)); @@ -74,8 +74,8 @@ const Create = () => { const changeSendAmount = (evt: InputEvent) => { const target = evt.currentTarget as HTMLInputElement; const amount = target.value.trim(); - const satAmount = convertAmount(Number(amount), denomination()); - const receiveAmount = calculateReceiveAmount(satAmount); + const satAmount = convertAmount(BigNumber(amount), denomination()); + const receiveAmount = calculateReceiveAmount(satAmount.toNumber()); setAmountChanged(sideSend); setSendAmount(BigNumber(satAmount)); setReceiveAmount(BigNumber(receiveAmount)); @@ -108,7 +108,7 @@ const Create = () => { const validatePaste = (evt: ClipboardEvent) => { const clipboardData = evt.clipboardData || globalThis.clipboardData; const pastedData = clipboardData.getData("Text").trim(); - if (!getValidationRegex().test(pastedData)) { + if (!getValidationRegex(maximum(), denomination()).test(pastedData)) { evt.stopPropagation(); evt.preventDefault(); } @@ -133,7 +133,10 @@ const Create = () => { if (lessThanMin || amount > maximum()) { const params = { - amount: formatAmount(lessThanMin ? minimum() : maximum()), + amount: formatAmount( + BigNumber(lessThanMin ? minimum() : maximum()), + denomination(), + ), denomination: denomination(), }; const label = lessThanMin ? "minimum_amount" : "maximum_amount"; @@ -185,11 +188,15 @@ const Create = () => { createMemo(() => { const rAmount = Number(receiveAmount()); if (rAmount > 0) { - setReceiveAmountFormatted(formatAmount(rAmount).toString()); + setReceiveAmountFormatted( + formatAmount(BigNumber(rAmount), denomination()).toString(), + ); } const sAmount = Number(sendAmount()); if (sAmount > 0) { - setSendAmountFormatted(formatAmount(sAmount).toString()); + setSendAmountFormatted( + formatAmount(BigNumber(sAmount), denomination()).toString(), + ); } }); @@ -247,8 +254,11 @@ const Create = () => { autofocus required type="text" - placeholder={formatAmount(minimum())} - maxlength={calculateDigits()} + placeholder={formatAmount( + BigNumber(minimum()), + denomination(), + )} + maxlength={calculateDigits(maximum(), denomination())} inputmode={ denomination() == "btc" ? "decimal" : "numeric" } @@ -272,9 +282,10 @@ const Create = () => { required type="text" placeholder={formatAmount( - calculateReceiveAmount(minimum()), + BigNumber(calculateReceiveAmount(minimum())), + denomination(), )} - maxlength={calculateDigits()} + maxlength={calculateDigits(maximum(), denomination())} inputmode={ denomination() == "btc" ? "decimal" : "numeric" } diff --git a/src/components/ClickableAmount.tsx b/src/components/ClickableAmount.tsx index da3054ee..d1c77f0b 100644 --- a/src/components/ClickableAmount.tsx +++ b/src/components/ClickableAmount.tsx @@ -1,6 +1,8 @@ +import { BigNumber } from "bignumber.js"; import { Show } from "solid-js"; import t from "../i18n"; +import { denomination } from "../signals"; import { formatAmount } from "../utils/denomination"; const ClickableAmount = ({ label, onClick, amount }) => { @@ -8,7 +10,7 @@ const ClickableAmount = ({ label, onClick, amount }) => { <> {t(label)}: onClick(amount())} class="btn-small btn-light"> - {formatAmount(amount())} + {formatAmount(BigNumber(amount()), denomination())} ); diff --git a/src/components/Fees.tsx b/src/components/Fees.tsx index 7a53fc9e..5ef89c3b 100644 --- a/src/components/Fees.tsx +++ b/src/components/Fees.tsx @@ -1,3 +1,4 @@ +import { BigNumber } from "bignumber.js"; import { createEffect } from "solid-js"; import btcSvg from "../assets/btc.svg"; @@ -76,7 +77,7 @@ const Fees = () => {