import React, { useContext } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory, useParams } from 'react-router-dom'; import { getCurrentChainId, getUnapprovedTransactions, } from '../../../../selectors'; import { transactionMatchesNetwork } from '../../../../../shared/modules/transaction.utils'; import { I18nContext } from '../../../../contexts/i18n'; import { CONFIRM_TRANSACTION_ROUTE } from '../../../../helpers/constants/routes'; import { clearConfirmTransaction } from '../../../../ducks/confirm-transaction/confirm-transaction.duck'; import { hexToDecimal } from '../../../../../shared/modules/conversion.utils'; const ConfirmPageContainerNavigation = () => { const t = useContext(I18nContext); const dispatch = useDispatch(); const history = useHistory(); const { id } = useParams(); const unapprovedTxs = useSelector(getUnapprovedTransactions); const currentChainId = useSelector(getCurrentChainId); const network = hexToDecimal(currentChainId); const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs) .filter((key) => transactionMatchesNetwork(unapprovedTxs[key], currentChainId, network), ) .reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {}); const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs); const currentPosition = enumUnapprovedTxs.indexOf(id); 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 onNextTx = (txId) => { if (txId) { dispatch(clearConfirmTransaction()); history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`); } }; return (