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

refactor: shared bridge types #29254

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: move BackgroundAction types to shared dir
  • Loading branch information
micaelae committed Dec 18, 2024
commit 0b95b88a8e0fb4de03284591428b2331432b8871
13 changes: 2 additions & 11 deletions app/scripts/controllers/bridge/types.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@ import {
} from '@metamask/network-controller';
import { SwapsTokenObject } from '../../../../shared/constants/swaps';
import {
BridgeBackgroundAction,
BridgeFeatureFlags,
BridgeUserAction,
L1GasFees,
QuoteRequest,
QuoteResponse,
@@ -35,17 +37,6 @@ export type BridgeControllerState = {
quotesRefreshCount: number;
};

export enum BridgeUserAction {
SELECT_SRC_NETWORK = 'selectSrcNetwork',
SELECT_DEST_NETWORK = 'selectDestNetwork',
UPDATE_QUOTE_PARAMS = 'updateBridgeQuoteRequestParams',
}
export enum BridgeBackgroundAction {
SET_FEATURE_FLAGS = 'setBridgeFeatureFlags',
RESET_STATE = 'resetState',
GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',
}

type BridgeControllerAction<FunctionName extends keyof BridgeController> = {
type: `${typeof BRIDGE_CONTROLLER_NAME}:${FunctionName}`;
handler: BridgeController[FunctionName];
8 changes: 4 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
@@ -250,6 +250,10 @@ import { isSnapId } from '../../ui/helpers/utils/snaps';
import { BridgeStatusAction } from '../../shared/types/bridge-status';
import { ENVIRONMENT } from '../../development/build/constants';
import fetchWithCache from '../../shared/lib/fetch-with-cache';
import {
BridgeUserAction,
BridgeBackgroundAction,
} from '../../shared/types/bridge';
import { BalancesController as MultichainBalancesController } from './lib/accounts/BalancesController';
import {
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
@@ -365,10 +369,6 @@ import { updateSecurityAlertResponse } from './lib/ppom/ppom-util';
import createEvmMethodsToNonEvmAccountReqFilterMiddleware from './lib/createEvmMethodsToNonEvmAccountReqFilterMiddleware';
import { isEthAddress } from './lib/multichain/address';
import { decodeTransactionData } from './lib/transaction/decode/util';
import {
BridgeUserAction,
BridgeBackgroundAction,
} from './controllers/bridge/types';
import BridgeController from './controllers/bridge/bridge-controller';
import { BRIDGE_CONTROLLER_NAME } from './controllers/bridge/constants';
import {
10 changes: 10 additions & 0 deletions shared/types/bridge.ts
Original file line number Diff line number Diff line change
@@ -173,3 +173,13 @@ export enum RequestStatus {
FETCHED,
ERROR,
}
export enum BridgeUserAction {
SELECT_SRC_NETWORK = 'selectSrcNetwork',
SELECT_DEST_NETWORK = 'selectDestNetwork',
UPDATE_QUOTE_PARAMS = 'updateBridgeQuoteRequestParams',
}
export enum BridgeBackgroundAction {
SET_FEATURE_FLAGS = 'setBridgeFeatureFlags',
RESET_STATE = 'resetState',
GET_BRIDGE_ERC20_ALLOWANCE = 'getBridgeERC20Allowance',
}
8 changes: 2 additions & 6 deletions ui/ducks/bridge/actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { Hex } from '@metamask/utils';
import {
BridgeBackgroundAction,
BridgeUserAction,
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../app/scripts/controllers/bridge/types';
QuoteRequest,
} from '../../../shared/types/bridge';
import { forceUpdateMetamaskState } from '../../store/actions';
import { submitRequestToBackground } from '../../store/background-connection';
import { QuoteRequest } from '../../../shared/types/bridge';
import { MetaMaskReduxDispatch } from '../../store/store';
import {
bridgeSlice,
4 changes: 1 addition & 3 deletions ui/ducks/bridge/bridge.test.ts
Original file line number Diff line number Diff line change
@@ -7,9 +7,7 @@ import { setBackgroundConnection } from '../../store/background-connection';
import {
BridgeBackgroundAction,
BridgeUserAction,
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../app/scripts/controllers/bridge/types';
} from '../../../shared/types/bridge';
import * as util from '../../helpers/utils/util';
import { BRIDGE_DEFAULT_SLIPPAGE } from '../../../shared/constants/bridge';
import bridgeReducer from './bridge';
8 changes: 3 additions & 5 deletions ui/ducks/bridge/selectors.ts
Original file line number Diff line number Diff line change
@@ -20,11 +20,9 @@ import {
BRIDGE_PREFERRED_GAS_ESTIMATE,
BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE,
} from '../../../shared/constants/bridge';
import {
BridgeControllerState,
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../app/scripts/controllers/bridge/types';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
Copy link
Contributor

Choose a reason for hiding this comment

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

Think you forgot to remove this comment?

import { BridgeControllerState } from '../../../app/scripts/controllers/bridge/types';
import { createDeepEqualSelector } from '../../../shared/modules/selectors/util';
import { SWAPS_CHAINID_DEFAULT_TOKEN_MAP } from '../../../shared/constants/swaps';
import {