mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
keyring - add and initialize obs-store
This commit is contained in:
parent
1fd1746744
commit
e9cdbf4f89
@ -1,12 +1,14 @@
|
|||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
const BN = ethUtil.BN
|
||||||
const bip39 = require('bip39')
|
const bip39 = require('bip39')
|
||||||
const EventEmitter = require('events').EventEmitter
|
const EventEmitter = require('events').EventEmitter
|
||||||
|
const ObservableStore = require('obs-store')
|
||||||
const filter = require('promise-filter')
|
const filter = require('promise-filter')
|
||||||
const encryptor = require('browser-passworder')
|
const encryptor = require('browser-passworder')
|
||||||
|
const createId = require('./lib/random-id')
|
||||||
const normalize = require('./lib/sig-util').normalize
|
const normalize = require('./lib/sig-util').normalize
|
||||||
const messageManager = require('./lib/message-manager')
|
const messageManager = require('./lib/message-manager')
|
||||||
const BN = ethUtil.BN
|
function noop () {}
|
||||||
|
|
||||||
// Keyrings:
|
// Keyrings:
|
||||||
const SimpleKeyring = require('./keyrings/simple')
|
const SimpleKeyring = require('./keyrings/simple')
|
||||||
@ -16,9 +18,8 @@ const keyringTypes = [
|
|||||||
HdKeyring,
|
HdKeyring,
|
||||||
]
|
]
|
||||||
|
|
||||||
const createId = require('./lib/random-id')
|
|
||||||
|
|
||||||
module.exports = class KeyringController extends EventEmitter {
|
class KeyringController extends EventEmitter {
|
||||||
|
|
||||||
// PUBLIC METHODS
|
// PUBLIC METHODS
|
||||||
//
|
//
|
||||||
@ -29,6 +30,8 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
constructor (opts) {
|
constructor (opts) {
|
||||||
super()
|
super()
|
||||||
|
const initState = opts.initState || {}
|
||||||
|
this.store = new ObservableStore(initState)
|
||||||
this.configManager = opts.configManager
|
this.configManager = opts.configManager
|
||||||
this.ethStore = opts.ethStore
|
this.ethStore = opts.ethStore
|
||||||
this.encryptor = encryptor
|
this.encryptor = encryptor
|
||||||
@ -643,5 +646,30 @@ module.exports = class KeyringController extends EventEmitter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Static Class Methods
|
||||||
|
//
|
||||||
|
|
||||||
|
KeyringController.selectFromState = (state) => {
|
||||||
|
const config = state.config
|
||||||
|
return {
|
||||||
|
vault: state.vault,
|
||||||
|
selectedAccount: config.selectedAccount,
|
||||||
|
walletNicknames: state.walletNicknames,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyringController.flattenToOldState = (state) => {
|
||||||
|
const data = {
|
||||||
|
vault: state.vault,
|
||||||
|
walletNicknames: state.walletNicknames,
|
||||||
|
config: {
|
||||||
|
selectedAccount: state.selectedAccount,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = KeyringController
|
||||||
|
|
||||||
function noop () {}
|
|
||||||
|
@ -29,9 +29,10 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
super()
|
super()
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
this.state = { network: 'loading' }
|
this.state = { network: 'loading' }
|
||||||
|
let initState = opts.initState || {}
|
||||||
|
|
||||||
// observable state store
|
// observable state store
|
||||||
this.store = new ObservableStore(opts.initState)
|
this.store = new ObservableStore(initState)
|
||||||
|
|
||||||
// config manager
|
// config manager
|
||||||
this.configManager = new ConfigManager({
|
this.configManager = new ConfigManager({
|
||||||
@ -50,6 +51,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
|
|
||||||
// key mgmt
|
// key mgmt
|
||||||
this.keyringController = new KeyringController({
|
this.keyringController = new KeyringController({
|
||||||
|
initState: initState.KeyringController,
|
||||||
ethStore: this.ethStore,
|
ethStore: this.ethStore,
|
||||||
configManager: this.configManager,
|
configManager: this.configManager,
|
||||||
getNetwork: this.getStateNetwork.bind(this),
|
getNetwork: this.getStateNetwork.bind(this),
|
||||||
|
Loading…
Reference in New Issue
Block a user