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

chore: remove bridge src token list from controller state #29492

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ export const SENTRY_BACKGROUND_STATE = {
chains: {},
},
},
destTokens: {},
destTopAssets: [],
destTokensLoadingStatus: true,
srcTokens: {},
srcTopAssets: [],
srcTokensLoadingStatus: true,
quoteRequest: {
walletAddress: false,
srcTokenAddress: true,
Expand Down
68 changes: 1 addition & 67 deletions app/scripts/controllers/bridge/bridge-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import * as balanceUtils from '../../../../shared/modules/bridge-utils/balance';
import mockBridgeQuotesErc20Native from '../../../../test/data/bridge/mock-quotes-erc20-native.json';
import mockBridgeQuotesNativeErc20 from '../../../../test/data/bridge/mock-quotes-native-erc20.json';
import mockBridgeQuotesNativeErc20Eth from '../../../../test/data/bridge/mock-quotes-native-erc20-eth.json';
import {
type QuoteResponse,
RequestStatus,
} from '../../../../shared/types/bridge';
import { type QuoteResponse } from '../../../../shared/types/bridge';
import { decimalToHex } from '../../../../shared/modules/conversion.utils';
import BridgeController from './bridge-controller';
import { BridgeControllerMessenger } from './types';
Expand Down Expand Up @@ -168,69 +165,6 @@ describe('BridgeController', function () {
);
});

it('selectDestNetwork should set the bridge dest tokens and top assets', async function () {
await bridgeController.selectDestNetwork('0xa');
expect(bridgeController.state.bridgeState.destTokens).toStrictEqual({
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': {
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
symbol: 'ABC',
decimals: 16,
aggregators: ['lifl', 'socket'],
},
'0x0000000000000000000000000000000000000000': {
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
iconUrl: './images/eth_logo.svg',
name: 'Ether',
symbol: 'ETH',
},
});
expect(
bridgeController.state.bridgeState.destTokensLoadingStatus,
).toStrictEqual(RequestStatus.FETCHED);
expect(bridgeController.state.bridgeState.destTopAssets).toStrictEqual([
{ address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', symbol: 'ABC' },
]);
expect(bridgeController.state.bridgeState.quoteRequest).toStrictEqual({
slippage: 0.5,
srcTokenAddress: '0x0000000000000000000000000000000000000000',
walletAddress: undefined,
});
});

it('selectSrcNetwork should set the bridge src tokens and top assets', async function () {
await bridgeController.selectSrcNetwork('0xa');
expect(bridgeController.state.bridgeState.srcTokens).toStrictEqual({
'0x0000000000000000000000000000000000000000': {
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
iconUrl: './images/eth_logo.svg',
name: 'Ether',
symbol: 'ETH',
},
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': {
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
symbol: 'ABC',
decimals: 16,
aggregators: ['lifl', 'socket'],
},
});
expect(
bridgeController.state.bridgeState.srcTokensLoadingStatus,
).toStrictEqual(RequestStatus.FETCHED);
expect(bridgeController.state.bridgeState.srcTopAssets).toStrictEqual([
{
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
symbol: 'ABC',
},
]);
expect(bridgeController.state.bridgeState.quoteRequest).toStrictEqual({
slippage: 0.5,
srcTokenAddress: '0x0000000000000000000000000000000000000000',
walletAddress: undefined,
});
});

