Skip to content

Commit 224e2af

Browse files
committed
refactor: make token name and symbol optional
1 parent c0429e1 commit 224e2af

File tree

4 files changed

+12
-134
lines changed

4 files changed

+12
-134
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export type PayUIOptions = Prettify<
7878
testMode?: boolean;
7979
prefillSource?: {
8080
chain: Chain;
81-
token?: TokenInfo;
81+
token?: Partial<TokenInfo> & { address: string };
8282
allowEdits?: {
8383
token: boolean;
8484
chain: boolean;
@@ -158,7 +158,7 @@ export type FundWalletOptions = {
158158
*/
159159
prefillBuy?: {
160160
chain: Chain;
161-
token?: TokenInfo;
161+
token?: Partial<TokenInfo> & { address: string };
162162
amount?: string;
163163
allowEdits?: {
164164
amount: boolean;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import type {
2424
} from "../../../../../core/hooks/connection/ConnectButtonProps.js";
2525
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
2626
import { invalidateWalletBalance } from "../../../../../core/providers/invalidateWalletBalance.js";
27-
import type { SupportedTokens } from "../../../../../core/utils/defaultTokens.js";
27+
import type {
28+
SupportedTokens,
29+
TokenInfo,
30+
} from "../../../../../core/utils/defaultTokens.js";
2831
import { ErrorState } from "../../../../wallets/shared/ErrorState.js";
2932
import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js";
3033
import type { PayEmbedConnectOptions } from "../../../PayEmbed.js";
@@ -539,7 +542,7 @@ function BuyScreenContent(props: BuyScreenContentProps) {
539542
toChain={toChain}
540543
toToken={toToken}
541544
fromChain={fromChain}
542-
fromToken={fromToken}
545+
fromToken={fromToken as TokenInfo}
543546
showFromTokenSelector={() => {
544547
setScreen({
545548
id: "select-from-token",

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
PayUIOptions,
77
} from "../../../../../../core/hooks/connection/ConnectButtonProps.js";
88
import { useActiveWalletChain } from "../../../../../../core/hooks/wallets/useActiveWalletChain.js";
9+
import type { TokenInfo } from "../../../../../../core/utils/defaultTokens.js";
910
import { useDebouncedValue } from "../../../../hooks/useDebouncedValue.js";
1011
import { type ERC20OrNativeToken, NATIVE_TOKEN } from "../../nativeToken.js";
1112
import {
@@ -49,7 +50,7 @@ export function useToTokenSelectionStates(options: {
4950
setToChain(prefillBuy.chain);
5051
}
5152
if (prefillBuy?.token) {
52-
setToToken(prefillBuy.token);
53+
setToToken(prefillBuy.token as TokenInfo);
5354
}
5455
}, [prefillBuy?.amount, prefillBuy?.chain, prefillBuy?.token]);
5556

@@ -68,7 +69,7 @@ export function useToTokenSelectionStates(options: {
6869
);
6970

7071
const [toToken, setToToken] = useState<ERC20OrNativeToken>(
71-
prefillBuy?.token ||
72+
(prefillBuy?.token as TokenInfo) ||
7273
(payOptions.mode === "direct_payment" && payOptions.paymentInfo.token) ||
7374
NATIVE_TOKEN,
7475
);

packages/thirdweb/src/react/web/ui/PayEmbed.tsx

Lines changed: 2 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useQuery } from "@tanstack/react-query";
4-
import { useEffect, useState } from "react";
4+
import {} from "react";
55
import type { Token } from "../../../bridge/index.js";
66
import type { Chain } from "../../../chains/types.js";
77
import type { ThirdwebClient } from "../../../client/client.js";
@@ -14,28 +14,19 @@ import type { AppMetadata } from "../../../wallets/types.js";
1414
import type { WalletId } from "../../../wallets/wallet-types.js";
1515
import { CustomThemeProvider } from "../../core/design-system/CustomThemeProvider.js";
1616
import type { Theme } from "../../core/design-system/index.js";
17-
import {
18-
type SiweAuthOptions,
19-
useSiweAuth,
20-
} from "../../core/hooks/auth/useSiweAuth.js";
17+
import type { SiweAuthOptions } from "../../core/hooks/auth/useSiweAuth.js";
2118
import type {
2219
ConnectButton_connectModalOptions,
2320
PayUIOptions,
2421
} from "../../core/hooks/connection/ConnectButtonProps.js";
25-
import { useActiveAccount } from "../../core/hooks/wallets/useActiveAccount.js";
26-
import { useActiveWallet } from "../../core/hooks/wallets/useActiveWallet.js";
27-
import { useConnectionManager } from "../../core/providers/connection-manager.js";
2822
import type { SupportedTokens } from "../../core/utils/defaultTokens.js";
29-
import { AutoConnect } from "../../web/ui/AutoConnect/AutoConnect.js";
3023
import {
3124
BridgeOrchestrator,
3225
type UIOptions,
3326
} from "./Bridge/BridgeOrchestrator.js";
3427
import { UnsupportedTokenScreen } from "./Bridge/UnsupportedTokenScreen.js";
3528
import { EmbedContainer } from "./ConnectWallet/Modal/ConnectEmbed.js";
3629
import { useConnectLocale } from "./ConnectWallet/locale/getConnectLocale.js";
37-
import BuyScreen from "./ConnectWallet/screens/Buy/BuyScreen.js";
38-
import { ExecutingTxScreen } from "./TransactionButton/ExecutingScreen.js";
3930
import { DynamicHeight } from "./components/DynamicHeight.js";
4031
import { Spinner } from "./components/Spinner.js";
4132
import type { LocaleId } from "./types.js";
@@ -493,123 +484,6 @@ export function PayEmbed(props: PayEmbedProps) {
493484
);
494485
}
495486

496-
export function LegacyPayEmbed(props: PayEmbedProps) {
497-
const localeQuery = useConnectLocale(props.locale || "en_US");
498-
const [screen, setScreen] = useState<"buy" | "execute-tx">("buy");
499-
const theme = props.theme || "dark";
500-
const connectionManager = useConnectionManager();
501-
const activeAccount = useActiveAccount();
502-
const activeWallet = useActiveWallet();
503-
const siweAuth = useSiweAuth(
504-
activeWallet,
505-
activeAccount,
506-
props.connectOptions?.auth,
507-
);
508-
509-
// Add props.chain and props.chains to defined chains store
510-
useEffect(() => {
511-
if (props.connectOptions?.chain) {
512-
connectionManager.defineChains([props.connectOptions?.chain]);
513-
}
514-
}, [props.connectOptions?.chain, connectionManager]);
515-
516-
useEffect(() => {
517-
if (props.connectOptions?.chains) {
518-
connectionManager.defineChains(props.connectOptions?.chains);
519-
}
520-
}, [props.connectOptions?.chains, connectionManager]);
521-
522-
useEffect(() => {
523-
if (props.activeWallet) {
524-
connectionManager.setActiveWallet(props.activeWallet);
525-
}
526-
}, [props.activeWallet, connectionManager]);
527-
528-
let content = null;
529-
const metadata =
530-
props.payOptions && "metadata" in props.payOptions
531-
? props.payOptions.metadata
532-
: null;
533-
534-
if (!localeQuery.data) {
535-
content = (
536-
<div
537-
style={{
538-
minHeight: "350px",
539-
display: "flex",
540-
justifyContent: "center",
541-
alignItems: "center",
542-
}}
543-
>
544-
<Spinner size="xl" color="secondaryText" />
545-
</div>
546-
);
547-
} else {
548-
content = (
549-
<>
550-
<AutoConnect client={props.client} siweAuth={siweAuth} />
551-
{screen === "buy" && (
552-
<BuyScreen
553-
title={metadata?.name || "Buy"}
554-
isEmbed={true}
555-
supportedTokens={props.supportedTokens}
556-
theme={theme}
557-
client={props.client}
558-
connectLocale={localeQuery.data}
559-
hiddenWallets={props.hiddenWallets}
560-
paymentLinkId={props.paymentLinkId}
561-
payOptions={
562-
props.payOptions || {
563-
mode: "fund_wallet",
564-
}
565-
}
566-
onDone={() => {
567-
if (props.payOptions?.mode === "transaction") {
568-
setScreen("execute-tx");
569-
}
570-
}}
571-
connectOptions={props.connectOptions}
572-
onBack={undefined}
573-
/>
574-
)}
575-
576-
{screen === "execute-tx" &&
577-
props.payOptions?.mode === "transaction" &&
578-
props.payOptions.transaction && (
579-
<ExecutingTxScreen
580-
tx={props.payOptions.transaction}
581-
closeModal={() => {
582-
setScreen("buy");
583-
}}
584-
onBack={() => {
585-
setScreen("buy");
586-
}}
587-
onTxSent={(data) => {
588-
props.payOptions?.onPurchaseSuccess?.({
589-
type: "transaction",
590-
chainId: data.chain.id,
591-
transactionHash: data.transactionHash,
592-
});
593-
}}
594-
/>
595-
)}
596-
</>
597-
);
598-
}
599-
600-
return (
601-
<CustomThemeProvider theme={theme}>
602-
<EmbedContainer
603-
modalSize="compact"
604-
style={props.style}
605-
className={props.className}
606-
>
607-
<DynamicHeight>{content}</DynamicHeight>
608-
</EmbedContainer>
609-
</CustomThemeProvider>
610-
);
611-
}
612-
613487
/**
614488
* Connection options for the `PayEmbed` component
615489
*

0 commit comments

Comments
 (0)