fix(bridge-ui): balance not updating on manual wallet connect #16312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
I experienced a lack of balance update when manually connecting my wallet to the bridge interface. The balance should display immediately upon connection, but I saw that "Balance: N/A" remained even after a successful wallet connection. This issue did not occur when the wallet auto-connected, it was only present when I needed to click the 'Connect Wallet' button.
Cause:
I believe the cause is in the
onNetworkChange
function, which has a condition that bothsrcChain
anddestChain
must be present to update the balance. This logic fails to account for cases where a user manually connects their wallet without a previous network change.Resolution:
To solve this, I modified the
onNetworkChange
function so the balance updates even if only thesrcChain
is present, which typically occurs when manually connecting a wallet. The updated logic now checks for the existence ofdestChain
, and if absent, proceeds withundefined
. The functionsgetTokenBalance
in bridge-ui/src/libs/token/fetchBalance.ts andgetAddress
in bridge-ui/src/libs/token/getAddress.ts seem unaffected by these changes since they can handle anundefined
value fordestChainId
.