File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " thirdweb " : patch
3+ ---
4+
5+ Handle wallet chain mismatch on post onramp flow
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments