From f7ef55d2fc05746f68051b9a858c65ebdc1536a6 Mon Sep 17 00:00:00 2001 From: nickkelly1 Date: Thu, 21 Nov 2024 19:01:33 -0600 Subject: [PATCH] fix: send input ui breaking with multiple periods --- .../providers/bitcoin/ui/send-transaction/index.vue | 5 ++++- .../common/ui/send-transaction/send-input-amount.vue | 11 +++++++++-- .../providers/ethereum/ui/send-transaction/index.vue | 4 +++- .../providers/solana/ui/send-transaction/index.vue | 4 +++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue index 476e459be..0019b36de 100644 --- a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue @@ -305,7 +305,10 @@ const isInputsValid = computed(() => { isSendToken.value ) return false; - if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false; + + const sendAmountBigNumber = new BigNumber(sendAmount.value) + if (sendAmountBigNumber.isNaN()) return false + if (sendAmountBigNumber.gt(assetMaxValue.value)) return false; return true; }); diff --git a/packages/extension/src/providers/common/ui/send-transaction/send-input-amount.vue b/packages/extension/src/providers/common/ui/send-transaction/send-input-amount.vue index 206a5fafd..d444b943a 100644 --- a/packages/extension/src/providers/common/ui/send-transaction/send-input-amount.vue +++ b/packages/extension/src/providers/common/ui/send-transaction/send-input-amount.vue @@ -73,9 +73,16 @@ const amount = computed({ const onlyNumber = ($event: KeyboardEvent) => { const keyCode = $event.keyCode ? $event.keyCode : $event.which; - if ((keyCode < 48 || keyCode > 57) && keyCode !== 46) { - $event.preventDefault(); + // Numeric + if (keyCode >= /* 0 */ 48 && keyCode <= /* 9 */ 57) { + return; } + // Only allow a single period + if (keyCode === /* '.' */ 46 && amount.value.indexOf('.') === -1) { + return; + } + // Alphabetical (/non-numeric) or mulitple periods. Don't propagate change + $event.preventDefault(); }; const changeFocus = () => { isFocus.value = !isFocus.value; diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index d042451b8..74929b82e 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -486,7 +486,9 @@ const isInputsValid = computed(() => { if (!isSendToken.value && !selectedNft.value.id) { return false; } - if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false; + const sendAmountBigNumber = new BigNumber(sendAmount.value) + if (sendAmountBigNumber.isNaN()) return false + if (sendAmountBigNumber.gt(assetMaxValue.value)) return false; if (gasCostValues.value.REGULAR.nativeValue === '0') return false; return true; }); diff --git a/packages/extension/src/providers/solana/ui/send-transaction/index.vue b/packages/extension/src/providers/solana/ui/send-transaction/index.vue index 12b74be95..55eaedd24 100644 --- a/packages/extension/src/providers/solana/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/solana/ui/send-transaction/index.vue @@ -399,7 +399,9 @@ const isInputsValid = computed(() => { if (!isSendToken.value && !selectedNft.value.id) { return false; } - if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false; + const sendAmountBigNumber = new BigNumber(sendAmount.value); + if (sendAmountBigNumber.isNaN()) return false; + if (sendAmountBigNumber.gt(assetMaxValue.value)) return false; return true; });