aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2018-12-14 03:14:46 +0800
committerGitHub <noreply@github.com>2018-12-14 03:14:46 +0800
commitb5d6452454de8d12340e5902914fba9f420865dc (patch)
tree34b68e4e54e2140e52e542cd9ae6a790fb45ca5d
parentc5861c88a5e8ca98e52a7acc13479dbba0341eb1 (diff)
downloadtangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.tar
tangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.tar.gz
tangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.tar.bz2
tangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.tar.lz
tangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.tar.xz
tangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.tar.zst
tangerine-wallet-browser-b5d6452454de8d12340e5902914fba9f420865dc.zip
Disallow loading as metamaskNetworkId (#5924)
* transactions - throw an error if a transaction is generated while the network is loading * add tests for failing when netId is loading
-rw-r--r--app/scripts/controllers/transactions/tx-state-manager.js4
-rw-r--r--test/unit/app/controllers/transactions/tx-controller-test.js13
2 files changed, 14 insertions, 3 deletions
diff --git a/app/scripts/controllers/transactions/tx-state-manager.js b/app/scripts/controllers/transactions/tx-state-manager.js
index 72d869fa8..420191d9c 100644
--- a/app/scripts/controllers/transactions/tx-state-manager.js
+++ b/app/scripts/controllers/transactions/tx-state-manager.js
@@ -45,11 +45,13 @@ class TransactionStateManager extends EventEmitter {
@returns {txMeta} the default txMeta object
*/
generateTxMeta (opts) {
+ const netId = this.getNetwork()
+ if (netId === 'loading') throw new Error('MetaMask is having trouble connecting to the network')
return extend({
id: createId(),
time: (new Date()).getTime(),
status: 'unapproved',
- metamaskNetworkId: this.getNetwork(),
+ metamaskNetworkId: netId,
loadingDefaults: true,
}, opts)
}
diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js
index 74161e26c..9000cd364 100644
--- a/test/unit/app/controllers/transactions/tx-controller-test.js
+++ b/test/unit/app/controllers/transactions/tx-controller-test.js
@@ -12,7 +12,7 @@ const { createTestProviderTools, getTestAccounts } = require('../../../../stub/p
const noop = () => true
const currentNetworkId = 42
-
+const netStore = new ObservableStore(currentNetworkId)
describe('Transaction Controller', function () {
let txController, provider, providerResultStub, fromAccount
@@ -32,7 +32,7 @@ describe('Transaction Controller', function () {
txController = new TransactionController({
provider,
getGasPrice: function () { return '0xee6b2800' },
- networkStore: new ObservableStore(currentNetworkId),
+ networkStore: netStore,
txHistoryLimit: 10,
blockTracker: blockTrackerStub,
signTransaction: (ethTx) => new Promise((resolve) => {
@@ -227,6 +227,15 @@ describe('Transaction Controller', function () {
txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
.catch(done)
})
+
+ it('should fail if netId is loading', function (done) {
+ txController.networkStore = new ObservableStore('loading')
+ txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
+ .catch((err) => {
+ if (err.message === 'MetaMask is having trouble connecting to the network') done()
+ else done(err)
+ })
+ })
})
describe('#addTxGasDefaults', function () {