Skip to content

Commit 69c802f

Browse files
authored
refactor: migrate to @metamask/bridge-controller (#31059)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR removes the BridgeController class and shared bridge utils from the extension repo, and replaces them with [@metamask/bridge-controller](https://www.npmjs.com/package/@metamask/bridge-controller) imports See [Copilot summary for more details](#31059 (review)) <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31059?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Bridge and swap functionality for EVM and Solana should be unchanged, just updating imports ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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.
1 parent 23314e3 commit 69c802f

File tree

90 files changed

+1206
-3236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1206
-3236
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ module.exports = {
353353
'app/scripts/controllers/alert-controller.test.ts',
354354
'app/scripts/metamask-controller.actions.test.js',
355355
'app/scripts/detect-multiple-instances.test.js',
356-
'app/scripts/controllers/bridge.test.ts',
357356
'app/scripts/controllers/swaps/**/*.test.js',
358357
'app/scripts/controllers/swaps/**/*.test.ts',
359358
'app/scripts/controllers/metametrics.test.js',

app/scripts/constants/sentry-state.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,28 @@ export const SENTRY_BACKGROUND_STATE = {
112112
assetsRates: false,
113113
},
114114
BridgeController: {
115-
bridgeState: {
116-
bridgeFeatureFlags: {
117-
extensionConfig: {
118-
support: false,
119-
chains: {},
120-
},
115+
bridgeFeatureFlags: {
116+
extensionConfig: {
117+
support: false,
118+
chains: {},
121119
},
122-
quoteRequest: {
123-
walletAddress: false,
124-
srcTokenAddress: true,
125-
slippage: true,
126-
srcChainId: true,
127-
destChainId: true,
128-
destTokenAddress: true,
129-
srcTokenAmount: true,
130-
},
131-
quotes: [],
132-
quotesInitialLoadTime: true,
133-
quotesLastFetched: true,
134-
quotesLoadingStatus: true,
135-
quoteFetchError: true,
136-
quotesRefreshCount: true,
120+
mobileConfig: false,
121+
},
122+
quoteRequest: {
123+
walletAddress: false,
124+
srcTokenAddress: true,
125+
slippage: true,
126+
srcChainId: true,
127+
destChainId: true,
128+
destTokenAddress: true,
129+
srcTokenAmount: true,
137130
},
131+
quotes: [],
132+
quotesInitialLoadTime: true,
133+
quotesLastFetched: true,
134+
quotesLoadingStatus: true,
135+
quoteFetchError: true,
136+
quotesRefreshCount: true,
138137
},
139138
BridgeStatusController: {
140139
bridgeStatusState: {

app/scripts/controllers/bridge-status/__snapshots__/bridge-status-controller.test.ts.snap

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
2020
],
2121
"destAsset": {
2222
"address": "0x0000000000000000000000000000000000000000",
23+
"assetId": "eip155:10/slip44:60",
2324
"chainId": 10,
2425
"coinKey": "ETH",
2526
"decimals": 18,
@@ -36,6 +37,7 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
3637
"amount": "8750000000000",
3738
"asset": {
3839
"address": "0x0000000000000000000000000000000000000000",
40+
"assetId": "eip155:42161/slip44:60",
3941
"chainId": 42161,
4042
"coinKey": "ETH",
4143
"decimals": 18,
@@ -50,6 +52,7 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
5052
"requestId": "197c402f-cb96-4096-9f8c-54aed84ca776",
5153
"srcAsset": {
5254
"address": "0x0000000000000000000000000000000000000000",
55+
"assetId": "eip155:42161/slip44:60",
5356
"chainId": 42161,
5457
"coinKey": "ETH",
5558
"decimals": 18,
@@ -67,6 +70,7 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
6770
"destAmount": "990654755978612",
6871
"destAsset": {
6972
"address": "0x0000000000000000000000000000000000000000",
73+
"assetId": "eip155:10/slip44:60",
7074
"chainId": 10,
7175
"coinKey": "ETH",
7276
"decimals": 18,
@@ -85,6 +89,7 @@ exports[`BridgeStatusController constructor rehydrates the tx history state 1`]
8589
"srcAmount": "991250000000000",
8690
"srcAsset": {
8791
"address": "0x0000000000000000000000000000000000000000",
92+
"assetId": "eip155:42161/slip44:60",
8893
"chainId": 42161,
8994
"coinKey": "ETH",
9095
"decimals": 18,
@@ -133,6 +138,7 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
133138
],
134139
"destAsset": {
135140
"address": "0x0000000000000000000000000000000000000000",
141+
"assetId": "eip155:10/slip44:60",
136142
"chainId": 10,
137143
"coinKey": "ETH",
138144
"decimals": 18,
@@ -149,6 +155,7 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
149155
"amount": "8750000000000",
150156
"asset": {
151157
"address": "0x0000000000000000000000000000000000000000",
158+
"assetId": "eip155:42161/slip44:60",
152159
"chainId": 42161,
153160
"coinKey": "ETH",
154161
"decimals": 18,
@@ -163,6 +170,7 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
163170
"requestId": "197c402f-cb96-4096-9f8c-54aed84ca776",
164171
"srcAsset": {
165172
"address": "0x0000000000000000000000000000000000000000",
173+
"assetId": "eip155:42161/slip44:60",
166174
"chainId": 42161,
167175
"coinKey": "ETH",
168176
"decimals": 18,
@@ -180,6 +188,7 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
180188
"destAmount": "990654755978612",
181189
"destAsset": {
182190
"address": "0x0000000000000000000000000000000000000000",
191+
"assetId": "eip155:10/slip44:60",
183192
"chainId": 10,
184193
"coinKey": "ETH",
185194
"decimals": 18,
@@ -198,6 +207,7 @@ exports[`BridgeStatusController startPollingForBridgeTxStatus sets the inital tx
198207
"srcAmount": "991250000000000",
199208
"srcAsset": {
200209
"address": "0x0000000000000000000000000000000000000000",
210+
"assetId": "eip155:42161/slip44:60",
201211
"chainId": 42161,
202212
"coinKey": "ETH",
203213
"decimals": 18,

app/scripts/controllers/bridge-status/bridge-status-controller.test.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChainId } from '@metamask/bridge-controller';
12
import { flushPromises } from '../../../../test/lib/timer-helpers';
23
import { Numeric } from '../../../../shared/modules/Numeric';
34
import BridgeStatusController from './bridge-status-controller';
@@ -358,7 +359,7 @@ describe('BridgeStatusController', () => {
358359
srcTxHash: '0xsrcTxHash2',
359360
txMetaId: 'bridgeTxMetaId2',
360361
srcChainId: 10,
361-
destChainId: 123,
362+
destChainId: ChainId.SOLANA,
362363
}),
363364
);
364365
jest.advanceTimersByTime(10_000);
@@ -381,7 +382,7 @@ describe('BridgeStatusController', () => {
381382
expect(
382383
bridgeStatusController.state.bridgeStatusState.txHistory.bridgeTxMetaId2
383384
.quote.destChainId,
384-
).toEqual(123);
385+
).toEqual(1151111081099710);
385386

386387
bridgeStatusController.wipeBridgeStatus({
387388
address: '0xaccount1',
@@ -455,7 +456,7 @@ describe('BridgeStatusController', () => {
455456
srcTxHash: '0xsrcTxHash2',
456457
txMetaId: 'bridgeTxMetaId2',
457458
srcChainId: 10,
458-
destChainId: 123,
459+
destChainId: 137,
459460
}),
460461
);
461462
jest.advanceTimersByTime(10_000);
@@ -478,7 +479,7 @@ describe('BridgeStatusController', () => {
478479
expect(
479480
bridgeStatusController.state.bridgeStatusState.txHistory.bridgeTxMetaId2
480481
.quote.destChainId,
481-
).toEqual(123);
482+
).toEqual(137);
482483

483484
bridgeStatusController.wipeBridgeStatus({
484485
address: '0xaccount1',
@@ -491,7 +492,7 @@ describe('BridgeStatusController', () => {
491492
);
492493
expect(txHistoryItems).toHaveLength(1);
493494
expect(txHistoryItems[0].quote.srcChainId).toEqual(10);
494-
expect(txHistoryItems[0].quote.destChainId).toEqual(123);
495+
expect(txHistoryItems[0].quote.destChainId).toEqual(137);
495496
});
496497
});
497498
});

app/scripts/controllers/bridge-status/mocks.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TransactionMeta } from '@metamask/transaction-controller';
2+
import { getNativeAssetForChainId } from '@metamask/bridge-controller';
23
import {
34
BridgeId,
45
StatusResponse,
@@ -123,6 +124,7 @@ export const getMockQuote = ({
123124
srcTokenAmount: '991250000000000',
124125
srcAsset: {
125126
address: '0x0000000000000000000000000000000000000000',
127+
assetId: getNativeAssetForChainId(srcChainId).assetId,
126128
chainId: srcChainId,
127129
symbol: 'ETH',
128130
decimals: 18,
@@ -137,6 +139,7 @@ export const getMockQuote = ({
137139
destTokenAmount: '990654755978612',
138140
destAsset: {
139141
address: '0x0000000000000000000000000000000000000000',
142+
assetId: getNativeAssetForChainId(destChainId).assetId,
140143
chainId: destChainId,
141144
symbol: 'ETH',
142145
decimals: 18,
@@ -152,6 +155,7 @@ export const getMockQuote = ({
152155
amount: '8750000000000',
153156
asset: {
154157
address: '0x0000000000000000000000000000000000000000',
158+
assetId: getNativeAssetForChainId(srcChainId).assetId,
155159
chainId: srcChainId,
156160
symbol: 'ETH',
157161
decimals: 18,
@@ -178,6 +182,7 @@ export const getMockQuote = ({
178182
},
179183
srcAsset: {
180184
address: '0x0000000000000000000000000000000000000000',
185+
assetId: getNativeAssetForChainId(srcChainId).assetId,
181186
chainId: srcChainId,
182187
symbol: 'ETH',
183188
decimals: 18,
@@ -190,6 +195,7 @@ export const getMockQuote = ({
190195
},
191196
destAsset: {
192197
address: '0x0000000000000000000000000000000000000000',
198+
assetId: getNativeAssetForChainId(destChainId).assetId,
193199
chainId: destChainId,
194200
symbol: 'ETH',
195201
decimals: 18,

app/scripts/controllers/bridge-status/utils.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { BRIDGE_CLIENT_ID } from '../../../../shared/constants/bridge';
1+
import { BridgeClientId, type Quote } from '@metamask/bridge-controller';
22
import fetchWithCache from '../../../../shared/lib/fetch-with-cache';
33
import {
44
StatusResponse,
55
StatusRequestWithSrcTxHash,
66
StatusRequestDto,
77
} from '../../../../shared/types/bridge-status';
8-
import type { Quote } from '../../../../shared/types/bridge';
98
import { validateResponse, validators } from './validators';
109
import { BRIDGE_STATUS_BASE_URL } from './constants';
1110

12-
const CLIENT_ID_HEADER = { 'X-Client-Id': BRIDGE_CLIENT_ID };
11+
const CLIENT_ID_HEADER = { 'X-Client-Id': BridgeClientId.EXTENSION };
1312

1413
export const getStatusRequestDto = (
1514
statusRequest: StatusRequestWithSrcTxHash,

0 commit comments

Comments
 (0)