import { FrameButtonLink, FrameV2, SupportedParsingSpecification, FrameButtonTx, TransactionTargetResponseSendTransaction, TransactionTargetResponseSignTypedDataV4, TransactionTargetResponse } from 'frames.js'; import { ParseFramesWithReportsResult, ParsedFrameV2, ParseResultFramesV2Success, ParseResultFramesV2Failure, ParseResultWithFrameworkDetails, ParseFramesV2ResultWithFrameworkDetails } from 'frames.js/frame-parsers'; import { Dispatch } from 'react'; import { ComposerActionState, ErrorMessageResponse } from 'frames.js/types'; import { q as SignerStateInstance, a as FrameContext, d as OnTransactionFunc, f as OnSignatureFunc, P as OnMintArgs, g as OnMissingSignerFunction, s as FramePOSTRequest, r as FrameGETRequest, t as FrameRequest, H as ButtonPressFunction, S as SignerStateActionContext, b as SignedFrameAction } from './types-CH60H6Gq.js'; type ResolvedSigner = { /** * Signer that will be used to sign all actions that require signers. */ signerState: SignerStateInstance; /** * The context of this frame, used for generating Frame Action payloads */ frameContext?: FrameContext; }; type OnTransactionFunction = OnTransactionFunc; type OnSignatureFunction = OnSignatureFunc; type OnMintFunction = (t: OnMintArgs) => void; type OnErrorFunction = (error: Error) => void; type OnLinkButtonClickFunction = (button: FrameButtonLink) => void; type OnRedirectFunction = (location: URL) => void; type ResolveSignerFunctionArg = { parseResult: ParseFramesWithReportsResult; }; type ResolveSignerFunction = (arg: ResolveSignerFunctionArg) => ResolvedSigner; type ResolveAddressFunction = () => Promise<`0x${string}` | null>; /** * If partial frame rendering is enabled this is the shape of the frame */ type PartialFrameV2 = Omit & { imageUrl: NonNullable; button: Omit, "action" | "title"> & { action: Omit["action"]>, "url" | "title"> & { url: NonNullable["action"]>["url"]>; }; title: NonNullable["title"]>>; }; }; type LaunchFrameButtonPressEvent = { status: "complete"; frame: FrameV2; parseResult: ParseResultFramesV2Success; } | { status: "partial"; frame: PartialFrameV2; parseResult: ParseResultFramesV2Failure; }; type LaunchFrameButtonPressFunction = (event: LaunchFrameButtonPressEvent) => void; type FrameCloseFunction = () => void; type UseFrameOptions = { /** * The frame state to be used for the frame. Allows to store extra data on stack items. */ frameStateHook?: (options: Pick, "initialFrameUrl" | "initialParseResult" | "resolveSpecification">) => UseFrameStateReturn; /** 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; /** * Will request the Farcaster Frames v2 manifest. * * This is only valid for Frames v2 and GET requests. * * @defaultValue false */ parseFarcasterManifest?: boolean; /** * Called on initial frame load. * * The function is called again if: * 1. initial frame changes * 2. homeframeUrl changes * 3. reset() method on FrameState is called */ resolveSigner: ResolveSignerFunction; /** * The url of the homeframe, if null / undefined won't load a frame nor render it. * * If the value changes the frame state is reset. */ homeframeUrl: string | null | undefined; /** * The initial frame. if not specified will fetch it from the homeframeUrl prop. * * Value should be memoized otherwise it will reset the frame state. */ frame?: ParseFramesWithReportsResult | null; /** * Called before onTransaction/onSignature is invoked to obtain an address to use. * * If the function returns null onTransaction/onSignature will not be called. * * Sent to the frame on transaction requests. */ resolveAddress: ResolveAddressFunction; /** a function to handle mint buttons */ onMint?: OnMintFunction; /** a function to handle transaction buttons that returned transaction data from the target, returns the transaction hash or null */ onTransaction?: OnTransactionFunction; /** 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?: OnSignatureFunction; /** * Extra data appended to the frame action payload */ extraButtonRequestPayload?: Record; /** * This function can be used to customize how error is reported to the user. */ onError?: OnErrorFunction; /** * This function can be used to customize how the link button click is handled. */ onLinkButtonClick?: OnLinkButtonClickFunction; /** * This function is called when opening a Frames v2 app is requested * * Only for frames v2 */ onLaunchFrameButtonPressed?: LaunchFrameButtonPressFunction; onMissingSigner?: OnMissingSignerFunction; } & Partial>; type FrameStackBase = { id: number; url: string; }; type FrameStackPostPending = Omit & { method: "POST"; status: "pending"; request: FramePOSTRequest; extra: TExtra; }; type FrameStackGetPending = Omit & { method: "GET"; status: "pending"; request: FrameGETRequest; extra: TExtra; }; type FrameStackPending = FrameStackGetPending | FrameStackPostPending; type FrameStackDone = FrameStackBase & { request: FrameRequest; frameResult: ParseResultWithFrameworkDetails | ParseFramesV2ResultWithFrameworkDetails; status: "done"; extra: TExtra; }; type FrameStackDoneRedirect = FrameStackBase & { request: FramePOSTRequest; location: string; status: "doneRedirect"; extra: TExtra; }; type FrameStackRequestError = FrameStackBase & { request: FrameRequest; status: "requestError"; requestError: Error; extra: TExtra; }; type FrameStackMessage = FrameStackBase & { request: FramePOSTRequest; status: "message"; message: string; type: "info" | "error"; extra: TExtra; }; type FramesStackItem = FrameStackPending | FrameStackDone | FrameStackDoneRedirect | FrameStackRequestError | FrameStackMessage; type UseFrameReturnValue = { /** * The signer state is set once it is resolved (on initial frame render) */ readonly signerState: SignerStateInstance | undefined; /** * The specification is set once it is resolved (on initial frame render) */ readonly specification: SupportedParsingSpecification | undefined; fetchFrame: FetchFrameFunction; clearFrameStack: () => void; dispatchFrameStack: Dispatch>; /** The frame at the top of the stack (at index 0) */ readonly currentFrameStackItem: FramesStackItem | undefined; /** A stack of frames with additional context, with the most recent frame at index 0 */ readonly framesStack: FramesStack; readonly inputText: string; setInputText: (s: string) => void; onButtonPress: ButtonPressFunction>; /** * Called by UI when the launch frame button is pressed. * * Only for frames v2 */ onLaunchFrameButtonPress: LaunchFrameButtonPressFunction; readonly homeframeUrl: string | null | undefined; /** * Resets the frame state to initial frame and resolves specification and signer again */ reset: () => void; }; 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_WITH_ERROR_MESSAGE"; pendingItem: FrameStackPending; item: Exclude, { type: "info"; }>; } | { action: "DONE"; pendingItem: FrameStackPending; parseResult: ParseFramesWithReportsResult; extra: TExtraDone; } | { action: "CLEAR"; } | { action: "RESET"; } | { action: "RESET_INITIAL_FRAME"; parseResult: ParseFramesWithReportsResult; homeframeUrl: string; extra: TExtraDone; }; type OnTransactionDataStartEvent = { button: FrameButtonTx; }; type OnTransactionDataStartFunction = (event: OnTransactionDataStartEvent) => void; type OnTransactionDataSuccessEvent = { button: FrameButtonTx; data: TransactionTargetResponse; }; type OnTransactionDataSuccessFunction = (event: OnTransactionDataSuccessEvent) => void; type OnTransactionStartEvent = { button: FrameButtonTx; data: TransactionTargetResponseSendTransaction; }; type OnTransactionStartFunction = (event: OnTransactionStartEvent) => void; type OnTransactionSuccessEvent = { button: FrameButtonTx; }; type OnTransactionSuccessFunction = (event: OnTransactionSuccessEvent) => void; type OnSignatureStartEvent = { button: FrameButtonTx; data: TransactionTargetResponseSignTypedDataV4; }; type OnSignatureStartFunction = (event: OnSignatureStartEvent) => void; type OnSignatureSuccessEvent = { button: FrameButtonTx; }; type OnSignatureSuccessFunction = (event: OnSignatureSuccessEvent) => void; type OnTransactionProcessingStartEvent = { button: FrameButtonTx; transactionId: `0x${string}`; }; type OnTransactionProcessingStartFunction = (event: OnTransactionProcessingStartEvent) => void; type OnTransactionProcessingSuccessEvent = { button: FrameButtonTx; transactionId: `0x${string}`; }; type OnTransactionProcessingSuccessFunction = (event: OnTransactionProcessingSuccessEvent) => void; type UseFetchFrameOptions = { frameState: FrameState; frameStateAPI: FrameStateAPI; /** * URL or path to the frame proxy handling GET requests. */ frameGetProxy: string; /** * URL or path to the frame proxy handling POST requests. */ frameActionProxy: string; /** * Will request the Farcaster Frames v2 manifest. * * This is only valid for Frames v2 and GET requests. * * @defaultValue false */ parseFarcasterManifest?: boolean; /** * Extra payload to be sent with the POST request. */ extraButtonRequestPayload?: Record; /** * Called after transaction data has been returned from the server and user needs to approve the transaction. */ onTransaction: OnTransactionFunction; /** 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: OnSignatureFunction; /** * This function can be used to customize how error is reported to the user. * * Should be memoized */ onError?: OnErrorFunction; /** * 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: OnRedirectFunction; /** * Called when user presses the tx button just before the action is signed and sent to the server * to obtain the transaction data. */ onTransactionDataStart?: OnTransactionDataStartFunction; /** * Called when transaction data has been successfully returned from the server. */ onTransactionDataSuccess?: OnTransactionDataSuccessFunction; /** * Called when anything failed between onTransactionDataStart and obtaining the transaction data. */ onTransactionDataError?: OnErrorFunction; /** * Called before onTransaction() is called * Called after onTransactionDataSuccess() is called */ onTransactionStart?: OnTransactionStartFunction; /** * Called when onTransaction() returns a transaction id */ onTransactionSuccess?: OnTransactionSuccessFunction; /** * Called when onTransaction() fails to return a transaction id */ onTransactionError?: OnErrorFunction; /** * Called before onSignature() is called * Called after onTransactionDataSuccess() is called */ onSignatureStart?: OnSignatureStartFunction; /** * Called when onSignature() returns a transaction id */ onSignatureSuccess?: OnSignatureSuccessFunction; /** * Called when onSignature() fails to return a transaction id */ onSignatureError?: OnErrorFunction; /** * Called after either onSignatureSuccess() or onTransactionSuccess() is called just before the transaction is sent to the server. */ onTransactionProcessingStart?: OnTransactionProcessingStartFunction; /** * Called after the transaction has been successfully sent to the server and returned a success response. */ onTransactionProcessingSuccess?: OnTransactionProcessingSuccessFunction; /** * Called when the transaction has been sent to the server but the server returned an error. */ onTransactionProcessingError?: OnErrorFunction; }; type FetchFrameFunction = (request: FrameRequest, /** * If true, the frame stack will be cleared before the new frame is loaded * * @defaultValue false */ shouldClear?: boolean) => Promise; type MarkAsDoneArg = { pendingItem: FrameStackGetPending | FrameStackPostPending; endTime: Date; response: Response; parseResult: ParseFramesWithReportsResult; responseBody: unknown; }; type MarkAsDonwWithRedirectArg = { pendingItem: FrameStackPostPending; endTime: Date; location: string; response: Response; responseBody: unknown; }; type MarkAsDoneWithErrorMessageArg = { pendingItem: FrameStackPostPending; endTime: Date; response: Response; responseData: ErrorMessageResponse; }; type MarkAsFailedArg = { pendingItem: FrameStackGetPending | FrameStackPostPending; endTime: Date; requestError: Error; response: Response | null; responseBody: unknown; responseStatus: number; }; type MarkAsFailedWithRequestErrorArg = { endTime: Date; pendingItem: FrameStackPostPending; error: Error; response: Response; responseBody: unknown; }; type CreateGetPendingItemArg = { request: FrameGETRequest; }; type CreatePOSTPendingItemArg = { action: SignedFrameAction; request: FramePOSTRequest; /** * Optional, allows to override the start time * * @defaultValue new Date() */ startTime?: Date; }; type UseFrameStateOptions = { initialParseResult?: ParseFramesWithReportsResult | null; initialFrameUrl?: string | null; initialPendingExtra?: TExtraPending; resolveSpecification: ResolveSignerFunction; resolveGETPendingExtra?: (arg: CreateGetPendingItemArg) => TExtraPending; resolvePOSTPendingExtra?: (arg: CreatePOSTPendingItemArg) => TExtraPending; resolveDoneExtra?: (arg: MarkAsDoneArg) => TExtraDone; resolveDoneRedirectExtra?: (arg: MarkAsDonwWithRedirectArg) => TExtraDoneRedirect; resolveDoneWithErrorMessageExtra?: (arg: MarkAsDoneWithErrorMessageArg) => TExtraMesssage; resolveFailedExtra?: (arg: MarkAsFailedArg) => TExtraRequestError; resolveFailedWithRequestErrorExtra?: (arg: MarkAsFailedWithRequestErrorArg) => TExtraRequestError; }; type FrameStateAPI = { dispatch: React.Dispatch>; clear: () => void; createGetPendingItem: (arg: CreateGetPendingItemArg) => FrameStackGetPending; createPostPendingItem: >(arg: { action: SignedFrameAction; request: FramePOSTRequest; /** * Optional, allows to override the start time * * @defaultValue new Date() */ startTime?: Date; }) => FrameStackPostPending; markAsDone: (arg: MarkAsDoneArg) => void; markAsDoneWithRedirect: (arg: MarkAsDonwWithRedirectArg) => void; markAsDoneWithErrorMessage: (arg: MarkAsDoneWithErrorMessageArg) => void; markAsFailed: (arg: MarkAsFailedArg) => void; markAsFailedWithRequestError: (arg: MarkAsFailedWithRequestErrorArg) => void; /** * If arg is omitted it will reset the frame stack to initial frame and resolves the specification again. * Otherwise it will set the frame state to provided values and resolve the specification. */ reset: (arg?: { homeframeUrl: string; parseResult: ParseFramesWithReportsResult; }) => void; }; type UseFrameStateReturn = [ FrameState, FrameStateAPI ]; type FrameState = { type: "initialized"; stack: FramesStack; signerState: SignerStateInstance; frameContext: FrameContext; specification: SupportedParsingSpecification; homeframeUrl: string; parseResult: ParseFramesWithReportsResult; } | { type: "not-initialized"; stack: FramesStack; }; type SignerStateComposerActionContext = { fid: number; url: string; state: ComposerActionState; }; type SignerComposerActionResult = { untrustedData: { fid: number; url: string; messageHash: `0x${string}`; timestamp: number; network: number; buttonIndex: number; state: string; }; trustedData: { messageBytes: string; }; }; /** * Used to sign composer action */ type SignComposerActionFunction = (signerPrivateKey: string, actionContext: SignerStateComposerActionContext) => Promise; type SignerStateCastActionContext = { fid: number; /** * The id of the cast from which the user initiated the action */ castId: { fid: number; hash: `0x${string}`; }; /** * Cast action post url */ postUrl: string; }; type SignerCastActionResult = { untrustedData: { fid: number; url: string; messageHash: `0x${string}`; timestamp: number; network: number; buttonIndex: number; }; trustedData: { messageBytes: string; }; }; /** * Used to sign cast action */ type SignCastActionFunction = (signerPrivateKey: string, actionContext: SignerStateCastActionContext) => Promise; export type { FetchFrameFunction, FrameCloseFunction, FrameReducerActions, FrameStackBase, FrameStackDone, FrameStackDoneRedirect, FrameStackGetPending, FrameStackMessage, FrameStackPending, FrameStackPostPending, FrameStackRequestError, FrameState, FrameStateAPI, FramesStack, FramesStackItem, LaunchFrameButtonPressEvent, LaunchFrameButtonPressFunction, OnErrorFunction, OnLinkButtonClickFunction, OnMintFunction, OnRedirectFunction, OnSignatureFunction, OnSignatureStartEvent, OnSignatureStartFunction, OnSignatureSuccessEvent, OnSignatureSuccessFunction, OnTransactionDataStartEvent, OnTransactionDataStartFunction, OnTransactionDataSuccessFunction, OnTransactionFunction, OnTransactionProcessingStartFunction, OnTransactionProcessingSuccessFunction, OnTransactionStartEvent, OnTransactionStartFunction, OnTransactionSuccessEvent, OnTransactionSuccessFunction, PartialFrameV2, ResolveAddressFunction, ResolveSignerFunction, ResolveSignerFunctionArg, ResolvedSigner, SignCastActionFunction, SignComposerActionFunction, SignerCastActionResult, SignerComposerActionResult, SignerStateCastActionContext, SignerStateComposerActionContext, UseFetchFrameOptions, UseFrameOptions, UseFrameReturnValue, UseFrameStateOptions, UseFrameStateReturn };