Skip to content

Commit

Permalink
Convert publicConfigStore to singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed Jan 13, 2021
1 parent 5cf9763 commit 7062fdf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ export default class MetamaskController extends EventEmitter {
) {
this.submitPassword(password)
}

// TODO:LegacyProvider: Delete
this.publicConfigStore = this.createPublicConfigStore()
}

/**
Expand Down Expand Up @@ -462,6 +465,7 @@ export default class MetamaskController extends EventEmitter {
}

/**
* TODO:LegacyProvider: Delete
* Constructor helper: initialize a public config store.
* This store is used to make some config info available to Dapps synchronously.
*/
Expand All @@ -474,11 +478,6 @@ export default class MetamaskController extends EventEmitter {
this.on('update', updatePublicConfigStore)
updatePublicConfigStore(this.getState())

publicConfigStore.destroy = () => {
this.removeEventListener &&
this.removeEventListener('update', updatePublicConfigStore)
}

function updatePublicConfigStore(memState) {
const chainId = networkController.getCurrentChainId()
if (memState.network !== 'loading') {
Expand Down Expand Up @@ -1870,6 +1869,7 @@ export default class MetamaskController extends EventEmitter {
// messages between inpage and background
this.setupProviderConnection(mux.createStream('metamask-provider'), sender)

// TODO:LegacyProvider: Delete
// legacy streams
this.setupPublicConfig(mux.createStream('publicConfig'))
}
Expand Down Expand Up @@ -2058,6 +2058,7 @@ export default class MetamaskController extends EventEmitter {
}

/**
* TODO:LegacyProvider: Delete
* A method for providing our public config info over a stream.
* This includes info we like to be synchronous if possible, like
* the current selected account, and network ID.
Expand All @@ -2068,11 +2069,9 @@ export default class MetamaskController extends EventEmitter {
* @param {*} outStream - The stream to provide public config over.
*/
setupPublicConfig(outStream) {
const configStore = this.createPublicConfigStore()
const configStream = storeAsStream(configStore)
const configStream = storeAsStream(this.publicConfigStore)

pump(configStream, outStream, (err) => {
configStore.destroy()
configStream.destroy()
if (err) {
log.error(err)
Expand Down

0 comments on commit 7062fdf

Please sign in to comment.