From 6db827ac4d8cf1780e8fdc67ff0349886410539a Mon Sep 17 00:00:00 2001 From: Christos Maris Date: Tue, 1 Oct 2024 16:33:17 +0300 Subject: [PATCH] [ENG-5333] Update Batch PSBT Signing Screen for Single PSBT --- src/app/components/batchPsbtSigning/index.tsx | 59 ++++++++++++------- src/locales/en.json | 1 + 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/app/components/batchPsbtSigning/index.tsx b/src/app/components/batchPsbtSigning/index.tsx index 8cbf51b0c..18a34d7cd 100644 --- a/src/app/components/batchPsbtSigning/index.tsx +++ b/src/app/components/batchPsbtSigning/index.tsx @@ -59,7 +59,8 @@ function BatchPsbtSigning({ onSigned, psbts, onCancel }: BatchPsbtSigningProps) const [isSigningComplete, setIsSigningComplete] = useState(false); const [signingPsbtIndex, setSigningPsbtIndex] = useState(1); const [currentPsbtIndex, setCurrentPsbtIndex] = useState(0); - const [reviewTransaction, setReviewTransaction] = useState(false); + const singlePsbt = psbts.length === 1; + const [reviewTransaction, setReviewTransaction] = useState(singlePsbt); const [isLoading, setIsLoading] = useState(true); const txnContext = useTransactionContext(); useTrackMixPanelPageViewed(); @@ -256,13 +257,36 @@ function BatchPsbtSigning({ onSigned, psbts, onCancel }: BatchPsbtSigningProps) ); }; - const reviewDoneText = hasDuplicateInputs ? t('CONFIRM_ALL') : t('DONE'); - const onReviewDone = hasDuplicateInputs - ? onSignPsbtConfirmed - : () => { - setReviewTransaction(false); - setCurrentPsbtIndex(0); - }; + const modalOnClose = + singlePsbt || hasDuplicateInputs + ? onCancel + : () => { + setReviewTransaction(false); + setCurrentPsbtIndex(0); + }; + + const reviewTitle = singlePsbt + ? t('SIGN_TRANSACTION') + : `${t('TRANSACTION')} ${currentPsbtIndex + 1}/${parsedPsbts.length}`; + const reviewBackText = singlePsbt ? t('CANCEL') : t('PREVIOUS'); + const reviewBackIcon = singlePsbt ? null : ; + const reviewBackDisabled = singlePsbt ? false : currentPsbtIndex === 0; + const onReviewBackClick = singlePsbt + ? onCancel + : () => setCurrentPsbtIndex((prevIndex) => prevIndex - 1); + + const reviewDoneText = hasDuplicateInputs + ? t('CONFIRM_ALL') + : singlePsbt + ? t('CONFIRM') + : t('DONE'); + const onReviewDone = + hasDuplicateInputs || singlePsbt + ? onSignPsbtConfirmed + : () => { + setReviewTransaction(false); + setCurrentPsbtIndex(0); + }; return ( <> @@ -271,16 +295,11 @@ function BatchPsbtSigning({ onSigned, psbts, onCancel }: BatchPsbtSigningProps) { - setReviewTransaction(false); - setCurrentPsbtIndex(0); - }} + onClose={modalOnClose} > - - {t('TRANSACTION')} {currentPsbtIndex + 1}/{parsedPsbts.length} - + {reviewTitle} {!!parsedPsbts[currentPsbtIndex] && ( @@ -290,13 +309,11 @@ function BatchPsbtSigning({ onSigned, psbts, onCancel }: BatchPsbtSigningProps)