Skip to content

Commit 1706b7c

Browse files
chore: emit events
1 parent e1c6a8c commit 1706b7c

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

packages/debugger/app/components/frame-app-debugger-notifications.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
22
import { Console } from "console-feed";
33
import { InboxIcon, Loader2Icon, TrashIcon } from "lucide-react";
4-
import type { ParseFramesV2ResultWithFrameworkDetails } from "frames.js/frame-parsers";
54
import { useEffect, useState } from "react";
65
import { Message } from "console-feed/lib/definitions/Component";
76
import { useQuery } from "@tanstack/react-query";
@@ -10,14 +9,16 @@ import { useFrameAppNotificationsManagerContext } from "../providers/FrameAppNot
109
import type { GETEventsResponseBody } from "../notifications/[namespaceId]/events/route";
1110
import { Button } from "@/components/ui/button";
1211
import { WithTooltip } from "./with-tooltip";
12+
import { UseFrameAppInIframeReturn } from "@frames.js/render/src/frame-app/iframe";
1313

1414
type FrameAppDebuggerNotificationsProps = {
15-
frame: ParseFramesV2ResultWithFrameworkDetails;
15+
frameApp: Extract<UseFrameAppInIframeReturn, { status: "success" }>;
1616
};
1717

1818
export function FrameAppDebuggerNotifications({
19-
frame,
19+
frameApp,
2020
}: FrameAppDebuggerNotificationsProps) {
21+
const frame = frameApp.frame;
2122
const frameAppNotificationManager = useFrameAppNotificationsManagerContext();
2223
const [events, setEvents] = useState<Message[]>([]);
2324
const notificationsQuery = useQuery({
@@ -152,7 +153,7 @@ export function FrameAppDebuggerNotifications({
152153
return (
153154
<div className="flex flex-row flex-grow gap-4 w-full h-full">
154155
<div className="w-1/3">
155-
<FrameAppNotificationsControlPanel />
156+
<FrameAppNotificationsControlPanel frameApp={frameApp} />
156157
</div>
157158
{events.length === 0 ? (
158159
<div className="flex flex-grow border rounded-lg p-2 items-center justify-center w-full">

packages/debugger/app/components/frame-app-debugger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export function FrameAppDebugger({
343343
className="overflow-hidden"
344344
value="notifications"
345345
>
346-
<FrameAppDebuggerNotifications frame={frameApp.frame} />
346+
<FrameAppDebuggerNotifications frameApp={frameApp} />
347347
</TabsContent>
348348
<TabsContent
349349
className="overflow-y-auto"

packages/debugger/app/components/frame-app-notifications-control-panel.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ import { useFrameAppNotificationsManagerContext } from "../providers/FrameAppNot
1313
import { useCallback, useState } from "react";
1414
import { cn } from "@/lib/utils";
1515
import { WithTooltip } from "./with-tooltip";
16+
import { UseFrameAppInIframeReturn } from "@frames.js/render/frame-app/iframe";
1617

17-
type FrameAppNotificationsControlPanelProps = {};
18+
type FrameAppNotificationsControlPanelProps = {
19+
frameApp: Extract<UseFrameAppInIframeReturn, { status: "success" }>;
20+
};
1821

19-
export function FrameAppNotificationsControlPanel({}: FrameAppNotificationsControlPanelProps) {
22+
export function FrameAppNotificationsControlPanel({
23+
frameApp,
24+
}: FrameAppNotificationsControlPanelProps) {
2025
const [state, setState] = useState<
2126
| "idle"
2227
| "adding-frame"
@@ -45,10 +50,13 @@ export function FrameAppNotificationsControlPanel({}: FrameAppNotificationsContr
4550
try {
4651
setState("removing-frame");
4752
await frameAppNotificationManager.removeFrame();
53+
frameApp.emitter.emit({
54+
event: "frame_removed",
55+
});
4856
} finally {
4957
setState("idle");
5058
}
51-
}, [frameAppNotificationManager]);
59+
}, [frameAppNotificationManager, frameApp.emitter]);
5260

5361
const reloadSettings = useCallback(async () => {
5462
try {
@@ -65,16 +73,24 @@ export function FrameAppNotificationsControlPanel({}: FrameAppNotificationsContr
6573
try {
6674
if (newValue) {
6775
setState("enabling-notifications");
68-
await frameAppNotificationManager.enableNotifications();
76+
const notificationDetails =
77+
await frameAppNotificationManager.enableNotifications();
78+
frameApp.emitter.emit({
79+
event: "notifications_enabled",
80+
notificationDetails,
81+
});
6982
} else {
7083
setState("disabling-notifications");
7184
await frameAppNotificationManager.disableNotifications();
85+
frameApp.emitter.emit({
86+
event: "notifications_disabled",
87+
});
7288
}
7389
} finally {
7490
setState("idle");
7591
}
7692
},
77-
[frameAppNotificationManager]
93+
[frameApp.emitter, frameAppNotificationManager]
7894
);
7995

8096
return (

packages/debugger/app/providers/FrameAppNotificationsManagerProvider.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
POSTNotificationsDetailRequestBody,
1313
POSTNotificationsDetailResponseBody,
1414
} from "../notifications/[namespaceId]/route";
15+
import type { FrameNotificationDetails } from "@farcaster/frame-sdk";
1516

1617
export const notificationManagerQueryKeys = {
1718
settingsQuery: (fid: string, frameAppUrl: string): string[] => [
@@ -27,7 +28,7 @@ export type FrameAppNotificationsManager = {
2728
Extract<NotificationSettings, { enabled: true }>["details"]
2829
>;
2930
removeFrame(): Promise<void>;
30-
enableNotifications(): Promise<void>;
31+
enableNotifications(): Promise<FrameNotificationDetails>;
3132
disableNotifications(): Promise<void>;
3233
reload(): Promise<void>;
3334
};
@@ -39,7 +40,9 @@ const FrameAppNotificationsManagerContext =
3940
throw new Error("Not implemented");
4041
},
4142
async removeFrame() {},
42-
async enableNotifications() {},
43+
async enableNotifications() {
44+
throw new Error("Not implemented");
45+
},
4346
async disableNotifications() {},
4447
async reload() {},
4548
});
@@ -183,14 +186,20 @@ export function useFrameAppNotificationsManager({
183186
});
184187
},
185188
async enableNotifications() {
186-
await sendEvent.mutateAsync({
189+
const result = await sendEvent.mutateAsync({
187190
action: "enable_notifications",
188191
});
189192

190193
// refetch notification settings
191194
await queryClient.refetchQueries({
192195
queryKey,
193196
});
197+
198+
if (result.type === "notifications_enabled") {
199+
return result.notificationDetails;
200+
}
201+
202+
throw new Error("Server returned incorrect response");
194203
},
195204
async disableNotifications() {
196205
await sendEvent.mutateAsync({

packages/render/src/frame-app/iframe.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ export function useFrameAppInIframe(
171171
endpointRef.current = endpoint;
172172
emitterRef.current = iframeFrameApp.getEmitter(endpoint);
173173

174+
logDebug("iframe endpoint created");
175+
174176
return () => {
175177
logDebug("iframe unmounted, cleaning up");
176178
endpointRef.current = null;

packages/render/src/frame-app/web-view.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ export function useFrameAppInWebView(
171171
endpointRef.current = endpoint;
172172
emitterRef.current = webViewFrameApp.getEmitter(endpoint);
173173

174+
logDebug("WebView endpoint created");
175+
174176
return () => {
175177
logDebug("WebView unmounted, cleaning up");
176178
webViewRef.current = null;

0 commit comments

Comments
 (0)