mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
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
This commit is contained in:
parent
c5861c88a5
commit
b5d6452454
@ -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)
|
||||
}
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user