-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
accountsChanged fired two times #2162
Comments
Hi @ochikov To understand impact of this on users, could you elaborate more on what problems this causes for you? |
Two events are fired. First the event with the new account address and then once again the event with the old address. |
@ochikov And how is it impacting your experience? |
I am listening for the event and after the account is changed, I am reloading the page, and make some other App-specific tasks. Dispatching two events one after another with wrong data is affecting my experience as I cannot load the right data for the user. |
Same exact issue as described by the other users. This also happens on Android (Samsung S20+), the event fires twice with different data in both calls. First Event - Correct Account Address Now, this doesn't happen at all on the desktop version and is a specific issue to Metamask Mobile. |
Having the same issue here. For me, it doesn't even give me the 2 different events. They're always returning the account that was originally logged in. They're not returning the newly switched account in the accountChanged callback. Is this still an issue for you too? How did you fix it? @ochikov |
[MetaMask DEBUG]: Analytics 'trackEvent' - {category: "Accounts", action: "Account Modal", name: "Switched Accounts"} {}proto: Object undefined undefined |
same issue here on android metamask app |
Same for me. accountsChanged is fired two times after accounts switching. First time with a proper account and the second time with an initial account (an account which had been selected upon page loading). When switching back accountsChanged isn't fired at al. The only solution now is full page reload either manual by users or automatic. Anyway it doesn't give the best user experience. Metamask browser's extension behaves as expected. Fires accountsChanged only once with the correct value after accounts switching. |
Same bug happening for me. let onAccountsChangedCooldown = false
function onAccountsChanged (accounts) {
if (onAccountsChangedCooldown) return
onAccountsChangedCooldown = true
setTimeout(() => { onAccountsChangedCooldown = false }, 1000)
setAccount(accounts[0])
}
connection.on('accountsChanged', onAccountsChanged) I tried using throttle functions, but they only delayed the second event firing. |
I was not able to try the build locally yet, but looking at the code perhaps this metamask-mobile/app/components/Views/BrowserTab/index.js Lines 364 to 379 in 3f9d91c
metamask-mobile/app/components/Views/BrowserTab/index.js Lines 402 to 407 in 3f9d91c
|
I've been experiencing similar behavior but it triggers at least 8 times. I listen for accountsChanged and have event put my code block in a conditional to check whether the new account matches the account stored in a state variable. Still results in 8+ triggers. I am also not using any loops in my file |
For me, Any solution or hacks so far? 😔 |
@wyaricky |
This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 7 days. Thank you for your contributions. |
This issue was closed because it has been stalled for 7 days with no activity. If you feel this was closed in error please reopen and provide evidence on the current production app. Thank you for your contributions. |
accountsChanged fired two times when the account is changed on Mobile App when the page is opened from the integrated browser and account is changed.
The text was updated successfully, but these errors were encountered: