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,