diff options
Made configuration migrateable
Abstract all configuration data into a singleton called `configManager`, who is responsible for reading and writing to the persisted storage (localStorage, in our case).
Uses my new module [pojo-migrator](https://www.npmjs.com/package/pojo-migrator), and wraps it with the `ConfigManager` class, which we can hang any state setting or getting methods we need.
By keeping all the persisted state in one place, we can stabilize its outward-facing API, making the interactions increasingly atomic, which will allow us to add features that require restructuring the persisted data in the long term without having to rewrite UI or even `background.js` code.
All the restructuring and data-type management is kept in one neat little place.
This should make it very easy to add new configuration options like user-configured providers, per-domain vaults, and more!
I know this doesn't seem like a big user-facing feature, but we have a big laundry list of features that I think this will really help streamline.
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r-- | app/scripts/background.js | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 1a0d36ef8..772c1de89 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -9,8 +9,7 @@ const PortStream = require('./lib/port-stream.js') const MetaMaskProvider = require('web3-provider-engine/zero.js') const IdentityStore = require('./lib/idStore') const createTxNotification = require('./lib/tx-notification.js') - -console.log('ready to roll') +const configManager = require('./lib/config-manager-singleton') // // connect to other contexts @@ -37,10 +36,9 @@ function handleEthRpcRequestStream(stream){ // state and network // -var config = getConfig() var idStore = new IdentityStore() var zeroClient = MetaMaskProvider({ - rpcUrl: config.rpcTarget, + rpcUrl: configManager.getCurrentRpcAddress(), getAccounts: function(cb){ var selectedAddress = idStore.getSelectedAddress() var result = selectedAddress ? [selectedAddress] : [] @@ -62,7 +60,7 @@ function getState(){ var state = extend( ethStore.getState(), idStore.getState(), - getConfig() + configManager.getConfig() ) return state } @@ -177,22 +175,10 @@ function addUnconfirmedTx(txParams, cb){ // called from popup function setRpcTarget(rpcTarget){ - var config = getConfig() - config.rpcTarget = rpcTarget - setConfig(config) + configManager.setRpcTarget(rpcTarget) chrome.runtime.reload() } -function getConfig(){ - return extend({ - rpcTarget: 'https://rawtestrpc.metamask.io/', - }, JSON.parse(localStorage['config'] || '{}')) -} - -function setConfig(state){ - localStorage['config'] = JSON.stringify(state) -} - // util function jsonParseStream(){ |