Skip to content

Commit

Permalink
Add chainId event
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm committed Sep 9, 2019
1 parent cdeac09 commit ab6fa45
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function MetamaskInpageProvider (connectionStream) {
const self = this
self.selectedAddress = undefined
self.networkVersion = undefined
self.chainId = undefined

// super constructor
SafeEventEmitter.call(self)
Expand Down Expand Up @@ -47,6 +48,12 @@ function MetamaskInpageProvider (connectionStream) {
self.networkVersion = state.networkVersion
self.emit('networkChanged', state.networkVersion)
}

// Emit networkChanged event on network change
if ('chainId' in state && state.chainId !== self.chainId) {
self.chainId = state.chainId
self.emit('chainIdChanged', state.chainId)
}
})

pump(
Expand Down

0 comments on commit ab6fa45

Please sign in to comment.