import type { JSX } from "react"; import type { Chain } from "../../../../chains/types.js"; import type { ThirdwebClient } from "../../../../client/client.js"; import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js"; import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js"; import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js"; import type { PurchaseData } from "../../../../pay/types.js"; import type { FiatProvider } from "../../../../pay/utils/commonTypes.js"; import type { AssetTabs } from "../../../../react/web/ui/ConnectWallet/screens/ViewAssets.js"; import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js"; import type { Hex } from "../../../../utils/encoding/hex.js"; import type { Prettify } from "../../../../utils/type-utils.js"; import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js"; import type { SmartWalletOptions } from "../../../../wallets/smart/types.js"; import type { AppMetadata } from "../../../../wallets/types.js"; import type { WalletId } from "../../../../wallets/wallet-types.js"; import type { NetworkSelectorProps } from "../../../web/ui/ConnectWallet/NetworkSelector.js"; import type { CurrencyMeta } from "../../../web/ui/ConnectWallet/screens/Buy/fiat/currencies.js"; import type { WelcomeScreen } from "../../../web/ui/ConnectWallet/screens/types.js"; import type { LocaleId } from "../../../web/ui/types.js"; import type { Theme } from "../../design-system/index.js"; import type { SupportedNFTs, SupportedTokens, TokenInfo, } from "../../utils/defaultTokens.js"; import type { SiweAuthOptions } from "../auth/useSiweAuth.js"; import type { OnConnectCallback } from "./types.js"; export type PaymentInfo = Prettify< { /** * The chain to receive the payment on. */ chain: Chain; /** * The address of the seller wallet to receive the payment on. */ sellerAddress: string; /** * Optional ERC20 token to receive the payment on. * If not provided, the native token will be used. */ token?: Partial & { address: string }; /** * For direct transfers, specify who will pay the transfer fee. Can be "sender" or "receiver". */ feePayer?: "sender" | "receiver"; } & ( | { /** * The amount of tokens to receive in ETH or tokens. * ex: 0.1 ETH or 100 USDC */ amount: string; } | { /** * The amount of tokens to receive in wei. * ex: 1000000000000000000 wei */ amountWei: bigint; } ) >; export type PayUIOptions = Prettify< { /** * Configure options for buying tokens using other token ( aka Swap ) * * By default, the "Crypto" option is enabled. You can disable it by setting `buyWithCrypto` to `false` * * You can prefill the source token and chain using `prefillSource` * You can also disable the edits for the prefilled values by setting `prefillSource.allowEdits` - By default all are editable * * For example, if you want to allow selecting chain and but disable selecting token, you can set `allowEdits` to `{ token: false, chain: true }` */ buyWithCrypto?: | false | { /** * @deprecated */ testMode?: boolean; prefillSource?: { chain: Chain; token?: Partial & { address: string }; allowEdits?: { token: boolean; chain: boolean; }; }; }; /** * By default "Credit card" option is enabled. you can disable it by setting `buyWithFiat` to `false` * * You can also enable the test mode for the on-ramp provider to test on-ramp without using real credit card. */ buyWithFiat?: | { /** * @deprecated */ testMode?: boolean; prefillSource?: { currency?: CurrencyMeta["shorthand"]; }; preferredProvider?: FiatProvider; supportedProviders?: FiatProvider[]; onrampChainId?: number; onrampTokenAddress?: string; } | false; /** * Extra details to store with the purchase. * * This details will be stored with the purchase and can be retrieved later via the status API or Webhook */ purchaseData?: PurchaseData; /** * Callback to be called when the user successfully completes the purchase. */ onPurchaseSuccess?: ( // TODO: remove this type from the callback entirely or adapt it from the new format info?: | { type: "crypto"; status: BuyWithCryptoStatus; } | { type: "fiat"; status: BuyWithFiatStatus; } | { type: "transaction"; chainId: number; transactionHash: Hex; }, ) => void; /** * Customize the display of the PayEmbed UI. */ metadata?: { name?: string; description?: string; image?: string; }; /** * Show the "Powered by Thirdweb" branding at the bottom of the PayEmbed UI. * * By default it is `true`. */ showThirdwebBranding?: boolean; } & (FundWalletOptions | DirectPaymentOptions | TransactionOptions) >; export type FundWalletOptions = { mode?: "fund_wallet"; /** * Prefill the Buy Token amount, chain and/or token. * You can also disable the edits for the prefilled values using `allowEdits` - By default all are editable * * For example, if you want to allow changing the amount, but disable changing the token and chain, * you can set `allowEdits` to `{ amount: true, token: false, chain: false }` * * If no `token` object is not specified, native token will be prefilled by default */ prefillBuy?: { chain: Chain; token?: Partial & { address: string }; amount?: string; allowEdits?: { amount: boolean; token: boolean; chain: boolean; }; presetOptions?: [number, number, number]; }; }; export type DirectPaymentOptions = { mode: "direct_payment"; /** * The payment information */ paymentInfo: PaymentInfo; }; export type TransactionOptions = { mode: "transaction"; /** * The transaction to be executed. */ transaction: PreparedTransaction; }; // Note: When adding props to ConnectButton_connectButtonOptions, // make sure to also add it in UseWalletDetailsModalOptions for useWalletDetailsModal hook /** * Options for configuring the `ConnectButton`'s Connect Button * @connectWallet */ export type ConnectButton_connectButtonOptions = { /** * Set a custom label for the button. The default is `"Connect"` * @example * ```tsx * * ``` */ label?: React.ReactNode; /** * CSS class to apply to the button element * * For some CSS properties, you may need to use the `!important` to override the default styles * * ```tsx * * ``` */ className?: string; /** * CSS styles to apply to the connectButton element * @example * ```tsx * * ``` */ style?: React.CSSProperties; }; /** * Options for configuring the `ConnectButton`'s Details Modal * @connectWallet */ export type ConnectButton_detailsModalOptions = { /** * Show a "Request Testnet funds" link in `ConnectButton` Details Modal when user is connected to a testnet. * * By default it is `false`, If you want to show the "Request Testnet funds" link when user is connected to a testnet, set this prop to `true`. * Keep in mind that the link will only be shown if there are faucet links registered with the chain. * @example * ```tsx * * ``` */ showTestnetFaucet?: boolean; /** * customize the Network selector shown in the `ConnectButton` Details Modal */ networkSelector?: NetworkSelectorProps; /** * Hide the "Switch Wallet" button in the `ConnectButton` Details Modal. * * By default it is `false` * @example * ```tsx * * ``` */ hideSwitchWallet?: boolean; /** * Hide the "Disconnect Wallet" button in the `ConnectButton` Details Modal. * * By default it is `false` * @example * ```tsx * * ``` */ hideDisconnect?: boolean; /** * Render custom UI at the bottom of the `ConnectButton` Details Modal * @param props - props passed to the footer component which includes a function to close the modal * @example * ```tsx * ... * } * }} * /> * ``` */ footer?: (props: { close: () => void }) => JSX.Element; /** * Configure options for thirdweb Pay. * * thirdweb Pay allows users to buy tokens using crypto or fiat currency. */ payOptions?: Extract; /** * Render custom UI for the connected wallet name in the `ConnectButton` Details Modal, overriding ENS name or wallet address. */ connectedAccountName?: React.ReactNode; /** * Use custom avatar URL for the connected wallet image in the `ConnectButton` Details Modal, overriding ENS avatar or Blobbie icon. */ connectedAccountAvatarUrl?: string; /** * Hide the "Send Funds" button in the `ConnectButton` Details Modal. * * By default the "Send Funds" button is shown. */ hideSendFunds?: boolean; /** * Hide the "Receive Funds" button in the `ConnectButton` Details Modal. * * By default the "Receive Funds" button is shown. */ hideReceiveFunds?: boolean; /** * Hide the "Buy Funds" button in the `ConnectButton` Details Modal. * * By default the "Buy Funds" button is shown. */ hideBuyFunds?: boolean; /** * All wallet IDs included in this array will be hidden from wallet selection when connected. */ hiddenWallets?: WalletId[]; /** * When you click on "View Assets", by default the "Tokens" tab is shown first. * If you want to show the "NFTs" tab first, change the order of the asset tabs to: ["nft", "token"] * Note: If an empty array is passed, the [View Funds] button will be hidden */ assetTabs?: AssetTabs[]; /** * Show the token balance's value in fiat. * Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown. */ showBalanceInFiat?: SupportedFiatCurrency; /** * Configure options for managing the connected wallet. */ manageWallet?: { /** * Allow linking other profiles to the connected wallet. * * By default it is `true`. */ allowLinkingProfiles?: boolean; }; /** * @param screen The screen's name that was last shown when user closed the modal * @returns */ onClose?: (screen: string) => void; }; /** * Options for configuring the `ConnectButton`'s Details Button * @connectWallet */ export type ConnectButton_detailsButtonOptions = { /** * CSS class to apply to the details button element */ className?: string; /** * CSS styles to apply to the details button element */ style?: React.CSSProperties; /** * Render a custom button to display connected wallet details instead of the default one * * ```tsx * .... * } * }} * /> * ``` */ render?: () => JSX.Element; /** * Display the balance of a token instead of the native token in `ConnectButton` details button. * @example * ```tsx * * ``` */ displayBalanceToken?: Record; /** * Render custom UI for the connected wallet name in the `ConnectButton` details button, overriding ENS name or wallet address. */ connectedAccountName?: React.ReactNode; /** * Use custom avatar URL for the connected wallet image in the `ConnectButton` details button, overriding ENS avatar or Blobbie icon. */ connectedAccountAvatarUrl?: string; /** * Show the token balance's value in fiat. * Note: Not all tokens are resolvable to a fiat value. In that case, nothing will be shown. */ showBalanceInFiat?: SupportedFiatCurrency; }; /** * Options for configuring the `ConnectButton`'s Connect Modal * @connectWallet */ export type ConnectButton_connectModalOptions = { /** * Title to show in `ConnectButton`'s Modal * * The default is `"Connect"` */ title?: string; /** * Replace the default thirdweb icon next to Modal title with your own icon * * Set to empty string (`""`) to hide the icon * @example * ```tsx * * ``` */ titleIcon?: string; /** * Set the size of the connect modal on desktop - `"compact"` or `"wide"` * * Modal size is always `compact` on mobile * * By default it is `"wide"` for desktop. */ size?: "compact" | "wide"; /** * URL of the "terms of service" page * * If provided, Modal will show a Terms of Service message at the bottom with below link * @example * ```tsx * * ``` */ termsOfServiceUrl?: string; /** * URL of the "privacy policy" page * * If provided, Modal will show a Privacy Policy message at the bottom with below link * @example * ```tsx * * ``` */ privacyPolicyUrl?: string; /** * Require terms of service and privacy policy to be accepted before connecting an in-app wallet. * * By default it's `false` * @example * ```tsx * * ``` */ requireApproval?: boolean; /** * Customize the welcome screen. This prop is only applicable when modalSize prop is set to "wide". On "wide" Modal size, a welcome screen is shown on the right side of the modal. * * This screen can be customized in two ways * * #### 1. Customize Metadata and Image * ```tsx * const welcomeScreen = { * title: "your title", * subtitle: "your subtitle", * img: { * src: "https://your-image-url.png", * width: 300, * height: 50, * }, * } * * * ``` * * #### 2. Render Custom Component * * ```tsx * * }} * /> * ``` */ welcomeScreen?: WelcomeScreen; /** * By default `ConnectButton`'s Modal shows "Powered by Thirdweb" branding at the bottom of the Modal. * * If you want to hide the branding, set this prop to `false` * @example * ```tsx * *``` */ showThirdwebBranding?: boolean; }; /** * Props for the [`ConnectButton`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton) component * @connectWallet */ export type ConnectButtonProps = { /** * A client is the entry point to the thirdweb SDK. * It is required for all other actions. * You can create a client using the `createThirdwebClient` function. Refer to the [Creating a Client](https://portal.thirdweb.com/typescript/v5/client) documentation for more information. * * You must provide a `clientId` or `secretKey` in order to initialize a client. Pass `clientId` if you want for client-side usage and `secretKey` for server-side usage. * * ```tsx * import { createThirdwebClient } from "thirdweb"; * * const client = createThirdwebClient({ * clientId: "", * }) * ``` */ client: ThirdwebClient; /** * By default - ConnectButton UI uses the `en-US` locale for english language users. * * You can customize the language used in the ConnectButton UI by setting the `locale` prop. * * Refer to the [`LocaleId`](https://portal.thirdweb.com/references/typescript/v5/LocaleId) type for supported locales. */ locale?: LocaleId; /** * Array of supported wallets. If not provided, default wallets will be used. * @example * ```tsx * import { AutoConnect } from "thirdweb/react"; * import { createWallet, inAppWallet } from "thirdweb/wallets"; * * const wallets = [ * inAppWallet(), * createWallet("io.metamask"), * createWallet("com.coinbase.wallet"), * createWallet("me.rainbow"), * ]; * * function Example() { * return ( * * ) * } * ``` * * If no wallets are specified. The component will show All the EIP-6963 compliant installed wallet extensions, as well as below default wallets: * * ```tsx * const defaultWallets = [ * inAppWallet(), * createWallet("io.metamask"), * createWallet("com.coinbase.wallet"), * createWallet("me.rainbow"), * createWallet("io.zerion.wallet"), * ] * ``` * * The `ConnectButton` also shows a "All wallets" button at the end of wallet list which allows user to connect to any of the 500+ wallets */ wallets?: Wallet[]; /** * When the user has connected their wallet to your site, this configuration determines whether or not you want to automatically connect to the last connected wallet when user visits your site again in the future. * * By default it is set to `{ timeout: 15000 }` meaning that autoConnect is enabled and if the autoConnection does not succeed within 15 seconds, it will be cancelled. * * If you want to disable autoConnect, set this prop to `false`. * * If you want to customize the timeout, you can assign an object with a `timeout` key to this prop. * ```tsx * * ``` */ autoConnect?: | { timeout: number; } | boolean; /** * Metadata of the app that will be passed to connected wallet. Setting this is highly recommended. * * Some wallets display this information to the user when they connect to your app. * @example * ```ts * { * name: "My App", * url: "https://my-app.com", * description: "some description about your app", * logoUrl: "https://path/to/my-app/logo.svg", * }; * ``` */ appMetadata?: AppMetadata; /** * The [`Chain`](https://portal.thirdweb.com/references/typescript/v5/Chain) object of the blockchain you want the wallet to connect to * * If a `chain` is not specified, Wallet will be connected to whatever is the default set in the wallet. * * If a `chain` is specified, Wallet will be prompted to switch to given chain after connection if it is not already connected to it. * This ensures that the wallet is connected to the correct blockchain before interacting with your app. * * The `ConnectButton` also shows a "Switch Network" button until the wallet is connected to the specified chain. Clicking on the "Switch Network" button triggers the wallet to switch to the specified chain. * * You can create a `Chain` object using the [`defineChain`](https://portal.thirdweb.com/references/typescript/v5/defineChain) function. * At minimum, you need to pass the `id` of the blockchain to `defineChain` function to create a `Chain` object. * @example * ```tsx * import { polygon } from "thirdweb/chains"; * * function Example() { * return
* } * ``` */ chain?: Chain; /** * Array of chains that your app supports. * * This is only relevant if your app is a multi-chain app and works across multiple blockchains. * If your app only works on a single blockchain, you should only specify the `chain` prop. * * Given list of chains will used in various ways: * - They will be displayed in the network selector in the `ConnectButton`'s details modal post connection * - They will be sent to wallet at the time of connection if the wallet supports requesting multiple chains ( example: WalletConnect ) so that users can switch between the chains post connection easily * * ```tsx * * ``` * * You can create a `Chain` object using the [`defineChain`](https://portal.thirdweb.com/references/typescript/v5/defineChain) function. * At minimum, you need to pass the `id` of the blockchain to `defineChain` function to create a `Chain` object. * * ```tsx * import { defineChain } from "thirdweb/chains"; * * const polygon = defineChain({ * id: 137, * }); * ``` */ chains?: Chain[]; /** * Set the theme for the `ConnectButton` component. By default it is set to `"dark"` * * theme can be set to either `"dark"`, `"light"` or a custom theme object. * You can also import [`lightTheme`](https://portal.thirdweb.com/references/typescript/v5/lightTheme) * or [`darkTheme`](https://portal.thirdweb.com/references/typescript/v5/darkTheme) * functions from `thirdweb/react` to use the default themes as base and overrides parts of it. * @example * ```ts * import { lightTheme } from "thirdweb/react"; * * const customTheme = lightTheme({ * colors: { * modalBg: 'red' * } * }) * * function Example() { * return * } * ``` */ theme?: "dark" | "light" | Theme; /** * Configurations for the button element that is shown when wallet is not connected * @example * ```tsx * ; * ``` */ connectButton?: ConnectButton_connectButtonOptions; /** * Configuration for the "Switch Network" button. * This button is rendered when the wallet is connected, but it is not connected to the `chain` prop provided in `ConnectButton` component * @example * ```tsx * ; * ``` */ switchButton?: { /** * Set a custom label for the "Switch Network" button */ label?: string; /** * CSS styles to apply to the switch button element */ style?: React.CSSProperties; /** * CSS class to apply to the switch button element */ className?: string; }; signInButton?: { /** * Set a custom label for the sign-in button * @example * ```tsx * * ``` */ label?: string; /** * CSS styles to apply to the sign-in button element * @example * ```tsx * * ``` */ style?: React.CSSProperties; /** * CSS class to apply to the sign-in button element * @example * ```tsx * * ``` */ className?: string; }; /** * Configurations for the `ConnectButton`'s Modal that is shown for connecting a wallet * Refer to the [`ConnectButton_connectModalOptions`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton_connectModalOptions) type for more details * @example * ```tsx * */ connectModal?: ConnectButton_connectModalOptions; /** * Configurations for the Details Button that is shown when wallet is connected * Refer to the [`ConnectButton_detailsButtonOptions`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton_detailsButtonOptions) type for more details * @example * ```tsx * ; * ``` */ detailsButton?: ConnectButton_detailsButtonOptions; /** * Configurations for the Details Modal that is shown when wallet is connected and user clicks on the details button to see the connected wallet details * Refer to the [`ConnectButton_detailsModalOptions`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton_detailsModalOptions) type for more details */ detailsModal?: ConnectButton_detailsModalOptions; /** * Customize the tokens shown in the "Send Funds" screen in Details Modal for various networks. * * By default, The "Send Funds" screen shows a few popular tokens for default chains and the native token. For other chains it only shows the native token. * @example * * supportedTokens prop allows you to customize this list as shown below which shows "Dai Stablecoin" when users wallet is connected to the "Base" mainnet. * * ```tsx * import { ConnectButton } from 'thirdweb/react'; * * function Example() { * return ( * * ); * } * ``` */ supportedTokens?: SupportedTokens; /** * Customize the NFTs shown in the "View Funds" screen in Details Modal for various networks. * * By default, The "View Funds" screen shows a few popular tokens for default chains and the native token. For other chains it only shows the native token. * @example * * supportedTokens prop allows you to customize this list as shown below which shows "Pudgy Penguins" help when users wallet is connected to Ethereum mainnet. * * ```tsx * import { ConnectButton } from 'thirdweb/react'; * * function Example() { * return ( * * ); * } * ``` */ supportedNFTs?: SupportedNFTs; /** * Called on connection of a wallet - including auto connect. * The callback is called with the connected wallet as an argument. * * ```tsx * { * console.log("connected to", activeWallet) * console.log("all connected wallets", allConnectedWallets) * }} * /> * ``` */ onConnect?: OnConnectCallback; /** * Called when the user disconnects the wallet by clicking on the "Disconnect Wallet" button in the `ConnectButton`'s Details Modal. * * ```tsx * { * console.log("disconnected", wallet, account) * }} * /> * ``` */ onDisconnect?: (info: { wallet: Wallet; account: Account }) => void; /** * Configure options for WalletConnect * * By default WalletConnect uses the thirdweb's default project id. * Setting your own project id is recommended. * * You can create a project id by signing up on [walletconnect.com](https://walletconnect.com/) */ walletConnect?: { projectId?: string; }; /** * Enable Account abstraction for all wallets. This will connect to the users's smart account based on the connected personal wallet and the given options. * * This allows to sponsor gas fees for your user's transaction using the thirdweb account abstraction infrastructure. * * ```tsx * */ accountAbstraction?: SmartWalletOptions; /** * Wallets to show as recommended in the `ConnectButton`'s Modal */ recommendedWallets?: Wallet[]; /** * By default, ConnectButton modal shows a "All Wallets" button that shows a list of 500+ wallets. * * You can disable this button by setting `showAllWallets` prop to `false` */ showAllWallets?: boolean; /** * All wallet IDs included in this array will be hidden from the wallet selection list. */ hiddenWallets?: WalletId[]; /** * Enable SIWE (Sign in with Ethererum) by passing an object of type `SiweAuthOptions` to * enforce the users to sign a message after connecting their wallet to authenticate themselves. * * Refer to the [`SiweAuthOptions`](https://portal.thirdweb.com/references/typescript/v5/SiweAuthOptions) for more details */ auth?: SiweAuthOptions; };