Skip to content

Commit 277c2e2

Browse files
authored
Feature: Add fallback when we cant fetch the token in new widgets (#7452)
1 parent 0ac5e59 commit 277c2e2

File tree

8 files changed

+47
-7
lines changed

8 files changed

+47
-7
lines changed

.changeset/crazy-bushes-stick.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+
Adds "Unsupported Token" fallback screen to TransactionWidget

apps/dashboard/src/app/pay/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default async function PayPage({
5757
<PayPageWidget
5858
amount={paymentLink.amount ? BigInt(paymentLink.amount) : undefined}
5959
chainId={Number(paymentLink.destinationToken.chainId)}
60-
clientId={paymentLink.clientId}
60+
clientId={undefined} // Payment links don't need to use the same client ID to be executed
6161
image={paymentLink.imageUrl}
6262
name={paymentLink.title}
6363
paymentLinkId={id}

apps/dashboard/src/app/pay/components/client/PayPageWidget.client.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function PayPageWidget({
2828
name?: string;
2929
image?: string;
3030
redirectUri?: string;
31-
clientId: string;
31+
clientId: string | undefined;
3232
theme?: "light" | "dark";
3333
purchaseData: Record<string, unknown> | undefined;
3434
}) {

apps/playground-web/src/app/connect/pay/commerce/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function BuyMerch() {
4242
client={THIRDWEB_CLIENT}
4343
theme="light"
4444
chain={base}
45-
amount={toUnits("2", 6)}
45+
amount={"2"}
4646
tokenAddress="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
4747
seller="0xEb0effdFB4dC5b3d5d3aC6ce29F3ED213E95d675"
4848
feePayer="seller"

apps/playground-web/src/app/connect/pay/transactions/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function BuyOnchainAsset() {
5151
5252
return (
5353
<TransactionWidget
54+
amount={"0.001"}
5455
client={THIRDWEB_CLIENT}
5556
theme={theme === "light" ? "light" : "dark"}
5657
transaction={claimTo({

apps/playground-web/src/components/pay/transaction-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function PayTransactionPreview() {
4141

4242
return (
4343
<TransactionWidget
44-
amount={"0.1"}
44+
amount={"0.001"}
4545
client={THIRDWEB_CLIENT}
4646
description={nft?.metadata?.description}
4747
image={nft?.metadata?.image}

packages/thirdweb/src/bridge/Webhook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const onrampWebhookSchema = z.discriminatedUnion("version", [
6969
onramp: z.string(),
7070
paymentLinkId: z.optional(z.string()),
7171
purchaseData: z.unknown(),
72-
receiver: z.optional(addressSchema),
72+
receiver: addressSchema,
7373
sender: z.optional(addressSchema),
7474
status: z.enum(["PENDING", "COMPLETED", "FAILED"]),
7575
token: tokenSchema,

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
1919
import type { AppMetadata } from "../../../../wallets/types.js";
2020
import type { WalletId } from "../../../../wallets/wallet-types.js";
2121
import { CustomThemeProvider } from "../../../core/design-system/CustomThemeProvider.js";
22-
import type { Theme } from "../../../core/design-system/index.js";
22+
import { iconSize, type Theme } from "../../../core/design-system/index.js";
2323
import type { SiweAuthOptions } from "../../../core/hooks/auth/useSiweAuth.js";
2424
import type { ConnectButton_connectModalOptions } from "../../../core/hooks/connection/ConnectButtonProps.js";
2525
import type { SupportedTokens } from "../../../core/utils/defaultTokens.js";
26+
import { AccentFailIcon } from "../ConnectWallet/icons/AccentFailIcon.js";
2627
import { useConnectLocale } from "../ConnectWallet/locale/getConnectLocale.js";
2728
import { EmbedContainer } from "../ConnectWallet/Modal/ConnectEmbed.js";
2829
import { DynamicHeight } from "../components/DynamicHeight.js";
30+
import { Spacer } from "../components/Spacer.js";
2931
import { Spinner } from "../components/Spinner.js";
32+
import { Text } from "../components/text.js";
3033
import type { LocaleId } from "../types.js";
3134
import { BridgeOrchestrator, type UIOptions } from "./BridgeOrchestrator.js";
3235
import { UnsupportedTokenScreen } from "./UnsupportedTokenScreen.js";
@@ -297,7 +300,19 @@ export function TransactionWidget(props: TransactionWidgetProps) {
297300
props.client,
298301
checksumAddress(tokenAddress),
299302
props.transaction.chain.id,
300-
);
303+
).catch((e) => {
304+
if (e instanceof Error && e.message.includes("not supported")) {
305+
return null;
306+
}
307+
throw e;
308+
});
309+
if (!token) {
310+
return {
311+
chain: props.transaction.chain,
312+
tokenAddress: checksumAddress(tokenAddress),
313+
type: "unsupported_token",
314+
};
315+
}
301316

302317
erc20Value = {
303318
amountWei: toUnits(props.amount, token.decimals),
@@ -324,6 +339,7 @@ export function TransactionWidget(props: TransactionWidgetProps) {
324339
};
325340
},
326341
queryKey: ["bridgeData", stringify(props)],
342+
retry: 1,
327343
});
328344

329345
let content = null;
@@ -340,6 +356,24 @@ export function TransactionWidget(props: TransactionWidgetProps) {
340356
<Spinner color="secondaryText" size="xl" />
341357
</div>
342358
);
359+
} else if (bridgeDataQuery.error) {
360+
content = (
361+
<div
362+
style={{
363+
alignItems: "center",
364+
display: "flex",
365+
flexDirection: "column",
366+
justifyContent: "center",
367+
minHeight: "350px",
368+
}}
369+
>
370+
<AccentFailIcon size={iconSize["3xl"]} />
371+
<Spacer y="lg" />
372+
<Text color="secondaryText" size="md">
373+
{bridgeDataQuery.error.message}
374+
</Text>
375+
</div>
376+
);
343377
} else if (bridgeDataQuery.data?.type === "unsupported_token") {
344378
// Show unsupported token screen
345379
content = (

0 commit comments

Comments
 (0)