diff --git a/src/components/chainButton.tsx b/src/components/chainButton.tsx index 3e8bff7..aeabfdc 100644 --- a/src/components/chainButton.tsx +++ b/src/components/chainButton.tsx @@ -1,8 +1,27 @@ -import { useCallback, useState } from "react"; +import { useCallback, useRef, useState } from "react"; import data from "../data/data.json"; import Image from "next/image"; +import { useTransfer } from "@/hooks"; +import { getChainLogoSrc, parseCross } from "@/utils"; +import { Asset, ChainConfig, WalletID } from "@/types"; export default function ChainButton() { + const { sourceChain, setSourceChain } = useTransfer(); + const { defaultSourceChainOptions } = parseCross(); + const [sourceChainOptions, _setSourceChainOptions] = useState(defaultSourceChainOptions); + + console.log("source chain", sourceChain); + + const sourceChainRef = useRef(sourceChain); + + const _setSourceChain = useCallback( + (chain: ChainConfig | undefined) => { + setSourceChain((prev) => chain ?? prev); + sourceChainRef.current = chain ?? sourceChainRef.current; + }, + [setSourceChain], + ); + const [subMenu, setSubMenu] = useState(false); const handleToggleSubMenu = useCallback(() => { setSubMenu((prev) => !prev); @@ -17,13 +36,18 @@ export default function ChainButton() { {subMenu && ( -
- {data.chains.map((chain) => ( -
- {chain.name} -
-

{chain.name}

-
+
+ {sourceChainOptions.map((chain) => ( +
{ + _setSourceChain(chain); + setSubMenu(false); + }} + > + {chain.name} +

{chain.name}

))}