From 8b186b072fa46df2032992267bb3fc6e581983e5 Mon Sep 17 00:00:00 2001 From: Alissa Crane Date: Wed, 21 Aug 2024 12:50:53 -0700 Subject: [PATCH] fix: Swap input amount bug fix (#1128) Co-authored-by: Alissa Crane --- .changeset/brave-icons-fix.md | 2 ++ src/swap/components/SwapProvider.tsx | 2 +- src/swap/utils/getAPIParamsForToken.ts | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.changeset/brave-icons-fix.md b/.changeset/brave-icons-fix.md index 34d5521322..56df4a4ba2 100644 --- a/.changeset/brave-icons-fix.md +++ b/.changeset/brave-icons-fix.md @@ -5,3 +5,5 @@ - **feat**: moved `onSuccess` and `onError` for Swap component at top level. By @zizzamia #1123 - **patch**: removed unneccessary address prop from `Transaction` component and fix issue where Sponsor component isn't visible. By @abcrane123 #1114 - **chore**: updated disconnect SVG image. By @cpcramer #1103 +- **fix**: improved issue with Swap where it wasn't fetching quote for amount without a leading 0. By @abcrane123 #1128 +g \ No newline at end of file diff --git a/src/swap/components/SwapProvider.tsx b/src/swap/components/SwapProvider.tsx index 580c1fd368..039a671b1d 100644 --- a/src/swap/components/SwapProvider.tsx +++ b/src/swap/components/SwapProvider.tsx @@ -103,7 +103,7 @@ export function SwapProvider({ if (source.token === undefined || destination.token === undefined) { return; } - if (amount === '' || Number.parseFloat(amount) === 0) { + if (amount === '' || amount === '.' || Number.parseFloat(amount) === 0) { return destination.setAmount(''); } diff --git a/src/swap/utils/getAPIParamsForToken.ts b/src/swap/utils/getAPIParamsForToken.ts index 47a9504342..3149eefdfe 100644 --- a/src/swap/utils/getAPIParamsForToken.ts +++ b/src/swap/utils/getAPIParamsForToken.ts @@ -33,7 +33,7 @@ export function getAPIParamsForToken( message: '', }; } - if (!/^(?:0|[1-9]\d*)(?:\.\d+)?$/.test(amount)) { + if (!/^(?:0|[1-9]\d*|\.\d+)(?:\.\d*)?$/.test(amount)) { return { code: 'INVALID_INPUT', error: 'Invalid input: amount must be a non-negative number string',