import React, { memo, useMemo } from "react"; import { Box, HStack, Pressable, ChevronDownIcon, Text, VStack } from "native-base"; import { Image, SvgXml } from "../../../core/images"; import { getBridgeNetworkIcon } from "../../../utils/icons"; import { getChainColor, getChainLabel, getValidTargetChains } from "./utils"; const chainContainerStyles = { flex: 1, bg: "white", borderRadius: "lg", padding: 2, borderWidth: "1", borderColor: "goodGrey.300", position: "relative", style: { overflow: "visible" } } as const; const chainIconStyles = { borderRadius: "full", width: "8", height: "8", alignItems: "center", justifyContent: "center", shadow: "sm" } as const; const chainIconImageStyles = { borderRadius: "full", width: "8", height: "8" } as const; const dropdownChainIconImageStyles = { borderRadius: "full", width: "6", height: "6" } as const; const chainPressableStyles = { flex: 1, flexDirection: "row", alignItems: "center", justifyContent: "space-between" } as const; const dropdownStyles = { position: "absolute", top: "100%", left: 0, right: 0, bg: "white", borderRadius: "lg", borderWidth: "1", borderColor: "goodGrey.300", shadow: "xl", zIndex: 999999, mt: 1, minWidth: "200px", maxWidth: "300px" } as const; const dropdownItemStyles = { padding: 4, borderBottomWidth: 1, borderBottomColor: "goodGrey.200", _pressed: { bg: "goodGrey.100" } } as const; const swapButtonStyles = { bg: "goodGrey.200", borderRadius: "full", width: "8", height: "8", alignItems: "center", justifyContent: "center", shadow: "sm", _pressed: { bg: "goodGrey.300" } } as const; interface ChainSelectorProps { sourceChain: string; targetChain: string; showSourceDropdown: boolean; showTargetDropdown: boolean; bridgeFees: any; bridgeProvider: string; feesLoading: boolean; onSourceChainSelect: (chain: string) => void; onTargetChainSelect: (chain: string) => void; onSwap: () => void; onSourceDropdownToggle: () => void; onTargetDropdownToggle: () => void; } export const ChainSelector: React.FC = memo( ({ sourceChain, targetChain, showSourceDropdown, showTargetDropdown, bridgeFees, bridgeProvider, feesLoading, onSourceChainSelect, onTargetChainSelect, onSwap, onSourceDropdownToggle, onTargetDropdownToggle }) => { const availableChains = useMemo(() => ["fuse", "celo", "mainnet", "xdc"], []); const validTargetChains = useMemo( () => getValidTargetChains(sourceChain, bridgeFees, bridgeProvider, feesLoading), [sourceChain, bridgeFees, bridgeProvider, feesLoading] ); return ( {getBridgeNetworkIcon(sourceChain) ? ( {sourceChain === "celo" ? ( ) : ( )} ) : ( {sourceChain.charAt(0).toUpperCase()} )} {getChainLabel(sourceChain)} {showSourceDropdown && ( {availableChains.map(chain => ( onSourceChainSelect(chain)} {...dropdownItemStyles} borderBottomWidth={chain === availableChains[availableChains.length - 1] ? 0 : 1} > {getBridgeNetworkIcon(chain) ? ( {chain === "celo" ? ( ) : ( )} ) : ( {chain.charAt(0).toUpperCase()} )} {getChainLabel(chain)} ))} )} {getBridgeNetworkIcon(targetChain) ? ( {targetChain === "celo" ? ( ) : ( )} ) : ( {targetChain.charAt(0).toUpperCase()} )} {getChainLabel(targetChain)} {showTargetDropdown && ( {validTargetChains.map(chain => { const isLastItem = chain === validTargetChains[validTargetChains.length - 1]; return ( onTargetChainSelect(chain)} {...dropdownItemStyles} borderBottomWidth={isLastItem ? 0 : 1} > {getBridgeNetworkIcon(chain) ? ( {chain === "celo" ? ( ) : ( )} ) : ( {chain.charAt(0).toUpperCase()} )} {getChainLabel(chain)} ); })} )} ); } );