From e78efab7efbf2001f39ac6639b5c160f25a8e1bd Mon Sep 17 00:00:00 2001 From: Anon dev Date: Fri, 8 Sep 2023 12:15:23 -0400 Subject: [PATCH] fix: bug in amount input --- .../src/views/Bridge/Inputs/AmountInput.tsx | 27 +++++-------------- wormhole-connect/src/views/Bridge/Preview.tsx | 3 ++- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/wormhole-connect/src/views/Bridge/Inputs/AmountInput.tsx b/wormhole-connect/src/views/Bridge/Inputs/AmountInput.tsx index bc2556347..de85dd4f3 100644 --- a/wormhole-connect/src/views/Bridge/Inputs/AmountInput.tsx +++ b/wormhole-connect/src/views/Bridge/Inputs/AmountInput.tsx @@ -1,12 +1,12 @@ import React, { useRef } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { RootState } from '../../../store'; -import { validate } from '../../../utils/transferValidation'; -import { toFixedDecimals } from '../../../utils/balance'; -import { NO_INPUT } from '../../../utils/style'; +import { RootState } from 'store'; +import { validate } from 'utils/transferValidation'; +import { toFixedDecimals } from 'utils/balance'; +import { NO_INPUT } from 'utils/style'; -import InputTransparent from '../../../components/InputTransparent'; +import InputTransparent from 'components/InputTransparent'; import Input from './Input'; type Props = { @@ -31,21 +31,8 @@ function AmountInput(props: Props) { ) { let value = e!.target.value; const index = value.indexOf('.'); - switch (true) { - case index === 0: { - value = '0.'; - break; - } - case Number.isInteger(Number.parseFloat(value)): { - break; - } - case index >= 0 && index < value.length - 1: { - value = toFixedDecimals(value, 8); - break; - } - default: { - break; - } + if (index > 0 && value.length - index - 8 > 0) { + value = toFixedDecimals(value, 8); } props.handleAmountChange(value); diff --git a/wormhole-connect/src/views/Bridge/Preview.tsx b/wormhole-connect/src/views/Bridge/Preview.tsx index 6c84e9c5b..cc25a72e2 100644 --- a/wormhole-connect/src/views/Bridge/Preview.tsx +++ b/wormhole-connect/src/views/Bridge/Preview.tsx @@ -83,8 +83,9 @@ function Preview(props: { collapsed: boolean }) { useEffect(() => { const computeRelayerFee = async () => { + if (!token || !fromChain || !toChain || !route) return; + try { - if (!token || !fromChain || !toChain || !route) return; const tokenConfig = token && TOKENS[token]; if (!tokenConfig) return;