import { useMemo, useState } from "react"; import type { Chain as BridgeChain } from "../../../../../bridge/index.js"; import type { ThirdwebClient } from "../../../../../client/client.js"; import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js"; import { fontSize, iconSize, radius, spacing, } from "../../../../core/design-system/index.js"; import { Container, Line, ModalHeader } from "../../components/basic.js"; import { Button } from "../../components/buttons.js"; import { Img } from "../../components/Img.js"; import { Skeleton } from "../../components/Skeleton.js"; import { Spacer } from "../../components/Spacer.js"; import { Text } from "../../components/text.js"; import { SearchInput } from "./SearchInput.js"; import { useBridgeChainsWithFilters } from "./use-bridge-chains.js"; import { cleanedChainName } from "./utils.js"; type SelectBuyTokenProps = { onBack: () => void; client: ThirdwebClient; onSelectChain: (chain: BridgeChain) => void; selectedChain: BridgeChain | undefined; isMobile: boolean; type: "buy" | "sell"; selections: { buyChainId: number | undefined; sellChainId: number | undefined; }; }; /** * @internal */ export function SelectBridgeChain(props: SelectBuyTokenProps) { const chainQuery = useBridgeChainsWithFilters({ client: props.client, type: props.type, buyChainId: props.selections.buyChainId, sellChainId: props.selections.sellChainId, }); return ( ); } /** * @internal */ export function SelectBridgeChainUI( props: SelectBuyTokenProps & { isPending: boolean; chains: BridgeChain[]; onSelectChain: (chain: BridgeChain) => void; selectedChain: BridgeChain | undefined; }, ) { const [search, setSearch] = useState(""); const [initiallySelectedChain] = useState(props.selectedChain); // put the initially selected chain first const sortedChains = useMemo(() => { if (initiallySelectedChain) { return [ initiallySelectedChain, ...props.chains.filter( (chain) => chain.chainId !== initiallySelectedChain.chainId, ), ]; } return props.chains; }, [props.chains, initiallySelectedChain]); const filteredChains = sortedChains.filter((chain) => { return chain.name.toLowerCase().includes(search.toLowerCase()); }); return ( {props.isMobile && ( <> )} {filteredChains.map((chain) => ( props.onSelectChain(chain)} isSelected={chain.chainId === props.selectedChain?.chainId} isMobile={props.isMobile} /> ))} {props.isPending && new Array(20).fill(0).map(() => ( // biome-ignore lint/correctness/useJsxKeyInIterable: ok ))} {filteredChains.length === 0 && !props.isPending && (
No chains found for "{search}"
)}
); } function ChainButtonSkeleton(props: { isMobile: boolean }) { const iconSizeValue = props.isMobile ? iconSize.lg : iconSize.md; return (
); } function ChainButton(props: { chain: BridgeChain; client: ThirdwebClient; onClick: () => void; isSelected: boolean; isMobile: boolean; }) { const theme = useCustomTheme(); const iconSizeValue = props.isMobile ? iconSize.lg : iconSize.md; return ( ); }