From f1f8bccd8c5e2d2200d7bc2b0e75f7320de5f993 Mon Sep 17 00:00:00 2001 From: Anthony Date: Mon, 26 Jul 2021 21:55:21 +0200 Subject: [PATCH] one bug left but almost working perfectly --- ui/component/walletSendTip/view.jsx | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/ui/component/walletSendTip/view.jsx b/ui/component/walletSendTip/view.jsx index 0e3d58890..c5ce96f1a 100644 --- a/ui/component/walletSendTip/view.jsx +++ b/ui/component/walletSendTip/view.jsx @@ -321,41 +321,22 @@ function WalletSendTip(props: Props) { function handleCustomPriceChange(event: SyntheticInputEvent<*>) { - console.log(event.target.value); - let tipAmountAsString = event.target.value; let tipAmount = parseFloat(tipAmountAsString); + const howManyDecimals = countDecimals(tipAmountAsString); + // allow maximum two decimals if (activeTab === TAB_FIAT) { - console.log(tipAmount); - - console.log(Number.isNaN(tipAmount)) - if (Number.isNaN(tipAmount)) { setCustomTipAmount(''); } - - const howManyDecimals = countDecimals(tipAmountAsString); - - console.log('how many decimals'); - console.log(howManyDecimals) - if (howManyDecimals > 2) { tipAmount = Math.floor(tipAmount * 100) / 100; - // setTipError('Value can only have two decimal places'); } - // else { - // tipAmount = ((tipAmount * 100) / 100).toFixed(2); - // } - - - // console.log(howManyDecimals); - - console.log(tipAmount); const howManyDigits = Math.trunc(tipAmount).toString().length; @@ -368,6 +349,11 @@ function WalletSendTip(props: Props) { setCustomTipAmount(tipAmount); } } else { + if (howManyDecimals > 9) { + tipAmount = Number(tipAmount.toString().match(/^-?\d+(?:\.\d{0,8})?/)[0]); + + setTipError('Please only use up to 8 decimals') + } setCustomTipAmount(tipAmount); } } @@ -601,7 +587,6 @@ function WalletSendTip(props: Props) { {__('Custom support amount')}{' '}