@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
49 lines (48 loc) • 2.16 kB
TypeScript
import type { Address } from 'viem';
import type { LoginType } from '../utils/userInfo';
/**
* Platform-agnostic **user** identity surface consumed by core hooks.
*
* Deliberately scoped to who the *end user* is — `apiKey` (the *customer*
* identity, set by the integrator) is kept on `useFunkitConfig` so the two
* concerns don't get conflated. Core hooks that need both read each from its
* own seam.
*
* On web this is derived from wagmi + `GeneralWalletProvider`; on React Native
* it will be derived from host-app props. Widen this surface only when a core
* hook genuinely needs more — keep it free of DOM- and wagmi-bound types so it
* can move to `@funkit/connect-core` untouched.
*/
export interface FunkitIdentity {
/**
* Stable user id used to key user-scoped API calls. Equals the configured
* `externalUserId` (or a synthetic namespaced id derived from it) when one is
* present, otherwise the connected wallet address, or the `'0x'` placeholder
* when neither is present. Mirrors `userInfo.id`.
*/
userId: string;
/**
* Effective wallet address user-scoped flows transact against, or `''` when
* there is no connected/trusted address. Distinct from a display address:
* this is the resolved address (`effectiveAddress`), not `userInfo.address`,
* which carries the `'0x'` placeholder for guests.
*/
walletAddress: Address | '';
/** How the user authenticated (guest vs web3). */
loginType: LoginType;
/**
* Email the integrator supplies to prefill the Swapped fiat ramp iframe, when
* present. Like `externalUserId`, it's set by the integrator but describes the
* end user, so it belongs on the identity seam rather than being read from
* `useFunkitConfig` directly by core hooks.
*/
prefillFiatEmail?: string;
}
/**
* Contract a platform implements to feed identity into core. Each platform
* supplies a `useIdentity` hook: web wraps wagmi + `GeneralWalletProvider`
* (see `useIdentity` there); React Native will wrap host-app-provided props.
*/
export interface IdentityProvider {
useIdentity(): FunkitIdentity;
}