fix: toField misbehaving when swap button clicked with one wallet connected#94
Conversation
|
@mizanxali is attempting to deploy a commit to the Avail Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
PR Summary
Improved handling of destination address state management in the bridge UI when swapping chains with a single connected wallet.
- Modified
useEffectin/components/sections/bridge/tofield.tsxto properly handletoAddressstate when switching between ETH/BASE and AVAIL chains - Added null checks for
selectedandethAddressto prevent undefined address assignments - Simplified chain-specific address assignment logic into cleaner conditional blocks
- Improved dependency tracking in
useEffectto properly react to wallet connection changes
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
| useEffect(() => { | ||
| if (toChain === Chain.AVAIL && selected) { | ||
| setToAddress(selected.address); | ||
| if (toChain === Chain.AVAIL) { | ||
| setToAddress(selected ? selected.address : ""); | ||
| } | ||
| if ((toChain === Chain.BASE || toChain === Chain.ETH) && ethAddress) { | ||
| setToAddress(ethAddress); | ||
| if ((toChain === Chain.BASE || toChain === Chain.ETH)) { | ||
| setToAddress(ethAddress ?? ""); | ||
| } | ||
| }, [connected, selected, toChain]); |
There was a problem hiding this comment.
logic: Missing setToAddress in useEffect dependencies array. Could cause stale closure issues if setToAddress changes.
| if ((toChain === Chain.BASE || toChain === Chain.ETH)) { | ||
| setToAddress(ethAddress ?? ""); | ||
| } |
There was a problem hiding this comment.
logic: Missing fromChain in dependencies array. The toAddress should be reset when fromChain changes since it affects the wallet connection requirements.
the bug: when only one wallet is connected (AVAIL or ETH) - and you click on swap button twice, the wrong chain address is set in the toField component (refer screenshots)
steps to reproduce:
ideal behaviour: