Skip to content

Commit b86fc0a

Browse files
fix: pass original frame app url to view (#540)
* fix: pass original frame app url to view * chore: fix comment
1 parent be836e2 commit b86fc0a

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

.changeset/slow-pigs-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@frames.js/render": patch
3+
---
4+
5+
fix: pass original frame app source url to view

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,7 @@ export function useFrameAppInIframe(
105105
case "pending":
106106
return frameApp;
107107
case "success": {
108-
const frameUrl = frameApp.frame.frame.button?.action?.url;
109-
110-
if (!frameUrl) {
111-
return {
112-
status: "error",
113-
error: new Error(
114-
"Frame URL is not provided, please check button.action.url"
115-
),
116-
};
117-
}
118-
108+
const frameUrl = frameApp.frameUrl.toString();
119109
const frameOrigin = new URL(frameUrl).origin;
120110

121111
return {

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,7 @@ export function useFrameAppInWebView(
120120
case "pending":
121121
return frameApp;
122122
case "success": {
123-
const frame = frameApp.frame.frame;
124-
const frameUrl = frame.button?.action?.url;
125-
126-
if (!frameUrl) {
127-
return {
128-
status: "error",
129-
error: new Error(
130-
"Frame URL is not provided, please check button.action.url"
131-
),
132-
};
133-
}
123+
const frameUrl = frameApp.frameUrl.toString();
134124

135125
return {
136126
...frameApp,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ export type UseFrameAppReturn =
205205
| {
206206
frame: ParseFramesV2ResultWithFrameworkDetails;
207207
client: FrameClientConfig;
208+
/**
209+
* Url that has been used to fetch the frame app.
210+
*
211+
* If the source was set to parse result object, this will contain url of the frame's button action definition.
212+
*/
213+
frameUrl: URL;
208214
status: "success";
209215
/**
210216
* Creates sdk that must be exposed to frame app endpoint
@@ -302,6 +308,22 @@ export function useFrameApp({
302308
switch (frameResolutionState.status) {
303309
case "success": {
304310
const frame = frameResolutionState.frame;
311+
let frameUrl: URL;
312+
313+
if (frameResolutionState.source instanceof URL) {
314+
frameUrl = frameResolutionState.source;
315+
} else if (typeof frameResolutionState.source === "string") {
316+
frameUrl = new URL(frameResolutionState.source);
317+
} else if (frame.frame.button?.action?.url) {
318+
frameUrl = new URL(frame.frame.button.action.url);
319+
} else {
320+
return {
321+
status: "error",
322+
error: new Error(
323+
"Frame URL is not provided, please check button.action.url"
324+
),
325+
};
326+
}
305327

306328
return {
307329
getEmitter: (endpoint) => ({
@@ -416,6 +438,7 @@ export function useFrameApp({
416438
}),
417439
status: "success",
418440
frame: frameResolutionState.frame,
441+
frameUrl,
419442
client: clientResolutionState.client,
420443
};
421444
}

0 commit comments

Comments
 (0)