Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add SIWE mismatch account warning alert and hide duplicate warnings in MultipleAlertModal #25559

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

digiwand
Copy link
Contributor

@digiwand digiwand commented Jun 27, 2024

Description

  • Adds account mismatch warning alerts to SIWE redesign pages
  • Adds support to hide duplicate warnings in MultipleAlertModal

Open in GitHub Codespaces

Related issues

Fixes: #25317

Manual testing steps

  1. comment out isSIWE condition in ui/pages/confirmations/hooks/useCurrentConfirmation.ts file
  2. turn on redesign in Experimental Settings
  3. yarn start
  4. Go to test-dapp and test SIWE Bad Account button

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-confirmations Push issues to confirmations team label Jun 27, 2024
Base automatically changed from feat-sign-refactor-alerts to develop June 27, 2024 16:21
@digiwand digiwand force-pushed the feat-sign-account-mistmatch-alerts branch from 32de38d to 69cc879 Compare June 27, 2024 17:02
Copy link

codecov bot commented Jun 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.66%. Comparing base (1d33d6f) to head (23cd578).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #25559      +/-   ##
===========================================
+ Coverage    69.65%   69.66%   +0.01%     
===========================================
  Files         1355     1356       +1     
  Lines        48007    48029      +22     
  Branches     13235    13239       +4     
===========================================
+ Hits         33437    33459      +22     
  Misses       14570    14570              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Collaborator

Builds ready [69cc879]
Page Load Metrics (322 ± 280 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint734471207837
domContentLoaded11160333115
load482038322584280
domInteractive11160333115
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 2.42 KiB (0.03%)
  • common: 153 Bytes (0.00%)

@digiwand digiwand marked this pull request as ready for review June 27, 2024 18:48
@digiwand digiwand requested review from a team as code owners June 27, 2024 18:48
@digiwand digiwand changed the title feat: add SIWE mismatch account warning alert feat: add SIWE mismatch account warning alert and hide duplicate warnings in MultipleAlertModal Jun 27, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [23cd578]
Page Load Metrics (91 ± 20 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint682931246029
domContentLoaded1088322211
load48206914120
domInteractive1088322211
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 2.54 KiB (0.04%)
  • common: 153 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [23cd578]
Page Load Metrics (91 ± 20 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint682931246029
domContentLoaded1088322211
load48206914120
domInteractive1088322211
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 2.54 KiB (0.04%)
  • common: 153 Bytes (0.00%)

}, [isMismatchAccount, t]);

return alerts;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Above hook will re-render only if confirmation changes, thus do we really need useMemo ?

Copy link
Member

Choose a reason for hiding this comment

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

We currently do this as standard on all alert hooks since they are returning arrays so it ensures any usages and future usages have stable data, at the cost of only around 4 extra lines.

const alerts = useMemo(() => {
return allAlerts.reduce((result: Alert[], alert: Alert) => {
const isDuplicateWarning = result.some((a: Alert) => {
return a.severity === Severity.Warning && a.message === alert.message;
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, the only use case is for warning alerts (mismatch account). While this addresses the present scenario, should we extend it to handle duplicates for all alert severities?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I think since the danger severity would require confirmation, it would require more updates. Because of this I think it’d be better to extend the functionality when we need it

Copy link
Member

Choose a reason for hiding this comment

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

Assuming we definitely want duplicate alerts on different fields, would it be cleaner to encapsulate this within useAlerts in a property such as uniqueAlerts?

severity: Severity.Warning,
},
{
field: 'signingInWith',
Copy link
Member

Choose a reason for hiding this comment

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

Why are we adding a single alert to two fields?

I understood our alert system assumes alerts are general or targeted to a single field?

Can we not pick the most relevant single field such as signing in with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh I think you may be right. I was referring to the design in the screenshot but in Figma, it does indeed look like the alert only exists on "Signing in with". Let me double-check w/ design

const alerts = useMemo(() => {
return allAlerts.reduce((result: Alert[], alert: Alert) => {
const isDuplicateWarning = result.some((a: Alert) => {
return a.severity === Severity.Warning && a.message === alert.message;
Copy link
Member

Choose a reason for hiding this comment

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

Assuming we definitely want duplicate alerts on different fields, would it be cleaner to encapsulate this within useAlerts in a property such as uniqueAlerts?

@@ -58,9 +58,13 @@ const PersonalSignInfo: React.FC = () => {
<ConfirmInfoRowUrl url={currentConfirmation.msgParams.origin} />
</ConfirmInfoAlertRow>
{isSIWE && (
<ConfirmInfoRow label={t('signingInWith')}>
<ConfirmInfoAlertRow
alertKey="signingInWith"
Copy link
Member

Choose a reason for hiding this comment

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

To avoid duplicate strings, there is now a RowAlertKey enum inside ui/components/app/confirm/info/row/constants.ts.

reason: t('alertReasonWrongAccount'),
severity: Severity.Warning,
},
] as Alert[];
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to cast? Does this suggest we have bad data or a bad type?

] as Alert[];
}, [isMismatchAccount, t]);

return alerts;
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but can we return the hook directly to make it explicit we're caching the result?

}, [isMismatchAccount, t]);

return alerts;
}
Copy link
Member

Choose a reason for hiding this comment

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

We currently do this as standard on all alert hooks since they are returning arrays so it ensures any usages and future usages have stable data, at the cost of only around 4 extra lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redesign Signature SIWE: add non-critical alert for account missmatch
5 participants