diff --git a/ui/app/components/app/transaction-list/transaction-list.component.js b/ui/app/components/app/transaction-list/transaction-list.component.js
index 5eea4645e..e089e75c6 100644
--- a/ui/app/components/app/transaction-list/transaction-list.component.js
+++ b/ui/app/components/app/transaction-list/transaction-list.component.js
@@ -1,4 +1,5 @@
import React, { useMemo, useEffect, useRef, useState, useCallback } from 'react'
+import PropTypes from 'prop-types'
import { useSelector, useDispatch } from 'react-redux'
import {
nonceSortedCompletedTransactionsSelector,
@@ -14,15 +15,38 @@ import Button from '../../ui/button'
const PAGE_INCREMENT = 10
-export default function TransactionList () {
+const getTransactionGroupRecipientAddressFilter = (recipientAddress) => {
+ return ({ initialTransaction: { txParams } }) => txParams && txParams.to === recipientAddress
+}
+
+export default function TransactionList ({ tokenAddress }) {
const [limit, setLimit] = useState(PAGE_INCREMENT)
const t = useI18nContext()
const dispatch = useDispatch()
- const pendingTransactions = useSelector(nonceSortedPendingTransactionsSelector)
- const completedTransactions = useSelector(nonceSortedCompletedTransactionsSelector)
+ const unfilteredPendingTransactions = useSelector(nonceSortedPendingTransactionsSelector)
+ const unfilteredCompletedTransactions = useSelector(nonceSortedCompletedTransactionsSelector)
const { transactionTime: transactionTimeFeatureActive } = useSelector(getFeatureFlags)
+ const pendingTransactions = useMemo(
+ () => (
+ tokenAddress && tokenAddress.startsWith('0x')
+ ? unfilteredPendingTransactions
+ .filter(getTransactionGroupRecipientAddressFilter(tokenAddress))
+ : unfilteredPendingTransactions
+ ),
+ [unfilteredPendingTransactions, tokenAddress]
+ )
+ const completedTransactions = useMemo(
+ () => (
+ tokenAddress && tokenAddress.startsWith('0x')
+ ? unfilteredCompletedTransactions
+ .filter(getTransactionGroupRecipientAddressFilter(tokenAddress))
+ : unfilteredCompletedTransactions
+ ),
+ [unfilteredCompletedTransactions, tokenAddress]
+ )
+
const { fetchGasEstimates, fetchBasicGasAndTimeEstimates } = useMemo(() => ({
fetchGasEstimates: (blockTime) => dispatch(actions.fetchGasEstimates(blockTime)),
fetchBasicGasAndTimeEstimates: () => dispatch(actions.fetchBasicGasAndTimeEstimates()),
@@ -96,3 +120,11 @@ export default function TransactionList () {
)
}
+
+TransactionList.propTypes = {
+ tokenAddress: PropTypes.string,
+}
+
+TransactionList.defaultProps = {
+ tokenAddress: undefined,
+}
diff --git a/ui/app/pages/home/home.component.js b/ui/app/pages/home/home.component.js
index ae98ad937..0be72eee8 100644
--- a/ui/app/pages/home/home.component.js
+++ b/ui/app/pages/home/home.component.js
@@ -256,7 +256,7 @@ export default class Home extends PureComponent {
data-testid="home__history-tab"
name="History"
>
-
+
diff --git a/ui/app/selectors/tests/transactions.test.js b/ui/app/selectors/tests/transactions.test.js
index 3f00c9e46..12a931e81 100644
--- a/ui/app/selectors/tests/transactions.test.js
+++ b/ui/app/selectors/tests/transactions.test.js
@@ -139,57 +139,6 @@ describe('Transaction Selectors', function () {
assert(Array.isArray(selectedTx))
assert.deepEqual(selectedTx, orderedTxList)
})
-
- it('returns token transactions from currentNetworkTxList when selectedTokenAddress is valid', function () {
-
- const state = {
- metamask: {
- provider: {
- nickname: 'mainnet',
- },
- featureFlags: {
- showIncomingTransactions: false,
- },
- selectedAddress: '0xAddress',
- selectedTokenAddress: '0xToken',
- currentNetworkTxList: [
- {
- id: 0,
- time: 0,
- txParams: {
- from: '0xAddress',
- to: '0xToken',
- },
- },
- {
- id: 1,
- time: 1,
- txParams: {
- from: '0xAddress',
- to: '0xRecipient',
- },
- },
- {
- id: 2,
- time: 2,
- txParams: {
- from: '0xAddress',
- to: '0xToken',
- },
- },
- ],
- },
- }
-
- const orderedTxList = state.metamask.currentNetworkTxList
- .filter((tx) => tx.txParams.to === '0xToken')
- .sort((a, b) => b.time - a.time)
-
- const selectedTx = transactionsSelector(state)
-
- assert(Array.isArray(selectedTx))
- assert.deepEqual(selectedTx, orderedTxList)
- })
})
describe('nonceSortedTransactionsSelector', function () {
diff --git a/ui/app/selectors/transactions.js b/ui/app/selectors/transactions.js
index d60138800..2906ff301 100644
--- a/ui/app/selectors/transactions.js
+++ b/ui/app/selectors/transactions.js
@@ -10,7 +10,6 @@ import {
TRANSACTION_TYPE_RETRY,
} from '../../../app/scripts/controllers/transactions/enums'
import { hexToDecimal } from '../helpers/utils/conversions.util'
-import { selectedTokenAddressSelector } from './tokens'
import { getFastPriceEstimateInHexWEI } from './custom-gas'
import {
getSelectedToken,
@@ -80,23 +79,14 @@ export const transactionSubSelector = createSelector(
}
)
-const transactionSelectorReturnHelper = (selectedTokenAddress, transactions) => {
- return selectedTokenAddress
- ? transactions
- .filter(({ txParams }) => txParams && txParams.to === selectedTokenAddress)
- .sort((a, b) => b.time - a.time)
- : transactions
- .sort((a, b) => b.time - a.time)
-}
-
export const transactionsSelector = createSelector(
- selectedTokenAddressSelector,
transactionSubSelector,
selectedAddressTxListSelector,
- (selectedTokenAddress, subSelectorTxList = [], selectedAddressTxList = []) => {
+ (subSelectorTxList = [], selectedAddressTxList = []) => {
const txsToRender = selectedAddressTxList.concat(subSelectorTxList)
- return transactionSelectorReturnHelper(selectedTokenAddress, txsToRender)
+ return txsToRender
+ .sort((a, b) => b.time - a.time)
}
)