-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
fix: Bridge{,Status}Controller
state types and restricted-path imports
#28971
fix: Bridge{,Status}Controller
state types and restricted-path imports
#28971
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
BridgeControllerState
, BridgeStatusControllerState
typesBridgeControllerState
, BridgeStatusControllerState
types do not represent full state object
601c055
to
ff835da
Compare
Builds ready [3a3754b]
Page Load Metrics (1940 ± 61 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [f9e9539]
Page Load Metrics (1874 ± 58 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
f9e9539
to
768412e
Compare
BridgeControllerState
, BridgeStatusControllerState
types do not represent full state objectBridge{,Status}Controller
state types, circular dependencies
Bridge{,Status}Controller
state types, circular dependenciesBridge{,Status}Controller
state types, restricted-path dependencies
9cc4bc8
to
2d5f4e2
Compare
Bridge{,Status}Controller
state types, restricted-path dependenciesBridge{,Status}Controller
state types and circular dependencies
2d5f4e2
to
0126ed3
Compare
0126ed3
to
4e4ae1d
Compare
2aa81b0
to
7a2578e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Walkthrough for reviewers:
shared/types/bridge.ts
Outdated
export type BridgeControllerState = { | ||
bridgeState: BridgeState; | ||
}; | ||
|
||
export type BridgeState = { | ||
bridgeFeatureFlags: BridgeFeatureFlags; | ||
srcTokens: Record<string, SwapsTokenObject>; | ||
srcTopAssets: { address: string }[]; | ||
destTokens: Record<string, SwapsTokenObject>; | ||
destTopAssets: { address: string }[]; | ||
quoteRequest: Partial<QuoteRequest>; | ||
quotes: (QuoteResponse & L1GasFees)[]; | ||
quotesInitialLoadTime?: number; | ||
quotesLastFetched?: number; | ||
quotesLoadingStatus?: RequestStatus; | ||
quoteFetchError?: string; | ||
quotesRefreshCount: number; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rename
BridgeControllerState
toBridgeState
- Define new
BridgeControllerState
export type BridgeStatusState = { | ||
txHistory: Record<SourceChainTxMetaId, BridgeHistoryItem>; | ||
}; | ||
|
||
export type BridgeStatusControllerState = { | ||
bridgeStatusState: BridgeStatusState; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rename
BridgeStatusControllerState
toBridgeStatusState
- Define new
BridgeStatusControllerState
export const DEFAULT_BRIDGE_STATE: BridgeState = { | ||
bridgeFeatureFlags: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rename
DEFAULT_BRIDGE_CONTROLLER_STATE
toDEFAULT_BRIDGE_STATE
export const DEFAULT_BRIDGE_CONTROLLER_STATE: BridgeControllerState = { | ||
bridgeState: { ...DEFAULT_BRIDGE_STATE }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Define new
DEFAULT_BRIDGE_CONTROLLER_STATE
export const DEFAULT_BRIDGE_STATUS_STATE: BridgeStatusState = { | ||
txHistory: {}, | ||
}; | ||
|
||
export const DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE: BridgeStatusControllerState = | ||
{ | ||
txHistory: {}, | ||
bridgeStatusState: DEFAULT_BRIDGE_STATUS_STATE, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rename
DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE
toDEFAULT_BRIDGE_STATUS_STATE
- Define new
DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE
ui/pages/bridge/types.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contents of this file were moved to shared/types/bridge.ts
shared/types/bridge.ts
Outdated
symbol: string; | ||
name: string; | ||
decimals: number; | ||
icon?: string; | ||
}; | ||
|
||
export type QuoteRequest = { | ||
walletAddress: string; | ||
destWalletAddress?: string; | ||
srcChainId: ChainId; | ||
destChainId: ChainId; | ||
srcTokenAddress: string; | ||
destTokenAddress: string; | ||
srcTokenAmount: string; // This is the amount sent | ||
slippage: number; | ||
aggIds?: string[]; | ||
bridgeIds?: string[]; | ||
insufficientBal?: boolean; | ||
resetApproval?: boolean; | ||
refuel?: boolean; | ||
}; | ||
|
||
type Protocol = { | ||
name: string; | ||
displayName?: string; | ||
icon?: string; | ||
}; | ||
|
||
enum ActionTypes { | ||
BRIDGE = 'bridge', | ||
SWAP = 'swap', | ||
REFUEL = 'refuel', | ||
} | ||
|
||
type Step = { | ||
action: ActionTypes; | ||
srcChainId: ChainId; | ||
destChainId?: ChainId; | ||
srcAsset: BridgeAsset; | ||
destAsset: BridgeAsset; | ||
srcAmount: string; | ||
destAmount: string; | ||
protocol: Protocol; | ||
}; | ||
|
||
type RefuelData = Step; | ||
|
||
export type Quote = { | ||
requestId: string; | ||
srcChainId: ChainId; | ||
srcAsset: BridgeAsset; | ||
// This is amount sent - metabridge fee, however, some tokens have a fee of 0 | ||
// So sometimes it's equal to amount sent | ||
srcTokenAmount: string; | ||
destChainId: ChainId; | ||
destAsset: BridgeAsset; | ||
destTokenAmount: string; | ||
feeData: Record<FeeType.METABRIDGE, FeeData> & | ||
Partial<Record<FeeType, FeeData>>; | ||
bridgeId: string; | ||
bridges: string[]; | ||
steps: Step[]; | ||
refuel?: RefuelData; | ||
}; | ||
|
||
export type QuoteResponse = { | ||
quote: Quote; | ||
approval: TxData | null; | ||
trade: TxData; | ||
estimatedProcessingTimeInSeconds: number; | ||
}; | ||
|
||
export enum ChainId { | ||
ETH = 1, | ||
OPTIMISM = 10, | ||
BSC = 56, | ||
POLYGON = 137, | ||
ZKSYNC = 324, | ||
BASE = 8453, | ||
ARBITRUM = 42161, | ||
AVALANCHE = 43114, | ||
LINEA = 59144, | ||
} | ||
|
||
export enum FeeType { | ||
METABRIDGE = 'metabridge', | ||
REFUEL = 'refuel', | ||
} | ||
export type FeeData = { | ||
amount: string; | ||
asset: BridgeAsset; | ||
}; | ||
export type TxData = { | ||
chainId: ChainId; | ||
to: string; | ||
from: string; | ||
value: string; | ||
data: string; | ||
gasLimit: number | null; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the former contents of ui/pages/bridge/types.ts
.
They were moved to resolve restricted-path import and circular dependency issues.
import { | ||
BridgeControllerState, | ||
BridgeFeatureFlagsKey, | ||
L1GasFees, | ||
QuoteRequest, | ||
QuoteResponse, | ||
TxData, | ||
// TODO: Remove restricted import | ||
// eslint-disable-next-line import/no-restricted-paths | ||
} from '../../../../ui/pages/bridge/types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
14 violations of import/no-restricted-paths
are resolved in this PR.
Builds ready [c8b4228]
Page Load Metrics (1748 ± 63 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
We’re removing the Extension Platform team from the reviewers list for now. If you need our input, feel free to re-add us—we’re happy to help! |
c8b4228
to
80ba0d3
Compare
Builds ready [80ba0d3]
Page Load Metrics (1621 ± 64 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
…_CONTROLLER_STATE` constant
…nstants/bridge.ts`: `RequestStatus`, `METABRIDGE_CHAIN_TO_ADDRESS_MAP`
80ba0d3
to
88c5311
Compare
Builds ready [d993ba2]
Page Load Metrics (1749 ± 56 ms)
Bundle size diffs [🚀 Bundle size reduced!]
|
…dgeControllerState-type
Superseded by #29254 |
Motivation
ControllerState
types should represent the entire state at root level that is passed toBaseController
andRestrictedMessengerController
.The current set of types for
Bridge{,Status}Controller
state have issues:getState
action, stateChange` event, and other messages that reference the controller's state are incorrect.For more information on writing controllers, see:
Description
Renames:
BridgeControllerState
type toBridgeState
BridgeStatusControllerState
type toBridgeStatusState
.DEFAULT_BRIDGE_CONTROLLER_STATE
constant toDEFAULT_BRIDGE_STATE
.DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE
constant toDEFAULT_BRIDGE_STATUS_STATE
.BridgeState
Redux slice type toBridgeSlice
.Defines new
BridgeControllerState
,BridgeStatusControllerState
types andDEFAULT_BRIDGE_CONTROLLER_STATE
,DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE
constants that represent the corresponding controllers' state at root level.Moves
Bridge{,Status}Controller
types and constants fromapp/scripts/{controllers,shared}
,ui/pages/bridge
toshared/types/bridge
, resolving restricted-path imports and circular dependencies.Note
See PR comments for a walkthrough of the changes.
Related issues
MetamaskController
stores #28723Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist