Skip to content

Commit 4126563

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
1 parent d5d5939 commit 4126563

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

.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: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ type SelectTokenUIProps = {
4545
activeWalletInfo: ActiveWalletInfo | undefined;
4646
};
4747

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

@@ -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)