From 0c93b4baca17bbef417318ef27647c8ddccb13e8 Mon Sep 17 00:00:00 2001 From: VSaric Date: Fri, 6 Jan 2023 13:39:49 +0100 Subject: [PATCH] Added navigation between multiple sign prompts and reject all sign prompts --- ...irm-page-container-navigation.component.js | 25 ++++--- .../signature-request-original.test.js.snap | 70 +++++++++++++++++++ .../app/signature-request-original/index.scss | 5 +- .../signature-request-original.component.js | 5 ++ .../signature-request-original.test.js | 6 ++ .../app/signature-request/index.scss | 7 +- .../signature-request.component.js | 44 +++++++++++- .../signature-request.container.js | 47 ++++++++++++- .../signature-request.container.test.js | 1 + .../confirm-transaction.container.js | 8 ++- 10 files changed, 201 insertions(+), 17 deletions(-) diff --git a/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js b/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js index 9dd4160b7dc5..76230d7c7a26 100755 --- a/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js +++ b/ui/components/app/confirm-page-container/confirm-page-container-navigation/confirm-page-container-navigation.component.js @@ -1,26 +1,31 @@ import React, { useContext } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory, useParams } from 'react-router-dom'; -import PropTypes from 'prop-types'; import { getCurrentChainId, getUnapprovedTransactions, + unconfirmedMessagesHashSelector, } from '../../../../selectors'; import { transactionMatchesNetwork } from '../../../../../shared/modules/transaction.utils'; import { I18nContext } from '../../../../contexts/i18n'; -import { CONFIRM_TRANSACTION_ROUTE } from '../../../../helpers/constants/routes'; +import { + CONFIRM_TRANSACTION_ROUTE, + SIGNATURE_REQUEST_PATH, +} from '../../../../helpers/constants/routes'; import { clearConfirmTransaction } from '../../../../ducks/confirm-transaction/confirm-transaction.duck'; import { hexToDecimal } from '../../../../../shared/lib/metamask-controller-utils'; -const ConfirmPageContainerNavigation = ({ txData }) => { +const ConfirmPageContainerNavigation = () => { const t = useContext(I18nContext); const dispatch = useDispatch(); const history = useHistory(); const { id } = useParams(); const unapprovedTxs = useSelector(getUnapprovedTransactions); + const unconfirmedMessages = useSelector(unconfirmedMessagesHashSelector); const currentChainId = useSelector(getCurrentChainId); const network = hexToDecimal(currentChainId); + const isUnapprovedTxsEmpty = Object.keys(unapprovedTxs).length === 0; const currentNetworkUnapprovedTxs = Object.keys(unapprovedTxs) .filter((key) => @@ -28,7 +33,9 @@ const ConfirmPageContainerNavigation = ({ txData }) => { ) .reduce((acc, key) => ({ ...acc, [key]: unapprovedTxs[key] }), {}); - const enumUnapprovedTxs = Object.keys(currentNetworkUnapprovedTxs); + const enumUnapprovedTxs = Object.keys( + isUnapprovedTxsEmpty ? unconfirmedMessages : currentNetworkUnapprovedTxs, + ); const currentPosition = enumUnapprovedTxs.indexOf(id); @@ -43,7 +50,11 @@ const ConfirmPageContainerNavigation = ({ txData }) => { const onNextTx = (txId) => { if (txId) { dispatch(clearConfirmTransaction()); - history.push(`${CONFIRM_TRANSACTION_ROUTE}/${txId}`); + history.push( + isUnapprovedTxsEmpty + ? `${CONFIRM_TRANSACTION_ROUTE}/${txId}${SIGNATURE_REQUEST_PATH}` + : `${CONFIRM_TRANSACTION_ROUTE}/${txId}`, + ); } }; @@ -109,8 +120,4 @@ const ConfirmPageContainerNavigation = ({ txData }) => { ); }; -ConfirmPageContainerNavigation.propTypes = { - txData: PropTypes.object, -}; - export default ConfirmPageContainerNavigation; diff --git a/ui/components/app/signature-request-original/__snapshots__/signature-request-original.test.js.snap b/ui/components/app/signature-request-original/__snapshots__/signature-request-original.test.js.snap index 38b691b7d563..1006d738dcc8 100644 --- a/ui/components/app/signature-request-original/__snapshots__/signature-request-original.test.js.snap +++ b/ui/components/app/signature-request-original/__snapshots__/signature-request-original.test.js.snap @@ -5,6 +5,76 @@ exports[`SignatureRequestOriginal should match snapshot 1`] = `
+
+ +