From 8012ede12698477692b80769781096b559159a32 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 19:04:19 -0800 Subject: background - introduce ObservableStore --- app/scripts/lib/config-manager.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'app/scripts/lib/config-manager.js') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 3a1f12ac0..01e6ccc3c 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -19,6 +19,7 @@ module.exports = ConfigManager function ConfigManager (opts) { // ConfigManager is observable and will emit updates this._subs = [] + this.store = opts.store /* The migrator exported on the config-manager * has two methods the user should be concerned with: @@ -36,12 +37,9 @@ function ConfigManager (opts) { // config data format, and returns the new one. migrations: migrations, - // How to load initial config. - // Includes step on migrating pre-pojo-migrator data. - loadData: opts.loadData, - - // How to persist migrated config. - setData: opts.setData, + // Data persistence methods + loadData: () => this.store.get(), + setData: (value) => this.store.put(value), }) } -- cgit From 3bc996878b467e1fa5fd63656bd465377daa137d Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 11 Jan 2017 22:47:56 -0800 Subject: background - move pojo migrator to outside of metamask controller --- app/scripts/lib/config-manager.js | 49 +++++++++++---------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) (limited to 'app/scripts/lib/config-manager.js') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 01e6ccc3c..6d7305377 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -1,6 +1,4 @@ -const Migrator = require('pojo-migrator') const MetamaskConfig = require('../config.js') -const migrations = require('./migrations') const ethUtil = require('ethereumjs-util') const normalize = require('./sig-util').normalize @@ -20,38 +18,17 @@ function ConfigManager (opts) { // ConfigManager is observable and will emit updates this._subs = [] this.store = opts.store - - /* The migrator exported on the config-manager - * has two methods the user should be concerned with: - * - * getData(), which returns the app-consumable data object - * saveData(), which persists the app-consumable data object. - */ - this.migrator = new Migrator({ - - // Migrations must start at version 1 or later. - // They are objects with a `version` number - // and a `migrate` function. - // - // The `migrate` function receives the previous - // config data format, and returns the new one. - migrations: migrations, - - // Data persistence methods - loadData: () => this.store.get(), - setData: (value) => this.store.put(value), - }) } ConfigManager.prototype.setConfig = function (config) { - var data = this.migrator.getData() + var data = this.store.get() data.config = config this.setData(data) this._emitUpdates(config) } ConfigManager.prototype.getConfig = function () { - var data = this.migrator.getData() + var data = this.store.get() if ('config' in data) { return data.config } else { @@ -94,15 +71,15 @@ ConfigManager.prototype.getProvider = function () { } ConfigManager.prototype.setData = function (data) { - this.migrator.saveData(data) + this.store.put(data) } ConfigManager.prototype.getData = function () { - return this.migrator.getData() + return this.store.get() } ConfigManager.prototype.setWallet = function (wallet) { - var data = this.migrator.getData() + var data = this.store.get() data.wallet = wallet this.setData(data) } @@ -119,11 +96,11 @@ ConfigManager.prototype.getVault = function () { } ConfigManager.prototype.getKeychains = function () { - return this.migrator.getData().keychains || [] + return this.store.get().keychains || [] } ConfigManager.prototype.setKeychains = function (keychains) { - var data = this.migrator.getData() + var data = this.store.get() data.keychains = keychains this.setData(data) } @@ -140,19 +117,19 @@ ConfigManager.prototype.setSelectedAccount = function (address) { } ConfigManager.prototype.getWallet = function () { - return this.migrator.getData().wallet + return this.store.get().wallet } // Takes a boolean ConfigManager.prototype.setShowSeedWords = function (should) { - var data = this.migrator.getData() + var data = this.store.get() data.showSeedWords = should this.setData(data) } ConfigManager.prototype.getShouldShowSeedWords = function () { - var data = this.migrator.getData() + var data = this.store.get() return data.showSeedWords } @@ -187,7 +164,7 @@ ConfigManager.prototype.getCurrentRpcAddress = function () { } ConfigManager.prototype.setData = function (data) { - this.migrator.saveData(data) + this.store.put(data) } // @@ -195,7 +172,7 @@ ConfigManager.prototype.setData = function (data) { // ConfigManager.prototype.getTxList = function () { - var data = this.migrator.getData() + var data = this.store.get() if (data.transactions !== undefined) { return data.transactions } else { @@ -204,7 +181,7 @@ ConfigManager.prototype.getTxList = function () { } ConfigManager.prototype.setTxList = function (txList) { - var data = this.migrator.getData() + var data = this.store.get() data.transactions = txList this.setData(data) } -- cgit From 76ce348a04b83693eda0e8a40f9888c1f5fe7ef5 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 24 Jan 2017 19:47:00 -0800 Subject: obs-store - use published module --- app/scripts/lib/config-manager.js | 44 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'app/scripts/lib/config-manager.js') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index daba8bc7b..6d088906c 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -21,14 +21,14 @@ function ConfigManager (opts) { } ConfigManager.prototype.setConfig = function (config) { - var data = this.store.get() + var data = this.getData() data.config = config this.setData(data) this._emitUpdates(config) } ConfigManager.prototype.getConfig = function () { - var data = this.store.get() + var data = this.getData() if ('config' in data) { return data.config } else { @@ -71,15 +71,15 @@ ConfigManager.prototype.getProvider = function () { } ConfigManager.prototype.setData = function (data) { - this.store.put(data) + this.store.putState(data) } ConfigManager.prototype.getData = function () { - return this.store.get() + return this.store.getState() } ConfigManager.prototype.setWallet = function (wallet) { - var data = this.store.get() + var data = this.getData() data.wallet = wallet this.setData(data) } @@ -96,11 +96,11 @@ ConfigManager.prototype.getVault = function () { } ConfigManager.prototype.getKeychains = function () { - return this.store.get().keychains || [] + return this.getData().keychains || [] } ConfigManager.prototype.setKeychains = function (keychains) { - var data = this.store.get() + var data = this.getData() data.keychains = keychains this.setData(data) } @@ -117,19 +117,19 @@ ConfigManager.prototype.setSelectedAccount = function (address) { } ConfigManager.prototype.getWallet = function () { - return this.store.get().wallet + return this.getData().wallet } // Takes a boolean ConfigManager.prototype.setShowSeedWords = function (should) { - var data = this.store.get() + var data = this.getData() data.showSeedWords = should this.setData(data) } ConfigManager.prototype.getShouldShowSeedWords = function () { - var data = this.store.get() + var data = this.getData() return data.showSeedWords } @@ -141,7 +141,7 @@ ConfigManager.prototype.setSeedWords = function (words) { ConfigManager.prototype.getSeedWords = function () { var data = this.getData() - return ('seedWords' in data) && data.seedWords + return data.seedWords } ConfigManager.prototype.getCurrentRpcAddress = function () { @@ -163,16 +163,12 @@ ConfigManager.prototype.getCurrentRpcAddress = function () { } } -ConfigManager.prototype.setData = function (data) { - this.store.put(data) -} - // // Tx // ConfigManager.prototype.getTxList = function () { - var data = this.store.get() + var data = this.getData() if (data.transactions !== undefined) { return data.transactions } else { @@ -181,7 +177,7 @@ ConfigManager.prototype.getTxList = function () { } ConfigManager.prototype.setTxList = function (txList) { - var data = this.store.get() + var data = this.getData() data.transactions = txList this.setData(data) } @@ -214,7 +210,7 @@ ConfigManager.prototype.setNicknameForWallet = function (account, nickname) { ConfigManager.prototype.getSalt = function () { var data = this.getData() - return ('salt' in data) && data.salt + return data.salt } ConfigManager.prototype.setSalt = function (salt) { @@ -248,7 +244,7 @@ ConfigManager.prototype.setConfirmedDisclaimer = function (confirmed) { ConfigManager.prototype.getConfirmedDisclaimer = function () { var data = this.getData() - return ('isDisclaimerConfirmed' in data) && data.isDisclaimerConfirmed + return data.isDisclaimerConfirmed } ConfigManager.prototype.setTOSHash = function (hash) { @@ -259,7 +255,7 @@ ConfigManager.prototype.setTOSHash = function (hash) { ConfigManager.prototype.getTOSHash = function () { var data = this.getData() - return ('TOSHash' in data) && data.TOSHash + return data.TOSHash } ConfigManager.prototype.setCurrentFiat = function (currency) { @@ -270,7 +266,7 @@ ConfigManager.prototype.setCurrentFiat = function (currency) { ConfigManager.prototype.getCurrentFiat = function () { var data = this.getData() - return ('fiatCurrency' in data) && data.fiatCurrency + return data.fiatCurrency } ConfigManager.prototype.updateConversionRate = function () { @@ -301,12 +297,12 @@ ConfigManager.prototype.setConversionDate = function (datestring) { ConfigManager.prototype.getConversionRate = function () { var data = this.getData() - return (('conversionRate' in data) && data.conversionRate) || 0 + return (data.conversionRate) || 0 } ConfigManager.prototype.getConversionDate = function () { var data = this.getData() - return (('conversionDate' in data) && data.conversionDate) || 'N/A' + return (data.conversionDate) || 'N/A' } ConfigManager.prototype.getShapeShiftTxList = function () { @@ -345,7 +341,7 @@ ConfigManager.prototype.createShapeShiftTx = function (depositAddress, depositTy ConfigManager.prototype.getGasMultiplier = function () { var data = this.getData() - return ('gasMultiplier' in data) && data.gasMultiplier + return data.gasMultiplier } ConfigManager.prototype.setGasMultiplier = function (gasMultiplier) { -- cgit