Skip to content

feat: trigger alert modal on confirm button#24049

Merged
vinistevam merged 131 commits intodevelopfrom
feat/trigger-alert-modal-confirm-btn
May 22, 2024
Merged

feat: trigger alert modal on confirm button#24049
vinistevam merged 131 commits intodevelopfrom
feat/trigger-alert-modal-confirm-btn

Conversation

@vinistevam
Copy link
Copy Markdown
Contributor

@vinistevam vinistevam commented Apr 16, 2024

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 MultipleAlerModal is displayed enabling users to review and take action on each alert individually. If all alerts are reviewed a ConfirmAlertModal is 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.

Open in GitHub Codespaces

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.

  • Regression for new confirmation screens.

Screenshots/Recordings

Before

After

image

frictionModal.webm

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

vinistevam and others added 30 commits March 18, 2024 10:35
…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>
<Text variant={TextVariant.bodySm}>{detail}</Text>
</Box>
))}
<>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to wrap with Fragment <>

Copy link
Copy Markdown
Contributor Author

@vinistevam vinistevam May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for it, removed here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
/>
)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

jpuri
jpuri previously approved these changes May 17, 2024
MultipleCriticalAlertModal.storyName = 'Multiple Critical Alert Modal';
MultipleCriticalAlertModal.args = {
alertKey: 'from',
}; No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this suggestion. I've fixed MultipleAlertModal, ConfirmAlertModal and AlertModal stories.

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [d918521]
Page Load Metrics (1206 ± 551 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint68150982412
domContentLoaded94718126
load56288112061148551
domInteractive94718126
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 18.04 KiB (0.27%)
  • common: 411 Bytes (0.01%)

)}
</Box>
</ModalFooter>
</ModalContent>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: will we add UI support for "Security advice by Blockaid" in this PR or a future iteration?
CleanShot 2024-05-21 at 00 57 35@2x

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation has the close button above a divider line though the Figma version has no divider line and the UI appears closer to the close button

Figma
CleanShot 2024-05-21 at 02 19 19

CleanShot 2024-05-21 at 02 19 35

Copy link
Copy Markdown
Contributor Author

@vinistevam vinistevam May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
        />
      }
    />
  

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] could rename customAlertTitle to customTitle as "Alert" is redundant here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed customAlertTitle to alertTitle. c68451f

function AlertDetails({ selectedAlert }: { selectedAlert: Alert }) {
function AlertDetails({
selectedAlert,
customAlertDetails,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] can rename customAlertDetails → customDetails

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed customAlertDetals to customDetails c68451f .

<Text variant={TextVariant.bodySm}>{detail}</Text>
</Box>
))}
<>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Defaults to Severity.Info

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed comment c68451f.

Comment on lines +28 to +31
if (hasUnconfirmedAlerts) {
return IconName.SecuritySearch;
}
return IconName.Danger;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (hasUnconfirmedAlerts) {
return IconName.SecuritySearch;
}
return IconName.Danger;
return hasUnconfirmedAlerts ? IconName.SecuritySearch : IconName.Danger;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied changes here.

@vinistevam vinistevam merged commit 85d7f8a into develop May 22, 2024
@vinistevam vinistevam deleted the feat/trigger-alert-modal-confirm-btn branch May 22, 2024 08:27
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [8c904da]
Page Load Metrics (775 ± 524 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint72163942311
domContentLoaded95719126
load5931427751092524
domInteractive95719126
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 18.04 KiB (0.27%)
  • common: 411 Bytes (0.01%)

@gauthierpetetin gauthierpetetin added the release-12.0.0 Issue or pull request that will be included in release 12.0.0 label Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-12.0.0 Issue or pull request that will be included in release 12.0.0 team-confirmations-system-deprecated DEPRECATED: please use "team-confirmations" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants