aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2019-02-26 03:10:13 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2019-02-26 03:10:13 +0800
commitf507f2a92710285679123c9429a37c9e330c7cac (patch)
tree30225a55e9d8fc273304f4e2548413a08f008aef /app
parentfdc7eb211340b3af035a7f7c023155a8f1b1675d (diff)
downloadtangerine-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')
-rw-r--r--app/_locales/en/messages.json27
-rw-r--r--app/scripts/controllers/preferences.js13
-rw-r--r--app/scripts/metamask-controller.js58
3 files changed, 97 insertions, 1 deletions
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json
index ee6437116..2bfe0ef07 100644
--- a/app/_locales/en/messages.json
+++ b/app/_locales/en/messages.json
@@ -794,6 +794,12 @@
"minutesShorthand": {
"message": "Min"
},
+ "mobileSyncTitle": {
+ "message": "Sync accounts with mobile"
+ },
+ "mobileSyncText": {
+ "message": "Please enter your password to confirm it's you!"
+ },
"myAccounts": {
"message": "My Accounts"
},
@@ -1333,6 +1339,27 @@
"symbolBetweenZeroTwelve": {
"message": "Symbol must be between 0 and 12 characters."
},
+ "syncWithMobile": {
+ "message": "Sync with mobile"
+ },
+ "syncWithMobileTitle": {
+ "message": "Sync with mobile"
+ },
+ "syncWithMobileDesc": {
+ "message": "You can sync your accounts and information with your mobile device. Open the MetaMask mobile app, go to \"Settings\" and tap on \"Sync from Browser Extension\""
+ },
+ "syncWithMobileDescNewUsers": {
+ "message": "If you just open the MetaMask Mobile app for the first time, just follow the steps in your phone."
+ },
+ "syncWithMobileScanThisCode": {
+ "message": "Scan this code with your MetaMask mobile app"
+ },
+ "syncWithMobileBeCareful": {
+ "message": "Make sure nobody else is looking at your screen when you scan this code"
+ },
+ "syncWithMobileComplete": {
+ "message": "Your data has been synced succesfully. Enjoy the MetaMask mobile app!"
+ },
"takesTooLong": {
"message": "Taking too long?"
},
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