From 2fbf105d156ee551eec29e545fa08c43fd649051 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Mon, 10 Feb 2025 19:41:42 -0800 Subject: [PATCH] [SDK] fix: Disable quote retries and show fiat values (#6210) --- .changeset/cool-pumpkins-punch.md | 5 +++ .../core/hooks/pay/useBuyWithCryptoQuote.ts | 31 +------------------ .../core/hooks/pay/useBuyWithFiatQuote.ts | 31 +------------------ .../ConnectWallet/screens/Buy/BuyScreen.tsx | 11 ++++++- .../screens/Buy/fiat/FiatSteps.tsx | 2 +- 5 files changed, 18 insertions(+), 62 deletions(-) create mode 100644 .changeset/cool-pumpkins-punch.md diff --git a/.changeset/cool-pumpkins-punch.md b/.changeset/cool-pumpkins-punch.md new file mode 100644 index 00000000000..1fd052104d3 --- /dev/null +++ b/.changeset/cool-pumpkins-punch.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Dont retry on quote errors, show fiat value in every step diff --git a/packages/thirdweb/src/react/core/hooks/pay/useBuyWithCryptoQuote.ts b/packages/thirdweb/src/react/core/hooks/pay/useBuyWithCryptoQuote.ts index d97f3d14da5..667300ed0f3 100644 --- a/packages/thirdweb/src/react/core/hooks/pay/useBuyWithCryptoQuote.ts +++ b/packages/thirdweb/src/react/core/hooks/pay/useBuyWithCryptoQuote.ts @@ -17,15 +17,6 @@ export type BuyWithCryptoQuoteQueryOptions = Omit< "queryFn" | "queryKey" | "enabled" >; -/** - * @internal - */ -type BuyWithCryptoQuoteError = { - status: string; - code: string; - statusCode: number; -}; - /** * Hook to get a price quote for performing a "Buy with crypto" transaction that allows users to buy a token with another token - aka a swap. * @@ -97,26 +88,6 @@ export function useBuyWithCryptoQuote( return getBuyWithCryptoQuote(params); }, enabled: !!params, - retry(failureCount, error) { - if (failureCount > 3) { - return false; - } - try { - // biome-ignore lint/suspicious/noExplicitAny: - const serverError = (error as any).error as BuyWithCryptoQuoteError; - - if (serverError.code === "MINIMUM_PURCHASE_AMOUNT") { - return false; - } - - if (serverError.statusCode === 404 || serverError.statusCode >= 500) { - return false; - } - } catch { - return true; - } - - return true; - }, + retry: false, }); } diff --git a/packages/thirdweb/src/react/core/hooks/pay/useBuyWithFiatQuote.ts b/packages/thirdweb/src/react/core/hooks/pay/useBuyWithFiatQuote.ts index 450cd6f8b5f..c645d974a46 100644 --- a/packages/thirdweb/src/react/core/hooks/pay/useBuyWithFiatQuote.ts +++ b/packages/thirdweb/src/react/core/hooks/pay/useBuyWithFiatQuote.ts @@ -17,15 +17,6 @@ export type BuyWithFiatQuoteQueryOptions = Omit< "queryFn" | "queryKey" | "enabled" >; -/** - * @internal - */ -type BuyWithFiatQuoteError = { - status: string; - code: string; - statusCode: number; -}; - /** * Hook to get a price quote for performing a "Buy with Fiat" transaction that allows users to buy a token with fiat currency. * @@ -85,26 +76,6 @@ export function useBuyWithFiatQuote( return getBuyWithFiatQuote(params); }, enabled: !!params, - retry(failureCount, error) { - if (failureCount > 3) { - return false; - } - try { - // biome-ignore lint/suspicious/noExplicitAny: - const serverError = (error as any).error as BuyWithFiatQuoteError; - - if (serverError.code === "MINIMUM_PURCHASE_AMOUNT") { - return false; - } - - if (serverError.statusCode === 404 || serverError.statusCode >= 500) { - return false; - } - } catch { - return true; - } - - return true; - }, + retry: false, }); } diff --git a/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx b/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx index c7189a08378..f5d81dd4064 100644 --- a/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +++ b/packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx @@ -52,6 +52,7 @@ import { useToTokenSelectionStates, } from "./main/useUISelectionStates.js"; import { BuyTokenInput } from "./swap/BuyTokenInput.js"; +import { FiatValue } from "./swap/FiatValue.js"; import { PaymentSelectionScreen } from "./swap/PaymentSelectionScreen.js"; import { SwapFlow } from "./swap/SwapFlow.js"; import { SwapScreenContent } from "./swap/SwapScreenContent.js"; @@ -669,7 +670,7 @@ function SelectedTokenInfo(props: { justifyContent: "space-between", }} > - + + + - {formatNumber(Number(toTokenAmount), 6)} + {formatNumber(Number(toTokenAmount), 6)}{" "} );