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: better storybook stories for the notification pages #27861

Merged
merged 25 commits into from
Oct 25, 2024

Conversation

matteoscurati
Copy link
Contributor

@matteoscurati matteoscurati commented Oct 15, 2024

Description

This pull request enhances the Storybook stories for the notification pages. The improvements aim to provide better clarity and usability for developers working with notification components. The changes include more detailed and organized stories, making it easier to understand and test different notification states and components.

### Important

  1. some of the components rendered by the new stories (ui/pages/notification-details/notification-details.stories.tsx) need to use an RPC endpoint to fetch certain data
  2. to avoid the fetch using the Infura ID used by the application in PROD, this PR introduces an INFURA_STORYBOOK_PROJECT_ID env (.metamaskrc.dist)
  3. If we’re in a Storybook environment, the Infura-Source header is not used in the utility (ui/helpers/utils/notification.util.ts)

Related issues

N/A

Manual testing steps

  1. Open Storybook in your development environment
  2. Navigate to the notification pages section
  3. Review the updated stories for clarity and completeness
  4. Verify that all notification states are represented and functioning as expected

Screenshots/Recordings

Before

N/A

After

Screen.Recording.2024-10-24.at.17.23.49.mov

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.

@matteoscurati matteoscurati added the team-notifications Notifications team label Oct 15, 2024
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 [cf66689]
Page Load Metrics (1909 ± 109 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint35025111827406195
domContentLoaded159324981878226109
load159725141909227109
domInteractive16184573718
backgroundConnect883332613
firstReactRender46210884321
getState56014167
initialActions01000
loadScripts116820501432219105
setupStore1272372512
uiStartup180027112135232112
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

sonarcloud bot commented Oct 16, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [2322c20]
Page Load Metrics (1795 ± 141 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28329841714440211
domContentLoaded151529231770287138
load151929561795294141
domInteractive27162482814
backgroundConnect889292211
firstReactRender453061025326
getState47414189
initialActions01000
loadScripts108325431309300144
setupStore1190292613
uiStartup173931872022324156
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [36288c3]
Page Load Metrics (1948 ± 98 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16532377193616378
domContentLoaded16042084187713766
load16532622194820398
domInteractive1995532412
backgroundConnect94947110751
firstReactRender494171329144
getState5225305125
initialActions00000
loadScripts11691600140411555
setupStore11304526531
uiStartup179744232298565271
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [7f9b8c6]
Page Load Metrics (1990 ± 97 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint34224221813502241
domContentLoaded16742386194819594
load16822402199020297
domInteractive279547199
backgroundConnect10118453215
firstReactRender6413695168
getState484272512
initialActions01000
loadScripts12031880144416680
setupStore1088332211
uiStartup187830952225285137
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@matteoscurati matteoscurati marked this pull request as ready for review October 22, 2024 10:19
@matteoscurati matteoscurati requested review from a team as code owners October 22, 2024 10:19
@metamaskbot
Copy link
Collaborator

Builds ready [4096501]
Page Load Metrics (1875 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1722208018779345
domContentLoaded1705202518438943
load1720208318758842
domInteractive25100552110
backgroundConnect980322311
firstReactRender501641012210
getState561182110
initialActions01000
loadScripts1211155813678440
setupStore1269312411
uiStartup1937227720789043
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [d44e45b]
Page Load Metrics (1868 ± 64 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16812174188213766
domContentLoaded16582102184313263
load16702145186813364
domInteractive168648189
backgroundConnect86429189
firstReactRender492071154120
getState55615168
initialActions01000
loadScripts1219156113719847
setupStore1068232110
uiStartup18352579210419192
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@legobeat legobeat changed the title feat: ✨ better storybook stories for the notification pages feat: better storybook stories for the notification pages Oct 22, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [14cacbc]
Page Load Metrics (1879 ± 64 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16532101188313163
domContentLoaded15992082184612962
load16082102187913464
domInteractive16208554119
backgroundConnect883382512
firstReactRender453011046632
getState481212311
initialActions01000
loadScripts11591573136710952
setupStore1176292512
uiStartup179726932112220105
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 37 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [312be96]
Page Load Metrics (1740 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16112049175111656
domContentLoaded1599190016968541
load16111989174010651
domInteractive255739105
backgroundConnect9172504421
firstReactRender44285915024
getState4130263517
initialActions01000
loadScripts1176135712506230
setupStore10109282713
uiStartup178727031955236113
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 46 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

mathieuartu
mathieuartu previously approved these changes Oct 25, 2024
Copy link
Member

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

Probably you don't need an additional env variable to check if the process is running under Storybook

headers: process.env.STORYBOOK_ENV
? undefined
: {
'Infura-Source': 'metamask/metamask',
Copy link
Member

Choose a reason for hiding this comment

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

Storybook registers certain global variables that you can check for during runtime. For instance, Storybook adds a window.STORYBOOK_ADDONS_CHANNEL property when it runs.

You can use this to conditionally detect Storybook like so:
const isStorybook = typeof window !== 'undefined' && !!window.__STORYBOOK_ADDONS_CHANNEL__;

This way, you won’t need the STORYBOOK_ENV variable; instead, you’re checking for a runtime indication that you’re in Storybook.

@metamaskbot
Copy link
Collaborator

Builds ready [843ef49]
Page Load Metrics (1987 ± 57 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint38822531905366176
domContentLoaded17692242193410852
load17822255198712057
domInteractive21129442311
backgroundConnect8141513818
firstReactRender562031013014
getState464282311
initialActions01000
loadScripts1288167314369546
setupStore1189332613
uiStartup19772609223517885
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 46 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Member

@andreahaku andreahaku left a comment

Choose a reason for hiding this comment

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

a couple of code optimisation comments

);
};

export const EthSent = Template.bind({});
Copy link
Member

Choose a reason for hiding this comment

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

what about reducing redundancy and something like:

// Dynamic export generation
const notificationStories = Object.keys(processedNotifications).reduce(
  (acc, key) => {
    acc[key] = Template.bind({});
    acc[key].args = { notification: processedNotifications[key] };
    return acc;
  },
  {}
);

export const {
  ethSent: EthSent,
  ethReceived: EthReceived,
  erc20Sent: ERC20Sent,
  erc20Received: ERC20Received,
  erc721Sent: ERC721Sent,
  erc721Received: ERC721Received,
  erc1155Sent: ERC1155Sent,
  erc1155Received: ERC1155Received,
  lidoReadyToBeWithdrawn: LidoReadyToBeWithdrawn,
  lidoStakeCompleted: LidoStakeCompleted,
  lidoWithdrawalCompleted: LidoWithdrawalCompleted,
  lidoWithdrawalRequested: LidoWithdrawalRequested,
  metaMaskSwapsCompleted: MetaMaskSwapsCompleted,
  rocketPoolStakeCompleted: RocketPoolStakeCompleted,
  rocketPoolUnStakeCompleted: RocketPoolUnStakeCompleted,
  featureAnnouncement: FeatureAnnouncement,
} = notificationStories;

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice cleanup, lets either add this now or in the next subsequent PR.

For context, the number of notification types we will support is going to grow substantially over time. So being able to create storybooks for each one easily (without much effort) will be important.

  • Web 3 Notifications: aave_v3_health_factor; ens_expiration; lido_staking_rewards; notional_loan_expiration; rocketpool_staking_rewards; spark_fi_health_factor
  • Price Alerts: Native Token Alerts, ERC Alerts (token/nft alerts)
  • And more (security, etc)

Copy link
Contributor Author

@matteoscurati matteoscurati Oct 25, 2024

Choose a reason for hiding this comment

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

Thanks, Andrea! Actually, I was thinking of optimizing these stories in a new PR I’m working on because we’re introducing new stories (as @Prithpal-Sooriya mentioned). But you’re right; better to do it right away!

},
]);

const {
Copy link
Member

Choose a reason for hiding this comment

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

similar approach here, doing something like:

const mockNotifications = {
  ethSent: NotificationServicesController.Mocks.createMockNotificationEthSent,
  ethReceived:
    NotificationServicesController.Mocks.createMockNotificationEthReceived,
  erc20Sent: NotificationServicesController.Mocks.createMockNotificationERC20Sent,
  erc20Received:
    NotificationServicesController.Mocks.createMockNotificationERC20Received,
  erc721Sent:
    NotificationServicesController.Mocks.createMockNotificationERC721Sent,
  erc721Received:
    NotificationServicesController.Mocks.createMockNotificationERC721Received,
  erc1155Sent:
    NotificationServicesController.Mocks.createMockNotificationERC1155Sent,
  erc1155Received:
    NotificationServicesController.Mocks.createMockNotificationERC1155Received,
  metaMaskSwapsCompleted:
    NotificationServicesController.Mocks.createMockNotificationMetaMaskSwapsCompleted,
  rocketPoolStakeCompleted:
    NotificationServicesController.Mocks.createMockNotificationRocketPoolStakeCompleted,
  rocketPoolUnStakeCompleted:
    NotificationServicesController.Mocks.createMockNotificationRocketPoolUnStakeCompleted,
  lidoStakeCompleted:
    NotificationServicesController.Mocks.createMockNotificationLidoStakeCompleted,
  lidoWithdrawalRequested:
    NotificationServicesController.Mocks.createMockNotificationLidoWithdrawalRequested,
  lidoReadyToBeWithdrawn:
    NotificationServicesController.Mocks.createMockNotificationLidoReadyToBeWithdrawn,
  lidoWithdrawalCompleted:
    NotificationServicesController.Mocks.createMockNotificationLidoWithdrawalCompleted,
  featureAnnouncement:
    NotificationServicesController.Mocks.createMockFeatureAnnouncementRaw,
};

const notifications: Notification[] = Object.values(mockNotifications).map(
  (createMock) => processNotification(createMock()),
);

mathieuartu
mathieuartu previously approved these changes Oct 25, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [15c45d9]
Page Load Metrics (2311 ± 116 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint24528492014758364
domContentLoaded196528302272240115
load198528442311242116
domInteractive339155168
backgroundConnect1183352412
firstReactRender733101265024
getState961302010
initialActions01000
loadScripts144022211703214103
setupStore1389362612
uiStartup219131762593287138
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 46 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [1162ecf]
Page Load Metrics (1978 ± 54 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint44022391899353170
domContentLoaded17562217195211656
load17662235197811254
domInteractive23115502211
backgroundConnect779242211
firstReactRender5111896199
getState46411136
initialActions01000
loadScripts12491684143710148
setupStore1277362713
uiStartup19712488219512761
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 46 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@matteoscurati matteoscurati added this pull request to the merge queue Oct 25, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 25, 2024
@matteoscurati matteoscurati added this pull request to the merge queue Oct 25, 2024
Merged via the queue into develop with commit aa6dd41 Oct 25, 2024
76 checks passed
@matteoscurati matteoscurati deleted the feat/improve-notifications-stories branch October 25, 2024 16:09
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.7.0 Issue or pull request that will be included in release 12.7.0 team-notifications Notifications team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants