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

metamask - organize into sections

This commit is contained in:
kumavis 2017-01-26 21:19:09 -08:00
parent 832772414e
commit fc1b11e373

View File

@ -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) => {