Skip to content

Commit e7bf498

Browse files
authored
Add testMode to buyWithCrypto pay options (#4435)
1 parent 498d543 commit e7bf498

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

.changeset/olive-steaks-vanish.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+
Add testMode to buyWithCrypto pay options

packages/thirdweb/src/react/core/hooks/connection/ConnectButtonProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export type PayUIOptions = Prettify<
6464
buyWithCrypto?:
6565
| false
6666
| {
67+
testMode?: boolean;
6768
prefillSource?: {
6869
chain: Chain;
6970
token?: TokenInfo;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ export type BuyScreenProps = {
9797
* @internal
9898
*/
9999
export default function BuyScreen(props: BuyScreenProps) {
100-
const supportedDestinationsQuery = useBuySupportedDestinations(props.client);
100+
const isTestMode = props.payOptions.buyWithCrypto
101+
? props.payOptions.buyWithCrypto.testMode
102+
: undefined;
103+
const supportedDestinationsQuery = useBuySupportedDestinations(
104+
props.client,
105+
isTestMode,
106+
);
101107

102108
if (!supportedDestinationsQuery.data) {
103109
return <LoadingScreen />;

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export function useToTokenSelectionStates(options: {
5050
// use active chain if its supported as destination
5151
supportedDestinations.find((x) => x.chain.id === activeChain?.id)
5252
?.chain ||
53-
// default to polygon
53+
// default to the first chain in supportedDestinations, or polygon if nothing is found at all
54+
supportedDestinations[0]?.chain ||
5455
polygon,
5556
);
5657

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ export type SupportedChainAndTokens = Array<{
3636

3737
export async function fetchBuySupportedDestinations(
3838
client: ThirdwebClient,
39+
isTestMode?: boolean,
3940
): Promise<SupportedChainAndTokens> {
4041
return withCache(
4142
async () => {
4243
const fetchWithHeaders = getClientFetch(client);
43-
const res = await fetchWithHeaders(getPaySupportedDestinations());
44+
const res = await fetchWithHeaders(
45+
`${getPaySupportedDestinations()}?isTestMode=${isTestMode}`,
46+
);
4447
const data = (await res.json()) as Response;
4548
return data.result.map((item) => ({
4649
chain: defineChain({
@@ -59,11 +62,14 @@ export async function fetchBuySupportedDestinations(
5962
/**
6063
* @internal
6164
*/
62-
export function useBuySupportedDestinations(client: ThirdwebClient) {
65+
export function useBuySupportedDestinations(
66+
client: ThirdwebClient,
67+
isTestMode?: boolean,
68+
) {
6369
return useQuery({
6470
queryKey: ["destination-tokens", client],
6571
queryFn: async () => {
66-
return fetchBuySupportedDestinations(client);
72+
return fetchBuySupportedDestinations(client, isTestMode);
6773
},
6874
});
6975
}

0 commit comments

Comments
 (0)