aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js110
1 files changed, 61 insertions, 49 deletions
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) => {