2021-02-04 19:15:23 +01:00
|
|
|
import { createSelector } from 'reselect';
|
2018-07-31 07:03:20 +02:00
|
|
|
import {
|
2020-05-26 22:49:11 +02:00
|
|
|
PRIORITY_STATUS_HASH,
|
|
|
|
PENDING_STATUS_HASH,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../helpers/constants/transactions';
|
|
|
|
import { hexToDecimal } from '../helpers/utils/conversions.util';
|
2021-04-28 21:53:59 +02:00
|
|
|
import txHelper from '../helpers/utils/tx-helper';
|
2020-11-03 23:57:51 +01:00
|
|
|
import {
|
|
|
|
TRANSACTION_STATUSES,
|
|
|
|
TRANSACTION_TYPES,
|
2022-02-18 17:48:38 +01:00
|
|
|
SMART_TRANSACTION_STATUSES,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../shared/constants/transaction';
|
|
|
|
import { transactionMatchesNetwork } from '../../shared/modules/transaction.utils';
|
2022-01-07 20:18:02 +01:00
|
|
|
import {
|
|
|
|
getCurrentChainId,
|
|
|
|
deprecatedGetCurrentNetworkId,
|
|
|
|
getSelectedAddress,
|
|
|
|
} from './selectors';
|
2018-08-06 07:25:58 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
export const incomingTxListSelector = (state) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { showIncomingTransactions } = state.metamask.featureFlags;
|
2019-08-21 20:42:14 +02:00
|
|
|
if (!showIncomingTransactions) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return [];
|
2019-08-21 20:42:14 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 16:15:42 +01:00
|
|
|
const {
|
|
|
|
network,
|
|
|
|
provider: { chainId },
|
|
|
|
} = state.metamask;
|
2021-02-04 19:15:23 +01:00
|
|
|
const selectedAddress = getSelectedAddress(state);
|
2020-11-03 00:41:28 +01:00
|
|
|
return Object.values(state.metamask.incomingTransactions).filter(
|
2021-03-01 16:15:42 +01:00
|
|
|
(tx) =>
|
|
|
|
tx.txParams.to === selectedAddress &&
|
|
|
|
transactionMatchesNetwork(tx, chainId, network),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
export const unapprovedMsgsSelector = (state) => state.metamask.unapprovedMsgs;
|
2020-11-03 00:41:28 +01:00
|
|
|
export const currentNetworkTxListSelector = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
state.metamask.currentNetworkTxList;
|
2020-11-03 00:41:28 +01:00
|
|
|
export const unapprovedPersonalMsgsSelector = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
state.metamask.unapprovedPersonalMsgs;
|
2020-11-03 00:41:28 +01:00
|
|
|
export const unapprovedDecryptMsgsSelector = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
state.metamask.unapprovedDecryptMsgs;
|
2020-11-03 00:41:28 +01:00
|
|
|
export const unapprovedEncryptionPublicKeyMsgsSelector = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
state.metamask.unapprovedEncryptionPublicKeyMsgs;
|
2020-11-03 00:41:28 +01:00
|
|
|
export const unapprovedTypedMessagesSelector = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
state.metamask.unapprovedTypedMessages;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2022-02-18 17:48:38 +01:00
|
|
|
export const smartTransactionsListSelector = (state) =>
|
|
|
|
state.metamask.smartTransactionsState?.smartTransactions?.[
|
|
|
|
getCurrentChainId(state)
|
|
|
|
]
|
|
|
|
?.filter((stx) => !stx.confirmed)
|
|
|
|
.map((stx) => ({
|
|
|
|
...stx,
|
|
|
|
transactionType: TRANSACTION_TYPES.SMART,
|
|
|
|
status: stx.status?.startsWith('cancelled')
|
|
|
|
? SMART_TRANSACTION_STATUSES.CANCELLED
|
|
|
|
: stx.status,
|
|
|
|
}));
|
|
|
|
|
2020-03-06 22:34:56 +01:00
|
|
|
export const selectedAddressTxListSelector = createSelector(
|
|
|
|
getSelectedAddress,
|
|
|
|
currentNetworkTxListSelector,
|
2022-02-18 17:48:38 +01:00
|
|
|
smartTransactionsListSelector,
|
|
|
|
(selectedAddress, transactions = [], smTransactions = []) => {
|
|
|
|
return transactions
|
|
|
|
.filter(({ txParams }) => txParams.from === selectedAddress)
|
|
|
|
.concat(smTransactions);
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
export const unapprovedMessagesSelector = createSelector(
|
|
|
|
unapprovedMsgsSelector,
|
|
|
|
unapprovedPersonalMsgsSelector,
|
2020-02-19 19:24:16 +01:00
|
|
|
unapprovedDecryptMsgsSelector,
|
|
|
|
unapprovedEncryptionPublicKeyMsgsSelector,
|
2018-12-09 21:48:06 +01:00
|
|
|
unapprovedTypedMessagesSelector,
|
2021-03-12 23:23:26 +01:00
|
|
|
deprecatedGetCurrentNetworkId,
|
2021-03-01 16:15:42 +01:00
|
|
|
getCurrentChainId,
|
2018-12-09 21:48:06 +01:00
|
|
|
(
|
|
|
|
unapprovedMsgs = {},
|
|
|
|
unapprovedPersonalMsgs = {},
|
2020-02-19 19:24:16 +01:00
|
|
|
unapprovedDecryptMsgs = {},
|
|
|
|
unapprovedEncryptionPublicKeyMsgs = {},
|
2018-12-09 21:48:06 +01:00
|
|
|
unapprovedTypedMessages = {},
|
2020-07-14 17:20:41 +02:00
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2020-11-03 00:41:28 +01:00
|
|
|
) =>
|
|
|
|
txHelper(
|
|
|
|
{},
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
|
|
|
unapprovedDecryptMsgs,
|
|
|
|
unapprovedEncryptionPublicKeyMsgs,
|
|
|
|
unapprovedTypedMessages,
|
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2020-11-03 00:41:28 +01:00
|
|
|
) || [],
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-31 07:03:20 +02:00
|
|
|
|
2020-03-06 22:34:56 +01:00
|
|
|
export const transactionSubSelector = createSelector(
|
2018-12-09 21:48:06 +01:00
|
|
|
unapprovedMessagesSelector,
|
2019-08-16 20:54:10 +02:00
|
|
|
incomingTxListSelector,
|
2020-04-24 17:33:24 +02:00
|
|
|
(unapprovedMessages = [], incomingTxList = []) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return unapprovedMessages.concat(incomingTxList);
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-03-06 22:34:56 +01:00
|
|
|
|
|
|
|
export const transactionsSelector = createSelector(
|
|
|
|
transactionSubSelector,
|
2018-07-31 07:03:20 +02:00
|
|
|
selectedAddressTxListSelector,
|
2020-05-28 05:11:15 +02:00
|
|
|
(subSelectorTxList = [], selectedAddressTxList = []) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const txsToRender = selectedAddressTxList.concat(subSelectorTxList);
|
2018-07-31 07:03:20 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return txsToRender.sort((a, b) => b.time - a.time);
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-31 07:03:20 +02:00
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
/**
|
|
|
|
* @name insertOrderedNonce
|
|
|
|
* @private
|
|
|
|
* @description Inserts (mutates) a nonce into an array of ordered nonces, sorted in ascending
|
|
|
|
* order.
|
|
|
|
* @param {string[]} nonces - Array of nonce strings in hex
|
|
|
|
* @param {string} nonceToInsert - Nonce string in hex to be inserted into the array of nonces.
|
|
|
|
*/
|
|
|
|
const insertOrderedNonce = (nonces, nonceToInsert) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let insertIndex = nonces.length;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
for (let i = 0; i < nonces.length; i++) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nonce = nonces[i];
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2019-01-14 23:34:37 +01:00
|
|
|
if (Number(hexToDecimal(nonce)) > Number(hexToDecimal(nonceToInsert))) {
|
2021-02-04 19:15:23 +01:00
|
|
|
insertIndex = i;
|
|
|
|
break;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
nonces.splice(insertIndex, 0, nonceToInsert);
|
|
|
|
};
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name insertTransactionByTime
|
|
|
|
* @private
|
|
|
|
* @description Inserts (mutates) a transaction object into an array of ordered transactions, sorted
|
|
|
|
* in ascending order by time.
|
|
|
|
* @param {Object[]} transactions - Array of transaction objects.
|
|
|
|
* @param {Object} transaction - Transaction object to be inserted into the array of transactions.
|
|
|
|
*/
|
|
|
|
const insertTransactionByTime = (transactions, transaction) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { time } = transaction;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let insertIndex = transactions.length;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
for (let i = 0; i < transactions.length; i++) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const tx = transactions[i];
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
if (tx.time > time) {
|
2021-02-04 19:15:23 +01:00
|
|
|
insertIndex = i;
|
|
|
|
break;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
transactions.splice(insertIndex, 0, transaction);
|
|
|
|
};
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains transactions and properties associated with those transactions of the same nonce.
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2018-12-09 21:48:06 +01:00
|
|
|
* @typedef {Object} transactionGroup
|
|
|
|
* @property {string} nonce - The nonce that the transactions within this transactionGroup share.
|
|
|
|
* @property {Object[]} transactions - An array of transaction (txMeta) objects.
|
|
|
|
* @property {Object} initialTransaction - The transaction (txMeta) with the lowest "time".
|
|
|
|
* @property {Object} primaryTransaction - Either the latest transaction or the confirmed
|
|
|
|
* transaction.
|
|
|
|
* @property {boolean} hasRetried - True if a transaction in the group was a retry transaction.
|
|
|
|
* @property {boolean} hasCancelled - True if a transaction in the group was a cancel transaction.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name insertTransactionGroupByTime
|
|
|
|
* @private
|
|
|
|
* @description Inserts (mutates) a transactionGroup object into an array of ordered
|
|
|
|
* transactionGroups, sorted in ascending order by nonce.
|
|
|
|
* @param {transactionGroup[]} transactionGroups - Array of transactionGroup objects.
|
|
|
|
* @param {transactionGroup} transactionGroup - transactionGroup object to be inserted into the
|
|
|
|
* array of transactionGroups.
|
|
|
|
*/
|
|
|
|
const insertTransactionGroupByTime = (transactionGroups, transactionGroup) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
primaryTransaction: { time: groupToInsertTime } = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = transactionGroup;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let insertIndex = transactionGroups.length;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
for (let i = 0; i < transactionGroups.length; i++) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const txGroup = transactionGroups[i];
|
|
|
|
const { primaryTransaction: { time } = {} } = txGroup;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2019-01-14 23:34:37 +01:00
|
|
|
if (time > groupToInsertTime) {
|
2021-02-04 19:15:23 +01:00
|
|
|
insertIndex = i;
|
|
|
|
break;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
transactionGroups.splice(insertIndex, 0, transactionGroup);
|
|
|
|
};
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2019-01-14 23:34:37 +01:00
|
|
|
/**
|
2019-08-16 20:54:10 +02:00
|
|
|
* @name mergeNonNonceTransactionGroups
|
2019-01-14 23:34:37 +01:00
|
|
|
* @private
|
2019-08-16 20:54:10 +02:00
|
|
|
* @description Inserts (mutates) transactionGroups that are not to be ordered by nonce into an array
|
2020-04-24 17:33:24 +02:00
|
|
|
* of nonce-ordered transactionGroups by time.
|
2019-01-14 23:34:37 +01:00
|
|
|
* @param {transactionGroup[]} orderedTransactionGroups - Array of transactionGroups ordered by
|
|
|
|
* nonce.
|
2019-08-16 20:54:10 +02:00
|
|
|
* @param {transactionGroup[]} nonNonceTransactionGroups - Array of transactionGroups not intended to be ordered by nonce,
|
|
|
|
* but intended to be ordered by timestamp
|
2019-01-14 23:34:37 +01:00
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
const mergeNonNonceTransactionGroups = (
|
|
|
|
orderedTransactionGroups,
|
|
|
|
nonNonceTransactionGroups,
|
|
|
|
) => {
|
2020-04-24 17:33:24 +02:00
|
|
|
nonNonceTransactionGroups.forEach((transactionGroup) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
insertTransactionGroupByTime(orderedTransactionGroups, transactionGroup);
|
|
|
|
});
|
|
|
|
};
|
2019-01-14 23:34:37 +01:00
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
/**
|
|
|
|
* @name nonceSortedTransactionsSelector
|
|
|
|
* @description Returns an array of transactionGroups sorted by nonce in ascending order.
|
|
|
|
* @returns {transactionGroup[]}
|
|
|
|
*/
|
|
|
|
export const nonceSortedTransactionsSelector = createSelector(
|
2018-07-31 07:03:20 +02:00
|
|
|
transactionsSelector,
|
2018-12-09 21:48:06 +01:00
|
|
|
(transactions = []) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const unapprovedTransactionGroups = [];
|
|
|
|
const incomingTransactionGroups = [];
|
|
|
|
const orderedNonces = [];
|
|
|
|
const nonceToTransactionsMap = {};
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
transactions.forEach((transaction) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
txParams: { nonce } = {},
|
|
|
|
status,
|
|
|
|
type,
|
|
|
|
time: txTime,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = transaction;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2021-03-10 21:16:44 +01:00
|
|
|
if (typeof nonce === 'undefined' || type === TRANSACTION_TYPES.INCOMING) {
|
2018-12-09 21:48:06 +01:00
|
|
|
const transactionGroup = {
|
|
|
|
transactions: [transaction],
|
|
|
|
initialTransaction: transaction,
|
|
|
|
primaryTransaction: transaction,
|
|
|
|
hasRetried: false,
|
|
|
|
hasCancelled: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2021-03-10 21:16:44 +01:00
|
|
|
if (type === TRANSACTION_TYPES.INCOMING) {
|
2021-02-04 19:15:23 +01:00
|
|
|
incomingTransactionGroups.push(transactionGroup);
|
2019-01-14 23:34:37 +01:00
|
|
|
} else {
|
2020-11-03 00:41:28 +01:00
|
|
|
insertTransactionGroupByTime(
|
|
|
|
unapprovedTransactionGroups,
|
|
|
|
transactionGroup,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-01-14 23:34:37 +01:00
|
|
|
}
|
2018-12-09 21:48:06 +01:00
|
|
|
} else if (nonce in nonceToTransactionsMap) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const nonceProps = nonceToTransactionsMap[nonce];
|
|
|
|
insertTransactionByTime(nonceProps.transactions, transaction);
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
primaryTransaction: { time: primaryTxTime = 0 } = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = nonceProps;
|
2020-11-03 00:41:28 +01:00
|
|
|
|
|
|
|
const previousPrimaryIsNetworkFailure =
|
2020-11-03 23:57:51 +01:00
|
|
|
nonceProps.primaryTransaction.status ===
|
|
|
|
TRANSACTION_STATUSES.FAILED &&
|
2021-02-04 19:15:23 +01:00
|
|
|
nonceProps.primaryTransaction?.txReceipt?.status !== '0x0';
|
2020-11-03 00:41:28 +01:00
|
|
|
const currentTransactionIsOnChainFailure =
|
2021-02-04 19:15:23 +01:00
|
|
|
transaction?.txReceipt?.status === '0x0';
|
2020-11-03 00:41:28 +01:00
|
|
|
|
|
|
|
if (
|
2020-11-03 23:57:51 +01:00
|
|
|
status === TRANSACTION_STATUSES.CONFIRMED ||
|
2020-11-03 00:41:28 +01:00
|
|
|
currentTransactionIsOnChainFailure ||
|
|
|
|
previousPrimaryIsNetworkFailure ||
|
|
|
|
(txTime > primaryTxTime && status in PRIORITY_STATUS_HASH)
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
nonceProps.primaryTransaction = transaction;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
initialTransaction: { time: initialTxTime = 0 } = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = nonceProps;
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
// Used to display the transaction action, since we don't want to overwrite the action if
|
|
|
|
// it was replaced with a cancel attempt transaction.
|
|
|
|
if (txTime < initialTxTime) {
|
2021-02-04 19:15:23 +01:00
|
|
|
nonceProps.initialTransaction = transaction;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
|
2021-09-15 23:42:06 +02:00
|
|
|
if (
|
|
|
|
type === TRANSACTION_TYPES.RETRY &&
|
|
|
|
status in PRIORITY_STATUS_HASH
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
nonceProps.hasRetried = true;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
|
2021-09-15 23:42:06 +02:00
|
|
|
if (
|
|
|
|
type === TRANSACTION_TYPES.CANCEL &&
|
|
|
|
status in PRIORITY_STATUS_HASH
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
nonceProps.hasCancelled = true;
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nonceToTransactionsMap[nonce] = {
|
|
|
|
nonce,
|
|
|
|
transactions: [transaction],
|
|
|
|
initialTransaction: transaction,
|
|
|
|
primaryTransaction: transaction,
|
2021-09-15 23:42:06 +02:00
|
|
|
hasRetried:
|
|
|
|
transaction.type === TRANSACTION_TYPES.RETRY &&
|
|
|
|
transaction.status in PRIORITY_STATUS_HASH,
|
|
|
|
hasCancelled:
|
|
|
|
transaction.type === TRANSACTION_TYPES.CANCEL &&
|
|
|
|
transaction.status in PRIORITY_STATUS_HASH,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
insertOrderedNonce(orderedNonces, nonce);
|
2018-12-09 21:48:06 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-12-09 21:48:06 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const orderedTransactionGroups = orderedNonces.map(
|
|
|
|
(nonce) => nonceToTransactionsMap[nonce],
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
mergeNonNonceTransactionGroups(
|
|
|
|
orderedTransactionGroups,
|
|
|
|
incomingTransactionGroups,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
return unapprovedTransactionGroups.concat(orderedTransactionGroups);
|
2020-07-14 17:20:41 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-12-09 21:48:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name nonceSortedPendingTransactionsSelector
|
|
|
|
* @description Returns an array of transactionGroups where transactions are still pending sorted by
|
|
|
|
* nonce in descending order.
|
|
|
|
* @returns {transactionGroup[]}
|
|
|
|
*/
|
|
|
|
export const nonceSortedPendingTransactionsSelector = createSelector(
|
|
|
|
nonceSortedTransactionsSelector,
|
2020-11-03 00:41:28 +01:00
|
|
|
(transactions = []) =>
|
|
|
|
transactions.filter(
|
|
|
|
({ primaryTransaction }) =>
|
|
|
|
primaryTransaction.status in PENDING_STATUS_HASH,
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-07-31 07:03:20 +02:00
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
/**
|
|
|
|
* @name nonceSortedCompletedTransactionsSelector
|
|
|
|
* @description Returns an array of transactionGroups where transactions are confirmed sorted by
|
|
|
|
* nonce in descending order.
|
|
|
|
* @returns {transactionGroup[]}
|
|
|
|
*/
|
|
|
|
export const nonceSortedCompletedTransactionsSelector = createSelector(
|
|
|
|
nonceSortedTransactionsSelector,
|
2020-11-03 00:41:28 +01:00
|
|
|
(transactions = []) =>
|
2019-01-14 23:34:37 +01:00
|
|
|
transactions
|
2020-11-03 00:41:28 +01:00
|
|
|
.filter(
|
|
|
|
({ primaryTransaction }) =>
|
|
|
|
!(primaryTransaction.status in PENDING_STATUS_HASH),
|
|
|
|
)
|
|
|
|
.reverse(),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-08-07 07:39:54 +02:00
|
|
|
|
2018-12-09 21:48:06 +01:00
|
|
|
export const submittedPendingTransactionsSelector = createSelector(
|
2018-07-31 07:03:20 +02:00
|
|
|
transactionsSelector,
|
2020-11-03 00:41:28 +01:00
|
|
|
(transactions = []) =>
|
|
|
|
transactions.filter(
|
2020-11-03 23:57:51 +01:00
|
|
|
(transaction) => transaction.status === TRANSACTION_STATUSES.SUBMITTED,
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|