-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat: swap and bridge asset picker components #38749
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
base: main
Are you sure you want to change the base?
Conversation
✨ Files requiring CODEOWNER review ✨🔄 @MetaMask/swaps-engineers (23 files, +1266 -293)
|
Builds ready [9ce6a36]
UI Startup Metrics (1260 ± 103 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
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.
Bug: Missing null check causes crash when token undefined
The refactored code removed a conditional check that handled when token is null. Previously, when isAmountReadOnly && !token, a plain Button was rendered. Now SelectedAssetButton is always rendered with asset={(token as never) ?? undefined}. The SelectedAssetButton component types asset as BridgeToken (non-nullable) but when token is null, undefined is passed. The component then accesses asset.symbol, asset.chainId, asset.image directly, which will throw a runtime error when the destination token hasn't been selected yet.
ui/pages/bridge/prepare/bridge-input-group.tsx#L235-L244
metamask-extension/ui/pages/bridge/prepare/bridge-input-group.tsx
Lines 235 to 244 in 4f1585f
| > | |
| {(onClickHandler) => | |
| ( | |
| <SelectedAssetButton | |
| onClick={onClickHandler} | |
| asset={(token as never) ?? undefined} | |
| data-testid={buttonProps.testId} | |
| /> | |
| ) | |
| } |
ui/pages/bridge/prepare/components/bridge-asset-picker/selected-asset-button.tsx#L29-L75
metamask-extension/ui/pages/bridge/prepare/components/bridge-asset-picker/selected-asset-button.tsx
Lines 29 to 75 in 4f1585f
| export const SelectedAssetButton = ({ | |
| asset, | |
| ...props | |
| }: { | |
| asset: BridgeToken; | |
| } & SelectButtonProps<'div'>) => ( | |
| <SelectButton | |
| borderRadius={BorderRadius.pill} | |
| backgroundColor={BackgroundColor.backgroundDefault} | |
| borderColor={BorderColor.borderMuted} | |
| style={{ | |
| padding: 8, | |
| paddingRight: 11, | |
| minWidth: 'fit-content', | |
| }} | |
| size={SelectButtonSize.Lg} | |
| alignItems={AlignItems.center} | |
| descriptionProps={{ | |
| overflowWrap: OverflowWrap.BreakWord, | |
| ellipsis: false, | |
| }} | |
| caretIconProps={{ | |
| name: IconName.ArrowDown, | |
| style: { display: Display.None }, | |
| }} | |
| label={asset.symbol} | |
| startAccessory={ | |
| <BadgeWrapper | |
| key={asset.assetId} | |
| style={{ marginRight: 2 }} | |
| badge={ | |
| <AvatarNetwork | |
| name={NETWORK_TO_SHORT_NETWORK_NAME_MAP[asset.chainId]} | |
| src={BRIDGE_CHAIN_ID_TO_NETWORK_IMAGE_MAP[asset.chainId]} | |
| size={AvatarNetworkSize.Xs} | |
| style={{ borderWidth: 1, borderRadius: 6 }} | |
| hasBorder | |
| /> | |
| } | |
| > | |
| <AvatarToken src={asset.image} name={asset.symbol} /> | |
| </BadgeWrapper> | |
| } | |
| {...props} | |
| /> | |
| ); |
Builds ready [4f1585f]
UI Startup Metrics (1313 ± 122 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
ui/pages/bridge/prepare/components/bridge-asset-picker/selected-asset-button.tsx
Outdated
Show resolved
Hide resolved
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
Builds ready [adcdb33]
UI Startup Metrics (1308 ± 128 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
Builds ready [3ef8d23]
UI Startup Metrics (1300 ± 113 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚀 Bundle size reduced!]
|
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
Builds ready [bfd56db]
UI Startup Metrics (1267 ± 118 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
Builds ready [22d1260]
UI Startup Metrics (1309 ± 97 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [e0bcf37]
UI Startup Metrics (1272 ± 94 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
ui/pages/bridge/prepare/components/bridge-asset-picker/lazy-asset-list.tsx
Show resolved
Hide resolved
Builds ready [05313a0]
UI Startup Metrics (1326 ± 132 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Description
This adds the utils and components that implement the new Bridge Asset Picker
Note that these components are not connected to the Swap page yet but can be previewed in the generated storybook link: https://diuv6g5fj9pvx.cloudfront.net/metamask-extension/20310062179/storybook-build/index.html?path=/docs/pages-bridge-assetpicker--docs
Changelog
CHANGELOG entry: feat: implement new bridge AssetPicker components
Related issues
Fixes:
Manual testing steps
Check storybook previews: https://diuv6g5fj9pvx.cloudfront.net/metamask-extension/20310062179/storybook-build/index.html?path=/docs/pages-bridge-assetpicker--docs
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Implements a new Bridge Asset Picker (with network filter, search, and popular tokens), integrates it into the bridge inputs, updates token/chain mappings and analytics, and refreshes tests, snapshots, styles, and stories.
NetworkPicker), searchable token list (BridgeAssetList/AssetListItem), loading skeleton, andSelectedAssetButton.BridgeInputGroup; remove oldBridgeAssetPickerButton.Rowpolymorphic withforwardRef; add related SCSS; update snapshots and Storybook stories.BridgeTokenwithname;TokenPayload.payloadgains optionalnameand is non-null.toBridgeTokennow non-null, sets defaultname,assetId, and image.setFromChainacceptstokennullable.BRIDGE_CHAIN_ID_TO_NETWORK_IMAGE_MAPbuilt fromCHAIN_ID_TO_NETWORK_IMAGE_URL_MAPand CAIP IDs; expose for picker badges.securityWarnings(descriptions from token/tx alerts) in quote updates and switch events; tighten switch event guard.name), and add Storybook stories for new components.Written by Cursor Bugbot for commit 05313a0. This will update automatically on new commits. Configure here.