@@ -11,7 +11,8 @@ import { useConfig } from "wagmi";
1111import type { EIP6963ProviderInfo } from "@farcaster/frame-sdk" ;
1212import type {
1313 FramePrimaryButton ,
14- ResolveClientFunction ,
14+ ResolveContextFunction ,
15+ FrameContext ,
1516} from "@frames.js/render/frame-app/types" ;
1617import { useCallback , useEffect , useRef , useState } from "react" ;
1718import type { UseQueryResult } from "@tanstack/react-query" ;
@@ -84,67 +85,79 @@ export function FrameApp({
8485 const frameAppNotificationManagerPromiseRef = useRef (
8586 frameAppNotificationManager . promise
8687 ) ;
87- const resolveClient : ResolveClientFunction = useCallback ( async ( ) => {
88- try {
89- const clientInfoResponse = await fetch ( "/client-info" ) ;
88+ const resolveContext : ResolveContextFunction = useCallback (
89+ async ( { signal } ) => {
90+ const location : FrameContext [ "location" ] =
91+ context . context === "button_press"
92+ ? {
93+ type : "launcher" ,
94+ }
95+ : {
96+ type : "cast_embed" ,
97+ embed : "" ,
98+ cast : fallbackFrameContext . castId ,
99+ } ;
90100
91- if ( ! clientInfoResponse . ok ) {
92- throw new Error ( "Failed to fetch client info" ) ;
93- }
101+ try {
102+ const clientInfoResponse = await fetch ( "/client-info" , {
103+ signal,
104+ } ) ;
94105
95- const parseClientInfo = z . object ( {
96- fid : z . number ( ) . int ( ) ,
97- } ) ;
106+ if ( ! clientInfoResponse . ok ) {
107+ throw new Error ( "Failed to fetch client info" ) ;
108+ }
98109
99- const clientInfo = parseClientInfo . parse ( await clientInfoResponse . json ( ) ) ;
110+ const parseClientInfo = z . object ( {
111+ fid : z . number ( ) . int ( ) ,
112+ } ) ;
100113
101- const { manager } = await frameAppNotificationManagerPromiseRef . current ;
102- const clientFid = clientInfo . fid ;
114+ const clientInfo = parseClientInfo . parse (
115+ await clientInfoResponse . json ( )
116+ ) ;
117+
118+ const { manager } = await frameAppNotificationManagerPromiseRef . current ;
119+ const clientFid = clientInfo . fid ;
103120
104- if ( ! manager . state || manager . state . frame . status === "removed" ) {
105121 return {
106- clientFid,
107- added : false ,
122+ client : {
123+ clientFid,
124+ added : manager . state ?. frame . status === "added" ,
125+ notificationDetails :
126+ manager . state ?. frame . status === "added"
127+ ? manager . state . frame . notificationDetails ?? undefined
128+ : undefined ,
129+ } ,
130+ location,
131+ user : userContext ,
108132 } ;
109- }
110-
111- return {
112- clientFid,
113- added : true ,
114- notificationDetails :
115- manager . state . frame . notificationDetails ?? undefined ,
116- } ;
117- } catch ( e ) {
118- console . error ( e ) ;
119-
120- toast ( {
121- title : "Unexpected error" ,
122- description :
123- "Failed to load notifications settings. Check the console for more details." ,
124- variant : "destructive" ,
125- } ) ;
133+ } catch ( e ) {
134+ if ( ! ( typeof e === "string" && e . startsWith ( "Aborted because" ) ) ) {
135+ console . error ( e ) ;
136+
137+ toast ( {
138+ title : "Unexpected error" ,
139+ description :
140+ "Failed to load notifications settings. Check the console for more details." ,
141+ variant : "destructive" ,
142+ } ) ;
143+ }
126144
127- return {
128- clientFid : - 1 ,
129- added : false ,
130- } ;
131- }
132- } , [ toast ] ) ;
145+ return {
146+ client : {
147+ clientFid : - 1 ,
148+ added : false ,
149+ } ,
150+ location,
151+ user : userContext ,
152+ } ;
153+ }
154+ } ,
155+ [ toast , context , userContext ]
156+ ) ;
133157 const frameApp = useFrameAppInIframe ( {
134158 debug : true ,
135159 source : context . parseResult ,
136- client : resolveClient ,
137- location :
138- context . context === "button_press"
139- ? {
140- type : "launcher" ,
141- }
142- : {
143- type : "cast_embed" ,
144- embed : "" ,
145- cast : fallbackFrameContext . castId ,
146- } ,
147- user : userContext ,
160+ context : resolveContext ,
148161 provider,
149162 proxyUrl : "/frames" ,
150163 addFrameRequestsCache,
0 commit comments