From 3e9eb49787e00c09c3286aeb4ad73826a2856e65 Mon Sep 17 00:00:00 2001 From: MananTank Date: Thu, 23 Oct 2025 23:39:57 +0000 Subject: [PATCH] [MNY-289] SDK: Fix token selection UI loading state when wallet is connected to a chain that is not supported by tw bridge (#8304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR addresses an issue with the `Select Token` UI being stuck in a loading state when the wallet is connected to an unsupported chain by the `thirdweb Bridge`. It modifies the logic for selecting the default chain in various widgets. ### Detailed summary - Updated the function from `getDefaultSelectedChain` to `findChain` for clarity. - Improved logic to handle cases where `activeChainId` is undefined. - Adjusted the selection of `selectedChain` to use the new `findChain` function, ensuring proper fallback options. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit ## Bug Fixes * Fixed Select Token components from remaining in loading state when the connected wallet chain is not supported by thirdweb Bridge. This affects BuyWidget, SwapWidget, and BridgeWidget. --- .changeset/fine-bobcats-rhyme.md | 5 +++++ .../ui/Bridge/swap-widget/select-token-ui.tsx | 18 ++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 .changeset/fine-bobcats-rhyme.md diff --git a/.changeset/fine-bobcats-rhyme.md b/.changeset/fine-bobcats-rhyme.md new file mode 100644 index 00000000000..03fb37b6a23 --- /dev/null +++ b/.changeset/fine-bobcats-rhyme.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Fix Select Token UI stuck in loading state if wallet is connected to a chain that is not supported by thirdweb Bridge in BuyWidget, SwapWidget and BridgeWidget diff --git a/packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx b/packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx index fe78747bab9..b587ae214a3 100644 --- a/packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx +++ b/packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx @@ -45,11 +45,11 @@ type SelectTokenUIProps = { activeWalletInfo: ActiveWalletInfo | undefined; }; -function getDefaultSelectedChain( - chains: BridgeChain[], - activeChainId: number | undefined, -) { - return chains.find((chain) => chain.chainId === (activeChainId || 1)); +function findChain(chains: BridgeChain[], activeChainId: number | undefined) { + if (!activeChainId) { + return undefined; + } + return chains.find((chain) => chain.chainId === activeChainId); } /** @@ -67,11 +67,9 @@ export function SelectToken(props: SelectTokenUIProps) { const selectedChain = _selectedChain || (chainQuery.data - ? getDefaultSelectedChain( - chainQuery.data, - props.selectedToken?.chainId || - props.activeWalletInfo?.activeChain.id, - ) + ? findChain(chainQuery.data, props.selectedToken?.chainId) || + findChain(chainQuery.data, props.activeWalletInfo?.activeChain.id) || + findChain(chainQuery.data, 1) : undefined); // all tokens