@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
122 lines (121 loc) • 4.45 kB
TypeScript
import type { AssetBalanceInfo } from '@funkit/api-base';
import React, { type ReactNode } from 'react';
import type { Address } from 'viem';
import type { IdentityProvider } from '../interfaces/identity';
import { type UseDisconnectReturnType, type UseReconnectReturnType } from '../wagmi/hooks';
import { type FunkitUserInfo } from '../consts/funkit';
import { LoginType } from '../utils/userInfo';
/** AssetBalanceInfo with known price and totalUsdValue */
export interface KnownAssetBalanceInfo extends AssetBalanceInfo {
price: number;
totalUsdValue: number;
}
export { LoginType } from '../utils/userInfo';
export interface GeneralWalletContextProps {
walletAddress: Address | '';
isUserLoggedIn: boolean;
loginType: LoginType;
userInfo: FunkitUserInfo;
handleLogout: () => void;
logoutSymbol: symbol | undefined;
}
export declare function GeneralWalletProvider({ children }: {
children: ReactNode;
}): React.JSX.Element;
export declare const useGeneralWallet: () => GeneralWalletContextProps;
/**
* Web implementation of the {@link IdentityProvider} contract: exposes the
* connected-wallet **user** identity (`GeneralWalletProvider`) as the
* platform-agnostic {@link FunkitIdentity} consumed by core hooks. React Native
* supplies its own implementation from host props.
*
* Customer identity (`apiKey`) is deliberately *not* included — it lives on
* `useFunkitConfig` so user identity and customer identity stay separable.
*
* `userId` is `userInfo.id` (not `userInfo.address`). `walletAddress` is the
* resolved `effectiveAddress` from context, normalized to the contract's `''`
* sentinel when absent — `GeneralWalletProvider` types the field `Address | ''`
* but leaks `undefined` for guests via a `@ts-expect-error`, so we coalesce
* here to keep web aligned with the contract (and with the eventual React
* Native implementation).
*/
export declare const useIdentity: IdentityProvider['useIdentity'];
/**
* Replacement for wagmi's `useAccount`
*/
export declare const useFunkitAccount: () => {
account: "" | `0x${string}`;
isConnected: boolean;
loginType: LoginType;
address: undefined;
addresses: undefined;
chain: undefined;
chainId: undefined;
connector: undefined;
isReconnecting: false;
isConnecting: false;
isDisconnected: true;
status: "disconnected";
} | {
account: "" | `0x${string}`;
isConnected: boolean;
loginType: LoginType;
address: Address;
addresses: readonly [Address, ...Address[]];
chain: import("viem").Chain | undefined;
chainId: number;
connector: import("wagmi").Connector;
isConnecting: false;
isDisconnected: false;
isReconnecting: false;
status: "connected";
} | {
account: "" | `0x${string}`;
isConnected: boolean;
loginType: LoginType;
address: Address | undefined;
addresses: readonly Address[] | undefined;
chain: import("viem").Chain | undefined;
chainId: number | undefined;
connector: import("wagmi").Connector | undefined;
isConnecting: false;
isDisconnected: false;
isReconnecting: true;
status: "reconnecting";
} | {
account: "" | `0x${string}`;
isConnected: boolean;
loginType: LoginType;
address: Address | undefined;
addresses: readonly Address[] | undefined;
chain: import("viem").Chain | undefined;
chainId: number | undefined;
connector: import("wagmi").Connector | undefined;
isReconnecting: false;
isConnecting: true;
isDisconnected: false;
status: "connecting";
};
export declare const useFunkitUserInfo: () => FunkitUserInfo;
export type FunkitDisconnectReturnType = UseDisconnectReturnType & {
disconnect: () => Promise<void> | void;
disconnectAsync: () => Promise<void> | void;
};
/**
* Replacement for wagmi's `disconnect` from `useDisconnect`
*/
export declare const useFunkitDisconnect: () => FunkitDisconnectReturnType;
/**
* Replacement for wagmi's `useReconnect`
*/
export declare const useFunkitReconnect: () => UseReconnectReturnType;
/**
* Replacement for wagmi's useSwitchChains
*/
export declare const useFunkitSwitchChains: ({ onSettled, }: {
onSettled?: () => void;
}) => {
switchChain: import("wagmi/query").SwitchChainMutate<import("wagmi").Config, undefined>;
switchChainAsync: import("wagmi/query").SwitchChainMutateAsync<import("wagmi").Config, undefined>;
pendingChainId: number | null;
};