Skip to content

Commit bbcc175

Browse files
refactor: notification UI config cleanup (#6124)
## Explanation We were missing the BASE chain from our UI config. Also did some cleanup for some config/constant values that are not being used anymore. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Changelog <!-- THIS SECTION IS NO LONGER NEEDED. The process for updating changelogs has changed. Please consult the "Updating changelogs" section of the Contributing doc for more. --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent e25ba88 commit bbcc175

File tree

4 files changed

+45
-135
lines changed

4 files changed

+45
-135
lines changed

packages/notification-services-controller/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `BASE` chain to notification UI config in `ui/constants.ts` ([#6124](https://github.com/MetaMask/core/pull/6124))
13+
14+
### Changed
15+
16+
- Update push notification utility `getChainSymbol` in `get-notification-message.ts` to use UI constants ([#6124](https://github.com/MetaMask/core/pull/6124))
17+
18+
### Removed
19+
20+
- **BREAKING:** Cleanup old config/constants ([#6124](https://github.com/MetaMask/core/pull/6124))
21+
- Remove `NOTIFICATION_CHAINS` constant from `notification-schema.ts`
22+
- Remove `CHAIN_SYMBOLS` constant from `notification-schema.ts`
23+
- Remove `SUPPORTED_CHAINS` constant from `notification-schema.ts`
24+
- Remove `Trigger` type from `notification-schema.ts`
25+
- Remove `TRIGGERS` constant from `notification-schema.ts`
26+
1027
## [14.0.0]
1128

1229
### Changed
Lines changed: 3 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Compute } from '../types/type-utils';
2-
31
export enum TRIGGER_TYPES {
42
FEATURES_ANNOUNCEMENT = 'features_announcement',
53
METAMASK_SWAP_COMPLETED = 'metamask_swap_completed',
@@ -54,136 +52,13 @@ export const NOTIFICATION_CHAINS_ID = {
5452
ETHEREUM: '1',
5553
OPTIMISM: '10',
5654
BSC: '56',
55+
BASE: '8453',
5756
POLYGON: '137',
5857
ARBITRUM: '42161',
5958
AVALANCHE: '43114',
6059
LINEA: '59144',
6160
SEI: '1329',
6261
} as const;
6362

64-
type ToPrimitiveKeys<TObj> = Compute<{
65-
[K in keyof TObj]: TObj[K] extends string ? string : TObj[K];
66-
}>;
67-
export const NOTIFICATION_CHAINS: ToPrimitiveKeys<
68-
typeof NOTIFICATION_CHAINS_ID
69-
> = NOTIFICATION_CHAINS_ID;
70-
71-
export const CHAIN_SYMBOLS = {
72-
[NOTIFICATION_CHAINS.ETHEREUM]: 'ETH',
73-
[NOTIFICATION_CHAINS.OPTIMISM]: 'ETH',
74-
[NOTIFICATION_CHAINS.BSC]: 'BNB',
75-
[NOTIFICATION_CHAINS.POLYGON]: 'POL',
76-
[NOTIFICATION_CHAINS.ARBITRUM]: 'ETH',
77-
[NOTIFICATION_CHAINS.AVALANCHE]: 'AVAX',
78-
[NOTIFICATION_CHAINS.LINEA]: 'ETH',
79-
};
80-
81-
export const SUPPORTED_CHAINS = [
82-
NOTIFICATION_CHAINS.ETHEREUM,
83-
NOTIFICATION_CHAINS.OPTIMISM,
84-
NOTIFICATION_CHAINS.BSC,
85-
NOTIFICATION_CHAINS.POLYGON,
86-
NOTIFICATION_CHAINS.ARBITRUM,
87-
NOTIFICATION_CHAINS.AVALANCHE,
88-
NOTIFICATION_CHAINS.LINEA,
89-
];
90-
91-
export type Trigger = {
92-
supported_chains: (typeof SUPPORTED_CHAINS)[number][];
93-
};
94-
95-
export const TRIGGERS: Partial<Record<TRIGGER_TYPES, Trigger>> = {
96-
[TRIGGER_TYPES.METAMASK_SWAP_COMPLETED]: {
97-
supported_chains: [
98-
NOTIFICATION_CHAINS.ETHEREUM,
99-
NOTIFICATION_CHAINS.OPTIMISM,
100-
NOTIFICATION_CHAINS.BSC,
101-
NOTIFICATION_CHAINS.POLYGON,
102-
NOTIFICATION_CHAINS.ARBITRUM,
103-
NOTIFICATION_CHAINS.AVALANCHE,
104-
],
105-
},
106-
[TRIGGER_TYPES.ERC20_SENT]: {
107-
supported_chains: [
108-
NOTIFICATION_CHAINS.ETHEREUM,
109-
NOTIFICATION_CHAINS.OPTIMISM,
110-
NOTIFICATION_CHAINS.BSC,
111-
NOTIFICATION_CHAINS.POLYGON,
112-
NOTIFICATION_CHAINS.ARBITRUM,
113-
NOTIFICATION_CHAINS.AVALANCHE,
114-
NOTIFICATION_CHAINS.LINEA,
115-
],
116-
},
117-
[TRIGGER_TYPES.ERC20_RECEIVED]: {
118-
supported_chains: [
119-
NOTIFICATION_CHAINS.ETHEREUM,
120-
NOTIFICATION_CHAINS.OPTIMISM,
121-
NOTIFICATION_CHAINS.BSC,
122-
NOTIFICATION_CHAINS.POLYGON,
123-
NOTIFICATION_CHAINS.ARBITRUM,
124-
NOTIFICATION_CHAINS.AVALANCHE,
125-
NOTIFICATION_CHAINS.LINEA,
126-
],
127-
},
128-
[TRIGGER_TYPES.ERC721_SENT]: {
129-
supported_chains: [
130-
NOTIFICATION_CHAINS.ETHEREUM,
131-
NOTIFICATION_CHAINS.POLYGON,
132-
],
133-
},
134-
[TRIGGER_TYPES.ERC721_RECEIVED]: {
135-
supported_chains: [
136-
NOTIFICATION_CHAINS.ETHEREUM,
137-
NOTIFICATION_CHAINS.POLYGON,
138-
],
139-
},
140-
[TRIGGER_TYPES.ERC1155_SENT]: {
141-
supported_chains: [
142-
NOTIFICATION_CHAINS.ETHEREUM,
143-
NOTIFICATION_CHAINS.POLYGON,
144-
],
145-
},
146-
[TRIGGER_TYPES.ERC1155_RECEIVED]: {
147-
supported_chains: [
148-
NOTIFICATION_CHAINS.ETHEREUM,
149-
NOTIFICATION_CHAINS.POLYGON,
150-
],
151-
},
152-
[TRIGGER_TYPES.ETH_SENT]: {
153-
supported_chains: [
154-
NOTIFICATION_CHAINS.ETHEREUM,
155-
NOTIFICATION_CHAINS.OPTIMISM,
156-
NOTIFICATION_CHAINS.BSC,
157-
NOTIFICATION_CHAINS.POLYGON,
158-
NOTIFICATION_CHAINS.ARBITRUM,
159-
NOTIFICATION_CHAINS.AVALANCHE,
160-
NOTIFICATION_CHAINS.LINEA,
161-
],
162-
},
163-
[TRIGGER_TYPES.ETH_RECEIVED]: {
164-
supported_chains: [
165-
NOTIFICATION_CHAINS.ETHEREUM,
166-
NOTIFICATION_CHAINS.OPTIMISM,
167-
NOTIFICATION_CHAINS.BSC,
168-
NOTIFICATION_CHAINS.POLYGON,
169-
NOTIFICATION_CHAINS.ARBITRUM,
170-
NOTIFICATION_CHAINS.AVALANCHE,
171-
NOTIFICATION_CHAINS.LINEA,
172-
],
173-
},
174-
[TRIGGER_TYPES.ROCKETPOOL_STAKE_COMPLETED]: {
175-
supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],
176-
},
177-
[TRIGGER_TYPES.ROCKETPOOL_UNSTAKE_COMPLETED]: {
178-
supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],
179-
},
180-
[TRIGGER_TYPES.LIDO_STAKE_COMPLETED]: {
181-
supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],
182-
},
183-
[TRIGGER_TYPES.LIDO_WITHDRAWAL_REQUESTED]: {
184-
supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],
185-
},
186-
[TRIGGER_TYPES.LIDO_WITHDRAWAL_COMPLETED]: {
187-
supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],
188-
},
189-
};
63+
export type NOTIFICATION_CHAINS_IDS =
64+
(typeof NOTIFICATION_CHAINS_ID)[keyof typeof NOTIFICATION_CHAINS_ID];

packages/notification-services-controller/src/NotificationServicesController/ui/constants.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
import { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema';
1+
import {
2+
NOTIFICATION_CHAINS_ID,
3+
type NOTIFICATION_CHAINS_IDS,
4+
} from '../constants/notification-schema';
25

36
export const NOTIFICATION_NETWORK_CURRENCY_NAME = {
47
[NOTIFICATION_CHAINS_ID.ETHEREUM]: 'Ethereum',
58
[NOTIFICATION_CHAINS_ID.ARBITRUM]: 'Arbitrum',
69
[NOTIFICATION_CHAINS_ID.AVALANCHE]: 'Avalanche',
710
[NOTIFICATION_CHAINS_ID.BSC]: 'Binance',
11+
[NOTIFICATION_CHAINS_ID.BASE]: 'Base',
812
[NOTIFICATION_CHAINS_ID.LINEA]: 'Linea',
913
[NOTIFICATION_CHAINS_ID.OPTIMISM]: 'Optimism',
1014
[NOTIFICATION_CHAINS_ID.POLYGON]: 'Polygon',
1115
[NOTIFICATION_CHAINS_ID.SEI]: 'Sei Network',
12-
} as const;
16+
} satisfies Record<NOTIFICATION_CHAINS_IDS, string>;
1317

1418
export const NOTIFICATION_NETWORK_CURRENCY_SYMBOL = {
1519
[NOTIFICATION_CHAINS_ID.ETHEREUM]: 'ETH',
1620
[NOTIFICATION_CHAINS_ID.ARBITRUM]: 'ETH',
1721
[NOTIFICATION_CHAINS_ID.AVALANCHE]: 'AVAX',
1822
[NOTIFICATION_CHAINS_ID.BSC]: 'BNB',
23+
[NOTIFICATION_CHAINS_ID.BASE]: 'ETH',
1924
[NOTIFICATION_CHAINS_ID.LINEA]: 'ETH',
2025
[NOTIFICATION_CHAINS_ID.OPTIMISM]: 'ETH',
2126
[NOTIFICATION_CHAINS_ID.POLYGON]: 'POL',
2227
[NOTIFICATION_CHAINS_ID.SEI]: 'SEI',
23-
};
28+
} satisfies Record<NOTIFICATION_CHAINS_IDS, string>;
2429

2530
export type BlockExplorerConfig = {
2631
url: string;
@@ -43,6 +48,11 @@ export const SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS = {
4348
url: 'https://bscscan.com',
4449
name: 'BscScan',
4550
},
51+
// BASE
52+
[NOTIFICATION_CHAINS_ID.BASE]: {
53+
url: 'https://basescan.org',
54+
name: 'BaseScan',
55+
},
4656
// POLYGON
4757
[NOTIFICATION_CHAINS_ID.POLYGON]: {
4858
url: 'https://polygonscan.com',
@@ -67,6 +77,6 @@ export const SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS = {
6777
url: 'https://seitrace.com/',
6878
name: 'SeiTrace',
6979
},
70-
} satisfies Record<string, BlockExplorerConfig>;
80+
} satisfies Record<NOTIFICATION_CHAINS_IDS, BlockExplorerConfig>;
7181

7282
export { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema';

packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { getAmount, formatAmount } from './get-notification-data';
2-
import type { Types } from '../../NotificationServicesController';
3-
import { Constants } from '../../NotificationServicesController';
2+
import type {
3+
NOTIFICATION_CHAINS_IDS,
4+
Types,
5+
} from '../../NotificationServicesController';
6+
import type { Constants } from '../../NotificationServicesController';
7+
import { NOTIFICATION_NETWORK_CURRENCY_SYMBOL } from '../../NotificationServicesController/ui';
48

59
export type TranslationKeys = {
610
pushPlatformNotificationsFundsSentTitle: () => string;
@@ -235,7 +239,11 @@ export const createOnChainPushNotificationMessages = (
235239
* @returns The symbol associated with the chain ID, or null if not found.
236240
*/
237241
function getChainSymbol(chainId: number) {
238-
return Constants.CHAIN_SYMBOLS[chainId] ?? null;
242+
return (
243+
NOTIFICATION_NETWORK_CURRENCY_SYMBOL[
244+
chainId.toString() as NOTIFICATION_CHAINS_IDS
245+
] ?? null
246+
);
239247
}
240248

241249
/**

0 commit comments

Comments
 (0)