From 286cd639bdeed0fd5cde41f78e81fbb828944a2b Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Sat, 22 Mar 2025 20:05:07 +1300 Subject: [PATCH] [SDK] fix: Fetch fresh quotes before post onramp step in PayEmbed --- .changeset/silly-times-shop.md | 5 ++ .../src/components/pay/embed.tsx | 10 ++++ .../screens/Buy/fiat/OnRampScreen.tsx | 55 ++++++++++--------- 3 files changed, 43 insertions(+), 27 deletions(-) create mode 100644 .changeset/silly-times-shop.md diff --git a/.changeset/silly-times-shop.md b/.changeset/silly-times-shop.md new file mode 100644 index 00000000000..a8c69a2a8f8 --- /dev/null +++ b/.changeset/silly-times-shop.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Always fetch fresh quotes before post onramp step in PayEmbed diff --git a/apps/playground-web/src/components/pay/embed.tsx b/apps/playground-web/src/components/pay/embed.tsx index 18bba36327a..ed85fe3d6b5 100644 --- a/apps/playground-web/src/components/pay/embed.tsx +++ b/apps/playground-web/src/components/pay/embed.tsx @@ -18,6 +18,10 @@ export function StyledPayEmbedPreview() {
0 && currentStepIndex < onRampSteps.length && - swapQuoteQuery.data && !swapTxHash ) { handleContinue(); @@ -475,7 +461,6 @@ function useOnRampScreenState(props: { }, [ props.isAutoMode, currentStepIndex, - swapQuoteQuery.data, swapTxHash, onRampSteps.length, handleContinue, @@ -643,8 +628,24 @@ function useSwapMutation(props: { }) { const queryClient = useQueryClient(); return useMutation({ - mutationFn: async (input: { quote: BuyWithCryptoQuote }) => { - const { quote } = input; + mutationFn: async (input: { + fromToken: PayTokenInfo; + toToken: PayTokenInfo; + amount: string; + }) => { + const { fromToken, toToken, amount } = input; + // always get a fresh quote before executing + const quote = await getBuyWithCryptoQuote({ + fromChainId: fromToken.chainId, + fromTokenAddress: fromToken.tokenAddress, + toAmount: amount, + toChainId: toToken.chainId, + toTokenAddress: toToken.tokenAddress, + fromAddress: props.payer.account.address, + toAddress: props.payer.account.address, + client: props.client, + }); + const canBatch = props.payer.account.sendBatchTransaction; const tokenContract = getContract({ client: props.client,