Skip to content

Commit e8af9c1

Browse files
committed
fix: add unsupported token screen to transaction widget
1 parent 45bb790 commit e8af9c1

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

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/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)