import React, { useContext } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory, useParams } from 'react-router-dom'; import { unconfirmedTransactionsHashSelector, unapprovedDecryptMsgsSelector, unapprovedEncryptionPublicKeyMsgsSelector, } from '../../../../selectors'; import { I18nContext } from '../../../../contexts/i18n'; import { CONFIRM_TRANSACTION_ROUTE, SIGNATURE_REQUEST_PATH, } from '../../../../helpers/constants/routes'; import { clearConfirmTransaction } from '../../../../ducks/confirm-transaction/confirm-transaction.duck'; const ConfirmPageContainerNavigation = () => { const t = useContext(I18nContext); const dispatch = useDispatch(); const history = useHistory(); const { id } = useParams(); const unapprovedDecryptMsgs = useSelector(unapprovedDecryptMsgsSelector); const unapprovedEncryptionPublicKeyMsgs = useSelector( unapprovedEncryptionPublicKeyMsgsSelector, ); const uncofirmedTransactions = useSelector( unconfirmedTransactionsHashSelector, ); const enumUnapprovedDecryptMsgsKey = Object.keys(unapprovedDecryptMsgs || {}); const enumUnapprovedEncryptMsgsKey = Object.keys( unapprovedEncryptionPublicKeyMsgs || {}, ); const enumDecryptAndEncryptMsgs = [ ...enumUnapprovedDecryptMsgsKey, ...enumUnapprovedEncryptMsgsKey, ]; const enumUnapprovedTxs = Object.keys(uncofirmedTransactions).filter( (key) => enumDecryptAndEncryptMsgs.includes(key) === false, ); 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( uncofirmedTransactions[txId]?.msgParams ? `${CONFIRM_TRANSACTION_ROUTE}/${txId}${SIGNATURE_REQUEST_PATH}` : `${CONFIRM_TRANSACTION_ROUTE}/${txId}`, ); } }; return (