Skip to content

Commit

Permalink
Fixed navigation through multiple unapproved transactions for ERC20 t…
Browse files Browse the repository at this point in the history
…okens
  • Loading branch information
filipsekulic committed Dec 14, 2022
1 parent 0511d6f commit 3ccbee0
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ui/pages/token-allowance/token-allowance.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ import { useGasFeeContext } from '../../contexts/gasFee';
import { getCustomTxParamsData } from '../confirm-approve/confirm-approve.util';
import { setCustomTokenAmount } from '../../ducks/app/app';
import { valuesFor } from '../../helpers/utils/util';
import { ConfirmPageContainerNavigation } from '../../components/app/confirm-page-container';
import { transactionMatchesNetwork } from '../../../shared/modules/transaction.utils';
import { hexToDecimal } from '../../../shared/lib/metamask-controller-utils';
import { CONFIRM_TRANSACTION_ROUTE } from '../../helpers/constants/routes';

export default function TokenAllowance({
origin,
Expand Down Expand Up @@ -208,6 +212,38 @@ export default function TokenAllowance({

const isEmpty = customTokenAmount === '';

const network = hexToDecimal(fullTxData.chainId);

const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs)
.filter((key) =>
transactionMatchesNetwork(
unapprovedTxs[key],
fullTxData.chainId,
network,
),
)
.reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {});

const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs);
const currentPosition = enumUnapprovedTxs.indexOf(
fullTxData.id ? fullTxData.id.toString() : '',
);

const totalTx = enumUnapprovedTxs.length;
const positionOfCurrentTx = currentPosition + 1;
const nextTxId = enumUnapprovedTxs[currentPosition + 1];
const prevTxId = enumUnapprovedTxs[currentPosition - 1];
const showNavigation = enumUnapprovedTxs.length > 1;
const firstTx = enumUnapprovedTxs[0];
const lastTx = enumUnapprovedTxs[enumUnapprovedTxs.length - 1];

const handleNextTx = (txId) => {
if (txId) {
dispatch(clearConfirmTransaction());
history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`);
}
};

const renderContractTokenValues = (
<Box marginTop={4} key={tokenAddress}>
<ContractTokenValues
Expand All @@ -221,6 +257,20 @@ export default function TokenAllowance({

return (
<Box className="token-allowance-container page-container">
<Box>
<ConfirmPageContainerNavigation
totalTx={totalTx}
positionOfCurrentTx={positionOfCurrentTx}
nextTxId={nextTxId}
prevTxId={prevTxId}
showNavigation={showNavigation}
onNextTx={(txId) => handleNextTx(txId)}
firstTx={firstTx}
lastTx={lastTx}
ofText={t('ofTextNofM')}
requestsWaitingText={t('requestsAwaitingAcknowledgement')}
/>
</Box>
<Box
paddingLeft={4}
paddingRight={4}
Expand Down

0 comments on commit 3ccbee0

Please sign in to comment.