it('updateBridgeQuoteRequestParams should update the quoteRequest state', function () {
bridgeController.updateBridgeQuoteRequestParams({ srcChainId: 1 });
expect(bridgeController.state.bridgeState.quoteRequest).toStrictEqual({
Expand Down
63 changes: 0 additions & 63 deletions app/scripts/controllers/bridge/bridge-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import type { ChainId } from '@metamask/controller-utils';
import {
fetchBridgeFeatureFlags,
fetchBridgeQuotes,
fetchBridgeTokens,
} from '../../../../shared/modules/bridge-utils/bridge.util';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { fetchTopAssetsList } from '../../../../ui/pages/swaps/swaps.util';
import {
decimalToHex,
sumHexes,
Expand Down Expand Up @@ -96,14 +92,6 @@ export default class BridgeController extends StaticIntervalPollingController<Br
`${BRIDGE_CONTROLLER_NAME}:setBridgeFeatureFlags`,
this.setBridgeFeatureFlags.bind(this),
);
this.messagingSystem.registerActionHandler(
`${BRIDGE_CONTROLLER_NAME}:selectSrcNetwork`,
this.selectSrcNetwork.bind(this),
);
this.messagingSystem.registerActionHandler(
`${BRIDGE_CONTROLLER_NAME}:selectDestNetwork`,
this.selectDestNetwork.bind(this),
);
this.messagingSystem.registerActionHandler(
`${BRIDGE_CONTROLLER_NAME}:updateBridgeQuoteRequestParams`,
this.updateBridgeQuoteRequestParams.bind(this),
Expand Down Expand Up @@ -215,38 +203,6 @@ export default class BridgeController extends StaticIntervalPollingController<Br
);
};

selectSrcNetwork = async (chainId: Hex) => {
this.update((state) => {
state.bridgeState.srcTokensLoadingStatus = RequestStatus.LOADING;
return state;
});
try {
await this.#setTopAssets(chainId, 'srcTopAssets');
await this.#setTokens(chainId, 'srcTokens');
} finally {
this.update((state) => {
state.bridgeState.srcTokensLoadingStatus = RequestStatus.FETCHED;
return state;
});
}
};

selectDestNetwork = async (chainId: Hex) => {
this.update((state) => {
state.bridgeState.destTokensLoadingStatus = RequestStatus.LOADING;
return state;
});
try {
await this.#setTopAssets(chainId, 'destTopAssets');
await this.#setTokens(chainId, 'destTokens');
} finally {
this.update((state) => {
state.bridgeState.destTokensLoadingStatus = RequestStatus.FETCHED;
return state;
});
}
};

#fetchBridgeQuotes = async ({
networkClientId: _networkClientId,
updatedQuoteRequest,
Expand Down Expand Up @@ -366,25 +322,6 @@ export default class BridgeController extends StaticIntervalPollingController<Br
);
};

#setTopAssets = async (
chainId: Hex,
stateKey: 'srcTopAssets' | 'destTopAssets',
) => {
const { bridgeState } = this.state;
const topAssets = await fetchTopAssetsList(chainId);
this.update((_state) => {
_state.bridgeState = { ...bridgeState, [stateKey]: topAssets };
});
};

#setTokens = async (chainId: Hex, stateKey: 'srcTokens' | 'destTokens') => {
const { bridgeState } = this.state;
const tokens = await fetchBridgeTokens(chainId);
this.update((_state) => {
_state.bridgeState = { ...bridgeState, [stateKey]: tokens };
});
};

#getSelectedAccount() {
return this.messagingSystem.call('AccountsController:getSelectedAccount');
}
Expand Down
8 changes: 1 addition & 7 deletions app/scripts/controllers/bridge/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { zeroAddress } from 'ethereumjs-util';
import { Hex } from '@metamask/utils';
import type { Hex } from '@metamask/utils';
import {
BRIDGE_DEFAULT_SLIPPAGE,
DEFAULT_MAX_REFRESH_COUNT,
Expand All @@ -20,12 +20,6 @@ export const DEFAULT_BRIDGE_CONTROLLER_STATE: BridgeControllerState = {
chains: {},
},
},
srcTokens: {},
srcTokensLoadingStatus: undefined,
destTokensLoadingStatus: undefined,
srcTopAssets: [],
destTokens: {},
destTopAssets: [],
quoteRequest: {
walletAddress: undefined,
srcTokenAddress: zeroAddress(),
Expand Down
2 changes: 0 additions & 2 deletions app/scripts/controllers/bridge/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ type BridgeControllerActions =
| BridgeControllerAction<BridgeBackgroundAction.SET_FEATURE_FLAGS>
| BridgeControllerAction<BridgeBackgroundAction.RESET_STATE>
| BridgeControllerAction<BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE>
| BridgeControllerAction<BridgeUserAction.SELECT_SRC_NETWORK>
| BridgeControllerAction<BridgeUserAction.SELECT_DEST_NETWORK>
| BridgeControllerAction<BridgeUserAction.UPDATE_QUOTE_PARAMS>;

type BridgeControllerEvents = ControllerStateChangeEvent<
Expand Down
9 changes: 0 additions & 9 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4162,15 +4162,6 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeBackgroundAction.GET_BRIDGE_ERC20_ALLOWANCE}`,
),
[BridgeUserAction.SELECT_SRC_NETWORK]: this.controllerMessenger.call.bind(
this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeUserAction.SELECT_SRC_NETWORK}`,
),
[BridgeUserAction.SELECT_DEST_NETWORK]:
this.controllerMessenger.call.bind(
this.controllerMessenger,
`${BRIDGE_CONTROLLER_NAME}:${BridgeUserAction.SELECT_DEST_NETWORK}`,
),
[BridgeUserAction.UPDATE_QUOTE_PARAMS]:
this.controllerMessenger.call.bind(
this.controllerMessenger,
Expand Down
8 changes: 0 additions & 8 deletions shared/types/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Hex } from '@metamask/utils';
import type { BigNumber } from 'bignumber.js';
import type { AssetType } from '../constants/transaction';
import type { SwapsTokenObject } from '../constants/swaps';

