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

Fix max value for sending ETH #1978

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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