Skip to content

Commit 2fbf105

Browse files
[SDK] fix: Disable quote retries and show fiat values (#6210)
1 parent afcaa91 commit 2fbf105

File tree

5 files changed

+18
-62
lines changed

5 files changed

+18
-62
lines changed

.changeset/cool-pumpkins-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Dont retry on quote errors, show fiat value in every step

packages/thirdweb/src/react/core/hooks/pay/useBuyWithCryptoQuote.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ export type BuyWithCryptoQuoteQueryOptions = Omit<
1717
"queryFn" | "queryKey" | "enabled"
1818
>;
1919

20-
/**
21-
* @internal
22-
*/
23-
type BuyWithCryptoQuoteError = {
24-
status: string;
25-
code: string;
26-
statusCode: number;
27-
};
28-
2920
/**
3021
* 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.
3122
*
@@ -97,26 +88,6 @@ export function useBuyWithCryptoQuote(
9788
return getBuyWithCryptoQuote(params);
9889
},
9990
enabled: !!params,
100-
retry(failureCount, error) {
101-
if (failureCount > 3) {
102-
return false;
103-
}
104-
try {
105-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
106-
const serverError = (error as any).error as BuyWithCryptoQuoteError;
107-
108-
if (serverError.code === "MINIMUM_PURCHASE_AMOUNT") {
109-
return false;
110-
}
111-
112-
if (serverError.statusCode === 404 || serverError.statusCode >= 500) {
113-
return false;
114-
}
115-
} catch {
116-
return true;
117-
}
118-
119-
return true;
120-
},
91+
retry: false,
12192
});
12293
}

packages/thirdweb/src/react/core/hooks/pay/useBuyWithFiatQuote.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ export type BuyWithFiatQuoteQueryOptions = Omit<
1717
"queryFn" | "queryKey" | "enabled"
1818
>;
1919

20-
/**
21-
* @internal
22-
*/
23-
type BuyWithFiatQuoteError = {
24-
status: string;
25-
code: string;
26-
statusCode: number;
27-
};
28-
2920
/**
3021
* Hook to get a price quote for performing a "Buy with Fiat" transaction that allows users to buy a token with fiat currency.
3122
*
@@ -85,26 +76,6 @@ export function useBuyWithFiatQuote(
8576
return getBuyWithFiatQuote(params);
8677
},
8778
enabled: !!params,
88-
retry(failureCount, error) {
89-
if (failureCount > 3) {
90-
return false;
91-
}
92-
try {
93-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
94-
const serverError = (error as any).error as BuyWithFiatQuoteError;
95-
96-
if (serverError.code === "MINIMUM_PURCHASE_AMOUNT") {
97-
return false;
98-
}
99-
100-
if (serverError.statusCode === 404 || serverError.statusCode >= 500) {
101-
return false;
102-
}
103-
} catch {
104-
return true;
105-
}
106-
107-
return true;
108-
},
79+
retry: false,
10980
});
11081
}

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
useToTokenSelectionStates,
5353
} from "./main/useUISelectionStates.js";
5454
import { BuyTokenInput } from "./swap/BuyTokenInput.js";
55+
import { FiatValue } from "./swap/FiatValue.js";
5556
import { PaymentSelectionScreen } from "./swap/PaymentSelectionScreen.js";
5657
import { SwapFlow } from "./swap/SwapFlow.js";
5758
import { SwapScreenContent } from "./swap/SwapScreenContent.js";
@@ -669,7 +670,7 @@ function SelectedTokenInfo(props: {
669670
justifyContent: "space-between",
670671
}}
671672
>
672-
<Container flex="row" gap="xs" center="y">
673+
<Container flex="row" gap="xxs" center="y">
673674
<Input
674675
variant="outline"
675676
pattern="^[0-9]*[.,]?[0-9]*$"
@@ -738,6 +739,14 @@ function SelectedTokenInfo(props: {
738739
token={props.selectedToken}
739740
/>
740741
</Container>
742+
743+
<FiatValue
744+
chain={props.selectedChain}
745+
client={props.client}
746+
tokenAmount={props.tokenAmount}
747+
token={props.selectedToken}
748+
size="sm"
749+
/>
741750
</Container>
742751

743752
<ChainName

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export function FiatSteps(props: {
233233

234234
const toTokenInfo = partialSuccessToTokenInfo || (
235235
<Text color="primaryText" size="sm">
236-
{formatNumber(Number(toTokenAmount), 6)}
236+
{formatNumber(Number(toTokenAmount), 6)}{" "}
237237
<TokenSymbol token={toToken} chain={toChain} size="sm" inline />
238238
</Text>
239239
);

0 commit comments

Comments
 (0)