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

fix: map the supported block explorers #25908

Merged
merged 17 commits into from
Jul 23, 2024

Conversation

matteoscurati
Copy link
Contributor

@matteoscurati matteoscurati commented Jul 17, 2024

Description

This PR introduces a new object to map the block explorers needed to display certain details of the notifications. The created object is intentionally as simple as possible. The goal of the notifications team is to define a more complete object in a shared library among the different clients to correctly render notifications where necessary.

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. Go to this page...

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.

@matteoscurati matteoscurati added the team-notifications Notifications team label Jul 17, 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.

@matteoscurati matteoscurati marked this pull request as ready for review July 17, 2024 17:21
@matteoscurati matteoscurati requested review from a team as code owners July 17, 2024 17:21
@legobeat legobeat changed the title fix: 🐛 map the supported block explorers fix: map the supported block explorers Jul 19, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [af53459]
Page Load Metrics (169 ± 199 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint842901144923
domContentLoaded108231178
load491974169415199
domInteractive108231178
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 1.29 KiB (0.02%)
  • common: 43 Bytes (0.00%)

Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 69.67%. Comparing base (721a38b) to head (648054b).

Files Patch % Lines
...tton/notification-detail-block-explorer-button.tsx 77.78% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #25908      +/-   ##
===========================================
- Coverage    69.67%   69.67%   -0.00%     
===========================================
  Files         1402     1403       +1     
  Lines        49652    49657       +5     
  Branches     13720    13720              
===========================================
+ Hits         34594    34597       +3     
- Misses       15058    15060       +2     

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

Comment on lines 11 to 47
export const SUPPORTED_BLOCK_EXPLORERS = {
// ETHEREUM
[CHAIN_IDS.MAINNET]: {
url: 'https://etherscan.io',
name: 'Etherscan',
},
// OPTIMISM
[CHAIN_IDS.OPTIMISM]: {
url: 'https://optimistic.etherscan.io',
name: 'Optimistic Etherscan',
},
// BSC
[CHAIN_IDS.BSC]: {
url: 'https://bscscan.com',
name: 'BscScan',
},
// POLYGON
[CHAIN_IDS.POLYGON]: {
url: 'https://polygonscan.com',
name: 'PolygonScan',
},
// ARBITRUM
[CHAIN_IDS.ARBITRUM]: {
url: 'https://arbiscan.io',
name: 'Arbiscan',
},
// AVALANCHE
[CHAIN_IDS.AVALANCHE]: {
url: 'https://snowtrace.io',
name: 'Snowtrace',
},
// LINEA
[CHAIN_IDS.LINEA_MAINNET]: {
url: 'https://lineascan.build',
name: 'LineaScan',
},
};
Copy link
Contributor

Choose a reason for hiding this comment

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

NOTE these will be ported to shared libraries.
Can we make a related PR in shared libraries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Ihave opened a ticket for us. However, I think it might be more practical to close the ticket like this for now

defaultNetwork?.rpcPrefs?.blockExplorerUrl ?? blockExplorerConfig?.url;

const blockExplorerButtonText = blockExplorerConfig?.name
? `${t('notificationItemViewOn')} ${blockExplorerConfig.name}`
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work with all languages. Instead use the I18n insert values.
View on $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.

I’m not sure it wouldn’t have worked, but I modified it anyway 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeee my bad, it would've been fine in english. Other languages might have placed the text in the wrong area :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point!

@Gudahtt
Copy link
Member

Gudahtt commented Jul 19, 2024

What does "supported block explorer" mean in this context? We should support any block explorer that complies with https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3091.md

@Prithpal-Sooriya
Copy link
Contributor

@Gudahtt good point, we should support any block explorer. @matteoscurati correct if wrong, but this fix is specifically for the <BLOCK_EXPLORER_URL> section. We need to support the correct domains for each client (portfolio, extension, mobile), this will be moved out into shared libs (unless if other controllers have these block explorer domains available.)

@Gudahtt
Copy link
Member

Gudahtt commented Jul 19, 2024

We have a shared library for generating block explorer links already, which should support EIP-3091 as well: https://github.com/MetaMask/etherscan-link (apologies for the misleading name, EIP-3091 support was added after it was named)

It has separate functions for Etherscan versus custom because EIP-3091 didn't support all Etherscan pages we link to.

@matteoscurati
Copy link
Contributor Author

Probably the chosen name doesn’t help. Context: the object is meant to describe the block explorers of the chains currently supported by Notifications. This PR is intended as just a FIX for some bugs reported in the extension v12 release. As @Prithpal-Sooriya mentioned, the goal is to bring this change into the shared libraries that we will release (and that we are already using on mobile) instead of the controllers directly inserted into the extension repo.

@Gudahtt , I’ll check the library you linked right away, thanks 👍

@matteoscurati
Copy link
Contributor Author

@Gudahtt , maybe I'm wrong, but I don’t see a method in the library you linked to also get the name of the block explorer (e.g., “BscScan”, etc.). It’s not a big problem; we can leave a generic “View it on the Block Explorer” in the UI, but maybe you know of a better solution :)

@Prithpal-Sooriya
Copy link
Contributor

@Gudahtt OOOH this would be perfect! Unfortunately I only see a limited set of chains supported.
https://github.com/MetaMask/etherscan-link/blob/main/src/prefix-for-chain.ts

I would love this to be the SoT for the growing list of networks we will support

@matteoscurati
Copy link
Contributor Author

Ok, for now, as a temporary fix for the reported bugs, I can change the name of the object. Next steps:

  1. move this fix to the shared libraries
  2. modify, if possible, the recommended library or use—similar to what Portfolio does—codefi/metafi-common

@Gudahtt @Prithpal-Sooriya

@Gudahtt
Copy link
Member

Gudahtt commented Jul 19, 2024

That function is only used for etherscan links. Not for custom block explorer links. There is no need to hard code as anything chain specific

@Prithpal-Sooriya
Copy link
Contributor

Prithpal-Sooriya commented Jul 19, 2024

@Gudahtt ok that sucks, we'll keep as is then (we have many chains and domains to support) - especially since this is to fix v12.0.0+.

We will refactor this into either the existing library you posted, or have this inside our notification controllers


Edit: sadly codefi/metafi-common is private not public.

@matteoscurati
Copy link
Contributor Author

To be precise, before this PR, we used this:

export const ETHERSCAN_SUPPORTED_NETWORKS = {

Two problems:

  1. It seems that the domain for Optimistic is not correct. It should be optimistic.etherscan.io
  2. Arbitrum is not described

@@ -3397,6 +3397,9 @@
"notificationItemUnStakingRequested": {
"message": "Unstaking requested"
},
"notificationItemViewOn": {
"message": "View on $1"
Copy link
Member

Choose a reason for hiding this comment

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

Could we rename notificationTransactionSuccessView here instead of defining an additional, identical localized message? Or is there some difference between these?

If we do need a separate message for some reason, we should include a description entry to explain what the message is for and what the $1 means

ui/helpers/utils/notification.util.ts Outdated Show resolved Hide resolved
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

Mostly looks good, left a couple of suggestions! Blocking on the question about the localized message, as getting new translations for v12 would be challenging on this timeframe.

@Gudahtt
Copy link
Member

Gudahtt commented Jul 22, 2024

Yes, it probably makes sense, but I wouldn't want this fix to create problems elsewhere. And in any case, Arbitrum would still be missing. Additionally, the idea of this patch is just to provide a temporary fix.

Got it, OK. To clarify, what I meant to suggest originally is that we fix both issues you highlighted, which would include adding Arbitrum.

It's a little unclear to me why changing this existing constant would be significantly more work, but I'm not too familiar with it. Coming back to this later sounds OK to me if you think it's easier.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR introduces a new object to map supported block explorers for better notification details.

  • app/_locales/en/messages.json: Added notificationItemViewOn key for dynamic block explorer names in notifications.
  • ui/components/multichain/notification-detail-block-explorer-button/notification-detail-block-explorer-button.tsx: Replaced nativeBlockExplorerUrl with blockExplorerConfig and added getBlockExplorerButtonText function.
  • ui/helpers/constants/metamask-notifications/metamask-notifications.ts: Introduced SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS object and BlockExplorerConfig type.
  • ui/helpers/utils/notification.util.ts: Updated logic to use SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS and added isKey type guard function.

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR introduces a new object to map supported block explorers for better notification details.

  • app/_locales/en/messages.json: Removed notificationItemViewOn and updated notificationTransactionSuccessView description.
  • ui/components/multichain/notification-detail-block-explorer-button/notification-detail-block-explorer-button.tsx: Modified button text to use notificationTransactionSuccessView for accurate block explorer descriptions.

These changes aim to fix issues with incorrect or missing block explorer links in notifications.

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Gudahtt
Gudahtt previously approved these changes Jul 22, 2024
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@matteoscurati matteoscurati dismissed stale reviews from Gudahtt and Prithpal-Sooriya via ff2f9a6 July 22, 2024 21:08
Copy link

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR introduces a new object to map supported block explorers for better notification details.

  • app/_locales/*/messages.json: Updated notificationTransactionSuccessView descriptions across multiple locales to clarify the inclusion of block explorer URLs.
  • ui/components/multichain/notification-detail-block-explorer-button/notification-detail-block-explorer-button.tsx: Modified to use the new block explorer mapping for accurate URLs.
  • ui/pages/notifications/notification-components/erc20-sent-received/erc20-sent-received.tsx: Integrated the new block explorer mapping for ERC20 notifications.
  • ui/pages/notifications/notification-components/swap-completed/swap-completed.tsx: Updated to utilize the new block explorer mapping for swap completion notifications.

These changes aim to fix issues with incorrect or missing block explorer links in notifications.

14 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR introduces a new object to map supported block explorers for better notification details.

  • app/scripts/controllers/user-storage/user-storage-controller.ts: Modified isProfileSyncingEnabled to allow null value for uninitialized state.
  • app/scripts/migrations/120.1.ts: Added migration script to set isProfileSyncingEnabled to null and initialize UserStorageController state.
  • test/e2e/tests/confirmations/signatures/siwe.spec.ts: Introduced E2E tests for Sign-In with Ethereum (SIWE) feature.
  • test/e2e/webdriver/index.js: Added constrainWindowSize parameter for controlled WebDriver test environments.
  • ui/components/app/assets/auto-detect-nft/auto-detect-nft-modal.tsx: Updated modal footer button properties for improved UI.

16 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@matteoscurati matteoscurati merged commit 9395988 into develop Jul 23, 2024
76 of 77 checks passed
@matteoscurati matteoscurati deleted the fix/metamask-notifications-block-explorers branch July 23, 2024 05:20
@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 23, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [c89757b]
Page Load Metrics (149 ± 150 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint742901156129
domContentLoaded98425189
load421498149313150
domInteractive98425189
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 1.52 KiB (0.02%)
  • common: -5 Bytes (-0.00%)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-notifications Notifications team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants