Skip to content

Commit 07aad25

Browse files
[SDK] fix: Handle wallet chain mismatch on post onramp flow
1 parent d3f7884 commit 07aad25

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.changeset/quiet-melons-jump.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+
Handle wallet chain mismatch on post onramp flow

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ function useSwapMutation(props: {
634634
amount: string;
635635
}) => {
636636
const { fromToken, toToken, amount } = input;
637+
const wallet = props.payer.wallet;
638+
637639
// always get a fresh quote before executing
638640
const quote = await getBuyWithCryptoQuote({
639641
fromChainId: fromToken.chainId,
@@ -646,6 +648,11 @@ function useSwapMutation(props: {
646648
client: props.client,
647649
});
648650

651+
// in case the wallet is not on the same chain as the fromToken, switch to it
652+
if (wallet.getChain()?.id !== fromToken.chainId) {
653+
await wallet.switchChain(getCachedChain(fromToken.chainId));
654+
}
655+
649656
const canBatch = props.payer.account.sendBatchTransaction;
650657
const tokenContract = getContract({
651658
client: props.client,

0 commit comments

Comments
 (0)