export type ChainConfiguration = {
isActiveSrc: boolean;
Expand Down Expand Up @@ -175,7 +174,6 @@ export enum RequestStatus {
ERROR,
}
export enum BridgeUserAction {
SELECT_SRC_NETWORK = 'selectSrcNetwork',
SELECT_DEST_NETWORK = 'selectDestNetwork',
UPDATE_QUOTE_PARAMS = 'updateBridgeQuoteRequestParams',
}
Expand All @@ -186,12 +184,6 @@ export enum BridgeBackgroundAction {
}
export type BridgeControllerState = {
bridgeFeatureFlags: BridgeFeatureFlags;
srcTokens: Record<string, SwapsTokenObject>;
srcTopAssets: { address: string }[];
srcTokensLoadingStatus?: RequestStatus;
destTokensLoadingStatus?: RequestStatus;
destTokens: Record<string, SwapsTokenObject>;
destTopAssets: { address: string }[];
quoteRequest: Partial<QuoteRequest>;
quotes: (QuoteResponse & L1GasFees)[];
quotesInitialLoadTime?: number;
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/default-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ function defaultFixture(inputChainId = CHAIN_IDS.LOCALHOST) {
},
},
},
destTokens: {},
destTopAssets: [],
srcTokens: {},
srcTopAssets: [],
},
},
CurrencyController: {
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,6 @@ class FixtureBuilder {
chains: {},
},
},
destTokens: {},
destTopAssets: [],
srcTokens: {},
srcTopAssets: [],
},
};
return this;
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/tests/metrics/errors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,6 @@ describe('Sentry errors', function () {
srcTokenAmount: true,
walletAddress: false,
},
destTokensLoadingStatus: false,
srcTokensLoadingStatus: false,
quotesLastFetched: true,
quotesLoadingStatus: true,
quotesRefreshCount: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@
"chains": { "0x1": "object", "0xa4b1": "object", "0xe708": "object" }
}
},
"srcTokens": {},
"srcTopAssets": {},
"destTokens": {},
"destTopAssets": {},
"quoteRequest": {
"srcTokenAddress": "0x0000000000000000000000000000000000000000",
"slippage": 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,6 @@
"chains": { "0x1": "object", "0xa4b1": "object", "0xe708": "object" }
}
},
"srcTokens": {},
"srcTopAssets": {},
"destTokens": {},
"destTopAssets": {},
"quoteRequest": {
"srcTokenAddress": "0x0000000000000000000000000000000000000000",
"slippage": 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@
"0xe708": "object"
}
}
},
"destTokens": {},
"destTopAssets": {},
"srcTokens": {},
"srcTopAssets": {}
}
}
},
"SubjectMetadataController": { "subjectMetadata": "object" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@
"0xe708": "object"
}
}
},
"destTokens": {},
"destTopAssets": {},
"srcTokens": {},
"srcTopAssets": {}
}
}
},
"TransactionController": { "transactions": "object" },
Expand Down
22 changes: 0 additions & 22 deletions ui/ducks/bridge/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ export const resetBridgeState = () => {
};

// User actions
export const setFromChain = (chainId: Hex) => {
return async (dispatch: MetaMaskReduxDispatch) => {
dispatch(
callBridgeControllerMethod<Hex>(
BridgeUserAction.SELECT_SRC_NETWORK,
chainId,
),
);
};
};

export const setToChain = (chainId: Hex) => {
return async (dispatch: MetaMaskReduxDispatch) => {
dispatch(
callBridgeControllerMethod<Hex>(
BridgeUserAction.SELECT_DEST_NETWORK,
chainId,
),
);
};
};

export const updateQuoteRequestParams = (params: Partial<QuoteRequest>) => {
return async (dispatch: MetaMaskReduxDispatch) => {
await dispatch(
Expand Down
Loading
Loading