Skip to content

Commit 3e9eb49

Browse files
committed
[MNY-289] SDK: Fix token selection UI loading state when wallet is connected to a chain that is not supported by tw bridge (#8304)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 630edad commit 3e9eb49

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

.changeset/fine-bobcats-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
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

packages/thirdweb/src/react/web/ui/Bridge/swap-widget/select-token-ui.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type SelectTokenUIProps = {
4545
activeWalletInfo: ActiveWalletInfo | undefined;
4646
};
4747

48-
function getDefaultSelectedChain(
49-
chains: BridgeChain[],
50-
activeChainId: number | undefined,
51-
) {
52-
return chains.find((chain) => chain.chainId === (activeChainId || 1));
48+
function findChain(chains: BridgeChain[], activeChainId: number | undefined) {
49+
if (!activeChainId) {
50+
return undefined;
51+
}
52+
return chains.find((chain) => chain.chainId === activeChainId);
5353
}
5454

5555
/**
@@ -67,11 +67,9 @@ export function SelectToken(props: SelectTokenUIProps) {
6767
const selectedChain =
6868
_selectedChain ||
6969
(chainQuery.data
70-
? getDefaultSelectedChain(
71-
chainQuery.data,
72-
props.selectedToken?.chainId ||
73-
props.activeWalletInfo?.activeChain.id,
74-
)
70+
? findChain(chainQuery.data, props.selectedToken?.chainId) ||
71+
findChain(chainQuery.data, props.activeWalletInfo?.activeChain.id) ||
72+
findChain(chainQuery.data, 1)
7573
: undefined);
7674

7775
// all tokens

0 commit comments

Comments
 (0)