import { Frame, SupportedParsingSpecification, TransactionTargetResponseSendTransaction, FrameButton, TransactionTargetResponseSignTypedDataV4, FrameButtonTx, TransactionTargetResponse, FrameButtonLink, FrameButtonPost, getFrame } from 'frames.js'; import { Dispatch } from 'react'; import { ParseResult } from 'frames.js/frame-parsers'; import { CastActionMessageResponse, ErrorMessageResponse, ComposerActionState, CastActionResponse, ComposerActionFormResponse } from 'frames.js/types'; type UseFrameStackOptions = { initialFrame?: Frame | ParseResult; initialFrameUrl?: string | null; initialSpecification: Exclude; }; type FrameStackAPI = { clear: () => void; createGetPendingItem: (arg: { request: FrameGETRequest; }) => FrameStackGetPending; createPostPendingItem: >(arg: { action: SignedFrameAction; request: FramePOSTRequest; /** * Optional, allows to override the start time * * @defaultValue new Date() */ startTime?: Date; }) => FrameStackPostPending; /** * Creates a pending item without dispatching it */ createCastOrComposerActionPendingItem: >(arg: { action: SignedFrameAction; request: FramePOSTRequest; }) => FrameStackPostPending; markCastMessageAsDone: (arg: { pendingItem: FrameStackPostPending; endTime: Date; response: Response; responseData: CastActionMessageResponse; }) => void; markCastFrameAsDone: (arg: { pendingItem: FrameStackPostPending; endTime: Date; }) => void; markComposerFormActionAsDone: (arg: { pendingItem: FrameStackPostPending; endTime: Date; }) => void; markAsDone: (arg: { pendingItem: FrameStackGetPending | FrameStackPostPending; endTime: Date; response: Response; frameResult: GetFrameResult; }) => void; markAsDoneWithRedirect: (arg: { pendingItem: FrameStackPostPending; endTime: Date; location: string; response: Response; responseBody: unknown; }) => void; markAsDoneWithErrorMessage: (arg: { pendingItem: FrameStackPostPending; endTime: Date; response: Response; responseData: ErrorMessageResponse; }) => void; markAsFailed: (arg: { pendingItem: FrameStackGetPending | FrameStackPostPending; endTime: Date; requestError: Error; response: Response | null; responseBody: unknown; responseStatus: number; }) => void; markAsFailedWithRequestError: (arg: { endTime: Date; pendingItem: FrameStackPostPending; error: Error; response: Response; responseBody: unknown; }) => void; }; declare function useFrameStack({ initialFrame, initialFrameUrl, initialSpecification, }: UseFrameStackOptions): [ FramesStack, React.Dispatch, FrameStackAPI ]; type OnTransactionArgs = { transactionData: TransactionTargetResponseSendTransaction; /** If the transaction was triggered by a frame button, this will be the frame that it was from */ frame?: Frame; /** If the transaction was triggered by a frame button, this will be the frame button that triggered it */ frameButton?: FrameButton; }; type OnTransactionFunc = (arg: OnTransactionArgs) => Promise<`0x${string}` | null>; type OnSignatureArgs = { signatureData: TransactionTargetResponseSignTypedDataV4; /** If the signature was triggered by a frame button, this will be the frame that it was from */ frame?: Frame; /** If the signature was triggered by a frame button, this will be the frame button that triggered it */ frameButton?: FrameButton; }; type OnSignatureFunc = (args: OnSignatureArgs) => Promise<`0x${string}` | null>; type OnMissingSignerFunction = () => void; type OnComposerFormActionFuncArgs = { form: ComposerActionFormResponse; cast: ComposerActionState; }; type OnComposeFormActionFuncReturnType = { /** * Updated composer action state */ composerActionState: ComposerActionState; } | undefined; /** * If the function resolves to undefined it means that the dialog was probably closed resulting in no operation at all. */ type OnComposerFormActionFunc = (arg: OnComposerFormActionFuncArgs) => Promise; /** * Called when user presses transaction button but there is no wallet connected. * * After wallet is connect, "connectAddress" option on useFrame() should be set to the connected address. */ type OnConnectWalletFunc = () => void; /** * Used to sign frame action */ type SignFrameActionFunc, TFrameActionBodyType extends FrameActionBodyPayload = FrameActionBodyPayload, TFrameContextType extends FrameContext = FrameContext> = (actionContext: SignerStateActionContext) => Promise>; type UseFetchFrameSignFrameActionFunction>, TFrameActionBodyType extends FrameActionBodyPayload = FrameActionBodyPayload> = (arg: { actionContext: TSignerStateActionContext; /** * @defaultValue false */ forceRealSigner?: boolean; }) => Promise>; type UseFetchFrameOptions, TFrameActionBodyType extends FrameActionBodyPayload = FrameActionBodyPayload, TFrameContextType extends FrameContext = FrameContext> = { stackAPI: FrameStackAPI; stackDispatch: React.Dispatch; specification: SupportedParsingSpecification; /** * URL or path to the frame proxy handling GET requests. */ frameGetProxy: string; /** * URL or path to the frame proxy handling POST requests. */ frameActionProxy: string; /** * Extra payload to be sent with the POST request. */ extraButtonRequestPayload?: Record; signFrameAction: UseFetchFrameSignFrameActionFunction, TFrameActionBodyType>; /** * Called after transaction data has been returned from the server and user needs to approve the transaction. */ onTransaction: OnTransactionFunc; /** Transaction data suffix */ transactionDataSuffix?: `0x${string}`; /** * Called after transaction data has been returned from the server and user needs to sign the typed data. */ onSignature: OnSignatureFunc; onComposerFormAction: OnComposerFormActionFunc; /** * This function can be used to customize how error is reported to the user. * * Should be memoized */ onError?: (error: Error) => void; /** * Custom fetch compatible function used to make requests. * * @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API */ fetchFn: typeof fetch; /** * This function is called when the frame returns a redirect in response to post_redirect button click. */ onRedirect: (location: URL) => void; /** * Called when user presses the tx button just before the action is signed and sent to the server * to obtain the transaction data. */ onTransactionDataStart?: (event: { button: FrameButtonTx; }) => void; /** * Called when transaction data has been successfully returned from the server. */ onTransactionDataSuccess?: (event: { button: FrameButtonTx; data: TransactionTargetResponse; }) => void; /** * Called when anything failed between onTransactionDataStart and obtaining the transaction data. */ onTransactionDataError?: (error: Error) => void; /** * Called before onTransaction() is called * Called after onTransactionDataSuccess() is called */ onTransactionStart?: (event: { button: FrameButtonTx; data: TransactionTargetResponseSendTransaction; }) => void; /** * Called when onTransaction() returns a transaction id */ onTransactionSuccess?: (event: { button: FrameButtonTx; }) => void; /** * Called when onTransaction() fails to return a transaction id */ onTransactionError?: (error: Error) => void; /** * Called before onSignature() is called * Called after onTransactionDataSuccess() is called */ onSignatureStart?: (event: { button: FrameButtonTx; data: TransactionTargetResponseSignTypedDataV4; }) => void; /** * Called when onSignature() returns a transaction id */ onSignatureSuccess?: (event: { button: FrameButtonTx; }) => void; /** * Called when onSignature() fails to return a transaction id */ onSignatureError?: (error: Error) => void; /** * Called after either onSignatureSuccess() or onTransactionSuccess() is called just before the transaction is sent to the server. */ onTransactionProcessingStart?: (event: { button: FrameButtonTx; transactionId: `0x${string}`; }) => void; /** * Called after the transaction has been successfully sent to the server and returned a success response. */ onTransactionProcessingSuccess?: (event: { button: FrameButtonTx; transactionId: `0x${string}`; }) => void; /** * Called when the transaction has been sent to the server but the server returned an error. */ onTransactionProcessingError?: (error: Error) => void; }; type UseFrameOptions, TFrameActionBodyType extends FrameActionBodyPayload = FrameActionBodyPayload, TFrameContextType extends FrameContext = FrameContext> = { /** skip frame signing, for frames that don't verify signatures */ dangerousSkipSigning?: boolean; /** the route used to POST frame actions. The post_url will be added as a the `url` query parameter */ frameActionProxy: string; /** the route used to GET the initial frame via proxy */ frameGetProxy: string; /** an signer state object used to determine what actions are possible */ signerState: SignerStateInstance; /** the url of the homeframe, if null / undefined won't load a frame */ homeframeUrl: string | null | undefined; /** the initial frame. if not specified will fetch it from the homeframeUrl prop */ frame?: Frame | ParseResult; /** * connected wallet address of the user, send to the frame for transaction requests */ connectedAddress: `0x${string}` | undefined; /** a function to handle mint buttons */ onMint?: (t: OnMintArgs) => void; /** a function to handle transaction buttons that returned transaction data from the target, returns the transaction hash or null */ onTransaction?: OnTransactionFunc; /** Transaction data suffix */ transactionDataSuffix?: `0x${string}`; /** A function to handle transaction buttons that returned signature data from the target, returns signature hash or null */ onSignature?: OnSignatureFunc; /** * Called when user presses transaction button but there is no wallet connected. */ onConnectWallet?: OnConnectWalletFunc; /** the context of this frame, used for generating Frame Action payloads */ frameContext: TFrameContextType; /** * Extra data appended to the frame action payload */ extraButtonRequestPayload?: Record; /** * Which specification to use for parsing the frame action payload * * @defaultValue 'farcaster' */ specification?: Exclude; /** * This function can be used to customize how error is reported to the user. */ onError?: (error: Error) => void; /** * This function can be used to customize how the link button click is handled. */ onLinkButtonClick?: (button: FrameButtonLink) => void; } & Partial>; type SignerStateActionSharedContext, TFrameContextType extends FrameContext = FrameContext> = { target?: string; frameButton: FrameButton; buttonIndex: number; url: string; inputText?: string; signer: TSignerStorageType | null; state?: string; transactionId?: `0x${string}`; address?: `0x${string}`; /** Transacting address is not included in non-transaction frame actions */ frameContext: TFrameContextType; }; type SignerStateDefaultActionContext, TFrameContextType extends FrameContext = FrameContext> = { type?: "default"; } & SignerStateActionSharedContext; type SignerStateTransactionDataActionContext, TFrameContextType extends FrameContext = FrameContext> = { type: "tx-data"; /** Wallet address used to create the transaction, available only for "tx" button actions */ address: `0x${string}`; } & SignerStateActionSharedContext; type SignerStateTransactionPostActionContext, TFrameContextType extends FrameContext = FrameContext> = { type: "tx-post"; /** Wallet address used to create the transaction, available only for "tx" button actions */ address: `0x${string}`; transactionId: `0x${string}`; } & SignerStateActionSharedContext; type SignerStateActionContext, TFrameContextType extends FrameContext = FrameContext> = SignerStateDefaultActionContext | SignerStateTransactionDataActionContext | SignerStateTransactionPostActionContext; type SignedFrameAction = { body: TFrameActionBodyType; searchParams: URLSearchParams; }; type SignFrameActionFunction> = SignerStateActionContext, TFrameActionBodyType extends FrameActionBodyPayload = FrameActionBodyPayload> = (actionContext: TSignerStateActionContext) => Promise>; interface SignerStateInstance, TFrameActionBodyType extends FrameActionBodyPayload = FrameActionBodyPayload, TFrameContextType extends FrameContext = FrameContext> { /** * For which specification is this signer required. * * If the value is an array it will take first valid specification if there is no valid specification * it will return the first specification in array no matter the validity. */ readonly specification: SupportedParsingSpecification | SupportedParsingSpecification[]; signer: TSignerStorageType | null; /** * True only if signer is approved or impersonating */ hasSigner: boolean; signFrameAction: SignFrameActionFunction, TFrameActionBodyType>; /** is loading the signer */ isLoadingSigner: boolean; /** A function called when a frame button is clicked without a signer */ onSignerlessFramePress: () => Promise; logout: () => Promise; withContext: (context: TFrameContextType, overrides?: { specification?: SupportedParsingSpecification | SupportedParsingSpecification[]; }) => { signerState: SignerStateInstance; frameContext: TFrameContextType; }; } type FrameGETRequest = { method: "GET"; url: string; }; type FramePOSTRequest> = SignerStateActionContext> = { method: "POST"; source?: never; frameButton: FrameButtonPost | FrameButtonTx; signerStateActionContext: TSignerStateActionContext; isDangerousSkipSigning: boolean; /** * The frame that was the source of the button press. */ sourceFrame: Frame; } | { method: "POST"; source: "cast-action" | "composer-action"; frameButton: FrameButtonPost | FrameButtonTx; signerStateActionContext: TSignerStateActionContext; isDangerousSkipSigning: boolean; sourceFrame: undefined; }; type FrameRequest> = SignerStateActionContext> = FrameGETRequest | FramePOSTRequest; type FrameStackBase = { id: number; timestamp: Date; /** speed in seconds */ speed: number; responseStatus: number; responseBody: unknown; requestDetails: { body?: object; searchParams?: URLSearchParams; }; url: string; }; type FrameStackPostPending = { id: number; method: "POST"; timestamp: Date; status: "pending"; request: FramePOSTRequest; requestDetails: { body?: object; searchParams?: URLSearchParams; }; url: string; }; type FrameStackGetPending = { id: number; method: "GET"; timestamp: Date; status: "pending"; request: FrameGETRequest; requestDetails: { body?: object; searchParams?: URLSearchParams; }; url: string; }; type FrameStackPending = FrameStackGetPending | FrameStackPostPending; type GetFrameResult = Awaited>; type FrameStackDone = FrameStackBase & { request: FrameRequest; response: Response; frameResult: GetFrameResult; status: "done"; }; type FrameStackDoneRedirect = FrameStackBase & { request: FramePOSTRequest; response: Response; location: string; status: "doneRedirect"; }; type FrameStackRequestError = FrameStackBase & { request: FrameRequest; response: Response | null; status: "requestError"; requestError: Error; }; type FrameStackMessage = FrameStackBase & { request: FramePOSTRequest; response: Response; status: "message"; message: string; type: "info" | "error"; }; type FramesStackItem = FrameStackPending | FrameStackDone | FrameStackDoneRedirect | FrameStackRequestError | FrameStackMessage; type FramesStack = FramesStackItem[]; type FrameReducerActions = { action: "LOAD"; item: FrameStackPending; } | { action: "REQUEST_ERROR"; pendingItem: FrameStackPending; item: FrameStackRequestError; } | { action: "DONE_REDIRECT"; pendingItem: FrameStackPending; item: FrameStackDoneRedirect; } | { action: "DONE"; pendingItem: FrameStackPending; item: FramesStackItem; } | { action: "CLEAR"; } | { action: "RESET_INITIAL_FRAME"; resultOrFrame: ParseResult | Frame; homeframeUrl: string | null | undefined; specification: Exclude; }; type ButtonPressFunction>> = (frame: Frame, frameButton: FrameButton, index: number, fetchFrameOverride?: FetchFrameFunction) => void | Promise; type CastActionButtonPressFunctionArg = { castAction: CastActionResponse & { /** URL to cast action handler */ url: string; }; /** * @defaultValue false */ clearStack?: boolean; }; type CastActionButtonPressFunction = (arg: CastActionButtonPressFunctionArg) => Promise; type ComposerActionButtonPressFunctionArg = { castAction: CastActionResponse & { /** URL to cast action handler */ url: string; }; composerActionState: ComposerActionState; /** * @defaultValue false */ clearStack?: boolean; }; type ComposerActionButtonPressFunction = (arg: ComposerActionButtonPressFunctionArg) => Promise; type CastActionRequest> = SignerStateActionContext> = Omit & { method: "CAST_ACTION"; action: CastActionResponse & { url: string; }; signerStateActionContext: Omit["signerStateActionContext"], "frameButton" | "inputText" | "state">; }; type ComposerActionRequest> = SignerStateActionContext> = Omit & { method: "COMPOSER_ACTION"; action: CastActionResponse & { url: string; }; composerActionState: ComposerActionState; signerStateActionContext: Omit["signerStateActionContext"], "frameButton" | "inputText" | "state">; }; type FetchFrameFunction> = SignerStateActionContext> = (request: FrameRequest | CastActionRequest | ComposerActionRequest, /** * If true, the frame stack will be cleared before the new frame is loaded * * @defaultValue false */ shouldClear?: boolean) => Promise; type FrameState, TFrameContextType extends FrameContext = FrameContext> = { fetchFrame: FetchFrameFunction>; clearFrameStack: () => void; dispatchFrameStack: Dispatch; /** The frame at the top of the stack (at index 0) */ currentFrameStackItem: FramesStackItem | undefined; /** A stack of frames with additional context, with the most recent frame at index 0 */ framesStack: FramesStack; inputText: string; setInputText: (s: string) => void; onButtonPress: ButtonPressFunction>; homeframeUrl: string | null | undefined; onCastActionButtonPress: CastActionButtonPressFunction; onComposerActionButtonPress: ComposerActionButtonPressFunction; }; type OnMintArgs = { target: string; frameButton: FrameButton; frame: Frame; }; declare const themeParams: readonly ["bg", "buttonColor", "buttonBg", "buttonBorderColor", "buttonRadius", "buttonHoverBg"]; type FrameTheme = Partial>; type FrameActionBodyPayload = Record; type FrameContext = Record; export { type FrameStackRequestError as A, type FrameStackMessage as B, type FramesStackItem as C, type FramesStack as D, type FrameReducerActions as E, type FrameActionBodyPayload as F, type GetFrameResult as G, type ButtonPressFunction as H, type CastActionButtonPressFunction as I, type ComposerActionButtonPressFunction as J, type CastActionRequest as K, type ComposerActionRequest as L, type FetchFrameFunction as M, type FrameState as N, type OnTransactionArgs as O, type OnMintArgs as P, themeParams as Q, type FrameTheme as R, type SignerStateActionContext as S, type FrameStackAPI as T, type UseFetchFrameSignFrameActionFunction as U, useFrameStack as V, type FrameContext as a, type SignedFrameAction as b, type SignFrameActionFunc as c, type OnTransactionFunc as d, type OnSignatureArgs as e, type OnSignatureFunc as f, type OnMissingSignerFunction as g, type OnComposeFormActionFuncReturnType as h, type OnComposerFormActionFunc as i, type OnConnectWalletFunc as j, type UseFetchFrameOptions as k, type UseFrameOptions as l, type SignerStateDefaultActionContext as m, type SignerStateTransactionDataActionContext as n, type SignerStateTransactionPostActionContext as o, type SignFrameActionFunction as p, type SignerStateInstance as q, type FrameGETRequest as r, type FramePOSTRequest as s, type FrameRequest as t, type FrameStackBase as u, type FrameStackPostPending as v, type FrameStackGetPending as w, type FrameStackPending as x, type FrameStackDone as y, type FrameStackDoneRedirect as z };