"use client"; import type { UseQueryOptions } from "@tanstack/react-query"; import type { JSX } from "react"; import type { AuthOption } from "../../../../../wallets/types.js"; import { getSocialIcon, useWalletIcon, } from "../../../../core/utils/walletIcon.js"; export interface WalletIconProps extends Omit, "src"> { /** * This component will be shown while the icon of the wallet is being fetched * If not passed, the component will return `null`. * * You can/should pass a loading sign or spinner to this prop. * @example * ```tsx * } /> * ``` */ loadingComponent?: JSX.Element; /** * This component will be shown if the icon fails to be retrieved * If not passed, the component will return `null`. * * You can/should pass a descriptive text/component to this prop, indicating that the * icon was not fetched successfully * @example * ```tsx * Failed to load} * /> * ``` */ fallbackComponent?: JSX.Element; /** * Optional `useQuery` params */ queryOptions?: Omit, "queryFn" | "queryKey">; } /** * This component tries to resolve the icon of a given wallet, then return an image. * @returns an with the src of the wallet icon * * @example * ### Basic usage * ```tsx * import { WalletProvider, WalletIcon } from "thirdweb/react"; * * * * * ``` * * Result: An component with the src of the icon * ```html * * ``` * * ### Show a loading sign while the icon is being loaded * ```tsx * } /> * ``` * * ### Fallback to a dummy image if the wallet icon fails to resolve * ```tsx * } /> * ``` * * ### Usage with queryOptions * WalletIcon uses useQuery() from tanstack query internally. * It allows you to pass a custom queryOptions of your choice for more control of the internal fetching logic * ```tsx * * ``` * * @component * @wallet * @beta */ export function WalletIcon({ loadingComponent, fallbackComponent, queryOptions, ...restProps }: WalletIconProps) { const imageQuery = useWalletIcon({ queryOptions }); if (imageQuery.isLoading) { return loadingComponent || null; } if (!imageQuery.data) { return fallbackComponent || null; } return {restProps.alt}; } export interface SocialIconProps extends Omit, "src"> { provider: AuthOption | string; } /** * Social auth provider icon * @returns an component with the src set to the svg * * @example * ```tsx * import { SocialIcon } from "thirdweb/react"; * * * ``` * * Result: An component with the src of the icon * ```html * * ``` * * @component * @wallet * @beta */ export function SocialIcon({ provider, ...restProps }: SocialIconProps) { const src = getSocialIcon(provider); return {restProps.alt}; }