From fc1b11e373851ad4ab3a3f74e7d6850aebe6ba82 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 21:19:09 -0800 Subject: metamask - organize into sections --- app/scripts/metamask-controller.js | 110 ++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 49 deletions(-) (limited to 'app') diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index ec5fd498b..841e35db2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -98,6 +98,63 @@ module.exports = class MetamaskController extends EventEmitter { this.txManager.on('update', this.sendUpdate.bind(this)) } + // + // Constructor helpers + // + + initializeProvider () { + let provider = MetaMaskProvider({ + static: { + eth_syncing: false, + web3_clientVersion: `MetaMask/v${version}`, + }, + rpcUrl: this.configManager.getCurrentRpcAddress(), + // account mgmt + getAccounts: (cb) => { + let selectedAccount = this.configManager.getSelectedAccount() + let result = selectedAccount ? [selectedAccount] : [] + cb(null, result) + }, + // tx signing + processTransaction: (txParams, cb) => this.newUnapprovedTransaction(txParams, cb), + // msg signing + approveMessage: this.newUnsignedMessage.bind(this), + signMessage: (...args) => { + this.keyringController.signMessage(...args) + this.sendUpdate() + }, + }) + return provider + } + + initPublicConfigStore () { + // get init state + const publicConfigStore = new ObservableStore() + + // sync publicConfigStore with transform + pipe( + this.store, + storeTransform(selectPublicState), + publicConfigStore + ) + + function selectPublicState(state) { + const result = { selectedAccount: undefined } + try { + result.selectedAccount = state.config.selectedAccount + } catch (_) { + // thats fine, im sure it will be there next time... + } + return result + } + + return publicConfigStore + } + + // + // Constructor helpers + // + getState () { return this.keyringController.getState() .then((keyringControllerState) => { @@ -114,6 +171,10 @@ module.exports = class MetamaskController extends EventEmitter { }) } + // + // Remote Features + // + getApi () { const keyringController = this.keyringController const txManager = this.txManager @@ -253,55 +314,6 @@ module.exports = class MetamaskController extends EventEmitter { }) } - initializeProvider () { - let provider = MetaMaskProvider({ - static: { - eth_syncing: false, - web3_clientVersion: `MetaMask/v${version}`, - }, - rpcUrl: this.configManager.getCurrentRpcAddress(), - // account mgmt - getAccounts: (cb) => { - let selectedAccount = this.configManager.getSelectedAccount() - let result = selectedAccount ? [selectedAccount] : [] - cb(null, result) - }, - // tx signing - processTransaction: (txParams, cb) => this.newUnapprovedTransaction(txParams, cb), - // msg signing - approveMessage: this.newUnsignedMessage.bind(this), - signMessage: (...args) => { - this.keyringController.signMessage(...args) - this.sendUpdate() - }, - }) - return provider - } - - initPublicConfigStore () { - // get init state - const publicConfigStore = new ObservableStore() - - // sync publicConfigStore with transform - pipe( - this.store, - storeTransform(selectPublicState), - publicConfigStore - ) - - function selectPublicState(state) { - const result = { selectedAccount: undefined } - try { - result.selectedAccount = state.config.selectedAccount - } catch (_) { - // thats fine, im sure it will be there next time... - } - return result - } - - return publicConfigStore - } - newUnapprovedTransaction (txParams, cb) { const self = this self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => { -- cgit