From 134ac00f0898f27a4482b2c3117a2da2e650d488 Mon Sep 17 00:00:00 2001 From: Hamid Roohi Date: Tue, 13 Aug 2024 14:02:29 +0330 Subject: [PATCH] fix(chain selection): fix target chain selection --- src/components/appBox.tsx | 4 +- src/components/chainSelectInput.tsx | 76 ++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/components/appBox.tsx b/src/components/appBox.tsx index 71219e6..855c41c 100644 --- a/src/components/appBox.tsx +++ b/src/components/appBox.tsx @@ -49,7 +49,7 @@ export default function AppBox() {

Sender

- +

Recipient

- +
{ + setTargetChain((prev) => chain ?? prev); + targetChainRef.current = chain ?? targetChainRef.current; + }, + [setTargetChain], + ); + + useEffect(() => { + const options = availableTargetChainOptions[sourceChain.network]?.[sourceAsset.symbol] || []; + setTargetChainOptions(options); + _setTargetChain(options.at(0)); + }, [sourceChain, sourceAsset, _setTargetChain]); + const _setSourceChain = useCallback( (chain: ChainConfig | undefined) => { setSourceChain((prev) => chain ?? prev); @@ -26,6 +50,20 @@ export default function ChainSelectInput() { }, [setSourceChain], ); + + const _setSourceAsset = useCallback( + (asset: Asset | undefined) => { + setSourceAsset((prev) => asset ?? prev); + sourceAssetRef.current = asset ?? sourceAssetRef.current; + }, + [setSourceAsset], + ); + + useEffect(() => { + const options = availableSourceAssetOptions[sourceChain.network] || []; + setSourceAssetOptions(options); + _setSourceAsset(options.at(0)); + }, [sourceChain, _setSourceAsset]); const [open, setOpen] = useState(false); return (
- {sourceChain.name} -

{sourceChain.name}

+ {who +

{who === "sender" ? sourceChain.name : targetChain.name}

{open && (
- {sourceChainOptions.map((item) => ( -
_setSourceChain(item)}> - {item.name} -

{item.name}

-
- ))} + {who === "sender" + ? sourceChainOptions.map((item) => ( +
_setSourceChain(item)}> + {item.name} +

{item.name}

+
+ )) + : targetChainOptions.map((item) => ( +
_setTargetChain(item)}> + {item.name} +

{item.name}

+
+ ))}
)}