Skip to content

Commit

Permalink
fix(enter amount): switching empty amounts should remain empty (#6297)
Browse files Browse the repository at this point in the history
### Description

As the title

### Test plan

Before:
https://valora-app.slack.com/archives/C04B61SJ6DS/p1733247536281249?thread_ts=1733245811.844689&cid=C04B61SJ6DS

After:
https://github.com/user-attachments/assets/5108ab1f-73d7-4941-9ad0-17bf338dd302

### Related issues

- Related to RET-1271

### Backwards compatibility

Y
### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [ ] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
kathaypacific authored Dec 6, 2024
1 parent a21a900 commit c858ab0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/TokenEnterAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ describe('TokenEnterAmount', () => {

await act(() => result.current.handleToggleAmountType())
expect(result.current.amountType).toBe('local')
// the processedAmounts should be unchanged when toggling amount type with no amount entered
expect(result.current.processedAmounts).toStrictEqual({
token: { bignum: null, displayAmount: '' },
local: { bignum: null, displayAmount: '' },
})
})
})

Expand Down
3 changes: 2 additions & 1 deletion src/components/TokenEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ export function useEnterAmount(props: {
.replace(new RegExp(`[${decimalSeparator}]?0+$`), '')
: ''

const parsedTokenAmount = parseInputAmount(convertedLocalToToken, decimalSeparator)
const parsedTokenAmount =
amount === '' ? null : parseInputAmount(convertedLocalToToken, decimalSeparator)
const balanceInLocal = convertTokenToLocalAmount({
tokenAmount: props.token.balance,
tokenInfo: props.token,
Expand Down

0 comments on commit c858ab0

Please sign in to comment.