From 48789f2a3df2c820b61902fb49057f9f7b6cbd8c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 15 Jun 2017 16:22:53 -0700 Subject: Add ability to add tokens to token list Fiex #1616 --- app/scripts/controllers/preferences.js | 29 +++++++++++++++++++++++++---- app/scripts/metamask-controller.js | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index aa8e05fcc..e45224593 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -8,13 +8,11 @@ class PreferencesController { const initState = extend({ frequentRpcList: [], currentAccountTab: 'history', + tokens: [], }, opts.initState) this.store = new ObservableStore(initState) } - - // - // PUBLIC METHODS - // +// PUBLIC METHODS setSelectedAddress (_address) { return new Promise((resolve, reject) => { @@ -28,6 +26,29 @@ class PreferencesController { return this.store.getState().selectedAddress } + addToken (rawAddress, symbol, decimals) { + const address = normalizeAddress(rawAddress) + const newEntry = { address, symbol, decimals } + + const tokens = this.store.getState().tokens + const previousIndex = tokens.find((token, index) => { + return token.address === address + }) + + if (previousIndex) { + tokens[previousIndex] = newEntry + } else { + tokens.push(newEntry) + } + + this.store.updateState({ tokens }) + return Promise.resolve() + } + + getTokens () { + return this.store.getState().tokens + } + updateFrequentRpcList (_url) { return this.addToFrequentRpcList(_url) .then((rpcList) => { diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 410693df4..e4267381d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -275,6 +275,7 @@ module.exports = class MetamaskController extends EventEmitter { // PreferencesController setSelectedAddress: nodeify(preferencesController.setSelectedAddress).bind(preferencesController), + addToken: nodeify(preferencesController.addToken).bind(preferencesController), setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab).bind(preferencesController), setDefaultRpc: nodeify(this.setDefaultRpc).bind(this), setCustomRpc: nodeify(this.setCustomRpc).bind(this), -- cgit v1.2.3 From 235cb1f2d790a7bda349ab0d33ad1009751a8536 Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Mon, 19 Jun 2017 17:50:06 -0700 Subject: Keeps dapp gas price if set --- app/scripts/controllers/transactions.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index d9d9849b1..e3c2d74d3 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -152,13 +152,15 @@ module.exports = class TransactionController extends EventEmitter { const txParams = txMeta.txParams // ensure value txParams.value = txParams.value || '0x0' - this.query.gasPrice((err, gasPrice) => { - if (err) return cb(err) - // set gasPrice - txParams.gasPrice = gasPrice - // set gasLimit - this.txProviderUtils.analyzeGasUsage(txMeta, cb) - }) + if (!txParams.gasPrice) { + this.query.gasPrice((err, gasPrice) => { + if (err) return cb(err) + // set gasPrice + txParams.gasPrice = gasPrice + }) + } + // set gasLimit + this.txProviderUtils.analyzeGasUsage(txMeta, cb) } getUnapprovedTxList () { -- cgit v1.2.3 From db2836a1ae5bfb2e641ab2b68a9853297e97b64b Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 27 Jun 2017 14:19:28 -0700 Subject: dont stop retrying brodcasting txs --- app/scripts/controllers/transactions.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index f6dea34e7..31cf8239a 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -8,8 +8,6 @@ const TxProviderUtil = require('../lib/tx-utils') const createId = require('../lib/random-id') const denodeify = require('denodeify') -const RETRY_LIMIT = 200 - module.exports = class TransactionController extends EventEmitter { constructor (opts) { super() @@ -435,8 +433,6 @@ module.exports = class TransactionController extends EventEmitter { // Only auto-submit already-signed txs: if (!('rawTx' in txMeta)) return cb() - if (txMeta.retryCount > RETRY_LIMIT) return - // Increment a try counter. txMeta.retryCount++ const rawTx = txMeta.rawTx -- cgit v1.2.3 From 4e0ec74bb7cb36e2e0fa035bf653ce0e57b7c2e7 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 27 Jun 2017 14:59:37 -0700 Subject: Create a migration for setting tx's with the message 'Gave up submitting tx.' as failed --- app/scripts/migrations/015.js | 38 ++++++++++++++++++++++++++++++++++++++ app/scripts/migrations/index.js | 1 + 2 files changed, 39 insertions(+) create mode 100644 app/scripts/migrations/015.js (limited to 'app') diff --git a/app/scripts/migrations/015.js b/app/scripts/migrations/015.js new file mode 100644 index 000000000..4b839580b --- /dev/null +++ b/app/scripts/migrations/015.js @@ -0,0 +1,38 @@ +const version = 15 + +/* + +This migration sets transactions with the 'Gave up submitting tx.' err message +to a 'failed' stated + +*/ + +const clone = require('clone') + +module.exports = { + version, + + migrate: function (originalVersionedData) { + const versionedData = clone(originalVersionedData) + versionedData.meta.version = version + try { + const state = versionedData.data + const newState = transformState(state) + versionedData.data = newState + } catch (err) { + console.warn(`MetaMask Migration #${version}` + err.stack) + } + return Promise.resolve(versionedData) + }, +} + +function transformState (state) { + const newState = state + const transactions = newState.TransactionController.transactions + newState.TransactionController.transactions = transactions.map((txMeta) => { + if (!txMeta.err) return txMeta + else if (txMeta.err.message === 'Gave up submitting tx.') txMeta.status = 'failed' + return txMeta + }) + return newState +} diff --git a/app/scripts/migrations/index.js b/app/scripts/migrations/index.js index fb1ad7863..651ee6a9c 100644 --- a/app/scripts/migrations/index.js +++ b/app/scripts/migrations/index.js @@ -25,4 +25,5 @@ module.exports = [ require('./012'), require('./013'), require('./014'), + require('./015'), ] -- cgit v1.2.3 From d7bcd9458f994bc7599c97623bf73a0c3367d7cf Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 28 Jun 2017 10:41:58 -0700 Subject: Version 3.8.0 --- app/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/manifest.json b/app/manifest.json index 7ae20158c..1cd909732 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "3.7.8", + "version": "3.8.0", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", -- cgit v1.2.3 From 2e7be151c556ee672803e527f34485fc2f276e48 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 30 Jun 2017 13:55:04 -0700 Subject: Version 3.8.1 --- app/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/manifest.json b/app/manifest.json index 1cd909732..c0d9af8a0 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "3.8.0", + "version": "3.8.1", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", -- cgit v1.2.3 From af8015c1c58589386acd6a2d00111944cffac44f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 3 Jul 2017 18:06:47 -0700 Subject: Version 3.8.2 --- app/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/manifest.json b/app/manifest.json index c0d9af8a0..12ff6c2ea 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "3.8.1", + "version": "3.8.2", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", -- cgit v1.2.3 From 68fc3603dfe72721e080a80b9a4103408e113c6c Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 4 Jul 2017 12:48:00 -0700 Subject: metamask - append dapp origin domain to rpc request --- app/scripts/metamask-controller.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 782641b3f..73093dfad 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -184,7 +184,9 @@ module.exports = class MetamaskController extends EventEmitter { eth_syncing: false, web3_clientVersion: `MetaMask/v${version}`, }, + // rpc data source rpcUrl: this.networkController.getCurrentRpcAddress(), + originHttpHeaderKey: 'X-Metamask-Origin', // account mgmt getAccounts: (cb) => { const isUnlocked = this.keyringController.memStore.getState().isUnlocked @@ -356,8 +358,13 @@ module.exports = class MetamaskController extends EventEmitter { } setupProviderConnection (outStream, originDomain) { - streamIntoProvider(outStream, this.provider, logger) - function logger (err, request, response) { + streamIntoProvider(outStream, this.provider, onRequest, onResponse) + // append dapp origin domain to request + function onRequest (request) { + request.origin = originDomain + } + // log rpc activity + function onResponse (err, request, response) { if (err) return console.error(err) if (response.error) { console.error('Error in RPC response:\n', response.error) -- cgit v1.2.3 From 3abceac55d16e41b37116a8dda565644ed0a9f52 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 5 Jul 2017 22:06:39 -0700 Subject: Fail pending txs with low balance or invalid nonce --- app/scripts/controllers/transactions.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 52251d66e..3f5834756 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -428,10 +428,28 @@ module.exports = class TransactionController extends EventEmitter { const gtBalance = Number.parseInt(txMeta.txParams.value) > Number.parseInt(balance) if (!('retryCount' in txMeta)) txMeta.retryCount = 0 - // if the value of the transaction is greater then the balance - // or the nonce of the transaction is lower then the accounts nonce - // dont resubmit the tx - if (gtBalance || txNonce < nonce) return cb() + // if the value of the transaction is greater then the balance, fail. + if (gtBalance) { + txMeta.err = { + isWarning: true, + message: 'Insufficient balance.', + } + this.updateTx(txMeta) + cb() + return log.error(txMeta.err.message) + } + + // if the nonce of the transaction is lower then the accounts nonce, fail. + if (txNonce < nonce) { + txMeta.err = { + isWarning: true, + message: 'Invalid nonce.', + } + this.updateTx(txMeta) + cb() + return log.error(txMeta.err.message) + } + // Only auto-submit already-signed txs: if (!('rawTx' in txMeta)) return cb() -- cgit v1.2.3 From 07d4e4fe6f31d99a9f15c3862671c5c07831ff2a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 5 Jul 2017 23:23:57 -0700 Subject: Fix failing test --- app/scripts/controllers/transactions.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 3f5834756..7946d10d1 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -430,24 +430,18 @@ module.exports = class TransactionController extends EventEmitter { // if the value of the transaction is greater then the balance, fail. if (gtBalance) { - txMeta.err = { - isWarning: true, - message: 'Insufficient balance.', - } - this.updateTx(txMeta) + const message = 'Insufficient balance.' + this.setTxStatusFailed(txMeta.id, message) cb() - return log.error(txMeta.err.message) + return log.error(message) } // if the nonce of the transaction is lower then the accounts nonce, fail. if (txNonce < nonce) { - txMeta.err = { - isWarning: true, - message: 'Invalid nonce.', - } - this.updateTx(txMeta) + const message = 'Invalid nonce.' + this.setTxStatusFailed(txMeta.id, message) cb() - return log.error(txMeta.err.message) + return log.error(message) } // Only auto-submit already-signed txs: -- cgit v1.2.3 From 289fdfb7015d2e09306246b7a6871cdd40063118 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 6 Jul 2017 10:05:51 -0700 Subject: Version 3.8.3 --- app/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/manifest.json b/app/manifest.json index 12ff6c2ea..aafc33e66 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "3.8.2", + "version": "3.8.3", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", -- cgit v1.2.3 From 11b744bb87b4858dd2ef982c7d27e9751d8a09a1 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 6 Jul 2017 22:30:25 -0700 Subject: if an error happens during a tx publication set tx status to fail --- app/scripts/controllers/transactions.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 7946d10d1..8d3445c6f 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -240,7 +240,16 @@ module.exports = class TransactionController extends EventEmitter { this.updateTx(txMeta) this.txProviderUtils.publishTransaction(rawTx, (err, txHash) => { - if (err) return cb(err) + if (err) { + const errorMessage = err.message.toLowerCase() + if (errorMessage !== 'replacement transaction underpriced' + && errorMessage !== 'gas price too low to replace' + && !errorMessage.startsWith('known transaction') + ) { + this.setTxStatusFailed(txId) + } + return cb(err) + } this.setTxHash(txId, txHash) this.setTxStatusSubmitted(txId) cb() -- cgit v1.2.3 From 99556684096ed788ef01c909ff4cb4b0e61d3a05 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 6 Jul 2017 22:34:54 -0700 Subject: add comment --- app/scripts/controllers/transactions.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 8d3445c6f..14de786b7 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -241,11 +241,17 @@ module.exports = class TransactionController extends EventEmitter { this.txProviderUtils.publishTransaction(rawTx, (err, txHash) => { if (err) { - const errorMessage = err.message.toLowerCase() - if (errorMessage !== 'replacement transaction underpriced' - && errorMessage !== 'gas price too low to replace' - && !errorMessage.startsWith('known transaction') - ) { + const errorMessage = err.message.toLowerCase() + /* + Dont marked as failed if the error is because + it's a "known" transaction + "there is already a transaction with the same sender-nonce + but higher/same gas price" + */ + + if (errorMessage !== 'replacement transaction underpriced' // geth + && errorMessage !== 'gas price too low to replace' // parity + && !errorMessage.startsWith('known transaction')) { // geth this.setTxStatusFailed(txId) } return cb(err) -- cgit v1.2.3 From 8661989f516ae4455117e5158a97b4a6912a1980 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 7 Jul 2017 01:37:45 -0700 Subject: tx controller - move comments --- app/scripts/controllers/transactions.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 14de786b7..42baaaadc 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -249,9 +249,13 @@ module.exports = class TransactionController extends EventEmitter { but higher/same gas price" */ - if (errorMessage !== 'replacement transaction underpriced' // geth - && errorMessage !== 'gas price too low to replace' // parity - && !errorMessage.startsWith('known transaction')) { // geth + // geth + if (errorMessage !== 'replacement transaction underpriced' + // geth + && !errorMessage.startsWith('known transaction') + // parity + && errorMessage !== 'gas price too low to replace' + ) { this.setTxStatusFailed(txId) } return cb(err) -- cgit v1.2.3 From 34e2f6650d0db42b9f820d56a7acf9b72ca14da2 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 7 Jul 2017 01:50:48 -0700 Subject: tx controller - clean code --- app/scripts/controllers/transactions.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 42baaaadc..b855f910c 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -241,23 +241,24 @@ module.exports = class TransactionController extends EventEmitter { this.txProviderUtils.publishTransaction(rawTx, (err, txHash) => { if (err) { - const errorMessage = err.message.toLowerCase() /* - Dont marked as failed if the error is because - it's a "known" transaction + Dont marked as failed if the error is a "known" transaction warning "there is already a transaction with the same sender-nonce but higher/same gas price" */ - - // geth - if (errorMessage !== 'replacement transaction underpriced' - // geth - && !errorMessage.startsWith('known transaction') - // parity - && errorMessage !== 'gas price too low to replace' - ) { - this.setTxStatusFailed(txId) - } + const errorMessage = err.message.toLowerCase() + const isKnownTx = ( + // geth + errorMessage === 'replacement transaction underpriced' + || errorMessage.startsWith('known transaction') + // parity + || errorMessage === 'gas price too low to replace' + ) + // ignore resubmit warnings, return early + if (isKnownTx) return cb() + + // encountered unknown error, set status to failed + this.setTxStatusFailed(txId, err.message) return cb(err) } this.setTxHash(txId, txHash) -- cgit v1.2.3 From 092a9c9defd4d9bd2db7f969a8076c8b624d30bb Mon Sep 17 00:00:00 2001 From: frankiebee Date: Fri, 7 Jul 2017 03:05:39 -0700 Subject: fail transactions that fail in resubmit --- app/scripts/controllers/transactions.js | 47 +++++++++++++++------------------ 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index b855f910c..41d70194e 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -23,7 +23,10 @@ module.exports = class TransactionController extends EventEmitter { this.query = opts.ethQuery this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('rawBlock', this.checkForTxInBlock.bind(this)) - this.blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) + // this is a little messy but until ethstore has been either + // removed or redone this is to guard against the race condition + // where ethStore hasent been populated by the results yet + this.blockTracker.once('latest', () => this.blockTracker.on('latest', this.resubmitPendingTxs.bind(this))) this.blockTracker.on('sync', this.queryPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) @@ -240,27 +243,7 @@ module.exports = class TransactionController extends EventEmitter { this.updateTx(txMeta) this.txProviderUtils.publishTransaction(rawTx, (err, txHash) => { - if (err) { - /* - Dont marked as failed if the error is a "known" transaction warning - "there is already a transaction with the same sender-nonce - but higher/same gas price" - */ - const errorMessage = err.message.toLowerCase() - const isKnownTx = ( - // geth - errorMessage === 'replacement transaction underpriced' - || errorMessage.startsWith('known transaction') - // parity - || errorMessage === 'gas price too low to replace' - ) - // ignore resubmit warnings, return early - if (isKnownTx) return cb() - - // encountered unknown error, set status to failed - this.setTxStatusFailed(txId, err.message) - return cb(err) - } + if (err) return cb(err) this.setTxHash(txId, txHash) this.setTxStatusSubmitted(txId) cb() @@ -434,10 +417,24 @@ module.exports = class TransactionController extends EventEmitter { // only try resubmitting if their are transactions to resubmit if (!pending.length) return const resubmit = denodeify(this._resubmitTx.bind(this)) - Promise.all(pending.map(txMeta => resubmit(txMeta))) + pending.forEach((txMeta) => resubmit(txMeta) .catch((reason) => { - log.info('Problem resubmitting tx', reason) - }) + /* + Dont marked as failed if the error is a "known" transaction warning + "there is already a transaction with the same sender-nonce + but higher/same gas price" + */ + const errorMessage = reason.message.toLowerCase() + const isKnownTx = ( + // geth + errorMessage === 'replacement transaction underpriced' + || errorMessage.startsWith('known transaction') + // parity + || errorMessage === 'gas price too low to replace' + ) + // ignore resubmit warnings, return early + if (!isKnownTx) this.setTxStatusFailed(txMeta.id, reason.message) + })) } _resubmitTx (txMeta, cb) { -- cgit v1.2.3