aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorEsteban MiƱo <efmino@uc.cl>2018-08-08 05:50:58 +0800
committerGitHub <noreply@github.com>2018-08-08 05:50:58 +0800
commit3f57d5f66b3bcb744f918238bf1831dbf9abec9c (patch)
tree2d1f6149928a6efaa38cc3c55afec6b5e1a7709e /app
parent00d1f6fec5457f05fb2e6aec1300dd2dbef51ec1 (diff)
parente9f74f005de581377bc0a605e4696840dfb95ba9 (diff)
downloadtangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.tar
tangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.tar.gz
tangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.tar.bz2
tangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.tar.lz
tangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.tar.xz
tangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.tar.zst
tangerine-wallet-browser-3f57d5f66b3bcb744f918238bf1831dbf9abec9c.zip
Merge branch 'develop' into WatchTokenFeature
Diffstat (limited to 'app')
-rw-r--r--app/_locales/en/messages.json3
-rw-r--r--app/phishing.html49
-rw-r--r--app/scripts/controllers/detect-tokens.js2
-rw-r--r--app/scripts/controllers/preferences.js94
-rw-r--r--app/scripts/metamask-controller.js3
-rw-r--r--app/scripts/migrations/028.js40
-rw-r--r--app/scripts/migrations/index.js1
7 files changed, 151 insertions, 41 deletions
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json
index 6f315bb7a..c4c19762d 100644
--- a/app/_locales/en/messages.json
+++ b/app/_locales/en/messages.json
@@ -513,6 +513,9 @@
"invalidRPC": {
"message": "Invalid RPC URI"
},
+ "invalidSeedPhrase": {
+ "message": "Invalid seed phrase"
+ },
"jsonFail": {
"message": "Something went wrong. Please make sure your JSON file is properly formatted."
},
diff --git a/app/phishing.html b/app/phishing.html
index 86f2985cc..e20c9ac9c 100644
--- a/app/phishing.html
+++ b/app/phishing.html
@@ -3,26 +3,29 @@
<html>
<head>
- <title>Phishing Warning</title>
+ <title>Dangerous Website Warning</title>
<style>
-body {
- background: #c50000;
- padding: 50px;
- display: flex;
- justify-content: center;
- font-family: sans-serif;
-}
-.centered {
- display: flex;
- flex-direction: column;
- justify-content: center;
- color: white;
- max-width: 600px;
-}
-a {
- color: white;
-}
+ body {
+ background: #c50000;
+ padding: 50px;
+ display: flex;
+ justify-content: center;
+ font-family: sans-serif;
+ }
+
+ .centered {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ color: white;
+ max-width: 600px;
+ }
+
+ a {
+ color: white;
+ }
+
</style>
<script>
@@ -50,11 +53,11 @@ a {
<img src="/images/ethereum-metamask-chrome.png" style="width:100%">
<h3>ATTENTION</h3>
- <p>MetaMask believes this domain to have malicious intent and has prevented you from interacting with it.</p>
- <p>This is because the site tested positive on the <a href="https://github.com/metamask/eth-phishing-detect">Ethereum Phishing Detector</a>.</p>
- <p>You can turn MetaMask off to interact with this site, but it's advised not to.</p>
- <p>If you think this domain is incorrectly flagged, <a href="https://github.com/metamask/eth-phishing-detect/issues/new">please file an issue</a>.</p>
+ <p>MetaMask believes this domain could currently compromise your security and has prevented you from interacting with it.</p>
+ <p>This is because the site tested positive on the <a href="https://github.com/metamask/eth-phishing-detect">Ethereum Phishing Detector</a>. This includes outright malicious websites and legitimate websites that have been compromised by a malicious actor.</p>
+ <p>You can turn MetaMask off to interact with this site, but it is advised not to.</p>
+ <p>If you think this domain is incorrectly flagged or if a blocked legitimate website has resolved its security issues, <a href="https://github.com/metamask/eth-phishing-detect/issues/new">please file an issue</a>.</p>
</div>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/app/scripts/controllers/detect-tokens.js b/app/scripts/controllers/detect-tokens.js
index 195ec918a..62e639795 100644
--- a/app/scripts/controllers/detect-tokens.js
+++ b/app/scripts/controllers/detect-tokens.js
@@ -85,7 +85,7 @@ class DetectTokensController {
set preferences (preferences) {
if (!preferences) { return }
this._preferences = preferences
- preferences.store.subscribe(({ tokens }) => { this.tokenAddresses = tokens.map((obj) => { return obj.address }) })
+ preferences.store.subscribe(({ tokens = [] }) => { this.tokenAddresses = tokens.map((obj) => { return obj.address }) })
preferences.store.subscribe(({ selectedAddress }) => {
if (this.selectedAddress !== selectedAddress) {
this.selectedAddress = selectedAddress
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index 3bbd48f06..a42bb77b3 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -14,6 +14,7 @@ class PreferencesController {
* @property {array} store.frequentRpcList A list of custom rpcs to provide the user
* @property {string} store.currentAccountTab Indicates the selected tab in the ui
* @property {array} store.tokens The tokens the user wants display in their token lists
+ * @property {object} store.accountTokens The tokens stored per account and then per network type
* @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
@@ -25,6 +26,7 @@ class PreferencesController {
const initState = extend({
frequentRpcList: [],
currentAccountTab: 'history',
+ accountTokens: {},
tokens: [],
suggestedTokens: {},
useBlockie: false,
@@ -35,9 +37,10 @@ class PreferencesController {
}, opts.initState)
this.diagnostics = opts.diagnostics
-
+ this.network = opts.network
this.store = new ObservableStore(initState)
this.showAddTokenUi = opts.showAddTokenUi
+ this._subscribeProviderType()
}
// PUBLIC METHODS
@@ -121,12 +124,19 @@ class PreferencesController {
*/
setAddresses (addresses) {
const oldIdentities = this.store.getState().identities
+ const oldAccountTokens = this.store.getState().accountTokens
+
const identities = addresses.reduce((ids, address, index) => {
const oldId = oldIdentities[address] || {}
ids[address] = {name: `Account ${index + 1}`, address, ...oldId}
return ids
}, {})
- this.store.updateState({ identities })
+ const accountTokens = addresses.reduce((tokens, address) => {
+ const oldTokens = oldAccountTokens[address] || {}
+ tokens[address] = oldTokens
+ return tokens
+ }, {})
+ this.store.updateState({ identities, accountTokens })
}
/**
@@ -137,11 +147,13 @@ class PreferencesController {
*/
removeAddress (address) {
const identities = this.store.getState().identities
+ const accountTokens = this.store.getState().accountTokens
if (!identities[address]) {
throw new Error(`${address} can't be deleted cause it was not found`)
}
delete identities[address]
- this.store.updateState({ identities })
+ delete accountTokens[address]
+ this.store.updateState({ identities, accountTokens })
// If the selected account is no longer valid,
// select an arbitrary other account:
@@ -161,14 +173,17 @@ class PreferencesController {
*/
addAddresses (addresses) {
const identities = this.store.getState().identities
+ const accountTokens = this.store.getState().accountTokens
addresses.forEach((address) => {
// skip if already exists
if (identities[address]) return
// add missing identity
const identityCount = Object.keys(identities).length
+
+ accountTokens[address] = {}
identities[address] = { name: `Account ${identityCount + 1}`, address }
})
- this.store.updateState({ identities })
+ this.store.updateState({ identities, accountTokens })
}
/*
@@ -226,15 +241,15 @@ class PreferencesController {
* Setter for the `selectedAddress` property
*
* @param {string} _address A new hex address for an account
- * @returns {Promise<void>} Promise resolves with undefined
+ * @returns {Promise<void>} Promise resolves with tokens
*
*/
setSelectedAddress (_address) {
- return new Promise((resolve, reject) => {
- const address = normalizeAddress(_address)
- this.store.updateState({ selectedAddress: address })
- resolve()
- })
+ const address = normalizeAddress(_address)
+ this._updateTokens(address)
+ this.store.updateState({ selectedAddress: address })
+ const tokens = this.store.getState().tokens
+ return Promise.resolve(tokens)
}
/**
@@ -283,9 +298,7 @@ class PreferencesController {
} else {
tokens.push(newEntry)
}
-
- this.store.updateState({ tokens })
-
+ this._updateAccountTokens(tokens)
return Promise.resolve(tokens)
}
@@ -298,10 +311,8 @@ class PreferencesController {
*/
removeToken (rawAddress) {
const tokens = this.store.getState().tokens
-
const updatedTokens = tokens.filter(token => token.address !== rawAddress)
-
- this.store.updateState({ tokens: updatedTokens })
+ this._updateAccountTokens(updatedTokens)
return Promise.resolve(updatedTokens)
}
@@ -443,6 +454,57 @@ class PreferencesController {
const numDecimals = parseInt(decimals, 10)
if (isNaN(numDecimals) || numDecimals > 18 || numDecimals < 0) throw new Error(`Invalid decimals ${decimals}`)
if (!isValidAddress(rawAddress)) throw new Error(`Invalid address ${rawAddress}`)
+
+ /**
+ * Subscription to network provider type.
+ *
+ *
+ */
+ _subscribeProviderType () {
+ this.network.providerStore.subscribe(() => {
+ const { tokens } = this._getTokenRelatedStates()
+ this.store.updateState({ tokens })
+ })
+ }
+
+ /**
+ * Updates `accountTokens` and `tokens` of current account and network according to it.
+ *
+ * @param {array} tokens Array of tokens to be updated.
+ *
+ */
+ _updateAccountTokens (tokens) {
+ const { accountTokens, providerType, selectedAddress } = this._getTokenRelatedStates()
+ accountTokens[selectedAddress][providerType] = tokens
+ this.store.updateState({ accountTokens, tokens })
+ }
+
+ /**
+ * Updates `tokens` of current account and network.
+ *
+ * @param {string} selectedAddress Account address to be updated with.
+ *
+ */
+ _updateTokens (selectedAddress) {
+ const { tokens } = this._getTokenRelatedStates(selectedAddress)
+ this.store.updateState({ tokens })
+ }
+
+ /**
+ * A getter for `tokens` and `accountTokens` related states.
+ *
+ * @param {string} selectedAddress A new hex address for an account
+ * @returns {Object.<array, object, string, string>} States to interact with tokens in `accountTokens`
+ *
+ */
+ _getTokenRelatedStates (selectedAddress) {
+ const accountTokens = this.store.getState().accountTokens
+ if (!selectedAddress) selectedAddress = this.store.getState().selectedAddress
+ const providerType = this.network.providerStore.getState().type
+ if (!(selectedAddress in accountTokens)) accountTokens[selectedAddress] = {}
+ if (!(providerType in accountTokens[selectedAddress])) accountTokens[selectedAddress][providerType] = []
+ const tokens = accountTokens[selectedAddress][providerType]
+ return { tokens, accountTokens, providerType, selectedAddress }
}
}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 801363cb0..1464b16a6 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -88,6 +88,7 @@ module.exports = class MetamaskController extends EventEmitter {
initState: initState.PreferencesController,
initLangCode: opts.initLangCode,
showAddTokenUi: opts.showAddTokenUi,
+ network: this.networkController,
})
// currency controller
@@ -1439,7 +1440,7 @@ module.exports = class MetamaskController extends EventEmitter {
}
/**
- * A method for activating the retrieval of price data and auto detect tokens,
+ * A method for activating the retrieval of price data,
* which should only be fetched when the UI is visible.
* @private
* @param {boolean} active - True if price data should be getting fetched.
diff --git a/app/scripts/migrations/028.js b/app/scripts/migrations/028.js
new file mode 100644
index 000000000..6553a1052
--- /dev/null
+++ b/app/scripts/migrations/028.js
@@ -0,0 +1,40 @@
+// next version number
+const version = 28
+
+/*
+
+normalizes txParams on unconfirmed txs
+
+*/
+const clone = require('clone')
+
+module.exports = {
+ version,
+
+ migrate: async function (originalVersionedData) {
+ const versionedData = clone(originalVersionedData)
+ versionedData.meta.version = version
+ const state = versionedData.data
+ const newState = transformState(state)
+ versionedData.data = newState
+ return versionedData
+ },
+}
+
+function transformState (state) {
+ const newState = state
+
+ if (newState.PreferencesController) {
+ if (newState.PreferencesController.tokens) {
+ const identities = newState.TransactionController.identities
+ const tokens = newState.PreferencesController.tokens
+ newState.PreferencesController.accountTokens = {}
+ for (const identity in identities) {
+ newState.PreferencesController.accountTokens[identity] = {'mainnet': tokens}
+ }
+ newState.PreferencesController.tokens = []
+ }
+ }
+
+ return newState
+}
diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js
index bd0005221..3b512715e 100644
--- a/app/scripts/migrations/index.js
+++ b/app/scripts/migrations/index.js
@@ -38,4 +38,5 @@ module.exports = [
require('./025'),
require('./026'),
require('./027'),
+ require('./028'),
]