|
|
@ -100,6 +100,14 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
encryptor: opts.encryptor || undefined, |
|
|
|
encryptor: opts.encryptor || undefined, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If only one account exists, make sure it is selected.
|
|
|
|
|
|
|
|
this.keyringController.store.subscribe((state) => { |
|
|
|
|
|
|
|
const addresses = Object.keys(state.walletNicknames || {}) |
|
|
|
|
|
|
|
if (addresses.length === 1) { |
|
|
|
|
|
|
|
const address = addresses[0] |
|
|
|
|
|
|
|
this.preferencesController.setSelectedAddress(address) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
this.keyringController.on('newAccount', (address) => { |
|
|
|
this.keyringController.on('newAccount', (address) => { |
|
|
|
this.preferencesController.setSelectedAddress(address) |
|
|
|
this.preferencesController.setSelectedAddress(address) |
|
|
|
this.accountTracker.addAccount(address) |
|
|
|
this.accountTracker.addAccount(address) |
|
|
@ -124,7 +132,6 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
provider: this.provider, |
|
|
|
provider: this.provider, |
|
|
|
blockTracker: this.blockTracker, |
|
|
|
blockTracker: this.blockTracker, |
|
|
|
ethQuery: this.ethQuery, |
|
|
|
ethQuery: this.ethQuery, |
|
|
|
accountTracker: this.accountTracker, |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts)) |
|
|
|
this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts)) |
|
|
|
|
|
|
|
|
|
|
@ -209,19 +216,17 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
initializeProvider () { |
|
|
|
initializeProvider () { |
|
|
|
return this.networkController.initializeProvider({ |
|
|
|
const providerOpts = { |
|
|
|
static: { |
|
|
|
static: { |
|
|
|
eth_syncing: false, |
|
|
|
eth_syncing: false, |
|
|
|
web3_clientVersion: `MetaMask/v${version}`, |
|
|
|
web3_clientVersion: `MetaMask/v${version}`, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// rpc data source
|
|
|
|
|
|
|
|
rpcUrl: this.networkController.getCurrentRpcAddress(), |
|
|
|
|
|
|
|
originHttpHeaderKey: 'X-Metamask-Origin', |
|
|
|
|
|
|
|
// account mgmt
|
|
|
|
// account mgmt
|
|
|
|
getAccounts: (cb) => { |
|
|
|
getAccounts: (cb) => { |
|
|
|
const isUnlocked = this.keyringController.memStore.getState().isUnlocked |
|
|
|
const isUnlocked = this.keyringController.memStore.getState().isUnlocked |
|
|
|
const result = [] |
|
|
|
const result = [] |
|
|
|
const selectedAddress = this.preferencesController.getSelectedAddress() |
|
|
|
const selectedAddress = this.preferencesController.getSelectedAddress() |
|
|
|
|
|
|
|
|
|
|
|
// only show address if account is unlocked
|
|
|
|
// only show address if account is unlocked
|
|
|
|
if (isUnlocked && selectedAddress) { |
|
|
|
if (isUnlocked && selectedAddress) { |
|
|
|
result.push(selectedAddress) |
|
|
|
result.push(selectedAddress) |
|
|
@ -234,7 +239,9 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
processMessage: this.newUnsignedMessage.bind(this), |
|
|
|
processMessage: this.newUnsignedMessage.bind(this), |
|
|
|
// personal_sign msg signing
|
|
|
|
// personal_sign msg signing
|
|
|
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), |
|
|
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
const providerProxy = this.networkController.initializeProvider(providerOpts) |
|
|
|
|
|
|
|
return providerProxy |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
initPublicConfigStore () { |
|
|
|
initPublicConfigStore () { |
|
|
@ -303,13 +310,14 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
const txController = this.txController |
|
|
|
const txController = this.txController |
|
|
|
const noticeController = this.noticeController |
|
|
|
const noticeController = this.noticeController |
|
|
|
const addressBookController = this.addressBookController |
|
|
|
const addressBookController = this.addressBookController |
|
|
|
|
|
|
|
const networkController = this.networkController |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
// etc
|
|
|
|
// etc
|
|
|
|
getState: (cb) => cb(null, this.getState()), |
|
|
|
getState: (cb) => cb(null, this.getState()), |
|
|
|
setProviderType: this.networkController.setProviderType.bind(this.networkController), |
|
|
|
|
|
|
|
setCurrentCurrency: this.setCurrentCurrency.bind(this), |
|
|
|
setCurrentCurrency: this.setCurrentCurrency.bind(this), |
|
|
|
markAccountsFound: this.markAccountsFound.bind(this), |
|
|
|
markAccountsFound: this.markAccountsFound.bind(this), |
|
|
|
|
|
|
|
|
|
|
|
// coinbase
|
|
|
|
// coinbase
|
|
|
|
buyEth: this.buyEth.bind(this), |
|
|
|
buyEth: this.buyEth.bind(this), |
|
|
|
// shapeshift
|
|
|
|
// shapeshift
|
|
|
@ -324,13 +332,15 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
// vault management
|
|
|
|
// vault management
|
|
|
|
submitPassword: this.submitPassword.bind(this), |
|
|
|
submitPassword: this.submitPassword.bind(this), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// network management
|
|
|
|
|
|
|
|
setProviderType: nodeify(networkController.setProviderType, networkController), |
|
|
|
|
|
|
|
setCustomRpc: nodeify(this.setCustomRpc, this), |
|
|
|
|
|
|
|
|
|
|
|
// PreferencesController
|
|
|
|
// PreferencesController
|
|
|
|
setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController), |
|
|
|
setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController), |
|
|
|
addToken: nodeify(preferencesController.addToken, preferencesController), |
|
|
|
addToken: nodeify(preferencesController.addToken, preferencesController), |
|
|
|
removeToken: nodeify(preferencesController.removeToken, preferencesController), |
|
|
|
removeToken: nodeify(preferencesController.removeToken, preferencesController), |
|
|
|
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController), |
|
|
|
setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController), |
|
|
|
setDefaultRpc: nodeify(this.setDefaultRpc, this), |
|
|
|
|
|
|
|
setCustomRpc: nodeify(this.setCustomRpc, this), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AddressController
|
|
|
|
// AddressController
|
|
|
|
setAddressBook: nodeify(addressBookController.setAddressBook, addressBookController), |
|
|
|
setAddressBook: nodeify(addressBookController.setAddressBook, addressBookController), |
|
|
@ -681,19 +691,13 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
createShapeShiftTx (depositAddress, depositType) { |
|
|
|
createShapeShiftTx (depositAddress, depositType) { |
|
|
|
this.shapeshiftController.createShapeShiftTx(depositAddress, depositType) |
|
|
|
this.shapeshiftController.createShapeShiftTx(depositAddress, depositType) |
|
|
|
} |
|
|
|
} |
|
|
|
// network
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setDefaultRpc () { |
|
|
|
// network
|
|
|
|
this.networkController.setRpcTarget('http://localhost:8545') |
|
|
|
|
|
|
|
return Promise.resolve('http://localhost:8545') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setCustomRpc (rpcTarget, rpcList) { |
|
|
|
async setCustomRpc (rpcTarget, rpcList) { |
|
|
|
this.networkController.setRpcTarget(rpcTarget) |
|
|
|
this.networkController.setRpcTarget(rpcTarget) |
|
|
|
|
|
|
|
await this.preferencesController.updateFrequentRpcList(rpcTarget) |
|
|
|
return this.preferencesController.updateFrequentRpcList(rpcTarget) |
|
|
|
return rpcTarget |
|
|
|
.then(() => { |
|
|
|
|
|
|
|
return Promise.resolve(rpcTarget) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|