Skip to content

Commit

Permalink
Update accountsChanged event when logged out (#8)
Browse files Browse the repository at this point in the history
The `accountsChanged` event would previously return `[undefined]` upon
logout (i.e. when `selectedAddress` was undefined).

Instead an empty array is now returned if the user is not logged in.
This seems more semantically correct, and is more in-line with
EIP-1193, which states that the event should emit an array of strings.
  • Loading branch information
Gudahtt authored and danfinlay committed Sep 12, 2019
1 parent a96d94f commit a68536a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ function MetamaskInpageProvider (connectionStream) {
// Emit accountsChanged event on account change
if ('selectedAddress' in state && state.selectedAddress !== self.selectedAddress) {
self.selectedAddress = state.selectedAddress
self.emit('accountsChanged', [self.selectedAddress])
const accounts = state.selectedAddress ?
[state.selectedAddress] :
[]
self.emit('accountsChanged', accounts)
}

// Emit networkChanged event on network change
Expand Down

0 comments on commit a68536a

Please sign in to comment.