Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mizanxali
Copy link

@mizanxali mizanxali commented Jan 20, 2025

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:

  1. connect only one wallet (avail or eth)
  2. click on swap button twice
  3. avail address is set in eth address input field and vice versa

ideal behaviour:

  1. if the other wallet ain't connected, the input field should be blank
Screenshot 2025-01-20 at 11 40 02 PM Screenshot 2025-01-20 at 11 41 15 PM

Copy link

vercel bot commented Jan 20, 2025

@mizanxali is attempting to deploy a commit to the Avail Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

@greptile-apps greptile-apps bot left a 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 handle toAddress state when switching between ETH/BASE and AVAIL chains
  • Added null checks for selected and ethAddress 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

Comment on lines 16 to 23
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]);
Copy link

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.

Comment on lines +20 to 22
if ((toChain === Chain.BASE || toChain === Chain.ETH)) {
setToAddress(ethAddress ?? "");
}
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant