1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

[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
This commit is contained in:
Frederik Bolding 2022-12-12 12:32:31 +01:00 committed by GitHub
parent 7a1f75d17f
commit 5cca4b9b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -176,9 +176,12 @@ export default function ConfirmationPage({
}; };
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
const { const snap = useSelector((state) =>
manifest: { proposedName }, getSnap(state, pendingConfirmation?.origin),
} = useSelector((state) => getSnap(state, pendingConfirmation?.origin)); );
// When pendingConfirmation is undefined, this will also be undefined
const proposedName = snap?.manifest.proposedName;
const SNAP_DIALOG_TYPE = [ const SNAP_DIALOG_TYPE = [
MESSAGE_TYPE.SNAP_DIALOG_ALERT, MESSAGE_TYPE.SNAP_DIALOG_ALERT,
@ -224,19 +227,6 @@ export default function ConfirmationPage({
///: END:ONLY_INCLUDE_IN ///: 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(() => { useEffect(() => {
// If the number of pending confirmations reduces to zero when the user // If the number of pending confirmations reduces to zero when the user
// return them to the default route. Otherwise, if the number of pending // return them to the default route. Otherwise, if the number of pending
@ -256,10 +246,24 @@ export default function ConfirmationPage({
currentPendingConfirmation, currentPendingConfirmation,
redirectToHomeOnZeroConfirmations, redirectToHomeOnZeroConfirmations,
]); ]);
if (!pendingConfirmation) { if (!pendingConfirmation) {
return null; 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 ( return (
<div className="confirmation-page"> <div className="confirmation-page">
{pendingConfirmations.length > 1 && ( {pendingConfirmations.length > 1 && (