-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: toField misbehaving when swap button clicked with one wallet connected #94
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Improved handling of destination address state management in the bridge UI when swapping chains with a single connected wallet.
- Modified
useEffect
in/components/sections/bridge/tofield.tsx
to properly handletoAddress
state when switching between ETH/BASE and AVAIL chains - Added null checks for
selected
andethAddress
to prevent undefined address assignments - Simplified chain-specific address assignment logic into cleaner conditional blocks
- Improved dependency tracking in
useEffect
to 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: