1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Nodeify and promisify calls to background.

This commit is contained in:
Kevin Serrano 2017-03-08 09:06:41 -08:00
parent 4562e41d33
commit cf2268c3d2
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
2 changed files with 29 additions and 11 deletions

View File

@ -244,8 +244,6 @@ module.exports = class MetamaskController extends EventEmitter {
return { return {
// etc // etc
getState: (cb) => cb(null, this.getState()), getState: (cb) => cb(null, this.getState()),
setDefaultRpc: this.setDefaultRpc.bind(this),
setCustomRpc: this.setCustomRpc.bind(this),
setProviderType: this.setProviderType.bind(this), setProviderType: this.setProviderType.bind(this),
useEtherscanProvider: this.useEtherscanProvider.bind(this), useEtherscanProvider: this.useEtherscanProvider.bind(this),
setCurrentCurrency: this.setCurrentCurrency.bind(this), setCurrentCurrency: this.setCurrentCurrency.bind(this),
@ -266,6 +264,8 @@ module.exports = class MetamaskController extends EventEmitter {
// PreferencesController // PreferencesController
setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController), setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController),
setDefaultRpc: nodeify(this.setDefaultRpc).bind(this),
setCustomRpc: nodeify(this.setCustomRpc).bind(this),
// KeyringController // KeyringController
setLocked: nodeify(keyringController.setLocked).bind(keyringController), setLocked: nodeify(keyringController.setLocked).bind(keyringController),
@ -666,6 +666,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.configManager.setRpcTarget('http://localhost:8545') this.configManager.setRpcTarget('http://localhost:8545')
extension.runtime.reload() extension.runtime.reload()
this.lookupNetwork() this.lookupNetwork()
return Promise.resolve('http://localhost:8545')
} }
setCustomRpc (rpcTarget, rpcList) { setCustomRpc (rpcTarget, rpcList) {
@ -674,6 +675,7 @@ module.exports = class MetamaskController extends EventEmitter {
.then(() => { .then(() => {
extension.runtime.reload() extension.runtime.reload()
this.lookupNetwork() this.lookupNetwork()
return Promise.resolve(rpcTarget)
}) })
} }

View File

@ -674,21 +674,37 @@ function markAccountsFound() {
// default rpc target refers to localhost:8545 in this instance. // default rpc target refers to localhost:8545 in this instance.
function setDefaultRpcTarget (rpcList) { function setDefaultRpcTarget (rpcList) {
log.debug(`background.setDefaultRpcTarget`) log.debug(`background.setDefaultRpcTarget`)
background.setDefaultRpc() return (dispatch) => {
return { background.setDefaultRpc((err, result) => {
type: actions.SET_RPC_TARGET, if (err) {
value: 'http://localhost:8545', console.error(err)
return dispatch(self.displayWarning('Had a problem changing networks.'))
}
dispatch(self.setRpc(result))
})
} }
} }
function setRpcTarget (newRpc) { function setRpcTarget (newRpc) {
return (dispatch) => {
log.debug(`background.setRpcTarget`) log.debug(`background.setRpcTarget`)
background.setCustomRpc(newRpc) return (dispatch) => {
return { background.setCustomRpc(newRpc, (err, result) => {
type: actions.SET_RPC_TARGET, if (err) {
value: newRpc, console.err(err)
return dispatch(self.displayWarning('Had a problem changing networks!'))
}
dispatch(self.setRpc(result))
})
} }
}
function setRpc (newRpc) {
return {
type: actions.SET_RPC_TARGET,
value: 'http://localhost:8545',
} }
} }