@treasure-dev/tdk-react
Version:
Treasure Development Kit for React-based projects
143 lines (132 loc) • 5.17 kB
text/typescript
import { ConnectMethod, User, EcosystemIdString, AppInfo, Device, AuthOptions, SessionOptions, Contract, AddressString, TDKAPI, TreasureConnectClient, LegacyProfile, PropertyValue } from '@treasure-dev/tdk-core';
export * from '@treasure-dev/tdk-core';
import * as react_jsx_runtime from 'react/jsx-runtime';
import { UseWalletDetailsModalOptions } from 'thirdweb/react';
import { Wallet } from 'thirdweb/wallets';
import { ButtonHTMLAttributes, AnchorHTMLAttributes, ReactNode, PropsWithChildren } from 'react';
import { LauncherOptions } from '@treasure-dev/launcher';
import { Chain } from 'thirdweb';
import { Wallet as Wallet$1 } from 'thirdweb/dist/types/exports/wallets';
type Options$2 = {
disablePasskey?: boolean;
disableWallet?: boolean;
};
type Options$1 = Options$2 & {
authMode?: "popup" | "redirect";
redirectUrl?: string;
passkeyDomain?: string;
passkeyName?: string;
hasStoredPasskey?: boolean;
onConnected?: (method: ConnectMethod, wallet: Wallet, user?: User) => void;
onConnectError?: (method: ConnectMethod, err: unknown) => void;
};
type Props$3 = Options$1 & {
open: boolean;
size?: "lg" | "xl" | "2xl" | "3xl";
onOpenChange: (open: boolean) => void;
};
declare const ConnectModal: ({ open, size, authMode, redirectUrl, passkeyDomain, passkeyName, hasStoredPasskey, onOpenChange, onConnected, onConnectError, ...methodSelectionProps }: Props$3) => react_jsx_runtime.JSX.Element;
type Options = Options$1 & {
supportedChainIds?: number[];
connectModalSize?: Props$3["size"];
accountModalProps?: UseWalletDetailsModalOptions;
};
declare const useConnect: (options?: Options) => {
openConnectModal: () => void;
openAccountModal: () => void;
};
type Props$2 = Options;
declare const ConnectButton: (props?: Props$2) => react_jsx_runtime.JSX.Element;
type BaseProps = {
variant?: "primary" | "secondary";
isLoading?: boolean;
};
type AsButtonProps = BaseProps & Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof BaseProps> & {
as?: "button";
};
type AsLinkProps = BaseProps & Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof BaseProps> & {
as: "link";
};
type Props$1 = AsButtonProps | AsLinkProps;
declare const Button: (props: Props$1) => react_jsx_runtime.JSX.Element;
declare const SUPPORTED_LANGUAGES: readonly ["en", "es", "ja", "ru"];
type Language = (typeof SUPPORTED_LANGUAGES)[number];
type AnalyticsEvent = {
name: string;
userId?: string;
address?: string;
email?: string | null;
externalWalletAddresses?: string[];
properties?: {
[key: string]: PropertyValue | PropertyValue[];
};
};
type AnalyticsOptions = {
apiUri?: string;
apiKey: string;
appInfo: AppInfo;
automaticTrackLogin?: boolean;
automaticTrackLogout?: boolean;
cartridgeTag: string;
device?: Device;
};
type Config = {
language?: Language;
appName: string;
appIconUri?: string;
apiUri?: string;
defaultChainId?: number;
clientId: string;
ecosystemId?: EcosystemIdString;
ecosystemPartnerId: string;
analyticsOptions?: AnalyticsOptions;
authOptions?: AuthOptions;
launcherOptions?: LauncherOptions;
sessionOptions?: SessionOptions;
autoConnectTimeout?: number;
onConnect?: (user: User) => void;
};
type ContextValues = {
language?: Language;
appName: string;
appIconUri?: string;
chain: Chain;
contractAddresses: Record<Contract, AddressString>;
tdk: TDKAPI;
client: TreasureConnectClient;
ecosystemId: EcosystemIdString;
ecosystemPartnerId: string;
isConnecting: boolean;
isUsingTreasureLauncher: boolean;
isUsingLauncherAuthToken: boolean;
logIn: (wallet: Wallet$1, chainId?: number, authMethod?: string, skipCurrentUser?: boolean) => Promise<{
user: User | undefined;
legacyProfiles: LegacyProfile[];
}>;
logOut: () => void;
updateUser: (user: Partial<User>) => void;
startUserSession: (options: SessionOptions) => void;
switchChain: (chainId: number) => Promise<void>;
setRootElement: (el: ReactNode) => void;
openLauncherAccountModal: (size?: "lg" | "xl" | "2xl" | "3xl") => void;
trackCustomEvent: (event: AnalyticsEvent) => Promise<string | undefined>;
} & ({
isConnected: false;
user: undefined;
userAddress: undefined;
} | {
isConnected: true;
user: User;
userAddress: string;
});
declare const useTreasure: () => ContextValues;
type Props = PropsWithChildren<Config>;
declare const TreasureProvider: ({ children, language, appName, appIconUri, apiUri, defaultChainId, clientId, ecosystemId, ecosystemPartnerId, analyticsOptions, authOptions, launcherOptions, sessionOptions, autoConnectTimeout, onConnect, }: Props) => react_jsx_runtime.JSX.Element;
declare const useContractAddress: ({ chainId, contract, }: {
chainId?: number;
contract: Contract;
}) => `0x${string}`;
declare const useContractAddresses: ({ chainId }: {
chainId?: number;
}) => Record<Contract, `0x${string}`>;
export { Button, ConnectButton, ConnectModal, TreasureProvider, useConnect, useContractAddress, useContractAddresses, useTreasure };