Skip to content

Commit

Permalink
[SDK] fix: Disable quote retries and show fiat values (#6210)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges authored Feb 11, 2025
1 parent afcaa91 commit 2fbf105
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-pumpkins-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Dont retry on quote errors, show fiat value in every step
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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: <explanation>
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,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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: <explanation>
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,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -669,7 +670,7 @@ function SelectedTokenInfo(props: {
justifyContent: "space-between",
}}
>
<Container flex="row" gap="xs" center="y">
<Container flex="row" gap="xxs" center="y">
<Input
variant="outline"
pattern="^[0-9]*[.,]?[0-9]*$"
Expand Down Expand Up @@ -738,6 +739,14 @@ function SelectedTokenInfo(props: {
token={props.selectedToken}
/>
</Container>

<FiatValue
chain={props.selectedChain}
client={props.client}
tokenAmount={props.tokenAmount}
token={props.selectedToken}
size="sm"
/>
</Container>

<ChainName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export function FiatSteps(props: {

const toTokenInfo = partialSuccessToTokenInfo || (
<Text color="primaryText" size="sm">
{formatNumber(Number(toTokenAmount), 6)}
{formatNumber(Number(toTokenAmount), 6)}{" "}
<TokenSymbol token={toToken} chain={toChain} size="sm" inline />
</Text>
);
Expand Down

0 comments on commit 2fbf105

Please sign in to comment.