import { ParseFramesV2ResultWithFrameworkDetails } from 'frames.js/frame-parsers'; import { FrameHost, HostEndpoint } from '@farcaster/frame-host'; import { EthProvider, FrameContext, ResolveContextFunction, OnPrimaryButtonSetFunction, OnAddFrameRequestedFunction, OnSignInFunction, OnViewProfileFunction, OnEIP6963RequestProviderRequestedFunction, OnSendTransactionRequestFunction, OnSignMessageRequestFunction, OnSignTypedDataRequestFunction, HostEndpointEmitter } from './frame-app/types.cjs'; import 'ox/Provider'; import 'ox/RpcSchema'; type UseFrameAppOptions = { /** * @example * ```ts * import { useWagmiProvider } from '@frames.js/render/frame-app/provider/wagmi'; * * function Component() { * const provider = useWagmiProvider(); * const frameApp = useFrameApp({ * provider, * }); * * //... * } * ``` */ provider: EthProvider; /** * Frame context which is used to render the frame app. * * The function is called after the frame app is loaded and it should return the context. * * The value (either an object or function) should be memoized otherwise it will cause unnecessary re-renders. */ context: FrameContext | ResolveContextFunction; /** * Either: * * - frame parse result obtained from useFrame() hook * - frame url as string or URL object * * If value changes it resets the internal state and refetches the frame if the new value is url. */ source: ParseFramesV2ResultWithFrameworkDetails | string | URL; /** * Custom fetch compatible function used to make requests. * * @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API */ fetchFn?: typeof fetch; /** * Frame proxyUrl used to fetch the frame parse result. */ proxyUrl: string; /** * Called when app calls `ready` method. */ onReady?: FrameHost["ready"]; /** * Called when app calls `close` method. */ onClose?: FrameHost["close"]; /** * Called when app calls `openUrl` method. */ onOpenUrl?: FrameHost["openUrl"]; /** * Called when app calls `setPrimaryButton` method. */ onPrimaryButtonSet?: OnPrimaryButtonSetFunction; /** * Called when app calls `addFrame` method. * * If the frame manifest is invalid it is automatically rejected. * If the method has been called during the session more than once it immediatelly rejects */ onAddFrameRequested?: OnAddFrameRequestedFunction; /** * Called when app calls `signIn` method. */ onSignIn?: OnSignInFunction; /** * Called when app calls `viewProfile` method. */ onViewProfile?: OnViewProfileFunction; /** * Called when app calls `eip6963RequestProvider` method. * * It will announce the provider to the frame app once this function returns the info */ onEIP6963RequestProviderRequested?: OnEIP6963RequestProviderRequestedFunction; /** * Enabled debugging * * @defaultValue false */ debug?: boolean; /** * Cache of frame app requests (calls to `addFrame` method). */ addFrameRequestsCache?: Set; onSendTransactionRequest?: OnSendTransactionRequestFunction; onSignMessageRequest?: OnSignMessageRequestFunction; onSignTypedDataRequest?: OnSignTypedDataRequestFunction; }; type UseFrameAppReturn = { frame: ParseFramesV2ResultWithFrameworkDetails; context: FrameContext; /** * Url that has been used to fetch the frame app. * * If the source was set to parse result object, this will contain url of the frame's button action definition. */ frameUrl: URL; status: "success"; /** * Creates sdk that must be exposed to frame app endpoint */ sdk: (endpoint: HostEndpoint) => Omit; /** * Gets emitter object that can be used to emit events to the frame app. */ getEmitter: (endpoint: HostEndpoint) => HostEndpointEmitter; } | { status: "pending"; } | { error: Error; status: "error"; }; /** * This hook is used to handle frames v2 apps. */ declare function useFrameApp({ context, provider, source, fetchFn, proxyUrl, onClose, onOpenUrl, onPrimaryButtonSet, onReady, debug, addFrameRequestsCache, onAddFrameRequested, onSendTransactionRequest, onSignMessageRequest, onSignTypedDataRequest, onViewProfile, onEIP6963RequestProviderRequested, onSignIn, }: UseFrameAppOptions): UseFrameAppReturn; export { type UseFrameAppOptions, type UseFrameAppReturn, useFrameApp };