From 5cca4b9b4444a65e4157e58ff598c25f31fc2fc3 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Mon, 12 Dec 2022 12:32:31 +0100 Subject: [PATCH] [FLASK] Fix a crash that occurred after a snap confirmation had been approved (#16864) * Fix a crash that occurred after a snap confirmation had been approved * Fix lint * Move code below early return --- ui/pages/confirmation/confirmation.js | 36 +++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/ui/pages/confirmation/confirmation.js b/ui/pages/confirmation/confirmation.js index 48b0b0fe0..ac390c421 100644 --- a/ui/pages/confirmation/confirmation.js +++ b/ui/pages/confirmation/confirmation.js @@ -176,9 +176,12 @@ export default function ConfirmationPage({ }; ///: BEGIN:ONLY_INCLUDE_IN(flask) - const { - manifest: { proposedName }, - } = useSelector((state) => getSnap(state, pendingConfirmation?.origin)); + const snap = useSelector((state) => + getSnap(state, pendingConfirmation?.origin), + ); + + // When pendingConfirmation is undefined, this will also be undefined + const proposedName = snap?.manifest.proposedName; const SNAP_DIALOG_TYPE = [ MESSAGE_TYPE.SNAP_DIALOG_ALERT, @@ -224,19 +227,6 @@ export default function ConfirmationPage({ ///: END:ONLY_INCLUDE_IN ]); - const hasInputState = (type) => { - return INPUT_STATE_CONFIRMATIONS.includes(type); - }; - - const handleSubmit = () => - templateState[pendingConfirmation.id]?.useWarningModal - ? setShowWarningModal(true) - : templatedValues.onSubmit( - hasInputState(pendingConfirmation.type) - ? inputStates[MESSAGE_TYPE.SNAP_DIALOG_PROMPT] - : null, - ); - useEffect(() => { // If the number of pending confirmations reduces to zero when the user // return them to the default route. Otherwise, if the number of pending @@ -256,10 +246,24 @@ export default function ConfirmationPage({ currentPendingConfirmation, redirectToHomeOnZeroConfirmations, ]); + if (!pendingConfirmation) { return null; } + const hasInputState = (type) => { + return INPUT_STATE_CONFIRMATIONS.includes(type); + }; + + const handleSubmit = () => + templateState[pendingConfirmation.id]?.useWarningModal + ? setShowWarningModal(true) + : templatedValues.onSubmit( + hasInputState(pendingConfirmation.type) + ? inputStates[MESSAGE_TYPE.SNAP_DIALOG_PROMPT] + : null, + ); + return (
{pendingConfirmations.length > 1 && (