@@ -11,7 +11,8 @@ import { useConfig } from "wagmi";
11
11
import type { EIP6963ProviderInfo } from "@farcaster/frame-sdk" ;
12
12
import type {
13
13
FramePrimaryButton ,
14
- ResolveClientFunction ,
14
+ ResolveContextFunction ,
15
+ FrameContext ,
15
16
} from "@frames.js/render/frame-app/types" ;
16
17
import { useCallback , useEffect , useRef , useState } from "react" ;
17
18
import type { UseQueryResult } from "@tanstack/react-query" ;
@@ -84,67 +85,79 @@ export function FrameApp({
84
85
const frameAppNotificationManagerPromiseRef = useRef (
85
86
frameAppNotificationManager . promise
86
87
) ;
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
+ } ;
90
100
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
+ } ) ;
94
105
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
+ }
98
109
99
- const clientInfo = parseClientInfo . parse ( await clientInfoResponse . json ( ) ) ;
110
+ const parseClientInfo = z . object ( {
111
+ fid : z . number ( ) . int ( ) ,
112
+ } ) ;
100
113
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 ;
103
120
104
- if ( ! manager . state || manager . state . frame . status === "removed" ) {
105
121
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 ,
108
132
} ;
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
+ }
126
144
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
+ ) ;
133
157
const frameApp = useFrameAppInIframe ( {
134
158
debug : true ,
135
159
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 ,
148
161
provider,
149
162
proxyUrl : "/frames" ,
150
163
addFrameRequestsCache,
0 commit comments