-
Notifications
You must be signed in to change notification settings - Fork 4
fix: tree shaking web3 icons #128
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 37 additions & 29 deletions
66
packages/circle-react-elements/src/components/ChainIcon/ChainIcon.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,57 @@ | ||
| import type { Blockchain } from '@circle-fin/developer-controlled-wallets'; | ||
| import { NetworkIcon } from '@web3icons/react'; | ||
| import { | ||
| NetworkArbitrumOne, | ||
| NetworkPolygon, | ||
| NetworkNearProtocol, | ||
| NetworkAvalanche, | ||
| NetworkSolana, | ||
| NetworkEthereum, | ||
| NetworkUnichain, | ||
| type IconComponentProps, | ||
| } from '@web3icons/react'; | ||
|
|
||
| /** | ||
| * Props for the ChainIcon component | ||
| */ | ||
| export interface ChainIconProps { | ||
| export interface ChainIconProps extends IconComponentProps { | ||
| /** | ||
| * The blockchain network to display an icon for | ||
| * Supports all networks from Circle's API including testnet variants | ||
| */ | ||
| blockchain: Blockchain; | ||
| } | ||
|
|
||
| /** | ||
| * Mapping of Circle blockchain identifiers to web3icons network names | ||
| */ | ||
| const BlockchainToIconMap: Record<Blockchain, string> = { | ||
| 'ARB-SEPOLIA': 'arbitrum', | ||
| ARB: 'arbitrum', | ||
| 'AVAX-FUJI': 'avalanche', | ||
| AVAX: 'avalanche', | ||
| 'ETH-SEPOLIA': 'ethereum', | ||
| ETH: 'ethereum', | ||
| 'EVM-TESTNET': '', | ||
| EVM: '', | ||
| 'MATIC-AMOY': 'polygon', | ||
| MATIC: 'polygon', | ||
| 'NEAR-TESTNET': 'near-protocol', | ||
| NEAR: 'near-protocol', | ||
| 'SOL-DEVNET': 'solana', | ||
| SOL: 'solana', | ||
| 'UNI-SEPOLIA': 'uni', | ||
| }; | ||
| const BlockchainToIconMap: Record<Blockchain, React.ComponentType<IconComponentProps>> = { | ||
| 'ARB-SEPOLIA': NetworkArbitrumOne, | ||
| ARB: NetworkArbitrumOne, | ||
| 'AVAX-FUJI': NetworkAvalanche, | ||
| AVAX: NetworkAvalanche, | ||
| 'ETH-SEPOLIA': NetworkEthereum, | ||
| ETH: NetworkEthereum, | ||
| 'EVM-TESTNET': NetworkEthereum, | ||
| EVM: NetworkEthereum, | ||
| 'MATIC-AMOY': NetworkPolygon, | ||
| MATIC: NetworkPolygon, | ||
| 'NEAR-TESTNET': NetworkNearProtocol, | ||
| NEAR: NetworkNearProtocol, | ||
| 'SOL-DEVNET': NetworkSolana, | ||
| SOL: NetworkSolana, | ||
| 'UNI-SEPOLIA': NetworkUnichain, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Displays a branded icon for a given blockchain network | ||
| * | ||
| * Features: | ||
| * - Shows branded network icons using web3icons library | ||
| * - Uses specific network icons from @web3icons/react | ||
| * - Supports all Circle-supported networks including testnets | ||
| * - Consistent 20px size for all icons | ||
| * - Uses official branded network colors | ||
| */ | ||
| export function ChainIcon({ blockchain }: ChainIconProps) { | ||
| return ( | ||
| <NetworkIcon network={BlockchainToIconMap[blockchain]} size={20} variant="branded" /> | ||
| ); | ||
| export function ChainIcon({ blockchain, ...props }: ChainIconProps) { | ||
| const Icon = BlockchainToIconMap[blockchain]; | ||
|
|
||
| if (!Icon) { | ||
| return null; | ||
| } | ||
|
|
||
| return <Icon size={20} variant="branded" {...props} />; | ||
| } |
20 changes: 20 additions & 0 deletions
20
packages/circle-react-elements/src/components/LazyTokenIcon/LazyTokenIcon.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { TokenIconProps } from '@web3icons/react'; | ||
| import { lazy, Suspense } from 'react'; | ||
|
|
||
| const TokenIcon = lazy(() => | ||
| import('@web3icons/react').then((mod) => ({ | ||
| default: mod.TokenIcon, | ||
| })), | ||
| ); | ||
|
|
||
| export type LazyTokenIconProps = TokenIconProps & { | ||
| ref?: React.Ref<SVGSVGElement>; | ||
| }; | ||
|
|
||
| export function LazyTokenIcon(props: LazyTokenIconProps) { | ||
| return ( | ||
| <Suspense fallback={<div className="w-10 h-10 bg-muted rounded-full" />}> | ||
| <TokenIcon {...props} /> | ||
| </Suspense> | ||
| ); | ||
| } | ||
1 change: 1 addition & 0 deletions
1
packages/circle-react-elements/src/components/LazyTokenIcon/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './LazyTokenIcon'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
lazy load icons on demand