Skip to content

Commit e688555

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 e688555

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
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: 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)