Skip to content

Commit b56c50e

Browse files
committed
Fix display bug caused by flipping inputs on SwapCreateScene
Because we're flipping the wallets and the amounts for each SwapInput component and each strategy to change this state is mixed between imperative and declarative, we converge with incorrect state. This is because the imperative change to the amounts happens to the SwapInput before it's wallet state is change (which is the declarative state change). Ultimately the mix of two techniques on state management is the cause of the bug. The solution is to add a delay to the imperative change, to allow for the component's state to be updated before making the imperative changes.
1 parent 1b4541a commit b56c50e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- fixed: Default swap pair logic from the trade modal was not prioritizing mainnet assets
1616
- fixed: "FIO Address does not exist" error after transferring a FIO name
1717
- fixed: Fix incorrect string comparison resulting in wrong rate used for 24 change calculation
18+
- fixed: Crypto amount display bug after flipping the wallet input on `SwapCreateScne`
1819
- removed: 'fasterpayments' payment type
1920
- removed: Turking bank transfer support
2021

src/components/scenes/SwapCreateScene.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,17 @@ export const SwapCreateScene = (props: Props) => {
215215
setInputNativeAmountFor(inputNativeAmountFor === 'from' ? 'to' : 'from')
216216

217217
// Swap the amounts:
218-
if (inputNativeAmountFor === 'from') {
219-
fromInputRef.current?.setAmount('fiat', '0')
220-
toInputRef.current?.setAmount('fiat', inputFiatAmount)
221-
} else {
222-
toInputRef.current?.setAmount('fiat', '0')
223-
fromInputRef.current?.setAmount('fiat', inputFiatAmount)
224-
}
218+
// Use setTimeout to allow the component's state to change before making
219+
// the imperative state changes.
220+
setTimeout(() => {
221+
if (inputNativeAmountFor === 'from') {
222+
fromInputRef.current?.setAmount('fiat', '0')
223+
toInputRef.current?.setAmount('fiat', inputFiatAmount)
224+
} else {
225+
toInputRef.current?.setAmount('fiat', '0')
226+
fromInputRef.current?.setAmount('fiat', inputFiatAmount)
227+
}
228+
}, 0)
225229
})
226230

227231
const handleSelectWallet = useHandler(async (walletId: string, tokenId: EdgeTokenId, direction: 'from' | 'to') => {

0 commit comments

Comments
 (0)