From 7854321faeeb8184b3171e3b214f57d6e61c0814 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Wed, 6 Dec 2017 22:49:24 +0100 Subject: Fix for #2644 - Specified Nonce isn't used Added nonceSpecified. And a check if nonce was specified - then we should use the specified nonce instead of generating a new one. --- app/scripts/controllers/transactions.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index ce709bd28..060484b87 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -177,6 +177,7 @@ module.exports = class TransactionController extends EventEmitter { const txParams = txMeta.txParams // ensure value txMeta.gasPriceSpecified = Boolean(txParams.gasPrice) + txMeta.nonceSpecified = Boolean(txParams.nonce) const gasPrice = txParams.gasPrice || await this.query.gasPrice() txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16)) txParams.value = txParams.value || '0x0' @@ -200,7 +201,11 @@ module.exports = class TransactionController extends EventEmitter { // wait for a nonce nonceLock = await this.nonceTracker.getNonceLock(fromAddress) // add nonce to txParams - txMeta.txParams.nonce = ethUtil.addHexPrefix(nonceLock.nextNonce.toString(16)) + if (txMeta.nonceSpecified) { + txMeta.txParams.nonce = ethUtil.addHexPrefix(txMeta.txParams.nonce.toString(16)) + } else { + txMeta.txParams.nonce = ethUtil.addHexPrefix(nonceLock.nextNonce.toString(16)) + } // add nonce debugging information to txMeta txMeta.nonceDetails = nonceLock.nonceDetails this.txStateManager.updateTx(txMeta, 'transactions#approveTransaction') -- cgit v1.2.3 From 6ff580584a74c6d85f54ce7cfc500db822904957 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 6 Dec 2017 22:20:11 -0500 Subject: Add retry background method and action --- app/scripts/controllers/transactions.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index ce709bd28..67043b401 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -184,6 +184,10 @@ module.exports = class TransactionController extends EventEmitter { return await this.txGasUtil.analyzeGasUsage(txMeta) } + async retryTransaction (txId) { + return this.txStateManager.setTxStatusUnapproved(txId) + } + async updateAndApproveTransaction (txMeta) { this.txStateManager.updateTx(txMeta, 'confTx: user approved transaction') await this.approveTransaction(txMeta.id) -- cgit v1.2.3 From 0e25129028dd45d717d27dfe0c06db8a4052bd4e Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 6 Dec 2017 23:42:47 -0500 Subject: Enforce retry tx at minimum gas of previous tx --- app/scripts/controllers/transactions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 67043b401..685db6269 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -185,7 +185,10 @@ module.exports = class TransactionController extends EventEmitter { } async retryTransaction (txId) { - return this.txStateManager.setTxStatusUnapproved(txId) + this.txStateManager.setTxStatusUnapproved(txId) + const txMeta = this.txStateManager.getTx(txId) + txMeta.lastGasPrice = txMeta.txParams.gasPrice + this.txStateManager.updateTx(txMeta, 'retryTransaction: manual retry') } async updateAndApproveTransaction (txMeta) { -- cgit v1.2.3 From 553d713636d317b74d819d62b5b931bdf2d112d8 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Thu, 7 Dec 2017 15:30:05 +0100 Subject: A more expressive way replaced ifs with ? : --- app/scripts/controllers/transactions.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 060484b87..6bdbd2cfc 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -201,11 +201,8 @@ module.exports = class TransactionController extends EventEmitter { // wait for a nonce nonceLock = await this.nonceTracker.getNonceLock(fromAddress) // add nonce to txParams - if (txMeta.nonceSpecified) { - txMeta.txParams.nonce = ethUtil.addHexPrefix(txMeta.txParams.nonce.toString(16)) - } else { - txMeta.txParams.nonce = ethUtil.addHexPrefix(nonceLock.nextNonce.toString(16)) - } + const nonce = txMeta.nonceSpecified ? txMeta.txParams.nonce : nonceLock.nextNonce + txMeta.txParams.nonce = ethUtil.addHexPrefix(nonce.toString(16)) // add nonce debugging information to txMeta txMeta.nonceDetails = nonceLock.nonceDetails this.txStateManager.updateTx(txMeta, 'transactions#approveTransaction') -- cgit v1.2.3 From 950ec9596c931055c3e0f2212f2733c9ca07739d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 7 Dec 2017 16:13:38 -0500 Subject: Do not allow nonces larger than the next valid nonce To avoid situations where a user signs a transaction that will become surprisingly valid in the future. --- app/scripts/controllers/transactions.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index bb408d445..6110b9c75 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -209,6 +209,10 @@ module.exports = class TransactionController extends EventEmitter { nonceLock = await this.nonceTracker.getNonceLock(fromAddress) // add nonce to txParams const nonce = txMeta.nonceSpecified ? txMeta.txParams.nonce : nonceLock.nextNonce + if (nonce > nonceLock.nextNonce) { + const message = `Specified nonce may not be larger than account's next valid nonce.` + throw new Error(message) + } txMeta.txParams.nonce = ethUtil.addHexPrefix(nonce.toString(16)) // add nonce debugging information to txMeta txMeta.nonceDetails = nonceLock.nonceDetails -- cgit v1.2.3 From a91200fd08b429c81d4096de17cdd9066a632ade Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 7 Dec 2017 18:04:14 -0500 Subject: tx-controller - failed state is a finished state --- app/scripts/controllers/transactions.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 6110b9c75..f95b5e39a 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -138,18 +138,20 @@ module.exports = class TransactionController extends EventEmitter { async newUnapprovedTransaction (txParams) { log.debug(`MetaMaskController newUnapprovedTransaction ${JSON.stringify(txParams)}`) - const txMeta = await this.addUnapprovedTransaction(txParams) - this.emit('newUnapprovedTx', txMeta) + const initialTxMeta = await this.addUnapprovedTransaction(txParams) + this.emit('newUnapprovedTx', initialTxMeta) // listen for tx completion (success, fail) return new Promise((resolve, reject) => { - this.txStateManager.once(`${txMeta.id}:finished`, (completedTx) => { - switch (completedTx.status) { + this.txStateManager.once(`${initialTxMeta.id}:finished`, (finishedTxMeta) => { + switch (finishedTxMeta.status) { case 'submitted': - return resolve(completedTx.hash) + return resolve(finishedTxMeta.hash) case 'rejected': return reject(new Error('MetaMask Tx Signature: User denied transaction signature.')) + case 'failed': + return reject(new Error(finishedTxMeta.err.message)) default: - return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(completedTx.txParams)}`)) + return reject(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(finishedTxMeta.txParams)}`)) } }) }) -- cgit v1.2.3 From 542e0035dd99d07f8a6613d231a36005c5b39825 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sat, 9 Dec 2017 19:58:09 -0500 Subject: Pass polling interval to zero client provider --- app/scripts/controllers/network.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 045bfcc5d..cee918796 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -106,7 +106,11 @@ module.exports = class NetworkController extends EventEmitter { } _configureStandardProvider (_providerParams) { - const providerParams = extend(this._baseProviderParams, _providerParams) + const providerParams = extend(this._baseProviderParams, _providerParams, { + engineParams: { + pollingInterval: 8000, + }, + }) const provider = createMetamaskProvider(providerParams) this._setProvider(provider) } -- cgit v1.2.3 From 33e6befdaa1c3f969581117b3ad6136ee263e353 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Dec 2017 13:51:36 -0800 Subject: network - for infura networks use the infura block tracker provider --- app/scripts/controllers/network.js | 57 +++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index cee918796..65d58008a 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -1,6 +1,7 @@ const assert = require('assert') const EventEmitter = require('events') const createMetamaskProvider = require('web3-provider-engine/zero.js') +const createInfuraProvider = require('eth-json-rpc-infura/src/createProvider') const ObservableStore = require('obs-store') const ComposedStore = require('obs-store/lib/composed') const extend = require('xtend') @@ -8,6 +9,7 @@ const EthQuery = require('eth-query') const createEventEmitterProxy = require('../lib/events-proxy.js') const RPC_ADDRESS_LIST = require('../config.js').network const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] +const INFURA_PROVIDER_TYPES = ['ropsten', 'rinkeby', 'kovan', 'mainnet'] module.exports = class NetworkController extends EventEmitter { @@ -24,8 +26,13 @@ module.exports = class NetworkController extends EventEmitter { initializeProvider (_providerParams) { this._baseProviderParams = _providerParams - const rpcUrl = this.getCurrentRpcAddress() - this._configureStandardProvider({ rpcUrl }) + const { type, rpcTarget } = this.providerStore.getState() + // map rpcTarget to rpcUrl + const opts = { + type, + rpcUrl: rpcTarget, + } + this._configureProvider(opts) this._proxy.on('block', this._logBlock.bind(this)) this._proxy.on('error', this.verifyNetwork.bind(this)) this.ethQuery = new EthQuery(this._proxy) @@ -83,7 +90,7 @@ module.exports = class NetworkController extends EventEmitter { const rpcTarget = this.getRpcAddressForType(type) assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`) this.providerStore.updateState({ type, rpcTarget }) - this._switchNetwork({ rpcUrl: rpcTarget }) + this._switchNetwork({ type }) } getProviderConfig () { @@ -99,14 +106,50 @@ module.exports = class NetworkController extends EventEmitter { // Private // - _switchNetwork (providerParams) { + _switchNetwork (opts) { this.setNetworkState('loading') - this._configureStandardProvider(providerParams) + this._configureProvider(opts) this.emit('networkDidChange') } - _configureStandardProvider (_providerParams) { - const providerParams = extend(this._baseProviderParams, _providerParams, { + _configureProvider (opts) { + // type-based rpc endpoints + const { type } = opts + if (type) { + // type-based infura rpc endpoints + const isInfura = INFURA_PROVIDER_TYPES.includes(type) + opts.rpcUrl = this.getRpcAddressForType(type) + if (isInfura) { + this._configureInfuraProvider(opts) + // other type-based rpc endpoints + } else { + this._configureStandardProvider(opts) + } + // url-based rpc endpoints + } else { + this._configureStandardProvider(opts) + } + } + + _configureInfuraProvider (opts) { + console.log('_configureInfuraProvider', opts) + const blockTrackerProvider = createInfuraProvider({ + network: opts.type, + }) + const providerParams = extend(this._baseProviderParams, { + rpcUrl: opts.rpcUrl, + engineParams: { + pollingInterval: 8000, + blockTrackerProvider, + }, + }) + const provider = createMetamaskProvider(providerParams) + this._setProvider(provider) + } + + _configureStandardProvider ({ rpcUrl }) { + const providerParams = extend(this._baseProviderParams, { + rpcUrl, engineParams: { pollingInterval: 8000, }, -- cgit v1.2.3 From 5df7dcd758c5a16b503a5ee237970c05c7e990c9 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 13 Dec 2017 17:46:56 -0800 Subject: Revert "network - for infura networks use the infura block tracker provider" --- app/scripts/controllers/network.js | 57 +++++--------------------------------- 1 file changed, 7 insertions(+), 50 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 65d58008a..cee918796 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -1,7 +1,6 @@ const assert = require('assert') const EventEmitter = require('events') const createMetamaskProvider = require('web3-provider-engine/zero.js') -const createInfuraProvider = require('eth-json-rpc-infura/src/createProvider') const ObservableStore = require('obs-store') const ComposedStore = require('obs-store/lib/composed') const extend = require('xtend') @@ -9,7 +8,6 @@ const EthQuery = require('eth-query') const createEventEmitterProxy = require('../lib/events-proxy.js') const RPC_ADDRESS_LIST = require('../config.js').network const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] -const INFURA_PROVIDER_TYPES = ['ropsten', 'rinkeby', 'kovan', 'mainnet'] module.exports = class NetworkController extends EventEmitter { @@ -26,13 +24,8 @@ module.exports = class NetworkController extends EventEmitter { initializeProvider (_providerParams) { this._baseProviderParams = _providerParams - const { type, rpcTarget } = this.providerStore.getState() - // map rpcTarget to rpcUrl - const opts = { - type, - rpcUrl: rpcTarget, - } - this._configureProvider(opts) + const rpcUrl = this.getCurrentRpcAddress() + this._configureStandardProvider({ rpcUrl }) this._proxy.on('block', this._logBlock.bind(this)) this._proxy.on('error', this.verifyNetwork.bind(this)) this.ethQuery = new EthQuery(this._proxy) @@ -90,7 +83,7 @@ module.exports = class NetworkController extends EventEmitter { const rpcTarget = this.getRpcAddressForType(type) assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`) this.providerStore.updateState({ type, rpcTarget }) - this._switchNetwork({ type }) + this._switchNetwork({ rpcUrl: rpcTarget }) } getProviderConfig () { @@ -106,50 +99,14 @@ module.exports = class NetworkController extends EventEmitter { // Private // - _switchNetwork (opts) { + _switchNetwork (providerParams) { this.setNetworkState('loading') - this._configureProvider(opts) + this._configureStandardProvider(providerParams) this.emit('networkDidChange') } - _configureProvider (opts) { - // type-based rpc endpoints - const { type } = opts - if (type) { - // type-based infura rpc endpoints - const isInfura = INFURA_PROVIDER_TYPES.includes(type) - opts.rpcUrl = this.getRpcAddressForType(type) - if (isInfura) { - this._configureInfuraProvider(opts) - // other type-based rpc endpoints - } else { - this._configureStandardProvider(opts) - } - // url-based rpc endpoints - } else { - this._configureStandardProvider(opts) - } - } - - _configureInfuraProvider (opts) { - console.log('_configureInfuraProvider', opts) - const blockTrackerProvider = createInfuraProvider({ - network: opts.type, - }) - const providerParams = extend(this._baseProviderParams, { - rpcUrl: opts.rpcUrl, - engineParams: { - pollingInterval: 8000, - blockTrackerProvider, - }, - }) - const provider = createMetamaskProvider(providerParams) - this._setProvider(provider) - } - - _configureStandardProvider ({ rpcUrl }) { - const providerParams = extend(this._baseProviderParams, { - rpcUrl, + _configureStandardProvider (_providerParams) { + const providerParams = extend(this._baseProviderParams, _providerParams, { engineParams: { pollingInterval: 8000, }, -- cgit v1.2.3 From 161aa66cb4c6791659a48738578aac1f8c0c1376 Mon Sep 17 00:00:00 2001 From: kumavis Date: Wed, 13 Dec 2017 18:57:27 -0800 Subject: Revert "Revert "network - for infura networks use the infura block tracker provider"" This reverts commit 5df7dcd758c5a16b503a5ee237970c05c7e990c9. --- app/scripts/controllers/network.js | 57 +++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index cee918796..65d58008a 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -1,6 +1,7 @@ const assert = require('assert') const EventEmitter = require('events') const createMetamaskProvider = require('web3-provider-engine/zero.js') +const createInfuraProvider = require('eth-json-rpc-infura/src/createProvider') const ObservableStore = require('obs-store') const ComposedStore = require('obs-store/lib/composed') const extend = require('xtend') @@ -8,6 +9,7 @@ const EthQuery = require('eth-query') const createEventEmitterProxy = require('../lib/events-proxy.js') const RPC_ADDRESS_LIST = require('../config.js').network const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] +const INFURA_PROVIDER_TYPES = ['ropsten', 'rinkeby', 'kovan', 'mainnet'] module.exports = class NetworkController extends EventEmitter { @@ -24,8 +26,13 @@ module.exports = class NetworkController extends EventEmitter { initializeProvider (_providerParams) { this._baseProviderParams = _providerParams - const rpcUrl = this.getCurrentRpcAddress() - this._configureStandardProvider({ rpcUrl }) + const { type, rpcTarget } = this.providerStore.getState() + // map rpcTarget to rpcUrl + const opts = { + type, + rpcUrl: rpcTarget, + } + this._configureProvider(opts) this._proxy.on('block', this._logBlock.bind(this)) this._proxy.on('error', this.verifyNetwork.bind(this)) this.ethQuery = new EthQuery(this._proxy) @@ -83,7 +90,7 @@ module.exports = class NetworkController extends EventEmitter { const rpcTarget = this.getRpcAddressForType(type) assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`) this.providerStore.updateState({ type, rpcTarget }) - this._switchNetwork({ rpcUrl: rpcTarget }) + this._switchNetwork({ type }) } getProviderConfig () { @@ -99,14 +106,50 @@ module.exports = class NetworkController extends EventEmitter { // Private // - _switchNetwork (providerParams) { + _switchNetwork (opts) { this.setNetworkState('loading') - this._configureStandardProvider(providerParams) + this._configureProvider(opts) this.emit('networkDidChange') } - _configureStandardProvider (_providerParams) { - const providerParams = extend(this._baseProviderParams, _providerParams, { + _configureProvider (opts) { + // type-based rpc endpoints + const { type } = opts + if (type) { + // type-based infura rpc endpoints + const isInfura = INFURA_PROVIDER_TYPES.includes(type) + opts.rpcUrl = this.getRpcAddressForType(type) + if (isInfura) { + this._configureInfuraProvider(opts) + // other type-based rpc endpoints + } else { + this._configureStandardProvider(opts) + } + // url-based rpc endpoints + } else { + this._configureStandardProvider(opts) + } + } + + _configureInfuraProvider (opts) { + console.log('_configureInfuraProvider', opts) + const blockTrackerProvider = createInfuraProvider({ + network: opts.type, + }) + const providerParams = extend(this._baseProviderParams, { + rpcUrl: opts.rpcUrl, + engineParams: { + pollingInterval: 8000, + blockTrackerProvider, + }, + }) + const provider = createMetamaskProvider(providerParams) + this._setProvider(provider) + } + + _configureStandardProvider ({ rpcUrl }) { + const providerParams = extend(this._baseProviderParams, { + rpcUrl, engineParams: { pollingInterval: 8000, }, -- cgit v1.2.3 From fb8744771a78eabe98b5be7fb32af19666b107bd Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Fri, 15 Dec 2017 14:43:55 -0600 Subject: Change console.log for opts in _configureInfuraProvider --- app/scripts/controllers/network.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 65d58008a..377ba6eca 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -132,7 +132,7 @@ module.exports = class NetworkController extends EventEmitter { } _configureInfuraProvider (opts) { - console.log('_configureInfuraProvider', opts) + log.info('_configureInfuraProvider', opts) const blockTrackerProvider = createInfuraProvider({ network: opts.type, }) -- cgit v1.2.3 From 10ff77477cf3163eaea5ac9485977d91bcc102c0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Sun, 17 Dec 2017 16:36:03 -0800 Subject: Add Recent Blocks controller Tracks recent blocks, useful for estimating recent successful gas prices. --- app/scripts/controllers/recent-blocks.js | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/scripts/controllers/recent-blocks.js (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/recent-blocks.js b/app/scripts/controllers/recent-blocks.js new file mode 100644 index 000000000..27f9013ff --- /dev/null +++ b/app/scripts/controllers/recent-blocks.js @@ -0,0 +1,37 @@ +const ObservableStore = require('obs-store') +const extend = require('xtend') + +class RecentBlocksController { + + constructor (opts = {}) { + const { blockTracker } = opts + this.blockTracker = blockTracker + this.historyLength = opts.historyLength || 40 + + const initState = extend({ + recentBlocks: [], + }, opts.initState) + this.store = new ObservableStore(initState) + + this.blockTracker.on('block', this.processBlock.bind(this)) + } + + resetState () { + this.store.updateState({ + recentBlocks: [], + }) + } + + processBlock (newBlock) { + const state = this.store.getState() + state.recentBlocks.push(newBlock) + + while (state.recentBlocks.length > this.historyLength) { + state.recentBlocks.shift() + } + + this.store.updateState(state) + } +} + +module.exports = RecentBlocksController -- cgit v1.2.3 From 975f7279c713d88bb59205073540b2185f3a812f Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 18 Dec 2017 15:57:04 -0800 Subject: Allow updating token details Fixes #2173 --- app/scripts/controllers/preferences.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index bc4848421..c42f47037 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -26,23 +26,23 @@ class PreferencesController { return this.store.getState().selectedAddress } - addToken (rawAddress, symbol, decimals) { + async 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) => { + const previousEntry = tokens.find((token, index) => { return token.address === address }) + const previousIndex = tokens.indexOf(previousEntry) - if (previousIndex) { + if (previousEntry) { tokens[previousIndex] = newEntry } else { tokens.push(newEntry) } this.store.updateState({ tokens }) - return Promise.resolve() } getTokens () { -- cgit v1.2.3 From 30b45c8a385e9ae4c6b78d0a7ec6929f7bad4d9a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 19 Dec 2017 12:22:48 -0800 Subject: Do not log whole txs in recent block controller. Only record gas prices, because that has a current use. --- app/scripts/controllers/recent-blocks.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/scripts/controllers') diff --git a/app/scripts/controllers/recent-blocks.js b/app/scripts/controllers/recent-blocks.js index 27f9013ff..4a906261e 100644 --- a/app/scripts/controllers/recent-blocks.js +++ b/app/scripts/controllers/recent-blocks.js @@ -23,8 +23,15 @@ class RecentBlocksController { } processBlock (newBlock) { + const block = extend(newBlock, { + gasPrices: newBlock.transactions.map((tx) => { + return tx.gasPrice + }), + }) + delete block.transactions + const state = this.store.getState() - state.recentBlocks.push(newBlock) + state.recentBlocks.push(block) while (state.recentBlocks.length > this.historyLength) { state.recentBlocks.shift() -- cgit v1.2.3