diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2019-02-26 03:10:13 +0800 |
---|---|---|
committer | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2019-02-26 03:10:13 +0800 |
commit | f507f2a92710285679123c9429a37c9e330c7cac (patch) | |
tree | 30225a55e9d8fc273304f4e2548413a08f008aef /app/scripts | |
parent | fdc7eb211340b3af035a7f7c023155a8f1b1675d (diff) | |
download | tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.tar tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.tar.gz tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.tar.bz2 tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.tar.lz tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.tar.xz tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.tar.zst tangerine-wallet-browser-f507f2a92710285679123c9429a37c9e330c7cac.zip |
Feature Flag + Mobile Sync (#5955)
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/controllers/preferences.js | 13 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 58 |
2 files changed, 70 insertions, 1 deletions
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 565f4f292..584b6bc51 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -18,7 +18,9 @@ class PreferencesController { * @property {object} store.assetImages Contains assets objects related to assets added * @property {boolean} store.useBlockie The users preference for blockie identicons within the UI * @property {object} store.featureFlags A key-boolean map, where keys refer to features and booleans to whether the - * user wishes to see that feature + * user wishes to see that feature. + * + * Feature flags can be set by the global function `setPreference(feature, enabled)`, and so should not expose any sensitive behavior. * @property {object} store.knownMethodData Contains all data methods known by the user * @property {string} store.currentLocale The preferred language locale key * @property {string} store.selectedAddress A hex string that matches the currently selected address in the app @@ -33,6 +35,11 @@ class PreferencesController { tokens: [], suggestedTokens: {}, useBlockie: false, + + // WARNING: Do not use feature flags for security-sensitive things. + // Feature flag toggling is available in the global namespace + // for convenient testing of pre-release features, and should never + // perform sensitive operations. featureFlags: {}, knownMethodData: {}, currentLocale: opts.initLangCode, @@ -52,6 +59,10 @@ class PreferencesController { this.store = new ObservableStore(initState) this.openPopup = opts.openPopup this._subscribeProviderType() + + global.setPreference = (key, value) => { + return this.setFeatureFlag(key, value) + } } // PUBLIC METHODS diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 6555f179d..41c3e3642 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -56,6 +56,7 @@ const EthQuery = require('eth-query') const ethUtil = require('ethereumjs-util') const sigUtil = require('eth-sig-util') + module.exports = class MetamaskController extends EventEmitter { /** @@ -410,6 +411,9 @@ module.exports = class MetamaskController extends EventEmitter { checkHardwareStatus: nodeify(this.checkHardwareStatus, this), unlockHardwareWalletAccount: nodeify(this.unlockHardwareWalletAccount, this), + // mobile + fetchInfoToSync: nodeify(this.fetchInfoToSync, this), + // vault management submitPassword: nodeify(this.submitPassword, this), @@ -586,6 +590,60 @@ module.exports = class MetamaskController extends EventEmitter { }) } + /** + * Collects all the information that we want to share + * with the mobile client for syncing purposes + * @returns Promise<Object> Parts of the state that we want to syncx + */ + async fetchInfoToSync () { + // Preferences + const { + accountTokens, + currentLocale, + frequentRpcList, + identities, + selectedAddress, + tokens, + } = this.preferencesController.store.getState() + + const preferences = { + accountTokens, + currentLocale, + frequentRpcList, + identities, + selectedAddress, + tokens, + } + + // Accounts + const hdKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0] + const hdAccounts = await hdKeyring.getAccounts() + const accounts = { + hd: hdAccounts.filter((item, pos) => (hdAccounts.indexOf(item) === pos)).map(address => ethUtil.toChecksumAddress(address)), + simpleKeyPair: [], + ledger: [], + trezor: [], + } + + // transactions + + let transactions = this.txController.store.getState().transactions + // delete tx for other accounts that we're not importing + transactions = transactions.filter(tx => { + const checksummedTxFrom = ethUtil.toChecksumAddress(tx.txParams.from) + return ( + accounts.hd.includes(checksummedTxFrom) + ) + }) + + return { + accounts, + preferences, + transactions, + network: this.networkController.store.getState(), + } + } + /* * Submits the user's password and attempts to unlock the vault. * Also synchronizes the preferencesController, to ensure its schema |