Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow loading as metamaskNetworkId #5924

Merged
merged 2 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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