Skip to content

Commit bd3d645

Browse files
authored
[SDK] Fix: Adds BuyWidget fallback when native isn't supported (#7601)
1 parent 5fedc2c commit bd3d645

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

apps/playground-web/src/hooks/useTokensData.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import { useQuery } from "@tanstack/react-query";
44
import type { TokenMetadata } from "@/lib/types";
55

66
async function fetchTokensFromApi(chainId?: number) {
7-
const domain = process.env.NEXT_PUBLIC_BRIDGE_URL;
8-
const url = new URL(`https://${domain}/v1/tokens`);
7+
const domain = process.env.NEXT_PUBLIC_BRIDGE_URL || "bridge.thirdweb.com";
8+
const url = new URL(
9+
`${domain.includes("localhost") ? "http" : "https"}://${domain}/v1/tokens`,
10+
);
911

1012
if (chainId) {
1113
url.searchParams.append("chainId", String(chainId));

packages/thirdweb/src/react/web/ui/Bridge/BuyWidget.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,18 @@ export function BuyWidget(props: BuyWidgetProps) {
312312
props.client,
313313
NATIVE_TOKEN_ADDRESS,
314314
props.chain.id,
315-
);
315+
).catch((err) => {
316+
err.message.includes("not supported")
317+
? undefined
318+
: Promise.reject(err);
319+
});
320+
if (!ETH) {
321+
return {
322+
chain: props.chain,
323+
tokenAddress: props.tokenAddress || NATIVE_TOKEN_ADDRESS,
324+
type: "unsupported_token",
325+
};
326+
}
316327
return {
317328
data: {
318329
destinationToken: ETH,

0 commit comments

Comments
 (0)