Skip to content

Commit

Permalink
Disallow loading as metamaskNetworkId (#5924)
Browse files Browse the repository at this point in the history
* transactions - throw an error if a transaction is generated while the network is loading

* add tests for failing when netId is loading
  • Loading branch information
frankiebee authored Dec 13, 2018
1 parent c5861c8 commit b5d6452
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions test/unit/app/controllers/transactions/tx-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit b5d6452

Please sign in to comment.