add chainId to all new transaction metadata (#10528)

feature/default_network_editable
Brad Decker 4 years ago committed by GitHub
parent 0f7e2dbf20
commit 616b71271a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/scripts/controllers/incoming-transactions.js
  2. 1
      app/scripts/controllers/transactions/index.js
  3. 12
      app/scripts/controllers/transactions/tx-state-manager.js
  4. 6
      shared/modules/transaction.utils.js
  5. 4
      test/unit/actions/tx_test.js
  6. 11
      test/unit/app/controllers/incoming-transactions-test.js
  7. 2
      test/unit/app/controllers/transactions/tx-controller-test.js
  8. 9
      test/unit/app/controllers/transactions/tx-helper-test.js
  9. 14
      test/unit/app/controllers/transactions/tx-state-manager-test.js
  10. 13
      ui/app/ducks/confirm-transaction/confirm-transaction.duck.test.js
  11. 6
      ui/app/pages/confirm-transaction-base/confirm-transaction-base.container.js
  12. 19
      ui/app/pages/confirm-transaction/conf-tx.js
  13. 28
      ui/app/selectors/confirm-transaction.js
  14. 14
      ui/app/selectors/tests/confirm-transaction.test.js
  15. 16
      ui/app/selectors/tests/transactions.test.js
  16. 18
      ui/app/selectors/transactions.js
  17. 2
      ui/app/store/actions.js
  18. 1
      ui/index.js
  19. 7
      ui/lib/tx-helper.js

@ -283,6 +283,7 @@ export default class IncomingTransactionsController {
return { return {
blockNumber: txMeta.blockNumber, blockNumber: txMeta.blockNumber,
id: createId(), id: createId(),
chainId,
metamaskNetworkId: CHAIN_ID_TO_NETWORK_ID_MAP[chainId], metamaskNetworkId: CHAIN_ID_TO_NETWORK_ID_MAP[chainId],
status, status,
time, time,

@ -84,6 +84,7 @@ export default class TransactionController extends EventEmitter {
initState: opts.initState, initState: opts.initState,
txHistoryLimit: opts.txHistoryLimit, txHistoryLimit: opts.txHistoryLimit,
getNetwork: this.getNetwork.bind(this), getNetwork: this.getNetwork.bind(this),
getCurrentChainId: opts.getCurrentChainId,
}); });
this._onBootCleanUp(); this._onBootCleanUp();

@ -4,6 +4,7 @@ import log from 'loglevel';
import createId from '../../lib/random-id'; import createId from '../../lib/random-id';
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller'; import { METAMASK_CONTROLLER_EVENTS } from '../../metamask-controller';
import { transactionMatchesNetwork } from '../../../../shared/modules/transaction.utils';
import { import {
generateHistoryEntry, generateHistoryEntry,
replayHistory, replayHistory,
@ -28,12 +29,13 @@ import { getFinalStates, normalizeTxParams } from './lib/util';
* @class * @class
*/ */
export default class TransactionStateManager extends EventEmitter { export default class TransactionStateManager extends EventEmitter {
constructor({ initState, txHistoryLimit, getNetwork }) { constructor({ initState, txHistoryLimit, getNetwork, getCurrentChainId }) {
super(); super();
this.store = new ObservableStore({ transactions: [], ...initState }); this.store = new ObservableStore({ transactions: [], ...initState });
this.txHistoryLimit = txHistoryLimit; this.txHistoryLimit = txHistoryLimit;
this.getNetwork = getNetwork; this.getNetwork = getNetwork;
this.getCurrentChainId = getCurrentChainId;
} }
/** /**
@ -42,6 +44,7 @@ export default class TransactionStateManager extends EventEmitter {
*/ */
generateTxMeta(opts) { generateTxMeta(opts) {
const netId = this.getNetwork(); const netId = this.getNetwork();
const chainId = this.getCurrentChainId();
if (netId === 'loading') { if (netId === 'loading') {
throw new Error('MetaMask is having trouble connecting to the network'); throw new Error('MetaMask is having trouble connecting to the network');
} }
@ -50,6 +53,7 @@ export default class TransactionStateManager extends EventEmitter {
time: new Date().getTime(), time: new Date().getTime(),
status: TRANSACTION_STATUSES.UNAPPROVED, status: TRANSACTION_STATUSES.UNAPPROVED,
metamaskNetworkId: netId, metamaskNetworkId: netId,
chainId,
loadingDefaults: true, loadingDefaults: true,
...opts, ...opts,
}; };
@ -65,13 +69,14 @@ export default class TransactionStateManager extends EventEmitter {
*/ */
getTxList(limit) { getTxList(limit) {
const network = this.getNetwork(); const network = this.getNetwork();
const chainId = this.getCurrentChainId();
const fullTxList = this.getFullTxList(); const fullTxList = this.getFullTxList();
const nonces = new Set(); const nonces = new Set();
const txs = []; const txs = [];
for (let i = fullTxList.length - 1; i > -1; i--) { for (let i = fullTxList.length - 1; i > -1; i--) {
const txMeta = fullTxList[i]; const txMeta = fullTxList[i];
if (txMeta.metamaskNetworkId !== network) { if (transactionMatchesNetwork(txMeta, chainId, network) === false) {
continue; continue;
} }
@ -452,13 +457,14 @@ export default class TransactionStateManager extends EventEmitter {
// network only tx // network only tx
const txs = this.getFullTxList(); const txs = this.getFullTxList();
const network = this.getNetwork(); const network = this.getNetwork();
const chainId = this.getCurrentChainId();
// Filter out the ones from the current account and network // Filter out the ones from the current account and network
const otherAccountTxs = txs.filter( const otherAccountTxs = txs.filter(
(txMeta) => (txMeta) =>
!( !(
txMeta.txParams.from === address && txMeta.txParams.from === address &&
txMeta.metamaskNetworkId === network transactionMatchesNetwork(txMeta, chainId, network)
), ),
); );

@ -0,0 +1,6 @@
export function transactionMatchesNetwork(transaction, chainId, networkId) {
if (typeof transaction.chainId !== 'undefined') {
return transaction.chainId === chainId;
}
return transaction.metamaskNetworkId === networkId;
}

@ -3,6 +3,7 @@ import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk'; import thunk from 'redux-thunk';
import * as actions from '../../../ui/app/store/actions'; import * as actions from '../../../ui/app/store/actions';
import * as actionConstants from '../../../ui/app/store/actionConstants'; import * as actionConstants from '../../../ui/app/store/actionConstants';
import { ROPSTEN_CHAIN_ID } from '../../../shared/constants/network';
const middlewares = [thunk]; const middlewares = [thunk];
const mockStore = configureMockStore(middlewares); const mockStore = configureMockStore(middlewares);
@ -19,6 +20,9 @@ describe('tx confirmation screen', function () {
time: 1457634084250, time: 1457634084250,
}, },
}, },
provider: {
chainId: ROPSTEN_CHAIN_ID,
},
}, },
}; };

@ -272,7 +272,8 @@ describe('IncomingTransactionsController', function () {
'0xfake': { '0xfake': {
blockNumber: '10', blockNumber: '10',
hash: '0xfake', hash: '0xfake',
metamaskNetworkId: '3', metamaskNetworkId: ROPSTEN_NETWORK_ID,
chainId: ROPSTEN_CHAIN_ID,
status: TRANSACTION_STATUSES.CONFIRMED, status: TRANSACTION_STATUSES.CONFIRMED,
time: 16000000000000000, time: 16000000000000000,
transactionCategory: TRANSACTION_CATEGORIES.INCOMING, transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
@ -615,7 +616,8 @@ describe('IncomingTransactionsController', function () {
'0xfake': { '0xfake': {
blockNumber: '10', blockNumber: '10',
hash: '0xfake', hash: '0xfake',
metamaskNetworkId: '3', metamaskNetworkId: ROPSTEN_NETWORK_ID,
chainId: ROPSTEN_CHAIN_ID,
status: TRANSACTION_STATUSES.CONFIRMED, status: TRANSACTION_STATUSES.CONFIRMED,
time: 16000000000000000, time: 16000000000000000,
transactionCategory: TRANSACTION_CATEGORIES.INCOMING, transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
@ -769,7 +771,8 @@ describe('IncomingTransactionsController', function () {
'0xfake': { '0xfake': {
blockNumber: '10', blockNumber: '10',
hash: '0xfake', hash: '0xfake',
metamaskNetworkId: '3', metamaskNetworkId: ROPSTEN_NETWORK_ID,
chainId: ROPSTEN_CHAIN_ID,
status: TRANSACTION_STATUSES.CONFIRMED, status: TRANSACTION_STATUSES.CONFIRMED,
time: 16000000000000000, time: 16000000000000000,
transactionCategory: TRANSACTION_CATEGORIES.INCOMING, transactionCategory: TRANSACTION_CATEGORIES.INCOMING,
@ -1347,6 +1350,7 @@ describe('IncomingTransactionsController', function () {
blockNumber: 333, blockNumber: 333,
id: 54321, id: 54321,
metamaskNetworkId: ROPSTEN_NETWORK_ID, metamaskNetworkId: ROPSTEN_NETWORK_ID,
chainId: ROPSTEN_CHAIN_ID,
status: TRANSACTION_STATUSES.FAILED, status: TRANSACTION_STATUSES.FAILED,
time: 4444000, time: 4444000,
txParams: { txParams: {
@ -1392,6 +1396,7 @@ describe('IncomingTransactionsController', function () {
blockNumber: 333, blockNumber: 333,
id: 54321, id: 54321,
metamaskNetworkId: ROPSTEN_NETWORK_ID, metamaskNetworkId: ROPSTEN_NETWORK_ID,
chainId: ROPSTEN_CHAIN_ID,
status: TRANSACTION_STATUSES.CONFIRMED, status: TRANSACTION_STATUSES.CONFIRMED,
time: 4444000, time: 4444000,
txParams: { txParams: {

@ -864,6 +864,7 @@ describe('Transaction Controller', function () {
return '0xee6b2800'; return '0xee6b2800';
}, },
networkStore: new ObservableStore(currentNetworkId), networkStore: new ObservableStore(currentNetworkId),
getCurrentChainId: () => currentChainId,
txHistoryLimit: 10, txHistoryLimit: 10,
blockTracker: _blockTrackerStub, blockTracker: _blockTrackerStub,
signTransaction: (ethTx) => signTransaction: (ethTx) =>
@ -903,6 +904,7 @@ describe('Transaction Controller', function () {
return '0xee6b2800'; return '0xee6b2800';
}, },
networkStore: new ObservableStore(currentNetworkId), networkStore: new ObservableStore(currentNetworkId),
getCurrentChainId: () => currentChainId,
txHistoryLimit: 10, txHistoryLimit: 10,
blockTracker: _blockTrackerStub, blockTracker: _blockTrackerStub,
signTransaction: (ethTx) => signTransaction: (ethTx) =>

@ -1,16 +1,21 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import {
MAINNET_CHAIN_ID,
MAINNET_NETWORK_ID,
} from '../../../../../shared/constants/network';
import txHelper from '../../../../../ui/lib/tx-helper'; import txHelper from '../../../../../ui/lib/tx-helper';
describe('txHelper', function () { describe('txHelper', function () {
it('always shows the oldest tx first', function () { it('always shows the oldest tx first', function () {
const metamaskNetworkId = '1'; const metamaskNetworkId = MAINNET_NETWORK_ID;
const chainId = MAINNET_CHAIN_ID;
const txs = { const txs = {
a: { metamaskNetworkId, time: 3 }, a: { metamaskNetworkId, time: 3 },
b: { metamaskNetworkId, time: 1 }, b: { metamaskNetworkId, time: 1 },
c: { metamaskNetworkId, time: 2 }, c: { metamaskNetworkId, time: 2 },
}; };
const sorted = txHelper(txs, null, null, metamaskNetworkId); const sorted = txHelper(txs, null, null, metamaskNetworkId, chainId);
assert.equal(sorted[0].time, 1, 'oldest tx first'); assert.equal(sorted[0].time, 1, 'oldest tx first');
assert.equal(sorted[2].time, 3, 'newest tx last'); assert.equal(sorted[2].time, 3, 'newest tx last');
}); });

@ -3,12 +3,17 @@ import sinon from 'sinon';
import TxStateManager from '../../../../../app/scripts/controllers/transactions/tx-state-manager'; import TxStateManager from '../../../../../app/scripts/controllers/transactions/tx-state-manager';
import { snapshotFromTxMeta } from '../../../../../app/scripts/controllers/transactions/lib/tx-state-history-helpers'; import { snapshotFromTxMeta } from '../../../../../app/scripts/controllers/transactions/lib/tx-state-history-helpers';
import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../../../shared/constants/transaction';
import {
KOVAN_CHAIN_ID,
KOVAN_NETWORK_ID,
} from '../../../../../shared/constants/network';
const noop = () => true; const noop = () => true;
describe('TransactionStateManager', function () { describe('TransactionStateManager', function () {
let txStateManager; let txStateManager;
const currentNetworkId = '42'; const currentNetworkId = KOVAN_NETWORK_ID;
const currentChainId = KOVAN_CHAIN_ID;
const otherNetworkId = '2'; const otherNetworkId = '2';
beforeEach(function () { beforeEach(function () {
@ -18,6 +23,7 @@ describe('TransactionStateManager', function () {
}, },
txHistoryLimit: 10, txHistoryLimit: 10,
getNetwork: () => currentNetworkId, getNetwork: () => currentNetworkId,
getCurrentChainId: () => currentChainId,
}); });
}); });
@ -137,6 +143,7 @@ describe('TransactionStateManager', function () {
transactions: [submittedTx, confirmedTx], transactions: [submittedTx, confirmedTx],
}, },
getNetwork: () => currentNetworkId, getNetwork: () => currentNetworkId,
getCurrentChainId: () => currentChainId,
}); });
assert.deepEqual(txm.getTxList(), [submittedTx, confirmedTx]); assert.deepEqual(txm.getTxList(), [submittedTx, confirmedTx]);
@ -201,6 +208,7 @@ describe('TransactionStateManager', function () {
], ],
}, },
getNetwork: () => currentNetworkId, getNetwork: () => currentNetworkId,
getCurrentChainId: () => currentChainId,
}); });
assert.deepEqual(txm.getTxList(2), [approvedTx2, confirmedTx3]); assert.deepEqual(txm.getTxList(2), [approvedTx2, confirmedTx3]);
@ -235,6 +243,7 @@ describe('TransactionStateManager', function () {
const unapprovedTx1 = { const unapprovedTx1 = {
id: 1, id: 1,
metamaskNetworkId: currentNetworkId, metamaskNetworkId: currentNetworkId,
chainId: currentChainId,
time: 1, time: 1,
txParams: { txParams: {
from: '0xAddress', from: '0xAddress',
@ -259,6 +268,7 @@ describe('TransactionStateManager', function () {
{ {
id: 2, id: 2,
metamaskNetworkId: currentNetworkId, metamaskNetworkId: currentNetworkId,
chainId: currentChainId,
time: 2, time: 2,
txParams: { txParams: {
from: '0xAddress', from: '0xAddress',
@ -284,6 +294,7 @@ describe('TransactionStateManager', function () {
{ {
id: 3, id: 3,
metamaskNetworkId: currentNetworkId, metamaskNetworkId: currentNetworkId,
chainId: currentChainId,
time: 3, time: 3,
txParams: { txParams: {
from: '0xAddress', from: '0xAddress',
@ -304,6 +315,7 @@ describe('TransactionStateManager', function () {
], ],
}, },
getNetwork: () => currentNetworkId, getNetwork: () => currentNetworkId,
getCurrentChainId: () => currentChainId,
}); });
assert.deepEqual(txm.getTxList(2), [...approvedTx2s, ...failedTx3s]); assert.deepEqual(txm.getTxList(2), [...approvedTx2s, ...failedTx3s]);

@ -2,6 +2,10 @@ import assert from 'assert';
import configureMockStore from 'redux-mock-store'; import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk'; import thunk from 'redux-thunk';
import sinon from 'sinon'; import sinon from 'sinon';
import {
ROPSTEN_CHAIN_ID,
ROPSTEN_NETWORK_ID,
} from '../../../../shared/constants/network';
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
import ConfirmTransactionReducer, * as actions from './confirm-transaction.duck'; import ConfirmTransactionReducer, * as actions from './confirm-transaction.duck';
@ -289,7 +293,7 @@ describe('Confirm Transaction Duck', function () {
history: [], history: [],
id: 2603411941761054, id: 2603411941761054,
loadingDefaults: false, loadingDefaults: false,
metamaskNetworkId: '3', metamaskNetworkId: ROPSTEN_NETWORK_ID,
origin: 'faucet.metamask.io', origin: 'faucet.metamask.io',
status: TRANSACTION_STATUSES.UNAPPROVED, status: TRANSACTION_STATUSES.UNAPPROVED,
time: 1530838113716, time: 1530838113716,
@ -355,13 +359,16 @@ describe('Confirm Transaction Duck', function () {
metamask: { metamask: {
conversionRate: 468.58, conversionRate: 468.58,
currentCurrency: 'usd', currentCurrency: 'usd',
network: '3', network: ROPSTEN_NETWORK_ID,
provider: {
chainId: ROPSTEN_CHAIN_ID,
},
unapprovedTxs: { unapprovedTxs: {
2603411941761054: { 2603411941761054: {
history: [], history: [],
id: 2603411941761054, id: 2603411941761054,
loadingDefaults: false, loadingDefaults: false,
metamaskNetworkId: '3', metamaskNetworkId: ROPSTEN_NETWORK_ID,
origin: 'faucet.metamask.io', origin: 'faucet.metamask.io',
status: TRANSACTION_STATUSES.UNAPPROVED, status: TRANSACTION_STATUSES.UNAPPROVED,
time: 1530838113716, time: 1530838113716,

@ -39,6 +39,7 @@ import {
transactionFeeSelector, transactionFeeSelector,
} from '../../selectors'; } from '../../selectors';
import { getMostRecentOverviewPage } from '../../ducks/history/history'; import { getMostRecentOverviewPage } from '../../ducks/history/history';
import { transactionMatchesNetwork } from '../../../../shared/modules/transaction.utils';
import ConfirmTransactionBase from './confirm-transaction-base.component'; import ConfirmTransactionBase from './confirm-transaction-base.component';
const casedContractMap = Object.keys(contractMap).reduce((acc, base) => { const casedContractMap = Object.keys(contractMap).reduce((acc, base) => {
@ -77,6 +78,7 @@ const mapStateToProps = (state, ownProps) => {
unapprovedTxs, unapprovedTxs,
metaMetricsSendCount, metaMetricsSendCount,
nextNonce, nextNonce,
provider: { chainId },
} = metamask; } = metamask;
const { tokenData, txData, tokenProps, nonce } = confirmTransaction; const { tokenData, txData, tokenProps, nonce } = confirmTransaction;
const { const {
@ -127,7 +129,9 @@ const mapStateToProps = (state, ownProps) => {
} }
const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs) const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs)
.filter((key) => unapprovedTxs[key].metamaskNetworkId === network) .filter((key) =>
transactionMatchesNetwork(unapprovedTxs[key], chainId, network),
)
.reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {}); .reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {});
const unapprovedTxCount = valuesFor(currentNetworkUnapprovedTxs).length; const unapprovedTxCount = valuesFor(currentNetworkUnapprovedTxs).length;

@ -32,6 +32,7 @@ function mapStateToProps(state) {
index: txId, index: txId,
warning: state.appState.warning, warning: state.appState.warning,
network: state.metamask.network, network: state.metamask.network,
chainId: state.metamask.provider.chainId,
currentCurrency: state.metamask.currentCurrency, currentCurrency: state.metamask.currentCurrency,
blockGasLimit: state.metamask.currentBlockGasLimit, blockGasLimit: state.metamask.currentBlockGasLimit,
unapprovedMsgCount, unapprovedMsgCount,
@ -49,6 +50,7 @@ class ConfirmTxScreen extends Component {
unapprovedPersonalMsgCount: PropTypes.number, unapprovedPersonalMsgCount: PropTypes.number,
unapprovedTypedMessagesCount: PropTypes.number, unapprovedTypedMessagesCount: PropTypes.number,
network: PropTypes.string, network: PropTypes.string,
chainId: PropTypes.string,
index: PropTypes.number, index: PropTypes.number,
unapprovedTxs: PropTypes.object, unapprovedTxs: PropTypes.object,
unapprovedMsgs: PropTypes.object, unapprovedMsgs: PropTypes.object,
@ -94,6 +96,7 @@ class ConfirmTxScreen extends Component {
unapprovedPersonalMsgs, unapprovedPersonalMsgs,
unapprovedTypedMessages, unapprovedTypedMessages,
match: { params: { id: transactionId } = {} }, match: { params: { id: transactionId } = {} },
chainId,
} = this.props; } = this.props;
const unconfTxList = txHelper( const unconfTxList = txHelper(
@ -102,6 +105,7 @@ class ConfirmTxScreen extends Component {
unapprovedPersonalMsgs, unapprovedPersonalMsgs,
unapprovedTypedMessages, unapprovedTypedMessages,
network, network,
chainId,
); );
log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`); log.info(`rendering a combined ${unconfTxList.length} unconf msgs & txs`);
@ -177,9 +181,10 @@ class ConfirmTxScreen extends Component {
history, history,
mostRecentOverviewPage, mostRecentOverviewPage,
network, network,
chainId,
send, send,
} = this.props; } = this.props;
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network); const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network, chainId);
if ( if (
unconfTxList.length === 0 && unconfTxList.length === 0 &&
@ -194,6 +199,7 @@ class ConfirmTxScreen extends Component {
const { const {
unapprovedTxs = {}, unapprovedTxs = {},
network, network,
chainId,
currentNetworkTxList, currentNetworkTxList,
send, send,
history, history,
@ -207,13 +213,20 @@ class ConfirmTxScreen extends Component {
prevTx = currentNetworkTxList.find(({ id }) => `${id}` === transactionId); prevTx = currentNetworkTxList.find(({ id }) => `${id}` === transactionId);
} else { } else {
const { index: prevIndex, unapprovedTxs: prevUnapprovedTxs } = prevProps; const { index: prevIndex, unapprovedTxs: prevUnapprovedTxs } = prevProps;
const prevUnconfTxList = txHelper(prevUnapprovedTxs, {}, {}, {}, network); const prevUnconfTxList = txHelper(
prevUnapprovedTxs,
{},
{},
{},
network,
chainId,
);
const prevTxData = prevUnconfTxList[prevIndex] || {}; const prevTxData = prevUnconfTxList[prevIndex] || {};
prevTx = prevTx =
currentNetworkTxList.find(({ id }) => id === prevTxData.id) || {}; currentNetworkTxList.find(({ id }) => id === prevTxData.id) || {};
} }
const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network); const unconfTxList = txHelper(unapprovedTxs, {}, {}, {}, network, chainId);
if (prevTx && prevTx.status === TRANSACTION_STATUSES.DROPPED) { if (prevTx && prevTx.status === TRANSACTION_STATUSES.DROPPED) {
this.props.dispatch( this.props.dispatch(

@ -10,6 +10,8 @@ import {
addEth, addEth,
} from '../helpers/utils/confirm-tx.util'; } from '../helpers/utils/confirm-tx.util';
import { sumHexes } from '../helpers/utils/transactions.util'; import { sumHexes } from '../helpers/utils/transactions.util';
import { transactionMatchesNetwork } from '../../../shared/modules/transaction.utils';
import { getCurrentChainId, getCurrentNetworkId } from './selectors';
import { getNativeCurrency } from '.'; import { getNativeCurrency } from '.';
const unapprovedTxsSelector = (state) => state.metamask.unapprovedTxs; const unapprovedTxsSelector = (state) => state.metamask.unapprovedTxs;
@ -22,7 +24,6 @@ const unapprovedEncryptionPublicKeyMsgsSelector = (state) =>
state.metamask.unapprovedEncryptionPublicKeyMsgs; state.metamask.unapprovedEncryptionPublicKeyMsgs;
const unapprovedTypedMessagesSelector = (state) => const unapprovedTypedMessagesSelector = (state) =>
state.metamask.unapprovedTypedMessages; state.metamask.unapprovedTypedMessages;
const networkSelector = (state) => state.metamask.network;
export const unconfirmedTransactionsListSelector = createSelector( export const unconfirmedTransactionsListSelector = createSelector(
unapprovedTxsSelector, unapprovedTxsSelector,
@ -31,7 +32,8 @@ export const unconfirmedTransactionsListSelector = createSelector(
unapprovedDecryptMsgsSelector, unapprovedDecryptMsgsSelector,
unapprovedEncryptionPublicKeyMsgsSelector, unapprovedEncryptionPublicKeyMsgsSelector,
unapprovedTypedMessagesSelector, unapprovedTypedMessagesSelector,
networkSelector, getCurrentNetworkId,
getCurrentChainId,
( (
unapprovedTxs = {}, unapprovedTxs = {},
unapprovedMsgs = {}, unapprovedMsgs = {},
@ -40,6 +42,7 @@ export const unconfirmedTransactionsListSelector = createSelector(
unapprovedEncryptionPublicKeyMsgs = {}, unapprovedEncryptionPublicKeyMsgs = {},
unapprovedTypedMessages = {}, unapprovedTypedMessages = {},
network, network,
chainId,
) => ) =>
txHelper( txHelper(
unapprovedTxs, unapprovedTxs,
@ -49,6 +52,7 @@ export const unconfirmedTransactionsListSelector = createSelector(
unapprovedEncryptionPublicKeyMsgs, unapprovedEncryptionPublicKeyMsgs,
unapprovedTypedMessages, unapprovedTypedMessages,
network, network,
chainId,
) || [], ) || [],
); );
@ -59,7 +63,8 @@ export const unconfirmedTransactionsHashSelector = createSelector(
unapprovedDecryptMsgsSelector, unapprovedDecryptMsgsSelector,
unapprovedEncryptionPublicKeyMsgsSelector, unapprovedEncryptionPublicKeyMsgsSelector,
unapprovedTypedMessagesSelector, unapprovedTypedMessagesSelector,
networkSelector, getCurrentNetworkId,
getCurrentChainId,
( (
unapprovedTxs = {}, unapprovedTxs = {},
unapprovedMsgs = {}, unapprovedMsgs = {},
@ -68,13 +73,15 @@ export const unconfirmedTransactionsHashSelector = createSelector(
unapprovedEncryptionPublicKeyMsgs = {}, unapprovedEncryptionPublicKeyMsgs = {},
unapprovedTypedMessages = {}, unapprovedTypedMessages = {},
network, network,
chainId,
) => { ) => {
const filteredUnapprovedTxs = Object.keys(unapprovedTxs).reduce( const filteredUnapprovedTxs = Object.keys(unapprovedTxs).reduce(
(acc, address) => { (acc, address) => {
const { metamaskNetworkId } = unapprovedTxs[address];
const transactions = { ...acc }; const transactions = { ...acc };
if (metamaskNetworkId === network) { if (
transactionMatchesNetwork(unapprovedTxs[address], chainId, network)
) {
transactions[address] = unapprovedTxs[address]; transactions[address] = unapprovedTxs[address];
} }
@ -111,7 +118,8 @@ export const unconfirmedTransactionsCountSelector = createSelector(
unapprovedDecryptMsgCountSelector, unapprovedDecryptMsgCountSelector,
unapprovedEncryptionPublicKeyMsgCountSelector, unapprovedEncryptionPublicKeyMsgCountSelector,
unapprovedTypedMessagesCountSelector, unapprovedTypedMessagesCountSelector,
networkSelector, getCurrentNetworkId,
getCurrentChainId,
( (
unapprovedTxs = {}, unapprovedTxs = {},
unapprovedMsgCount = 0, unapprovedMsgCount = 0,
@ -120,12 +128,10 @@ export const unconfirmedTransactionsCountSelector = createSelector(
unapprovedEncryptionPublicKeyMsgCount = 0, unapprovedEncryptionPublicKeyMsgCount = 0,
unapprovedTypedMessagesCount = 0, unapprovedTypedMessagesCount = 0,
network, network,
chainId,
) => { ) => {
const filteredUnapprovedTxIds = Object.keys(unapprovedTxs).filter( const filteredUnapprovedTxIds = Object.keys(unapprovedTxs).filter((txId) =>
(txId) => { transactionMatchesNetwork(unapprovedTxs[txId], chainId, network),
const { metamaskNetworkId } = unapprovedTxs[txId];
return metamaskNetworkId === network;
},
); );
return ( return (

@ -1,4 +1,9 @@
import assert from 'assert'; import assert from 'assert';
import {
KOVAN_CHAIN_ID,
KOVAN_NETWORK_ID,
MAINNET_CHAIN_ID,
} from '../../../../shared/constants/network';
import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction'; import { TRANSACTION_CATEGORIES } from '../../../../shared/constants/transaction';
import { import {
unconfirmedTransactionsCountSelector, unconfirmedTransactionsCountSelector,
@ -22,16 +27,19 @@ describe('Confirm Transaction Selector', function () {
metamask: { metamask: {
unapprovedTxs: { unapprovedTxs: {
1: { 1: {
metamaskNetworkId: 'test', metamaskNetworkId: KOVAN_NETWORK_ID,
}, },
2: { 2: {
metmaskNetworkId: 'other network', chainId: MAINNET_CHAIN_ID,
}, },
}, },
unapprovedMsgCount: 1, unapprovedMsgCount: 1,
unapprovedPersonalMsgCount: 1, unapprovedPersonalMsgCount: 1,
unapprovedTypedMessagesCount: 1, unapprovedTypedMessagesCount: 1,
network: 'test', network: KOVAN_NETWORK_ID,
provider: {
chainId: KOVAN_CHAIN_ID,
},
}, },
}; };

@ -1,4 +1,8 @@
import { strict as assert } from 'assert'; import { strict as assert } from 'assert';
import {
KOVAN_CHAIN_ID,
MAINNET_CHAIN_ID,
} from '../../../../shared/constants/network';
import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction'; import { TRANSACTION_STATUSES } from '../../../../shared/constants/transaction';
import { import {
unapprovedMessagesSelector, unapprovedMessagesSelector,
@ -29,6 +33,9 @@ describe('Transaction Selectors', function () {
unapprovedMsgs: { unapprovedMsgs: {
1: msg, 1: msg,
}, },
provider: {
chainId: KOVAN_CHAIN_ID,
},
}, },
}; };
@ -56,6 +63,9 @@ describe('Transaction Selectors', function () {
unapprovedPersonalMsgs: { unapprovedPersonalMsgs: {
1: msg, 1: msg,
}, },
provider: {
chainId: KOVAN_CHAIN_ID,
},
}, },
}; };
@ -84,6 +94,9 @@ describe('Transaction Selectors', function () {
unapprovedTypedMessages: { unapprovedTypedMessages: {
1: msg, 1: msg,
}, },
provider: {
chainId: KOVAN_CHAIN_ID,
},
}, },
}; };
@ -100,6 +113,7 @@ describe('Transaction Selectors', function () {
metamask: { metamask: {
provider: { provider: {
nickname: 'mainnet', nickname: 'mainnet',
chainId: MAINNET_CHAIN_ID,
}, },
featureFlags: { featureFlags: {
showIncomingTransactions: false, showIncomingTransactions: false,
@ -163,6 +177,7 @@ describe('Transaction Selectors', function () {
metamask: { metamask: {
provider: { provider: {
nickname: 'mainnet', nickname: 'mainnet',
chainId: MAINNET_CHAIN_ID,
}, },
selectedAddress: '0xAddress', selectedAddress: '0xAddress',
featureFlags: { featureFlags: {
@ -247,6 +262,7 @@ describe('Transaction Selectors', function () {
metamask: { metamask: {
provider: { provider: {
nickname: 'mainnet', nickname: 'mainnet',
chainId: MAINNET_CHAIN_ID,
}, },
selectedAddress: '0xAddress', selectedAddress: '0xAddress',
featureFlags: { featureFlags: {

@ -10,6 +10,8 @@ import {
TRANSACTION_STATUSES, TRANSACTION_STATUSES,
TRANSACTION_TYPES, TRANSACTION_TYPES,
} from '../../../shared/constants/transaction'; } from '../../../shared/constants/transaction';
import { transactionMatchesNetwork } from '../../../shared/modules/transaction.utils';
import { getCurrentChainId, getCurrentNetworkId } from './selectors';
import { getSelectedAddress } from '.'; import { getSelectedAddress } from '.';
export const incomingTxListSelector = (state) => { export const incomingTxListSelector = (state) => {
@ -18,11 +20,15 @@ export const incomingTxListSelector = (state) => {
return []; return [];
} }
const { network } = state.metamask; const {
network,
provider: { chainId },
} = state.metamask;
const selectedAddress = getSelectedAddress(state); const selectedAddress = getSelectedAddress(state);
return Object.values(state.metamask.incomingTransactions).filter( return Object.values(state.metamask.incomingTransactions).filter(
({ metamaskNetworkId, txParams }) => (tx) =>
txParams.to === selectedAddress && metamaskNetworkId === network, tx.txParams.to === selectedAddress &&
transactionMatchesNetwork(tx, chainId, network),
); );
}; };
export const unapprovedMsgsSelector = (state) => state.metamask.unapprovedMsgs; export const unapprovedMsgsSelector = (state) => state.metamask.unapprovedMsgs;
@ -36,7 +42,6 @@ export const unapprovedEncryptionPublicKeyMsgsSelector = (state) =>
state.metamask.unapprovedEncryptionPublicKeyMsgs; state.metamask.unapprovedEncryptionPublicKeyMsgs;
export const unapprovedTypedMessagesSelector = (state) => export const unapprovedTypedMessagesSelector = (state) =>
state.metamask.unapprovedTypedMessages; state.metamask.unapprovedTypedMessages;
export const networkSelector = (state) => state.metamask.network;
export const selectedAddressTxListSelector = createSelector( export const selectedAddressTxListSelector = createSelector(
getSelectedAddress, getSelectedAddress,
@ -54,7 +59,8 @@ export const unapprovedMessagesSelector = createSelector(
unapprovedDecryptMsgsSelector, unapprovedDecryptMsgsSelector,
unapprovedEncryptionPublicKeyMsgsSelector, unapprovedEncryptionPublicKeyMsgsSelector,
unapprovedTypedMessagesSelector, unapprovedTypedMessagesSelector,
networkSelector, getCurrentNetworkId,
getCurrentChainId,
( (
unapprovedMsgs = {}, unapprovedMsgs = {},
unapprovedPersonalMsgs = {}, unapprovedPersonalMsgs = {},
@ -62,6 +68,7 @@ export const unapprovedMessagesSelector = createSelector(
unapprovedEncryptionPublicKeyMsgs = {}, unapprovedEncryptionPublicKeyMsgs = {},
unapprovedTypedMessages = {}, unapprovedTypedMessages = {},
network, network,
chainId,
) => ) =>
txHelper( txHelper(
{}, {},
@ -71,6 +78,7 @@ export const unapprovedMessagesSelector = createSelector(
unapprovedEncryptionPublicKeyMsgs, unapprovedEncryptionPublicKeyMsgs,
unapprovedTypedMessages, unapprovedTypedMessages,
network, network,
chainId,
) || [], ) || [],
); );

@ -930,6 +930,7 @@ export function completedTx(id) {
unapprovedPersonalMsgs, unapprovedPersonalMsgs,
unapprovedTypedMessages, unapprovedTypedMessages,
network, network,
provider: { chainId },
} = state.metamask; } = state.metamask;
const unconfirmedActions = txHelper( const unconfirmedActions = txHelper(
unapprovedTxs, unapprovedTxs,
@ -937,6 +938,7 @@ export function completedTx(id) {
unapprovedPersonalMsgs, unapprovedPersonalMsgs,
unapprovedTypedMessages, unapprovedTypedMessages,
network, network,
chainId,
); );
const otherUnconfirmedActions = unconfirmedActions.filter( const otherUnconfirmedActions = unconfirmedActions.filter(
(tx) => tx.id !== id, (tx) => tx.id !== id,

@ -117,6 +117,7 @@ async function startApp(metamaskState, backgroundConnection, opts) {
metamaskState.unapprovedEncryptionPublicKeyMsgs, metamaskState.unapprovedEncryptionPublicKeyMsgs,
metamaskState.unapprovedTypedMessages, metamaskState.unapprovedTypedMessages,
metamaskState.network, metamaskState.network,
metamaskState.provider.chainId,
); );
const numberOfUnapprovedTx = unapprovedTxsAll.length; const numberOfUnapprovedTx = unapprovedTxsAll.length;
if (numberOfUnapprovedTx > 0) { if (numberOfUnapprovedTx > 0) {

@ -1,4 +1,5 @@
import log from 'loglevel'; import log from 'loglevel';
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils';
import { valuesFor } from '../app/helpers/utils/util'; import { valuesFor } from '../app/helpers/utils/util';
export default function txHelper( export default function txHelper(
@ -9,6 +10,7 @@ export default function txHelper(
encryptionPublicKeyMsgs, encryptionPublicKeyMsgs,
typedMessages, typedMessages,
network, network,
chainId,
) { ) {
log.debug('tx-helper called with params:'); log.debug('tx-helper called with params:');
log.debug({ log.debug({
@ -19,11 +21,12 @@ export default function txHelper(
encryptionPublicKeyMsgs, encryptionPublicKeyMsgs,
typedMessages, typedMessages,
network, network,
chainId,
}); });
const txValues = network const txValues = network
? valuesFor(unapprovedTxs).filter( ? valuesFor(unapprovedTxs).filter((txMeta) =>
(txMeta) => txMeta.metamaskNetworkId === network, transactionMatchesNetwork(txMeta, chainId, network),
) )
: valuesFor(unapprovedTxs); : valuesFor(unapprovedTxs);
log.debug(`tx helper found ${txValues.length} unapproved txs`); log.debug(`tx helper found ${txValues.length} unapproved txs`);

Loading…
Cancel
Save