feat: trigger alert modal on confirm button#24049
Conversation
…lert-modal-component
…lert-modal-component
…ne-alert-info-row-component
…ne-alert-info-row-component
…al.tsx Co-authored-by: Matthew Walsh <matthew.walsh@consensys.net>
…al.tsx Co-authored-by: Matthew Walsh <matthew.walsh@consensys.net>
…al.test.tsx Co-authored-by: Matthew Walsh <matthew.walsh@consensys.net>
…lert-modal-component
| <Text variant={TextVariant.bodySm}>{detail}</Text> | ||
| </Box> | ||
| ))} | ||
| <> |
There was a problem hiding this comment.
no need to wrap with Fragment <>
There was a problem hiding this comment.
I'm confused since it is still showing 😅 This comment also applies to AlertHeader above. Tested locally to check that this works without the fragments
There was a problem hiding this comment.
Sorry I pasted the wrong link, I pushed this change to the PR where I was applying the changes requested by Sayalee.
| isConfirmed={isConfirmed} | ||
| setAlertConfirmed={setAlertConfirmed} | ||
| /> | ||
| )} |
There was a problem hiding this comment.
rather than adding new props to pass child components to override existing components, I think it'd be better to abstract the logic so that shared logic resides in AlertModal or could be used by AlertModal. Shared logic could also be separate, reusable components.
The labels have the same values so we can remove confirmAlertModalAcknowledge and reuse the existing alertModalAcknowledge
The customAcknowledgeCheckbox is very similar to the existing one in AlertModal. We could move the existing AcknowledgeCheckbox outside of this component and into its own file to be reused. If all AlertModals are guaranteed to have these AcknowledgeCheckbox, we could consider not passing customAcknowledgeCheckbox, but more specific params
similar comments for the other "custom" child components
There was a problem hiding this comment.
Great point, AcknowledgeCheckbox is a good candidate to abstract the logic.
I created an AcknowledgeCheckboxBase component to abstract the logic and re-utilized it into the confirm-alert-modal.tsx.
Unfortunately, some of those internal components changed over the most recent PRs such as #24214 and #24400. I will reassess the customAcknowledgeButton in the PRs mentioned to see if we can do something similar.
| MultipleCriticalAlertModal.storyName = 'Multiple Critical Alert Modal'; | ||
| MultipleCriticalAlertModal.args = { | ||
| alertKey: 'from', | ||
| }; No newline at end of file |
There was a problem hiding this comment.
The storybook pages lock up the storybook left navigation (still seen but unusable), and the controls are unusable since there is no way to hide the modal. We should be able to utilize the component-library Modal features as expected. Similarly, to https://metamask.github.io/metamask-storybook/?path=/docs/components-componentlibrary-modal--docs
This behavior was introduced before this PR but would be nice to include.
There was a problem hiding this comment.
Thanks for this suggestion. I've fixed MultipleAlertModal, ConfirmAlertModal and AlertModal stories.
Builds ready [d918521]
Page Load Metrics (1206 ± 551 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| )} | ||
| </Box> | ||
| </ModalFooter> | ||
| </ModalContent> |
There was a problem hiding this comment.
There was some discussion on removing the Security advice by... So I ended up leaving to the last PR (implement alert to personal sign) the introduction of the provider in the banner and now into the modal here. My bad I should have described it here.
| <AlertHeader | ||
| selectedAlert={selectedAlert} | ||
| customAlertTitle={customAlertTitle} | ||
| /> |
There was a problem hiding this comment.
That is a good point I asked Sayalee because there are some inconsistencies in the figma and it makes sense to have a clear separation of the header and the content.
In any case, I have reduced the distance here already, and depending on Syalee's feedback I will push it to a subsequent PR.
| function AlertDetails({ selectedAlert }: { selectedAlert: Alert }) { | ||
| function AlertDetails({ | ||
| selectedAlert, | ||
| customAlertDetails, |
There was a problem hiding this comment.
rather than custom why not turn AlertModal into a presentational component so that it is not dependent on Alert? or... why does ConfirmAlertModal not utilize the selectedAlert system? Is it possible only multiple-alert-modal utilizes the "selectedAlert" logic?
e.g. something like, instead of the current MultipleAlertModal
<AlertModal
ownerId={ownerId}
onAcknowledgeClick={handleAcknowledgeClick}
alertKey={selectedAlert.key}
onClose={onClose}
headerStartAccessory={
<PageNavigation
alerts={alerts}
onBackButtonClick={handleBackButtonClick}
onNextButtonClick={handleNextButtonClick}
selectedIndex={selectedIndex}
/>
}
/>
);
<AlertModal
ownerId={ownerId}
onAcknowledgeClick={handleAcknowledgeClick}
title={selectedAlert.reason}
details={selectedAlert.alertDetails}
message={selectedAlert.message}
severity={selectedAlert.severity}
onClose={onClose}
headerStartAccessory={
<PageNavigation
alerts={alerts}
onBackButtonClick={handleBackButtonClick}
onNextButtonClick={handleNextButtonClick}
selectedIndex={selectedIndex}
/>
}
/>
There was a problem hiding this comment.
Thank you for the suggestion!
Initially, I considered using AlertModal purely as a presentational component for alerts as you suggested. However, I chose not to go this route because the ConfirmAlerModal does not have any specific alert it only knows the ownerId and the alertKey to render the MultipleAlertModal so the user can review those alerts.
Additionally, restructuring to use AlertModal would still require passing custom components within ConfirmAlertModal, which seems to diminish the benefit of making AlertModal purely presentational.
There was a problem hiding this comment.
Okay I see now. ConfirmAlertModal also renders MultipleAlertModal which I missed the first time. I also see that it also passes the selected alert related props ownerId and alertKey to AlertModal. Thanks for the clarification!
| marginBottom={4} | ||
| > | ||
| {selectedAlert.reason ?? t('alert')} | ||
| {customAlertTitle ?? selectedAlert.reason ?? t('alert')} |
There was a problem hiding this comment.
[suggestion] could rename customAlertTitle to customTitle as "Alert" is redundant here
There was a problem hiding this comment.
Renamed customAlertTitle to alertTitle. c68451f
| function AlertDetails({ selectedAlert }: { selectedAlert: Alert }) { | ||
| function AlertDetails({ | ||
| selectedAlert, | ||
| customAlertDetails, |
There was a problem hiding this comment.
Okay I see now. ConfirmAlertModal also renders MultipleAlertModal which I missed the first time. I also see that it also passes the selected alert related props ownerId and alertKey to AlertModal. Thanks for the clarification!
| customAlertDetails, | ||
| }: { | ||
| selectedAlert: Alert; | ||
| customAlertDetails?: React.ReactNode; |
There was a problem hiding this comment.
[suggestion] can rename customAlertDetails → customDetails
There was a problem hiding this comment.
Renamed customAlertDetals to customDetails c68451f .
| <Text variant={TextVariant.bodySm}>{detail}</Text> | ||
| </Box> | ||
| ))} | ||
| <> |
There was a problem hiding this comment.
I'm confused since it is still showing 😅 This comment also applies to AlertHeader above. Tested locally to check that this works without the fragments
| @@ -0,0 +1,186 @@ | |||
| import React, { useCallback, useState } from 'react'; | |||
There was a problem hiding this comment.
what if we renamed ConfirmAlertModal to ConfirmMultipleAlertModal? The thought behind this is that is does also handle multiple alerts so this would provide more context
| <MultipleAlertModal | ||
| alertKey={alertKey} | ||
| ownerId={ownerId} | ||
| onFinalAcknowledgeClick={handleCloseMultipleAlertModal} |
There was a problem hiding this comment.
onFinalAcknowledgeClick is handled as the regular onClose. It does seem redundant that the user will acknowledge each alert individually and then need to acknowledge the final checkbox again after. maybe we could consider checking the final box if all others are checked cc: @SayaGT
current behavior:
https://github.com/MetaMask/metamask-extension/assets/20778143/da7b3915-492a-4fd7-9c5d-981ef805ba9b
There was a problem hiding this comment.
It is happening like this because in the storybook it shows the full behaviour of the component, but if the user already acknowledges the alert using the Alert row component it would display only the ConfirmAlertModal component.
| return BackgroundColor.errorMuted; | ||
| case Severity.Warning: | ||
| return BackgroundColor.warningMuted; | ||
| // Defaults to Severity.Info |
There was a problem hiding this comment.
| // Defaults to Severity.Info |
| if (hasUnconfirmedAlerts) { | ||
| return IconName.SecuritySearch; | ||
| } | ||
| return IconName.Danger; |
There was a problem hiding this comment.
| if (hasUnconfirmedAlerts) { | |
| return IconName.SecuritySearch; | |
| } | |
| return IconName.Danger; | |
| return hasUnconfirmedAlerts ? IconName.SecuritySearch : IconName.Danger; |
Builds ready [8c904da]
Page Load Metrics (775 ± 524 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|



Description
This PR aims to add a button to review alerts when there are unacknowledged alerts in a confirmation Once the button is clicked the
MultipleAlerModalis displayed enabling users to review and take action on each alert individually. If all alerts are reviewed aConfirmAlertModalis displayed warning the user and with the possibility to again review all the alerts before confirming it.Create the logic to support the friction modal when all the alerts are reviewed and the confirm button is clicked.
Background
As with the inline alerts alongside the confirmation fields, the confirmation confirm button should also display all the confirmation alerts sequentially in the alert modal.
In addition the confirm button should be suitably styled to indicate alerts are present.
Based on figma.
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2292
Manual testing steps
Those components are currently not in use and are not available to users. It is part of the new alert system, and we will have a dedicated PR to integrate this component into the new confirmation screens.
Screenshots/Recordings
Before
After
frictionModal.webm
Pre-merge author checklist
Pre-merge reviewer checklist