diff options
Improve refactor
Replace config-manager-singleton with one that is instantiated within the `background-controller`, and takes its persistence callbacks from its instantiated options.
Replaced class getters with more familiar get___() functions.
Diffstat (limited to 'app/scripts/lib/config-manager.js')
-rw-r--r-- | app/scripts/lib/config-manager.js | 55 |
1 files changed, 3 insertions, 52 deletions
diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index a3ff0bdfb..9793728bb 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -3,7 +3,6 @@ const extend = require('xtend') const MetamaskConfig = require('../config.js') const migrations = require('./migrations') -const STORAGE_KEY = 'metamask-config' const TESTNET_RPC = MetamaskConfig.network.testnet const MAINNET_RPC = MetamaskConfig.network.mainnet @@ -15,7 +14,7 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet * particular portions of the state. */ module.exports = ConfigManager -function ConfigManager () { +function ConfigManager (opts) { // ConfigManager is observable and will emit updates this._subs = [] @@ -37,12 +36,10 @@ function ConfigManager () { // How to load initial config. // Includes step on migrating pre-pojo-migrator data. - loadData: loadData, + loadData: opts.loadData, // How to persist migrated config. - setData: function (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) - }, + setData: opts.setData, }) } @@ -280,49 +277,3 @@ ConfigManager.prototype.getConfirmed = function () { return ('isConfirmed' in data) && data.isConfirmed } -function loadData () { - var oldData = getOldStyleData() - var newData - try { - newData = JSON.parse(window.localStorage[STORAGE_KEY]) - } catch (e) {} - - var data = extend({ - meta: { - version: 0, - }, - data: { - config: { - provider: { - type: 'testnet', - }, - }, - }, - }, oldData || null, newData || null) - return data -} - -function getOldStyleData () { - var config, wallet, seedWords - - var result = { - meta: { version: 0 }, - data: {}, - } - - try { - config = JSON.parse(window.localStorage['config']) - result.data.config = config - } catch (e) {} - try { - wallet = JSON.parse(window.localStorage['lightwallet']) - result.data.wallet = wallet - } catch (e) {} - try { - seedWords = window.localStorage['seedWords'] - result.data.seedWords = seedWords - } catch (e) {} - - return result -} - |