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

New SecurityProviderBannerAlert component #19825

Merged
merged 30 commits into from
Jul 21, 2023

Conversation

digiwand
Copy link
Contributor

@digiwand digiwand commented Jun 29, 2023

Explanation

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/558
Blocked By: #19768
Blocks: #19257

We will be replacing the OpenSea security provider warning message. The current SecurityProviderBannerMessage component that displays this has specific logic for OpenSea. This PR creates a new UI component that allows for scalability and general use cases. UI differences from the OpenSea provider warning message include the option to include details, an updated footer copy, and a SecurityTick icon.

Screenshots/Screencaps

New Component

Screen Shot 2023-06-29 at 4 44 33 PM

Manual Testing Steps

  1. run storybook - yarn storybook
  2. view new component - http://localhost:6006/?path=/docs/components-app-securityproviderbanneralert--docs

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
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
Copy link
Collaborator

Builds ready [97d7355]
Page Load Metrics (1602 ± 46 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint108177128189
domContentLoaded1465187316029746
load1465187416029746
domInteractive1465187316029746
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 1112 bytes
  • common: 153 bytes

@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #19825 (0e151d5) into develop (26225aa) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop   #19825      +/-   ##
===========================================
+ Coverage    69.36%   69.37%   +0.01%     
===========================================
  Files          986      987       +1     
  Lines        37279    37286       +7     
  Branches     10010    10012       +2     
===========================================
+ Hits         25857    25867      +10     
+ Misses       11422    11419       -3     
Impacted Files Coverage Δ
shared/constants/security-provider.ts 100.00% <100.00%> (ø)
...der-banner-alert/security-provider-banner-alert.js 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@digiwand digiwand added the team-confirmations-secure-ux-PR PRs from the confirmations team label Jun 29, 2023
@digiwand digiwand marked this pull request as ready for review June 29, 2023 20:15
@digiwand digiwand requested a review from a team as a code owner June 29, 2023 20:15
@metamaskbot
Copy link
Collaborator

Builds ready [20c1b8e]
Page Load Metrics (1729 ± 64 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1142361483215
domContentLoaded15082063172713464
load15082063172913464
domInteractive15072063172713464
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 1112 bytes
  • common: 153 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [eb13162]
Page Load Metrics (1521 ± 46 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1021911312412
domContentLoaded1372172015219746
load1372172015219746
domInteractive1372172015219746
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 1112 bytes
  • common: 153 bytes

@metamaskbot
Copy link
Collaborator

Builds ready [8af4e6f]
Page Load Metrics (1949 ± 128 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1183851846230
domContentLoaded152725071947266128
load152725071949266128
domInteractive152725061947266128
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 1112 bytes
  • common: 153 bytes

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

Looking excellent 💯 just some small suggestions. I'm a bit manic this morning but want to give timely reviews so apologies if the comments are a little uncoherent

Comment on lines 44 to 46
<Text variant={TextVariant.bodySm} as="h6" marginTop={2}>
{description}
</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use the description prop inside the BannerAlert? I think it should be bodyMd? Our typography is responsive so if you see 14px the design might be using the small screen typography. It should be 16px on larger screens. Also I know a lot of the Text are rendering as h6 this is probably not the best semantic mark up but I think was a decision instead of getting new contributors to update e2e tests. Probably not the best in hindsight. I think it could just be a p tag which is what bodySm renders by default

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 see now. description is inherited from BannerBase. Got it

I was carrying over code and preserving styles from our OpenSea SecurityProviderMessage component. These are great updates 👍 Thank you!

applied in 647eda9 and a7fdeee

I also adjusted the Disclosure component text size here 8ac9248

One thing using the description param is that is a lack of padding between the title and description which does not match the figma design. Any suggestions? @georgewrmarshall

Copy link
Contributor Author

Choose a reason for hiding this comment

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

before:
Screen Shot 2023-07-10 at 9 15 35 PM

after using description param:
Screen Shot 2023-07-12 at 12 08 47 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @georgewrmarshall! hope you had a nice weekend. In addition to the lack of padding/margin between the title and the description, I realized there is another issue we have using the description BannerAlert/BannerBase property instead of passing children elements.


The description currently expects a string property. The problem is that SecurityProviderBannerAlert will allow hyperlinks, or other HTML elements, in the description.

error:

BannerBase 

> checkPropTypes.js:20 Warning: Failed prop type: Invalid prop description of type object supplied to BannerAlert



Do you have suggestions to address the two issues above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the meantime I have reverted the use of description param to fix the console and UI issues. I think it would be better to address this in a separate PR to unblock dependent work ahead

Revert commit 1c3d550

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 am thinking, maybe, we can do something similar to our plans with the Disclosure component and add support using Text as=“div”

@metamaskbot
Copy link
Collaborator

Builds ready [1deac07]
Page Load Metrics (1717 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint119157135136
domContentLoaded15702143171613565
load15702144171713465
domInteractive15702143171613565
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 1465 bytes
  • common: 153 bytes

Comment on lines 5 to 20
/**
* @typedef {object} SecurityProviderConfig
* @property {string} tKeyName - translation key for security provider name
* @property {string} url - URL to securty provider website
*/

/** @type {Record<string, SecurityProviderConfig>} */
export const SECURITY_PROVIDER_CONFIG = {
[SecurityProvider.Blockaid]: {
tKeyName: 'blockaid',
url: 'https://blockaid.io/',
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Besides the jsdoc why not create actual type and benefit from the full extent of TS? You could have something like:

type SecurityProviderConfig = Record<
  SecurityProvider,
  {
    tKeyName: string;
    url: string;
  }
>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lgtm! I was following patterns from shared/constants/gas.ts and other files. updated here fac7473

does this look okay or are there any more suggestions?

cc: @cryptotavares

Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]
Do we want this const to be readonly (at least for TS)? If yes then we can:

const SECURITY_PROVIDER_CONFIG: Readonly<SecurityProviderConfig>

or ditch the type and use const assertion (TS docs for readonly and const assertion)

export const SECURITY_PROVIDER_CONFIG = {
  [SecurityProvider.Blockaid]: {
    tKeyName: 'blockaid',
    url: 'https://blockaid.io/',
  },
} as const;

Using the const assertion seems more inline with what is being done on other constants TS files (example).

(Sorry for asking to add the type and then replacing it for const assertion.. I am mostly used to use the Readonly mapped type, but that does not seem to be the standard on the Extension code 😅 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @cryptotavares, thanks for the suggestion and references! I applied the const assertion and I am thinking the type you suggested earlier is also nice to help define the types for each of the config objects. (Before, I was using jsdoc @typedef instead of the type you first proposed.)

Copy link
Contributor

Choose a reason for hiding this comment

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

If you use the const assertion TS should automatically pick the correct type.
If you do const assertion and type the const at the same time, then TS will interpret the explicit type as the actual type (meaning that if you do not add the readonly utility type, then it will allow overriding the current property values). Example:

// Just using const assertion
const test = {
  yolo: 1
} as const;

test.yolo = 2; // TS will complain about this because when we asserted to const, test is readonly
type Test = {
  yolo: number
}

// explicit typing with const assertion
const test: Test = {
  yolo: 1
} as const;

test.yolo = 2; // TS will accept this, as it considers that test.yolo is a number and is not readonly

Anyway, I was suggesting that you can either use const assertion or you can explicitly type it (and use the Readonly utility type). But as const assertion seems to be the pattern used in the rest of the codebase you can do just that.

Btw, other examples on how we can force it to be readonly with explicit typing:

// Using Readonly utility type ensures that all properties are readonly and cannot be reassigned. 
const test: Readonly<Test> = {
  yolo: 1
};
const test: Test = {
  // using readonly modifier ensures that that specific property is readonly and cannot be reassigned
  readonly yolo: 1
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooh I see now. I think I got it #19825 cc: @cryptotavares

cryptotavares
cryptotavares previously approved these changes Jul 13, 2023
Copy link
Contributor

@cryptotavares cryptotavares left a comment

Choose a reason for hiding this comment

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

Left a really small comment, but looks good!

Base automatically changed from ds-disclosure-add-isArrowSummary-option to develop July 13, 2023 20:38
@digiwand digiwand dismissed cryptotavares’s stale review July 13, 2023 20:38

The base branch was changed.

@metamaskbot
Copy link
Collaborator

Builds ready [3aea156]
Page Load Metrics (1474 ± 32 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint97173126199
domContentLoaded1371159214746732
load1371159314746732
domInteractive1371159214746732
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 222 bytes
  • common: 153 bytes

cryptotavares
cryptotavares previously approved these changes Jul 14, 2023
@metamaskbot
Copy link
Collaborator

Builds ready [dbfc92e]
Page Load Metrics (1580 ± 23 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint113154126115
domContentLoaded1472168215804923
load1472168315804923
domInteractive1472168215804923
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 bytes
  • ui: 222 bytes
  • common: 153 bytes

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

  • Checked UI in storybook build

cryptotavares
cryptotavares previously approved these changes Jul 18, 2023

/**
* Optional
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

??

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 thought it would be nice to separate the optional / not isRequired parameters

jpuri
jpuri previously approved these changes Jul 19, 2023
Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

🚀

@digiwand digiwand dismissed stale reviews from jpuri and cryptotavares via 78c0c17 July 19, 2023 18:12
@digiwand digiwand force-pushed the new-security-provider-banner-alert-component branch from 78c0c17 to 0e151d5 Compare July 20, 2023 10:14
@digiwand
Copy link
Contributor Author

@jpuri @cryptotavares @georgewrmarshall

sorry had to force push to resolve a rebase conflict. Should be the same. I double-checked that the code works as expected in storybook. may I get a re-approval please?

@metamaskbot
Copy link
Collaborator

Builds ready [0e151d5]
Page Load Metrics (1655 ± 40 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1121871452110
domContentLoaded1498183216558340
load1498183216558340
domInteractive1498183216558340
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 222 Bytes (0.00%)
  • common: 153 Bytes (0.00%)

@digiwand digiwand merged commit 59102e3 into develop Jul 21, 2023
@digiwand digiwand deleted the new-security-provider-banner-alert-component branch July 21, 2023 09:04
@metamaskbot metamaskbot added the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Jul 21, 2023
@Gudahtt Gudahtt added release-11.1.0 Issue or pull request that will be included in release 11.1.0 and removed release-10.36.0 Issue or pull request that will be included in release 10.36.0 labels Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-11.1.0 Issue or pull request that will be included in release 11.1.0 team-confirmations-secure-ux-PR PRs from the confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants