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

ethereum.selectedAddress update is delayed. #9027

Closed
DeltaBalances opened this issue Jul 17, 2020 · 1 comment · Fixed by #9046
Closed

ethereum.selectedAddress update is delayed. #9027

DeltaBalances opened this issue Jul 17, 2020 · 1 comment · Fixed by #9046

Comments

@DeltaBalances
Copy link

DeltaBalances commented Jul 17, 2020

Describe the bug
A minor bug, but ethereum.selectedAddress isn't immediately changed on the accountsChanged event, which is different behaviour from the previous version. Calling ethereum.selectedAddress from within the callback will return the old account.
A small timeout in javascript will show the change happening.

ethereum.selectedAddress is marked as deprecated in the docs, but it is still available for now.

No big issue because the accounts value is correct, but it might cause issues in a case where the callback calls a function that internally uses selectedAccount.

To Reproduce (REQUIRED)
MetaMask with 2 accounts connected.

Take the following javascript logging:

window.ethereum.on("accountsChanged", function (accounts) {
    if (accounts && accounts.length > 0) {
        console.log('log1: ' + accounts[0] + ' - ' + ethereum.selectedAddress);
        // wait for 1 millisecond to log again
        window.setTimeout(function() {
            console.log('log2: ' + accounts[0] + ' - ' + ethereum.selectedAddress);
        }, 1);
    }
})

log1 prints the accounts immediately after the event and log2 is identical with a small delay.

MetaMask 8.0.4

  • on MetaMask login
    log1: account1 - null
    log2: account1 - account1
  • on change from account1 -> account2 in MetaMask
    log1: account2 - account1
    log2: account2 - account2

MetaMask 7.7.9

  • on MetaMask login
    log1: account1 - account1
    log2: account1 - account1
  • on change from account1 -> account2 in MetaMask
    log1: account2 - account2
    log2: account2 - account2

Browser details (please complete the following information):

  • OS: Windows 10
  • Metamask 7.7.9 & MetaMask 8.0.4 on Firefox 78.0.2 & Brave 1.2.43.
@rekmarks
Copy link
Member

@DeltaBalances thank you for bringing this to our attention. This will be fixed in MetaMask@8.0.6. We'll keep the issue open until then.

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 a pull request may close this issue.

2 participants