Nodeify and promisify calls to background.

feature/default_network_editable
Kevin Serrano 8 years ago
parent 4562e41d33
commit cf2268c3d2
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
  1. 6
      app/scripts/metamask-controller.js
  2. 34
      ui/app/actions.js

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

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

Loading…
Cancel
Save