From 7256894f51e3ef3073d7c5d8ab7b745ee5d36d2b Mon Sep 17 00:00:00 2001 From: Alex Lunyov Date: Thu, 21 Sep 2017 15:13:53 +0800 Subject: [PATCH 01/17] Fix CORS issues in FireFox --- app/manifest.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/manifest.json b/app/manifest.json index 67fb543b9..05e8d30de 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -57,7 +57,11 @@ "permissions": [ "storage", "clipboardWrite", - "http://localhost:8545/" + "http://localhost:8545/", + "https://rinkeby.infura.io/metamask/", + "https://mainnet.infura.io/metamask/", + "https://ropsten.infura.io/metamask/", + "https://kovan.infura.io/metamask/" ], "web_accessible_resources": [ "scripts/inpage.js" From bfaacd311806b9ff902f0b5178469b5ef9133358 Mon Sep 17 00:00:00 2001 From: Alex Lunyov Date: Fri, 22 Sep 2017 12:14:04 +0800 Subject: [PATCH 02/17] Wildcard for infura.io permissions, added permission for cryptonator api --- app/manifest.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/manifest.json b/app/manifest.json index 05e8d30de..83a967a26 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -58,10 +58,8 @@ "storage", "clipboardWrite", "http://localhost:8545/", - "https://rinkeby.infura.io/metamask/", - "https://mainnet.infura.io/metamask/", - "https://ropsten.infura.io/metamask/", - "https://kovan.infura.io/metamask/" + "https://*.infura.io/", + "https://api.cryptonator.com" ], "web_accessible_resources": [ "scripts/inpage.js" From 861bd877f3bf1c0c71a00f1b90048e93dec03488 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 29 Sep 2017 11:19:54 -0700 Subject: [PATCH 03/17] Ensure selected account is always set if possible Fixes #2218 Subscribes to keyringController, and if only one account exists, sets it as selected. --- CHANGELOG.md | 1 + app/scripts/metamask-controller.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0faf6fe85..40663dcf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Current Master +- Fixed bug where sometimes the current account was not correctly set and exposed to web apps. - Added AUD, HKD, SGD, IDR, PHP to currency conversion list ## 3.10.6 2017-9-27 diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5b3161bc6..b28f2738a 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -100,6 +100,14 @@ module.exports = class MetamaskController extends EventEmitter { encryptor: opts.encryptor || undefined, }) + // If only one account exists, make sure it is selected. + this.keyringController.store.subscribe((state) => { + const addresses = Object.keys(state.walletNicknames || {}) + if (addresses.length === 1) { + const address = addresses[0] + this.preferencesController.setSelectedAddress(address) + } + }) this.keyringController.on('newAccount', (address) => { this.preferencesController.setSelectedAddress(address) this.accountTracker.addAccount(address) @@ -222,6 +230,7 @@ module.exports = class MetamaskController extends EventEmitter { const isUnlocked = this.keyringController.memStore.getState().isUnlocked const result = [] const selectedAddress = this.preferencesController.getSelectedAddress() + // only show address if account is unlocked if (isUnlocked && selectedAddress) { result.push(selectedAddress) From 19e7adad1920ac506b3ef5c639ec110a2615bd7c Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Sep 2017 11:50:24 -0700 Subject: [PATCH 04/17] development - fix ui dev --- development/index.html | 102 ++++++++++++++++++++--------------------- ui-dev.js | 45 ++++++++++-------- 2 files changed, 75 insertions(+), 72 deletions(-) diff --git a/development/index.html b/development/index.html index a0814cb55..e5a027447 100644 --- a/development/index.html +++ b/development/index.html @@ -3,62 +3,58 @@ MetaMask - - - -
+ + + + - - - - diff --git a/ui-dev.js b/ui-dev.js index de5dfd8ef..620d81667 100644 --- a/ui-dev.js +++ b/ui-dev.js @@ -61,30 +61,37 @@ const actions = { var css = MetaMaskUiCss() injectCss(css) -const container = document.querySelector('#test-container') - // parse opts var store = configureStore(states[selectedView]) // start app -render( - h('.super-dev-container', [ +startApp() - h(Selector, { actions, selectedKey: selectedView, states, store }), +function startApp(){ + const body = document.body + const container = document.createElement('div') + container.id = 'test-container' + body.appendChild(container) - h('#app-content', { - style: { - height: '500px', - width: '360px', - boxShadow: 'grey 0px 2px 9px', - margin: '20px', - }, - }, [ - h(Root, { - store: store, - }), - ]), + render( + h('.super-dev-container', [ - ] -), container) + h(Selector, { actions, selectedKey: selectedView, states, store }), + + h('#app-content', { + style: { + height: '500px', + width: '360px', + boxShadow: 'grey 0px 2px 9px', + margin: '20px', + }, + }, [ + h(Root, { + store: store, + }), + ]), + + ] + ), container) +} From ac80eaca1fc9923cd5696282ba2bc6bace22ff83 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Fri, 29 Sep 2017 12:54:05 -0700 Subject: [PATCH 05/17] pending-tx - dont check the balance to rebrodcast --- app/scripts/controllers/transactions.js | 11 +--------- app/scripts/lib/pending-tx-tracker.js | 15 -------------- app/scripts/metamask-controller.js | 1 - test/unit/pending-tx-test.js | 27 +------------------------ test/unit/tx-controller-test.js | 25 ----------------------- 5 files changed, 2 insertions(+), 77 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 4f5c94675..9fdec1ead 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -32,7 +32,6 @@ module.exports = class TransactionController extends EventEmitter { this.provider = opts.provider this.blockTracker = opts.blockTracker this.signEthTx = opts.signTransaction - this.accountTracker = opts.accountTracker this.memStore = new ObservableStore({}) this.query = new EthQuery(this.provider) @@ -61,11 +60,6 @@ module.exports = class TransactionController extends EventEmitter { provider: this.provider, nonceTracker: this.nonceTracker, retryLimit: 3500, // Retry 3500 blocks, or about 1 day. - getBalance: (address) => { - const account = this.accountTracker.store.getState().accounts[address] - if (!account) return - return account.balance - }, publishTransaction: (rawTx) => this.query.sendRawTransaction(rawTx), getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager), }) @@ -84,10 +78,7 @@ module.exports = class TransactionController extends EventEmitter { this.blockTracker.on('block', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker)) // this is a little messy but until ethstore has been either // removed or redone this is to guard against the race condition - // where accountTracker hasent been populated by the results yet - this.blockTracker.once('latest', () => { - this.blockTracker.on('latest', this.pendingTxTracker.resubmitPendingTxs.bind(this.pendingTxTracker)) - }) + this.blockTracker.on('latest', this.pendingTxTracker.resubmitPendingTxs.bind(this.pendingTxTracker)) this.blockTracker.on('sync', this.pendingTxTracker.queryPendingTxs.bind(this.pendingTxTracker)) // memstore is computed from a few different stores this._updateMemstore() diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js index b97cec9ce..3d358b00e 100644 --- a/app/scripts/lib/pending-tx-tracker.js +++ b/app/scripts/lib/pending-tx-tracker.js @@ -1,6 +1,5 @@ const EventEmitter = require('events') const EthQuery = require('ethjs-query') -const sufficientBalance = require('./util').sufficientBalance /* Utility class for tracking the transactions as they @@ -12,7 +11,6 @@ const sufficientBalance = require('./util').sufficientBalance requires a: { provider: //, nonceTracker: //see nonce tracker, - getBalnce: //(address) a function for getting balances, getPendingTransactions: //() a function for getting an array of transactions, publishTransaction: //(rawTx) a async function for publishing raw transactions, } @@ -25,7 +23,6 @@ module.exports = class PendingTransactionTracker extends EventEmitter { this.query = new EthQuery(config.provider) this.nonceTracker = config.nonceTracker this.retryLimit = config.retryLimit || Infinity - this.getBalance = config.getBalance this.getPendingTransactions = config.getPendingTransactions this.publishTransaction = config.publishTransaction } @@ -99,23 +96,11 @@ module.exports = class PendingTransactionTracker extends EventEmitter { } async _resubmitTx (txMeta) { - const address = txMeta.txParams.from - const balance = this.getBalance(address) - if (balance === undefined) return - if (txMeta.retryCount > this.retryLimit) { const err = new Error(`Gave up submitting after ${this.retryLimit} blocks un-mined.`) return this.emit('tx:failed', txMeta.id, err) } - // if the value of the transaction is greater then the balance, fail. - if (!sufficientBalance(txMeta.txParams, balance)) { - const insufficientFundsError = new Error('Insufficient balance during rebroadcast.') - this.emit('tx:failed', txMeta.id, insufficientFundsError) - log.error(insufficientFundsError) - return - } - // Only auto-submit already-signed txs: if (!('rawTx' in txMeta)) return diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b28f2738a..e152dfedb 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -132,7 +132,6 @@ module.exports = class MetamaskController extends EventEmitter { provider: this.provider, blockTracker: this.blockTracker, ethQuery: this.ethQuery, - accountTracker: this.accountTracker, }) this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts)) diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js index 1af464656..4da0eff5d 100644 --- a/test/unit/pending-tx-test.js +++ b/test/unit/pending-tx-test.js @@ -40,14 +40,12 @@ describe('PendingTransactionTracker', function () { pendingTxTracker = new PendingTransactionTracker({ provider, - getBalance: () => {}, nonceTracker: { getGlobalLock: async () => { return { releaseLock: () => {} } } }, getPendingTransactions: () => {return []}, - sufficientBalance: () => {}, publishTransaction: () => {}, }) }) @@ -213,30 +211,7 @@ describe('PendingTransactionTracker', function () { pendingTxTracker.resubmitPendingTxs() }) }) - describe('#_resubmitTx with a too-low balance', function () { - it('should return before publishing the transaction because to low of balance', function (done) { - const lowBalance = '0x0' - pendingTxTracker.getBalance = (address) => { - assert.equal(address, txMeta.txParams.from, 'Should pass the address') - return lowBalance - } - pendingTxTracker.publishTransaction = async (rawTx) => { - done(new Error('tried to publish transaction')) - } - - // Stubbing out current account state: - // Adding the fake tx: - pendingTxTracker.once('tx:failed', (txId, err) => { - assert(err, 'Should have a error') - done() - }) - pendingTxTracker._resubmitTx(txMeta) - .catch((err) => { - assert.ifError(err, 'should not throw an error') - done(err) - }) - }) - + describe('#_resubmitTx', function () { it('should publishing the transaction', function (done) { const enoughBalance = '0x100000' pendingTxTracker.getBalance = (address) => { diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index 66772ff88..bb51ab01f 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -25,7 +25,6 @@ describe('Transaction Controller', function () { networkStore: new ObservableStore(currentNetworkId), txHistoryLimit: 10, blockTracker: { getCurrentBlock: noop, on: noop, once: noop }, - accountTracker: { store: { getState: noop } }, signTransaction: (ethTx) => new Promise((resolve) => { ethTx.sign(privKey) resolve() @@ -383,30 +382,6 @@ describe('Transaction Controller', function () { }) }) - describe('#getBalance', function () { - it('gets balance', function () { - sinon.stub(txController.accountTracker.store, 'getState').callsFake(() => { - return { - accounts: { - '0x1678a085c290ebd122dc42cba69373b5953b831d': { - address: '0x1678a085c290ebd122dc42cba69373b5953b831d', - balance: '0x00000000000000056bc75e2d63100000', - code: '0x', - nonce: '0x0', - }, - '0xc684832530fcbddae4b4230a47e991ddcec2831d': { - address: '0xc684832530fcbddae4b4230a47e991ddcec2831d', - balance: '0x0', - code: '0x', - nonce: '0x0', - }, - }, - } - }) - assert.equal(txController.pendingTxTracker.getBalance('0x1678a085c290ebd122dc42cba69373b5953b831d'), '0x00000000000000056bc75e2d63100000') - assert.equal(txController.pendingTxTracker.getBalance('0xc684832530fcbddae4b4230a47e991ddcec2831d'), '0x0') - }) - }) describe('#getPendingTransactions', function () { beforeEach(function () { From 14d58e630d6b806c9ef23adf7aff4b2fd30609c0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 29 Sep 2017 13:17:21 -0700 Subject: [PATCH 06/17] Version 3.10.7 --- CHANGELOG.md | 2 ++ app/manifest.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40663dcf5..8c39bbc1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +## 3.10.7 2017-9-28 + - Fixed bug where sometimes the current account was not correctly set and exposed to web apps. - Added AUD, HKD, SGD, IDR, PHP to currency conversion list diff --git a/app/manifest.json b/app/manifest.json index 639f3fb4b..146b27f89 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "3.10.6", + "version": "3.10.7", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", From b88d11f86ede907bdf51cd224e5ea6285e56147b Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Sep 2017 16:09:38 -0700 Subject: [PATCH 07/17] network controller - small refactor --- app/scripts/controllers/network.js | 47 ++++++++++++++++++------------ app/scripts/metamask-controller.js | 38 +++++++++++++----------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 2a17cdae8..9e05afe75 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -1,5 +1,6 @@ +const assert = require('assert') const EventEmitter = require('events') -const MetaMaskProvider = require('web3-provider-engine/zero.js') +const createMetamaskProvider = require('web3-provider-engine/zero.js') const ObservableStore = require('obs-store') const ComposedStore = require('obs-store/lib/composed') const extend = require('xtend') @@ -18,13 +19,13 @@ module.exports = class NetworkController extends EventEmitter { this._proxy = createEventEmitterProxy() this.on('networkDidChange', this.lookupNetwork) - this.providerStore.subscribe((state) => this.switchNetwork({ rpcUrl: state.rpcTarget })) + this.providerStore.subscribe((state) => this._switchNetwork({ rpcUrl: state.rpcTarget })) } - initializeProvider (opts, providerContructor = MetaMaskProvider) { - this._baseProviderParams = opts - const provider = providerContructor(opts) - this._setProvider(provider) + initializeProvider (_providerParams) { + this._baseProviderParams = _providerParams + 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) @@ -32,17 +33,8 @@ module.exports = class NetworkController extends EventEmitter { return this._proxy } - switchNetwork (opts) { - this.setNetworkState('loading') - const providerParams = extend(this._baseProviderParams, opts) - this._baseProviderParams = providerParams - const provider = MetaMaskProvider(providerParams) - this._setProvider(provider) - this.emit('networkDidChange') - } - verifyNetwork () { - // Check network when restoring connectivity: + // Check network when restoring connectivity: if (this.isNetworkLoading()) this.lookupNetwork() } @@ -79,10 +71,13 @@ module.exports = class NetworkController extends EventEmitter { return this.getRpcAddressForType(provider.type) } - setProviderType (type) { + async setProviderType (type) { + assert(type !== 'rpc', `NetworkController.setProviderType - cannot connect by type "rpc"`) + // skip if type already matches if (type === this.getProviderConfig().type) return const rpcTarget = this.getRpcAddressForType(type) - this.providerStore.updateState({type, rpcTarget}) + assert(rpcTarget, `NetworkController - unknown rpc address for type "${type}"`) + this.providerStore.updateState({ type, rpcTarget }) } getProviderConfig () { @@ -94,6 +89,22 @@ module.exports = class NetworkController extends EventEmitter { return provider && provider.rpcTarget ? provider.rpcTarget : DEFAULT_RPC } + // + // Private + // + + _switchNetwork (providerParams) { + this.setNetworkState('loading') + this._configureStandardProvider(providerParams) + this.emit('networkDidChange') + } + + _configureStandardProvider(_providerParams) { + const providerParams = extend(this._baseProviderParams, _providerParams) + const provider = createMetamaskProvider(providerParams) + this._setProvider(provider) + } + _setProvider (provider) { // collect old block tracker events const oldProvider = this._provider diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b28f2738a..fa6f1a245 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -217,13 +217,11 @@ module.exports = class MetamaskController extends EventEmitter { // initializeProvider () { - return this.networkController.initializeProvider({ + const providerOpts = { static: { eth_syncing: false, web3_clientVersion: `MetaMask/v${version}`, }, - // rpc data source - rpcUrl: this.networkController.getCurrentRpcAddress(), originHttpHeaderKey: 'X-Metamask-Origin', // account mgmt getAccounts: (cb) => { @@ -243,7 +241,9 @@ module.exports = class MetamaskController extends EventEmitter { processMessage: this.newUnsignedMessage.bind(this), // personal_sign msg signing processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), - }) + } + const providerProxy = this.networkController.initializeProvider(providerOpts) + return providerProxy } initPublicConfigStore () { @@ -312,13 +312,14 @@ module.exports = class MetamaskController extends EventEmitter { const txController = this.txController const noticeController = this.noticeController const addressBookController = this.addressBookController + const networkController = this.networkController return { // etc getState: (cb) => cb(null, this.getState()), - setProviderType: this.networkController.setProviderType.bind(this.networkController), setCurrentCurrency: this.setCurrentCurrency.bind(this), markAccountsFound: this.markAccountsFound.bind(this), + // coinbase buyEth: this.buyEth.bind(this), // shapeshift @@ -333,12 +334,15 @@ module.exports = class MetamaskController extends EventEmitter { // vault management submitPassword: this.submitPassword.bind(this), + // network management + setProviderType: nodeify(networkController.setProviderType, networkController), + setDefaultRpc: nodeify(this.setDefaultRpc, this), + setCustomRpc: nodeify(this.setCustomRpc, this), + // PreferencesController setSelectedAddress: nodeify(preferencesController.setSelectedAddress, preferencesController), addToken: nodeify(preferencesController.addToken, preferencesController), setCurrentAccountTab: nodeify(preferencesController.setCurrentAccountTab, preferencesController), - setDefaultRpc: nodeify(this.setDefaultRpc, this), - setCustomRpc: nodeify(this.setCustomRpc, this), // AddressController setAddressBook: nodeify(addressBookController.setAddressBook, addressBookController), @@ -689,19 +693,19 @@ module.exports = class MetamaskController extends EventEmitter { createShapeShiftTx (depositAddress, depositType) { this.shapeshiftController.createShapeShiftTx(depositAddress, depositType) } -// network - setDefaultRpc () { - this.networkController.setRpcTarget('http://localhost:8545') - return Promise.resolve('http://localhost:8545') + // network + + async setDefaultRpc () { + const localhost = 'http://localhost:8545' + this.networkController.setRpcTarget(localhost) + return localhost } - setCustomRpc (rpcTarget, rpcList) { + async setCustomRpc (rpcTarget, rpcList) { this.networkController.setRpcTarget(rpcTarget) - - return this.preferencesController.updateFrequentRpcList(rpcTarget) - .then(() => { - return Promise.resolve(rpcTarget) - }) + await this.preferencesController.updateFrequentRpcList(rpcTarget) + return rpcTarget } + } From d6ea2fa425c90f6e05d2d59d4a79f1b573cc2e06 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Sep 2017 16:35:58 -0700 Subject: [PATCH 08/17] network - convert localhost from custom rpc to network type --- app/scripts/config.js | 2 ++ app/scripts/controllers/network.js | 1 + app/scripts/metamask-controller.js | 7 ------- ui/app/actions.js | 23 ++++++++--------------- ui/app/app.js | 2 +- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/app/scripts/config.js b/app/scripts/config.js index c5f260583..1d4ff7c0d 100644 --- a/app/scripts/config.js +++ b/app/scripts/config.js @@ -2,11 +2,13 @@ const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask' const ROPSTEN_RPC_URL = 'https://ropsten.infura.io/metamask' const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' const RINKEBY_RPC_URL = 'https://rinkeby.infura.io/metamask' +const LOCALHOST_RPC_URL = 'http://localhost:8545' global.METAMASK_DEBUG = 'GULP_METAMASK_DEBUG' module.exports = { network: { + localhost: LOCALHOST_RPC_URL, mainnet: MAINET_RPC_URL, ropsten: ROPSTEN_RPC_URL, kovan: KOVAN_RPC_URL, diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 9e05afe75..9079e0653 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -10,6 +10,7 @@ const RPC_ADDRESS_LIST = require('../config.js').network const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] module.exports = class NetworkController extends EventEmitter { + constructor (config) { super() config.provider.rpcTarget = this.getRpcAddressForType(config.provider.type, config.provider) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index fa6f1a245..eb978115d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -336,7 +336,6 @@ module.exports = class MetamaskController extends EventEmitter { // network management setProviderType: nodeify(networkController.setProviderType, networkController), - setDefaultRpc: nodeify(this.setDefaultRpc, this), setCustomRpc: nodeify(this.setCustomRpc, this), // PreferencesController @@ -696,12 +695,6 @@ module.exports = class MetamaskController extends EventEmitter { // network - async setDefaultRpc () { - const localhost = 'http://localhost:8545' - this.networkController.setRpcTarget(localhost) - return localhost - } - async setCustomRpc (rpcTarget, rpcList) { this.networkController.setRpcTarget(rpcTarget) await this.preferencesController.updateFrequentRpcList(rpcTarget) diff --git a/ui/app/actions.js b/ui/app/actions.js index e793e6a21..4844dd56e 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -126,7 +126,6 @@ var actions = { showAddTokenPage, addToken, setRpcTarget: setRpcTarget, - setDefaultRpcTarget: setDefaultRpcTarget, setProviderType: setProviderType, // loading overlay SHOW_LOADING: 'SHOW_LOADING_INDICATION', @@ -706,16 +705,19 @@ function markAccountsFound () { // config // -// default rpc target refers to localhost:8545 in this instance. -function setDefaultRpcTarget () { - log.debug(`background.setDefaultRpcTarget`) +function setProviderType (type) { return (dispatch) => { - background.setDefaultRpc((err, result) => { + log.debug(`background.setProviderType`) + background.setProviderType(type, (err, result) => { if (err) { log.error(err) - return dispatch(self.displayWarning('Had a problem changing networks.')) + return dispatch(self.displayWarning('Had a problem changing networks!')) } }) + return { + type: actions.SET_PROVIDER_TYPE, + value: type, + } } } @@ -744,15 +746,6 @@ function addToAddressBook (recipient, nickname) { } } -function setProviderType (type) { - log.debug(`background.setProviderType`) - background.setProviderType(type) - return { - type: actions.SET_PROVIDER_TYPE, - value: type, - } -} - function useEtherscanProvider () { log.debug(`background.useEtherscanProvider`) background.useEtherscanProvider() diff --git a/ui/app/app.js b/ui/app/app.js index ee800ea90..50121b055 100644 --- a/ui/app/app.js +++ b/ui/app/app.js @@ -319,7 +319,7 @@ App.prototype.renderNetworkDropdown = function () { { key: 'default', closeMenu: () => this.setState({ isNetworkMenuOpen: !isOpen }), - onClick: () => props.dispatch(actions.setDefaultRpcTarget()), + onClick: () => props.dispatch(actions.setProviderType('localhost')), style: { fontSize: '18px', }, From a2b6d3ffc56a3f7fdab6b5ef42426f0a65fda7c7 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Sep 2017 16:37:01 -0700 Subject: [PATCH 09/17] network - remove long dead etherscan provider code --- ui/app/actions.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ui/app/actions.js b/ui/app/actions.js index 4844dd56e..3ea092e57 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -119,8 +119,6 @@ var actions = { SET_RPC_TARGET: 'SET_RPC_TARGET', SET_DEFAULT_RPC_TARGET: 'SET_DEFAULT_RPC_TARGET', SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE', - USE_ETHERSCAN_PROVIDER: 'USE_ETHERSCAN_PROVIDER', - useEtherscanProvider: useEtherscanProvider, showConfigPage, SHOW_ADD_TOKEN_PAGE: 'SHOW_ADD_TOKEN_PAGE', showAddTokenPage, @@ -746,14 +744,6 @@ function addToAddressBook (recipient, nickname) { } } -function useEtherscanProvider () { - log.debug(`background.useEtherscanProvider`) - background.useEtherscanProvider() - return { - type: actions.USE_ETHERSCAN_PROVIDER, - } -} - function showLoadingIndication (message) { return { type: actions.SHOW_LOADING, From 1ad8a9a0ffb84d11baeb2ae143986d3fb10b89c8 Mon Sep 17 00:00:00 2001 From: kumavis Date: Fri, 29 Sep 2017 17:10:34 -0700 Subject: [PATCH 10/17] network - make network controller internal network switching explicit --- app/scripts/controllers/network.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/scripts/controllers/network.js b/app/scripts/controllers/network.js index 9079e0653..0f9db4d53 100644 --- a/app/scripts/controllers/network.js +++ b/app/scripts/controllers/network.js @@ -10,7 +10,7 @@ const RPC_ADDRESS_LIST = require('../config.js').network const DEFAULT_RPC = RPC_ADDRESS_LIST['rinkeby'] module.exports = class NetworkController extends EventEmitter { - + constructor (config) { super() config.provider.rpcTarget = this.getRpcAddressForType(config.provider.type, config.provider) @@ -20,7 +20,6 @@ module.exports = class NetworkController extends EventEmitter { this._proxy = createEventEmitterProxy() this.on('networkDidChange', this.lookupNetwork) - this.providerStore.subscribe((state) => this._switchNetwork({ rpcUrl: state.rpcTarget })) } initializeProvider (_providerParams) { @@ -64,6 +63,7 @@ module.exports = class NetworkController extends EventEmitter { type: 'rpc', rpcTarget: rpcUrl, }) + this._switchNetwork({ rpcUrl }) } getCurrentRpcAddress () { @@ -79,6 +79,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 }) } getProviderConfig () { From d5b0d8af4f4907398154449239465efba601eb4d Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 29 Sep 2017 20:57:15 -0700 Subject: [PATCH 11/17] Version 3.10.8 - Fix Currency Conversion In our conversion to the new Infura API, somehow we were sending upper-cased conversions to their lower-case sensitive API. Fixes the first part of #2240 --- CHANGELOG.md | 4 ++++ app/manifest.json | 2 +- app/scripts/controllers/currency.js | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c39bbc1a..e635f6158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Current Master +## 3.10.8 2017-9-28 + +- Fixed usage of new currency fetching API. + ## 3.10.7 2017-9-28 - Fixed bug where sometimes the current account was not correctly set and exposed to web apps. diff --git a/app/manifest.json b/app/manifest.json index 146b27f89..e71018211 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "MetaMask", "short_name": "Metamask", - "version": "3.10.7", + "version": "3.10.8", "manifest_version": 2, "author": "https://metamask.io", "description": "Ethereum Browser Extension", diff --git a/app/scripts/controllers/currency.js b/app/scripts/controllers/currency.js index 9e696ce55..25a7a942e 100644 --- a/app/scripts/controllers/currency.js +++ b/app/scripts/controllers/currency.js @@ -45,7 +45,7 @@ class CurrencyController { updateConversionRate () { const currentCurrency = this.getCurrentCurrency() - return fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency}`) + return fetch(`https://api.infura.io/v1/ticker/eth${currentCurrency.toLowerCase()}`) .then(response => response.json()) .then((parsedResponse) => { this.setConversionRate(Number(parsedResponse.bid)) From 36bc8f3c60ffbcc3789a683a6a74a52e355c0c2b Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Mon, 2 Oct 2017 10:59:15 -0700 Subject: [PATCH 12/17] Update manifest.json --- app/manifest.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/manifest.json b/app/manifest.json index 83a967a26..5f8cf6979 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -58,8 +58,7 @@ "storage", "clipboardWrite", "http://localhost:8545/", - "https://*.infura.io/", - "https://api.cryptonator.com" + "https://*.infura.io/" ], "web_accessible_resources": [ "scripts/inpage.js" From e68261130142db52cb3cf0d94633f560a87c0655 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 11:35:26 -0700 Subject: [PATCH 13/17] deps - bump pe for block cache fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9a38ac71..918531f15 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "^0.20.1", - "web3-provider-engine": "^13.2.12", + "web3-provider-engine": "^13.3.1", "web3-stream-provider": "^3.0.1", "xtend": "^4.0.1" }, From d29b5f10ef5137ab56ecc9615e5e894082db9803 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 13:14:42 -0700 Subject: [PATCH 14/17] tx state history - fix bug where initial snapshot was mutated on updateTx --- app/scripts/lib/tx-state-history-helper.js | 3 ++- app/scripts/lib/tx-state-manager.js | 2 +- test/unit/tx-state-history-helper.js | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/tx-state-history-helper.js b/app/scripts/lib/tx-state-history-helper.js index 304069d57..5ebd78689 100644 --- a/app/scripts/lib/tx-state-history-helper.js +++ b/app/scripts/lib/tx-state-history-helper.js @@ -24,7 +24,8 @@ function generateHistoryEntry(previousState, newState) { return jsonDiffer.compare(previousState, newState) } -function replayHistory(shortHistory) { +function replayHistory(_shortHistory) { + const shortHistory = clone(_shortHistory) return shortHistory.reduce((val, entry) => jsonDiffer.applyPatch(val, entry).newDocument) } diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index abb9d7910..4493889bf 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -97,7 +97,7 @@ module.exports = class TransactionStateManger extends EventEmitter { const previousState = txStateHistoryHelper.replayHistory(txMeta.history) // generate history entry and add to history const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState) - txMeta.history.push(entry) + txMeta.history.push(entry) // commit txMeta to state const txId = txMeta.id diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js index 5bb6c9bee..e5075af88 100644 --- a/test/unit/tx-state-history-helper.js +++ b/test/unit/tx-state-history-helper.js @@ -20,4 +20,26 @@ describe('tx-state-history-helper', function () { }) }) }) + + it('replaying history does not mutate the original obj', function () { + const initialState = { test: true, message: 'hello', value: 1 } + const diff1 = { + "op": "replace", + "path": "/message", + "value": "haay", + } + const diff2 = { + "op": "replace", + "path": "/value", + "value": 2, + } + const history = [initialState, diff1, diff2] + + const beforeStateSnapshot = JSON.stringify(initialState) + const latestState = txStateHistoryHelper.replayHistory(history) + const afterStateSnapshot = JSON.stringify(initialState) + + assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state') + assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run') + }) }) From 833da191c37db5b5b470c69a6d4d438ff4719fec Mon Sep 17 00:00:00 2001 From: frankiebee Date: Mon, 2 Oct 2017 13:41:29 -0700 Subject: [PATCH 15/17] transaction - provide notes for history --- app/scripts/controllers/transactions.js | 16 +++++++++------- app/scripts/lib/tx-state-manager.js | 10 +++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 9fdec1ead..94e04c429 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -66,13 +66,15 @@ module.exports = class TransactionController extends EventEmitter { this.txStateManager.store.subscribe(() => this.emit('update:badge')) - this.pendingTxTracker.on('tx:warning', this.txStateManager.updateTx.bind(this.txStateManager)) + this.pendingTxTracker.on('tx:warning', (txMeta) => { + this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:warning') + }) this.pendingTxTracker.on('tx:failed', this.txStateManager.setTxStatusFailed.bind(this.txStateManager)) this.pendingTxTracker.on('tx:confirmed', this.txStateManager.setTxStatusConfirmed.bind(this.txStateManager)) this.pendingTxTracker.on('tx:retry', (txMeta) => { if (!('retryCount' in txMeta)) txMeta.retryCount = 0 txMeta.retryCount++ - this.txStateManager.updateTx(txMeta) + this.txStateManager.updateTx(txMeta, 'transactions/pending-tx-tracker#event: tx:retry') }) this.blockTracker.on('block', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker)) @@ -168,14 +170,14 @@ module.exports = class TransactionController extends EventEmitter { const txParams = txMeta.txParams // ensure value const gasPrice = txParams.gasPrice || await this.query.gasPrice() - txParams.value = txParams.value || '0x0' txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16)) + txParams.value = txParams.value || '0x0' // set gasLimit return await this.txGasUtil.analyzeGasUsage(txMeta) } async updateAndApproveTransaction (txMeta) { - this.txStateManager.updateTx(txMeta) + this.txStateManager.updateTx(txMeta, 'confTx: user approved transaction') await this.approveTransaction(txMeta.id) } @@ -193,7 +195,7 @@ module.exports = class TransactionController extends EventEmitter { txMeta.txParams.nonce = ethUtil.addHexPrefix(nonceLock.nextNonce.toString(16)) // add nonce debugging information to txMeta txMeta.nonceDetails = nonceLock.nonceDetails - this.txStateManager.updateTx(txMeta) + this.txStateManager.updateTx(txMeta, 'transactions#approveTransaction') // sign transaction const rawTx = await this.signTransaction(txId) await this.publishTransaction(txId, rawTx) @@ -224,7 +226,7 @@ module.exports = class TransactionController extends EventEmitter { async publishTransaction (txId, rawTx) { const txMeta = this.txStateManager.getTx(txId) txMeta.rawTx = rawTx - this.txStateManager.updateTx(txMeta) + this.txStateManager.updateTx(txMeta, 'transactions#publishTransaction') const txHash = await this.query.sendRawTransaction(rawTx) this.setTxHash(txId, txHash) this.txStateManager.setTxStatusSubmitted(txId) @@ -239,7 +241,7 @@ module.exports = class TransactionController extends EventEmitter { // Add the tx hash to the persisted meta-tx object const txMeta = this.txStateManager.getTx(txId) txMeta.hash = txHash - this.txStateManager.updateTx(txMeta) + this.txStateManager.updateTx(txMeta, 'transactions#setTxHash') } // diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js index abb9d7910..cf8117864 100644 --- a/app/scripts/lib/tx-state-manager.js +++ b/app/scripts/lib/tx-state-manager.js @@ -82,7 +82,7 @@ module.exports = class TransactionStateManger extends EventEmitter { return txMeta } - updateTx (txMeta) { + updateTx (txMeta, note) { if (txMeta.txParams) { Object.keys(txMeta.txParams).forEach((key) => { let value = txMeta.txParams[key] @@ -96,8 +96,8 @@ module.exports = class TransactionStateManger extends EventEmitter { // recover previous tx state obj const previousState = txStateHistoryHelper.replayHistory(txMeta.history) // generate history entry and add to history - const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState) - txMeta.history.push(entry) + const entry = txStateHistoryHelper.generateHistoryEntry(previousState, currentState, note) + txMeta.history.push(entry) // commit txMeta to state const txId = txMeta.id @@ -113,7 +113,7 @@ module.exports = class TransactionStateManger extends EventEmitter { updateTxParams (txId, txParams) { const txMeta = this.getTx(txId) txMeta.txParams = extend(txMeta.txParams, txParams) - this.updateTx(txMeta) + this.updateTx(txMeta, `txStateManager#updateTxParams`) } /* @@ -233,7 +233,7 @@ module.exports = class TransactionStateManger extends EventEmitter { if (status === 'submitted' || status === 'rejected') { this.emit(`${txMeta.id}:finished`, txMeta) } - this.updateTx(txMeta) + this.updateTx(txMeta, `txStateManager: setting status to ${status}`) this.emit('update:badge') } From c9c0e6f674c06d30794c73994c7776eb68ebedc0 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 13:43:26 -0700 Subject: [PATCH 16/17] tx state history - test - fix format of history entries --- test/unit/tx-state-history-helper.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js index 5bb6c9bee..1590f83d0 100644 --- a/test/unit/tx-state-history-helper.js +++ b/test/unit/tx-state-history-helper.js @@ -20,4 +20,30 @@ describe('tx-state-history-helper', function () { }) }) }) +<<<<<<< Updated upstream +======= + + it('replaying history does not mutate the original obj', function () { + const initialState = { test: true, message: 'hello', value: 1 } + const diff1 = [{ + "op": "replace", + "path": "/message", + "value": "haay", + }] + const diff2 = [{ + "op": "replace", + "path": "/value", + "value": 2, + }] + const history = [initialState, diff1, diff2] + + const beforeStateSnapshot = JSON.stringify(initialState) + const latestState = txStateHistoryHelper.replayHistory(history) + const afterStateSnapshot = JSON.stringify(initialState) + + assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state') + assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run') + }) + +>>>>>>> Stashed changes }) From df59ef9942a950a1c5437c69b1af4111f8c07817 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 13:44:11 -0700 Subject: [PATCH 17/17] tx state history - append note to first op of diff --- app/scripts/lib/tx-state-history-helper.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/tx-state-history-helper.js b/app/scripts/lib/tx-state-history-helper.js index 304069d57..ecf0d076e 100644 --- a/app/scripts/lib/tx-state-history-helper.js +++ b/app/scripts/lib/tx-state-history-helper.js @@ -20,8 +20,11 @@ function migrateFromSnapshotsToDiffs(longHistory) { ) } -function generateHistoryEntry(previousState, newState) { - return jsonDiffer.compare(previousState, newState) +function generateHistoryEntry(previousState, newState, note) { + const entry = jsonDiffer.compare(previousState, newState) + // Add a note to the first op, since it breaks if we append it to the entry + if (note && entry[0]) entry[0].note = note + return entry } function replayHistory(shortHistory) {