mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
preferences - introduce preferences controller
This commit is contained in:
parent
b6909574a7
commit
0a1918f71a
30
app/scripts/lib/controllers/preferences.js
Normal file
30
app/scripts/lib/controllers/preferences.js
Normal file
@ -0,0 +1,30 @@
|
||||
const ObservableStore = require('obs-store')
|
||||
const normalizeAddress = require('../sig-util').normalize
|
||||
|
||||
class PreferencesController {
|
||||
|
||||
constructor (opts = {}) {
|
||||
const initState = opts.initState || {}
|
||||
this.store = new ObservableStore(initState)
|
||||
}
|
||||
|
||||
//
|
||||
// PUBLIC METHODS
|
||||
//
|
||||
|
||||
setSelectedAddress(_address) {
|
||||
const address = normalizeAddress(_address)
|
||||
this.store.updateState({ selectedAddress: address })
|
||||
}
|
||||
|
||||
getSelectedAddress(_address) {
|
||||
return this.store.getState().selectedAddress
|
||||
}
|
||||
|
||||
//
|
||||
// PRIVATE METHODS
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
module.exports = PreferencesController
|
@ -11,6 +11,7 @@ const streamIntoProvider = require('web3-stream-provider/handler')
|
||||
const MetaMaskProvider = require('web3-provider-engine/zero.js')
|
||||
const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
|
||||
const KeyringController = require('./keyring-controller')
|
||||
const PreferencesController = require('./lib/controllers/preferences')
|
||||
const NoticeController = require('./notice-controller')
|
||||
const messageManager = require('./lib/message-manager')
|
||||
const TxManager = require('./transaction-manager')
|
||||
@ -40,6 +41,11 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
})
|
||||
this.configManager.updateConversionRate()
|
||||
|
||||
// preferences controller
|
||||
this.prefencesController = new PreferencesController({
|
||||
initState: initState.PrefencesController,
|
||||
})
|
||||
|
||||
// rpc provider
|
||||
this.provider = this.initializeProvider(opts)
|
||||
this.provider.on('block', this.logBlock.bind(this))
|
||||
@ -101,6 +107,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
||||
this.keyringController.store.subscribe((state) => {
|
||||
this.store.updateState({ KeyringController: state })
|
||||
})
|
||||
this.prefencesController.store.subscribe((state) => {
|
||||
this.store.updateState({ PrefencesController: state })
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user