Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Fix max value for sending ETH (#1978)
Browse files Browse the repository at this point in the history
Entered `max` value might be invalid by changing fees afterwards. This PR fixes it by resetting entered value to ZERO
whenever selected fee has been changed.
  • Loading branch information
veado authored Dec 15, 2021
1 parent 8de48ca commit 033ef55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Fix Tooltip styles [#1944](https://github.com/thorchain/asgardex-electron/pull/1944)
- [Swap] Limits added to memo needs to be 1e8 [#1946](https://github.com/thorchain/asgardex-electron/issues/1946)
- [PoolShare] Don't combine `asym` with `sym` shares in PoolShare [#1964](https://github.com/thorchain/asgardex-electron/pull/1964)
- [Send] Fix max value for sending ETH [#1978](https://github.com/thorchain/asgardex-electron/pull/1978)

## Internal

Expand Down
23 changes: 17 additions & 6 deletions src/renderer/components/wallet/txs/send/SendFormETH.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ export const SendFormETH: React.FC<Props> = (props): JSX.Element => {
)

const renderFeeOptions = useMemo(() => {
const onChangeHandler = (e: RadioChangeEvent) => setSelectedFeeOption(e.target.value)
const onChangeHandler = (e: RadioChangeEvent) => {
// Change amount back to `none` (ZERO) whenever selected fee is changed
// Just to avoid using a previous `max` value, which can be invalid now
setAmountToSend(O.none)
setSelectedFeeOption(e.target.value)
}
const disabled = !feesAvailable || isLoading

return (
Expand Down Expand Up @@ -216,13 +221,19 @@ export const SendFormETH: React.FC<Props> = (props): JSX.Element => {
}, [selectedFee, oEthAmount, balance])

useEffect(() => {
// Whenever `amountToSend` has been updated, we put it back into input field
FP.pipe(
amountToSend,
O.map((amount) =>
form.setFieldsValue({
amount: baseToAsset(amount).amount()
})
O.fold(
// reset value to ZERO whenever amount is not set
() =>
form.setFieldsValue({
amount: ZERO_BN
}),
// Whenever `amountToSend` has been updated, we put it back into input field
(amount) =>
form.setFieldsValue({
amount: baseToAsset(amount).amount()
})
)
)
}, [amountToSend, form])
Expand Down

0 comments on commit 033ef55

Please sign in to comment.