@funkit/connect
Version:
Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.
87 lines (86 loc) • 3.89 kB
TypeScript
import type { Dnum } from 'dnum';
import React, { type Dispatch, type ReactNode } from 'react';
import type { FunkitCheckoutQuoteResult } from '../domains/quote';
import { type FunkitActiveCheckoutItem } from './FunkitCheckoutContext';
export type ApprovalMethod = 'approve' | 'sign';
export declare const APPROVAL_METHOD_DEFAULT: ApprovalMethod;
export type CheckoutQuoteError = {
maxTargetAssetAmount?: Dnum;
minTargetAssetAmount?: Dnum;
reason: 'insufficientBalance';
} | {
maxTargetAssetAmount?: Dnum;
minTargetAssetAmount?: Dnum;
minTargetUsdAmount?: number;
reason: 'insufficientAmount';
} | {
originalError: Error;
reason: 'internal';
};
export type CheckoutQuoteResult = {
success: true;
} | {
error: CheckoutQuoteError;
success: false;
};
type GetCheckoutQuoteResponse = CheckoutQuoteResult & {
shellCheckoutItemWithNextQuote: FunkitActiveCheckoutItem;
quoteState: CheckoutQuoteState;
};
interface CheckoutQuoteState {
/** Whether the checkout quote is being fetched **/
isQuoting: boolean;
/** Latest checkout estimated fees and time **/
latestQuote: null | FunkitCheckoutQuoteResult;
/** The quotation step message **/
quoteStepMessage: string;
/** Error messages associated with checkout quote **/
quoteErrorMessage: ReactNode;
}
interface FunkitQuoteContextInterface extends CheckoutQuoteState {
clearCheckoutQuoteMessages: () => void;
getCheckoutQuote: (disableInformationStreaming?: boolean) => Promise<GetCheckoutQuoteResponse>;
setCheckoutQuote: Dispatch<React.SetStateAction<FunkitCheckoutQuoteResult | null>>;
setQuoteProgress: (state: Omit<CheckoutQuoteState, 'latestQuote'>) => void;
usePermit: boolean | undefined;
preferredApprovalMethod: ApprovalMethod;
setPreferredApprovalMethod: (next: ApprovalMethod) => void;
showApprovalMethodToggle: boolean;
/**
* Per-checkout EIP-2612 permit capability of the target asset. `undefined` =
* unknown (loading or feature-agnostic — Relay falls back server-side), set
* by prefetch hooks (e.g., Aave's `useAaveTargetReservePermit`). Folded into
* `showApprovalMethodToggle` so consumers don't need their own asset gate.
*/
targetAssetSupportsPermit: boolean | undefined;
setTargetAssetSupportsPermit: (value: boolean | undefined) => void;
/**
* Current on-chain ERC-20 allowance from the user to the destination spender
* (e.g. the Aave Pool). When ≥ the supply amount, no approve / permit is
* needed and the toggle is hidden via `showApprovalMethodToggle`. `undefined`
* = unknown (loading or not applicable to this flow).
*/
targetAssetPoolAllowance: bigint | undefined;
setTargetAssetPoolAllowance: (value: bigint | undefined) => void;
}
/**
* Shared preconditions (wallet-executed account-balance flows only), then a
* per-flow gate. Aave native supply is capability-gated: EIP-2612 support
* (`undefined` = still loading → show optimistically, `false` = hide) and no
* covering Pool allowance — never the feature flag (ENG-4070). The Relay
* flow's source-side Permit2-vs-approve choice stays behind the
* `enable-permit-toggle` Statsig rollout gate.
*/
export declare function shouldShowApprovalMethodToggle({ isPermitToggleGateOn, isDirectExecution, isAccountBalancePayment, isAaveNativeSupplyFlow, targetAssetSupportsPermit, targetAssetAllowanceCoversAmount, }: {
isPermitToggleGateOn: boolean;
isDirectExecution: boolean;
isAccountBalancePayment: boolean;
isAaveNativeSupplyFlow: boolean;
targetAssetSupportsPermit: boolean | undefined;
targetAssetAllowanceCoversAmount: boolean;
}): boolean;
export declare function FunkitQuoteProvider({ children }: {
children: ReactNode;
}): React.JSX.Element;
export declare function useQuoteContext(): FunkitQuoteContextInterface;
export {};