diff --git a/packages/notification-services-controller/CHANGELOG.md b/packages/notification-services-controller/CHANGELOG.md index bf52c7632e3..68b52867d00 100644 --- a/packages/notification-services-controller/CHANGELOG.md +++ b/packages/notification-services-controller/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication. - Modified background push utilities to handle more edgecases and not throw errors ([#7275](https://github.com/MetaMask/core/pull/7275)) - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.18.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583)) +- Move Notifications networks metadata to backend ([#7840](https://github.com/MetaMask/core/pull/7840)) ### Fixed diff --git a/packages/notification-services-controller/notification-services/ui/package.json b/packages/notification-services-controller/notification-services/ui/package.json deleted file mode 100644 index 75d655f391f..00000000000 --- a/packages/notification-services-controller/notification-services/ui/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": "1.0.0", - "private": true, - "description": "", - "license": "MIT", - "sideEffects": false, - "main": "../../dist/NotificationServicesController/ui/index.cjs", - "types": "../../dist/NotificationServicesController/ui/index.d.cts" -} diff --git a/packages/notification-services-controller/package.json b/packages/notification-services-controller/package.json index c49f3fe67c5..d544f7f4a30 100644 --- a/packages/notification-services-controller/package.json +++ b/packages/notification-services-controller/package.json @@ -37,16 +37,6 @@ "default": "./dist/NotificationServicesController/index.cjs" } }, - "./notification-services/ui": { - "import": { - "types": "./dist/NotificationServicesController/ui/index.d.mts", - "default": "./dist/NotificationServicesController/ui/index.mjs" - }, - "require": { - "types": "./dist/NotificationServicesController/ui/index.d.cts", - "default": "./dist/NotificationServicesController/ui/index.cjs" - } - }, "./notification-services/mocks": { "import": { "types": "./dist/NotificationServicesController/mocks/index.d.mts", diff --git a/packages/notification-services-controller/src/NotificationServicesController/constants/notification-schema.ts b/packages/notification-services-controller/src/NotificationServicesController/constants/notification-schema.ts index 256ac2dde93..12644d658b7 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/constants/notification-schema.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/constants/notification-schema.ts @@ -40,20 +40,3 @@ export const NOTIFICATION_API_TRIGGER_TYPES_SET: Set = new Set([ TRIGGER_TYPES.ERC1155_RECEIVED, TRIGGER_TYPES.PLATFORM, ]); - -export const NOTIFICATION_CHAINS_ID = { - ETHEREUM: '1', - OPTIMISM: '10', - BSC: '56', - BASE: '8453', - POLYGON: '137', - ARBITRUM: '42161', - AVALANCHE: '43114', - LINEA: '59144', - SEI: '1329', -} as const; - -// Kept as SCREAMING_SNAKE_CASE for backwards compatibility -// eslint-disable-next-line @typescript-eslint/naming-convention -export type NOTIFICATION_CHAINS_IDS = - (typeof NOTIFICATION_CHAINS_ID)[keyof typeof NOTIFICATION_CHAINS_ID]; diff --git a/packages/notification-services-controller/src/NotificationServicesController/index.ts b/packages/notification-services-controller/src/NotificationServicesController/index.ts index a85278e58a5..cccbfb61498 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/index.ts @@ -11,6 +11,5 @@ export * from './processors'; export * as Constants from './constants'; export * from './constants'; export * as Mocks from './mocks'; -export * as UI from './ui'; export * from '../shared'; export { isVersionInBounds } from './utils/isVersionInBounds'; diff --git a/packages/notification-services-controller/src/NotificationServicesController/mocks/mock-raw-notifications.ts b/packages/notification-services-controller/src/NotificationServicesController/mocks/mock-raw-notifications.ts index 89095c29884..68e57b71c32 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/mocks/mock-raw-notifications.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/mocks/mock-raw-notifications.ts @@ -20,6 +20,14 @@ export function createMockNotificationEthSent(): NormalisedAPINotification { tx_hash: '0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'eth_sent', network_fee: { @@ -58,6 +66,14 @@ export function createMockNotificationEthReceived(): NormalisedAPINotification { tx_hash: '0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'eth_received', network_fee: { @@ -96,6 +112,14 @@ export function createMockNotificationERC20Sent(): NormalisedAPINotification { tx_hash: '0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'erc20_sent', network_fee: { @@ -140,6 +164,14 @@ export function createMockNotificationERC20Received(): NormalisedAPINotification tx_hash: '0xb2256b183f2fb3872f99294ab55fb03e6a479b0d4aca556a3b27568b712505a6', address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'erc20_received', network_fee: { @@ -182,6 +214,14 @@ export function createMockNotificationERC721Sent(): NormalisedAPINotification { block_timestamp: '1700043467', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { to: '0xf47f628fe3bd2595e9ab384bfffc3859b448e451', nft: { @@ -229,6 +269,14 @@ export function createMockNotificationERC721Received(): NormalisedAPINotificatio block_timestamp: '1699980623', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { to: '0xba7f3daa8adfdad686574406ab9bd5d2f0a49d2e', nft: { @@ -276,6 +324,14 @@ export function createMockNotificationERC1155Sent(): NormalisedAPINotification { block_timestamp: '1700510003', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { to: '0x15bd77ccacf2da39b84f0c31fee2e451225bb190', nft: { @@ -323,6 +379,14 @@ export function createMockNotificationERC1155Received(): NormalisedAPINotificati block_timestamp: '1700510003', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { to: '0x15bd77ccacf2da39b84f0c31fee2e451225bb190', nft: { @@ -370,6 +434,14 @@ export function createMockNotificationMetaMaskSwapsCompleted(): NormalisedAPINot block_timestamp: '1697637275', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'metamask_swap_completed', rate: '1558.27', @@ -423,6 +495,14 @@ export function createMockNotificationRocketPoolStakeCompleted(): NormalisedAPIN block_timestamp: '1700145059', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'rocketpool_stake_completed', stake_in: { @@ -475,6 +555,14 @@ export function createMockNotificationRocketPoolUnStakeCompleted(): NormalisedAP block_timestamp: '1697718011', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'rocketpool_unstake_completed', stake_in: { @@ -527,6 +615,14 @@ export function createMockNotificationLidoStakeCompleted(): NormalisedAPINotific block_timestamp: '1698961091', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'lido_stake_completed', stake_in: { @@ -579,6 +675,14 @@ export function createMockNotificationLidoWithdrawalRequested(): NormalisedAPINo block_timestamp: '1697638415', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'lido_withdrawal_requested', stake_in: { @@ -631,6 +735,14 @@ export function createMockNotificationLidoWithdrawalCompleted(): NormalisedAPINo block_timestamp: '1697643851', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'lido_withdrawal_completed', stake_in: { @@ -683,6 +795,14 @@ export function createMockNotificationLidoReadyToBeWithdrawn(): NormalisedAPINot block_timestamp: '1697643851', chain_id: 1, address: '0x881D40237659C251811CEC9c364ef91dC08D300C', + network: { + name: 'Ethereum', + native_symbol: 'ETH', + block_explorer: { + url: 'https://etherscan.io', + name: 'Etherscan', + }, + }, data: { kind: 'lido_stake_ready_to_be_withdrawn', request_id: '123456789', diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/notification-api.ts b/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/notification-api.ts index 5a366061031..4c1e3747f23 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/notification-api.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/notification-api.ts @@ -24,6 +24,8 @@ export type Data_ERC20Sent = components['schemas']['Data_ERC20Sent']; export type Data_ERC20Received = components['schemas']['Data_ERC20Received']; export type Data_ERC721Sent = components['schemas']['Data_ERC721Sent']; export type Data_ERC721Received = components['schemas']['Data_ERC721Received']; +export type NetworkMetadata = components['schemas']['NetworkMetadata']; +export type BlockExplorer = components['schemas']['BlockExplorer']; type Notification = components['schemas']['NotificationOutputV3'][number]; type PlatformNotification = Extract< diff --git a/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/schema.ts b/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/schema.ts index ef3b5ea78f1..84c085a9d5f 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/schema.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/types/notification-api/schema.ts @@ -170,6 +170,7 @@ export type components = { /** @example 0x881D40237659C251811CEC9c364ef91dC08D300C */ tx_hash: string; address: string; + network: components['schemas']['NetworkMetadata']; data?: | components['schemas']['Data_MetamaskSwapCompleted'] | components['schemas']['Data_LidoStakeReadyToBeWithdrawn'] @@ -376,6 +377,28 @@ export type components = { /** Format: decimal */ usd: string; }; + BlockExplorer: { + /** + * Format: uri + * @example https://etherscan.io + */ + url: string; + /** @example Etherscan */ + name: string; + }; + NetworkMetadata: { + /** + * @description Human-readable network name + * @example Ethereum + */ + name: string; + /** + * @description Native token symbol + * @example ETH + */ + native_symbol: string; + block_explorer: components['schemas']['BlockExplorer']; + }; }; responses: never; parameters: never; diff --git a/packages/notification-services-controller/src/NotificationServicesController/ui/constants.ts b/packages/notification-services-controller/src/NotificationServicesController/ui/constants.ts deleted file mode 100644 index f49448bd36b..00000000000 --- a/packages/notification-services-controller/src/NotificationServicesController/ui/constants.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema'; -import type { NOTIFICATION_CHAINS_IDS } from '../constants/notification-schema'; - -export const NOTIFICATION_NETWORK_CURRENCY_NAME = { - [NOTIFICATION_CHAINS_ID.ETHEREUM]: 'Ethereum', - [NOTIFICATION_CHAINS_ID.ARBITRUM]: 'Arbitrum', - [NOTIFICATION_CHAINS_ID.AVALANCHE]: 'Avalanche', - [NOTIFICATION_CHAINS_ID.BSC]: 'Binance', - [NOTIFICATION_CHAINS_ID.BASE]: 'Base', - [NOTIFICATION_CHAINS_ID.LINEA]: 'Linea', - [NOTIFICATION_CHAINS_ID.OPTIMISM]: 'Optimism', - [NOTIFICATION_CHAINS_ID.POLYGON]: 'Polygon', - [NOTIFICATION_CHAINS_ID.SEI]: 'Sei Network', -} satisfies Record; - -export const NOTIFICATION_NETWORK_CURRENCY_SYMBOL = { - [NOTIFICATION_CHAINS_ID.ETHEREUM]: 'ETH', - [NOTIFICATION_CHAINS_ID.ARBITRUM]: 'ETH', - [NOTIFICATION_CHAINS_ID.AVALANCHE]: 'AVAX', - [NOTIFICATION_CHAINS_ID.BSC]: 'BNB', - [NOTIFICATION_CHAINS_ID.BASE]: 'ETH', - [NOTIFICATION_CHAINS_ID.LINEA]: 'ETH', - [NOTIFICATION_CHAINS_ID.OPTIMISM]: 'ETH', - [NOTIFICATION_CHAINS_ID.POLYGON]: 'POL', - [NOTIFICATION_CHAINS_ID.SEI]: 'SEI', -} satisfies Record; - -export type BlockExplorerConfig = { - url: string; - name: string; -}; - -export const SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS = { - // ETHEREUM - [NOTIFICATION_CHAINS_ID.ETHEREUM]: { - url: 'https://etherscan.io', - name: 'Etherscan', - }, - // OPTIMISM - [NOTIFICATION_CHAINS_ID.OPTIMISM]: { - url: 'https://optimistic.etherscan.io', - name: 'Optimistic Etherscan', - }, - // BSC - [NOTIFICATION_CHAINS_ID.BSC]: { - url: 'https://bscscan.com', - name: 'BscScan', - }, - // BASE - [NOTIFICATION_CHAINS_ID.BASE]: { - url: 'https://basescan.org', - name: 'BaseScan', - }, - // POLYGON - [NOTIFICATION_CHAINS_ID.POLYGON]: { - url: 'https://polygonscan.com', - name: 'PolygonScan', - }, - // ARBITRUM - [NOTIFICATION_CHAINS_ID.ARBITRUM]: { - url: 'https://arbiscan.io', - name: 'Arbiscan', - }, - // AVALANCHE - [NOTIFICATION_CHAINS_ID.AVALANCHE]: { - url: 'https://snowtrace.io', - name: 'Snowtrace', - }, - // LINEA - [NOTIFICATION_CHAINS_ID.LINEA]: { - url: 'https://lineascan.build', - name: 'LineaScan', - }, - [NOTIFICATION_CHAINS_ID.SEI]: { - url: 'https://seitrace.com/', - name: 'SeiTrace', - }, -} satisfies Record; - -export { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema'; diff --git a/packages/notification-services-controller/src/NotificationServicesController/ui/index.ts b/packages/notification-services-controller/src/NotificationServicesController/ui/index.ts deleted file mode 100644 index c94f80f843a..00000000000 --- a/packages/notification-services-controller/src/NotificationServicesController/ui/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './constants'; diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts b/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts index d6b107f86df..650f84bfaab 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts @@ -1,10 +1,6 @@ import { getAmount, formatAmount } from './get-notification-data'; -import type { - NOTIFICATION_CHAINS_IDS, - Types, -} from '../../NotificationServicesController'; +import type { Types } from '../../NotificationServicesController'; import type { Constants } from '../../NotificationServicesController'; -import { NOTIFICATION_NETWORK_CURRENCY_SYMBOL } from '../../NotificationServicesController/ui'; export type TranslationKeys = { pushPlatformNotificationsFundsSentTitle: () => string; @@ -108,7 +104,7 @@ export const createOnChainPushNotificationMessages = ( defaultDescription: (): string | null => translate('pushPlatformNotificationsFundsSentDescriptionDefault'), getDescription: (notification): string | null => { - const symbol = getChainSymbol(notification?.payload?.chain_id); + const symbol = notification?.payload?.network?.native_symbol; const tokenAmount = notification?.payload?.data?.amount?.eth; if (!symbol || !tokenAmount) { return null; @@ -153,7 +149,7 @@ export const createOnChainPushNotificationMessages = ( defaultDescription: (): string | null => translate('pushPlatformNotificationsFundsReceivedDescriptionDefault'), getDescription: (notification): string | null => { - const symbol = getChainSymbol(notification?.payload?.chain_id); + const symbol = notification?.payload?.network?.native_symbol; const tokenAmount = notification?.payload?.data?.amount?.eth; if (!symbol || !tokenAmount) { return null; @@ -267,20 +263,6 @@ export const createOnChainPushNotificationMessages = ( }; }; -/** - * Retrieves the symbol associated with a given chain ID. - * - * @param chainId - The ID of the chain. - * @returns The symbol associated with the chain ID, or null if not found. - */ -function getChainSymbol(chainId: number): string | null { - return ( - NOTIFICATION_NETWORK_CURRENCY_SYMBOL[ - chainId.toString() as NOTIFICATION_CHAINS_IDS - ] ?? null - ); -} - /** * Creates a push notification message based on the given on-chain raw notification. *