mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add minimal method signatures to new keyring controller
This commit is contained in:
parent
93ed918caa
commit
cd2c00a318
@ -1,11 +1,14 @@
|
|||||||
const scrypt = require('scrypt-async')
|
const scrypt = require('scrypt-async')
|
||||||
const bitcore = require('bitcore-lib')
|
const bitcore = require('bitcore-lib')
|
||||||
const configManager = require('./lib/config-manager')
|
const configManager = require('./lib/config-manager')
|
||||||
|
const EventEmitter = require('events').EventEmitter
|
||||||
|
|
||||||
module.exports = class KeyringController {
|
module.exports = class KeyringController extends EventEmitter {
|
||||||
|
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
|
super()
|
||||||
this.configManager = opts.configManager
|
this.configManager = opts.configManager
|
||||||
|
this.ethStore = opts.ethStore
|
||||||
this.keyChains = []
|
this.keyChains = []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +38,63 @@ module.exports = class KeyringController {
|
|||||||
scrypt(password, salt, logN, r, dkLen, interruptStep, cb, null)
|
scrypt(password, salt, logN, r, dkLen, interruptStep, cb, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getState() {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
setStore(ethStore) {
|
||||||
|
this.ethStore = ethStore
|
||||||
|
}
|
||||||
|
|
||||||
|
createNewVault(password, entropy, cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
|
submitPassword(password, cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedAddress(address, cb) {
|
||||||
|
this.selectedAddress = address
|
||||||
|
cb(null, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
approveTransaction(txId, cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelTransaction(txId, cb) {
|
||||||
|
if (cb && typeof cb === 'function') {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
signMessage(msgParams, cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelMessage(msgId, cb) {
|
||||||
|
if (cb && typeof cb === 'function') {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setLocked(cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
|
exportAccount(address, cb) {
|
||||||
|
cb(null, '0xPrivateKey')
|
||||||
|
}
|
||||||
|
|
||||||
|
saveAccountLabel(account, label, cb) {
|
||||||
|
cb(/* null, label */)
|
||||||
|
}
|
||||||
|
|
||||||
|
tryPassword(password, cb) {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateSalt (byteCount) {
|
function generateSalt (byteCount) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
const EthStore = require('eth-store')
|
const EthStore = require('eth-store')
|
||||||
const MetaMaskProvider = require('web3-provider-engine/zero.js')
|
const MetaMaskProvider = require('web3-provider-engine/zero.js')
|
||||||
const IdentityStore = require('./lib/idStore')
|
const IdentityStore = require('./keyring-controller')
|
||||||
const messageManager = require('./lib/message-manager')
|
const messageManager = require('./lib/message-manager')
|
||||||
const HostStore = require('./lib/remote-store.js').HostStore
|
const HostStore = require('./lib/remote-store.js').HostStore
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
@ -11,6 +11,7 @@ const extension = require('./lib/extension')
|
|||||||
module.exports = class MetamaskController {
|
module.exports = class MetamaskController {
|
||||||
|
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
|
this.state = { network: 'loading' }
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
this.listeners = []
|
this.listeners = []
|
||||||
this.configManager = new ConfigManager(opts)
|
this.configManager = new ConfigManager(opts)
|
||||||
@ -20,6 +21,7 @@ module.exports = class MetamaskController {
|
|||||||
this.provider = this.initializeProvider(opts)
|
this.provider = this.initializeProvider(opts)
|
||||||
this.ethStore = new EthStore(this.provider)
|
this.ethStore = new EthStore(this.provider)
|
||||||
this.idStore.setStore(this.ethStore)
|
this.idStore.setStore(this.ethStore)
|
||||||
|
this.getNetwork()
|
||||||
this.messageManager = messageManager
|
this.messageManager = messageManager
|
||||||
this.publicConfigStore = this.initPublicConfigStore()
|
this.publicConfigStore = this.initPublicConfigStore()
|
||||||
|
|
||||||
@ -30,11 +32,11 @@ module.exports = class MetamaskController {
|
|||||||
this.checkTOSChange()
|
this.checkTOSChange()
|
||||||
|
|
||||||
this.scheduleConversionInterval()
|
this.scheduleConversionInterval()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getState () {
|
getState () {
|
||||||
return extend(
|
return extend(
|
||||||
|
this.state,
|
||||||
this.ethStore.getState(),
|
this.ethStore.getState(),
|
||||||
this.idStore.getState(),
|
this.idStore.getState(),
|
||||||
this.configManager.getConfig()
|
this.configManager.getConfig()
|
||||||
@ -58,7 +60,6 @@ module.exports = class MetamaskController {
|
|||||||
|
|
||||||
// forward directly to idStore
|
// forward directly to idStore
|
||||||
createNewVault: idStore.createNewVault.bind(idStore),
|
createNewVault: idStore.createNewVault.bind(idStore),
|
||||||
recoverFromSeed: idStore.recoverFromSeed.bind(idStore),
|
|
||||||
submitPassword: idStore.submitPassword.bind(idStore),
|
submitPassword: idStore.submitPassword.bind(idStore),
|
||||||
setSelectedAddress: idStore.setSelectedAddress.bind(idStore),
|
setSelectedAddress: idStore.setSelectedAddress.bind(idStore),
|
||||||
approveTransaction: idStore.approveTransaction.bind(idStore),
|
approveTransaction: idStore.approveTransaction.bind(idStore),
|
||||||
@ -66,12 +67,9 @@ module.exports = class MetamaskController {
|
|||||||
signMessage: idStore.signMessage.bind(idStore),
|
signMessage: idStore.signMessage.bind(idStore),
|
||||||
cancelMessage: idStore.cancelMessage.bind(idStore),
|
cancelMessage: idStore.cancelMessage.bind(idStore),
|
||||||
setLocked: idStore.setLocked.bind(idStore),
|
setLocked: idStore.setLocked.bind(idStore),
|
||||||
clearSeedWordCache: idStore.clearSeedWordCache.bind(idStore),
|
|
||||||
exportAccount: idStore.exportAccount.bind(idStore),
|
exportAccount: idStore.exportAccount.bind(idStore),
|
||||||
revealAccount: idStore.revealAccount.bind(idStore),
|
|
||||||
saveAccountLabel: idStore.saveAccountLabel.bind(idStore),
|
saveAccountLabel: idStore.saveAccountLabel.bind(idStore),
|
||||||
tryPassword: idStore.tryPassword.bind(idStore),
|
tryPassword: idStore.tryPassword.bind(idStore),
|
||||||
recoverSeed: idStore.recoverSeed.bind(idStore),
|
|
||||||
// coinbase
|
// coinbase
|
||||||
buyEth: this.buyEth.bind(this),
|
buyEth: this.buyEth.bind(this),
|
||||||
// shapeshift
|
// shapeshift
|
||||||
@ -160,11 +158,11 @@ module.exports = class MetamaskController {
|
|||||||
|
|
||||||
var provider = MetaMaskProvider(providerOpts)
|
var provider = MetaMaskProvider(providerOpts)
|
||||||
var web3 = new Web3(provider)
|
var web3 = new Web3(provider)
|
||||||
|
this.web3 = web3
|
||||||
idStore.web3 = web3
|
idStore.web3 = web3
|
||||||
idStore.getNetwork()
|
|
||||||
|
|
||||||
provider.on('block', this.processBlock.bind(this))
|
provider.on('block', this.processBlock.bind(this))
|
||||||
provider.on('error', idStore.getNetwork.bind(idStore))
|
provider.on('error', this.getNetwork.bind(this))
|
||||||
|
|
||||||
return provider
|
return provider
|
||||||
}
|
}
|
||||||
@ -261,8 +259,8 @@ module.exports = class MetamaskController {
|
|||||||
|
|
||||||
verifyNetwork () {
|
verifyNetwork () {
|
||||||
// Check network when restoring connectivity:
|
// Check network when restoring connectivity:
|
||||||
if (this.idStore._currentState.network === 'loading') {
|
if (this.state.network === 'loading') {
|
||||||
this.idStore.getNetwork()
|
this.getNetwork()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,13 +343,13 @@ module.exports = class MetamaskController {
|
|||||||
setRpcTarget (rpcTarget) {
|
setRpcTarget (rpcTarget) {
|
||||||
this.configManager.setRpcTarget(rpcTarget)
|
this.configManager.setRpcTarget(rpcTarget)
|
||||||
extension.runtime.reload()
|
extension.runtime.reload()
|
||||||
this.idStore.getNetwork()
|
this.getNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
setProviderType (type) {
|
setProviderType (type) {
|
||||||
this.configManager.setProviderType(type)
|
this.configManager.setProviderType(type)
|
||||||
extension.runtime.reload()
|
extension.runtime.reload()
|
||||||
this.idStore.getNetwork()
|
this.getNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
useEtherscanProvider () {
|
useEtherscanProvider () {
|
||||||
@ -362,7 +360,7 @@ module.exports = class MetamaskController {
|
|||||||
buyEth (address, amount) {
|
buyEth (address, amount) {
|
||||||
if (!amount) amount = '5'
|
if (!amount) amount = '5'
|
||||||
|
|
||||||
var network = this.idStore._currentState.network
|
var network = this.state.network
|
||||||
var url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`
|
var url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH`
|
||||||
|
|
||||||
if (network === '2') {
|
if (network === '2') {
|
||||||
@ -377,4 +375,24 @@ module.exports = class MetamaskController {
|
|||||||
createShapeShiftTx (depositAddress, depositType) {
|
createShapeShiftTx (depositAddress, depositType) {
|
||||||
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNetwork(err) {
|
||||||
|
if (err) {
|
||||||
|
this.state.network = 'loading'
|
||||||
|
this.sendUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.web3.version.getNetwork((err, network) => {
|
||||||
|
if (err) {
|
||||||
|
this.state.network = 'loading'
|
||||||
|
return this.sendUpdate()
|
||||||
|
}
|
||||||
|
if (global.METAMASK_DEBUG) {
|
||||||
|
console.log('web3.getNetwork returned ' + network)
|
||||||
|
}
|
||||||
|
this.state.network = network
|
||||||
|
this.sendUpdate()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,8 @@ function createNewVault (password, entropy) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return dispatch(actions.showWarning(err.message))
|
return dispatch(actions.showWarning(err.message))
|
||||||
}
|
}
|
||||||
dispatch(actions.goHome())
|
dispatch(this.goHome())
|
||||||
|
dispatch(this.hideLoadingIndication())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user