Skip to content

Commit

Permalink
fix: Swap input amount bug fix (#1128)
Browse files Browse the repository at this point in the history
Co-authored-by: Alissa Crane <[email protected]>
  • Loading branch information
abcrane123 and alissacrane-cb authored Aug 21, 2024
1 parent 59ec2e0 commit 8b186b0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changeset/brave-icons-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/swap/components/SwapProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}

Expand Down
2 changes: 1 addition & 1 deletion src/swap/utils/getAPIParamsForToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 8b186b0

Please sign in to comment.