Skip to content

Commit

Permalink
fix: pass original frame app url to view
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkvasnicak committed Jan 28, 2025
1 parent be836e2 commit 43fee15
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-pigs-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frames.js/render": patch
---

fix: pass original frame app source url to view
12 changes: 1 addition & 11 deletions packages/render/src/frame-app/iframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,7 @@ export function useFrameAppInIframe(
case "pending":
return frameApp;
case "success": {
const frameUrl = frameApp.frame.frame.button?.action?.url;

if (!frameUrl) {
return {
status: "error",
error: new Error(
"Frame URL is not provided, please check button.action.url"
),
};
}

const frameUrl = frameApp.frameUrl.toString();
const frameOrigin = new URL(frameUrl).origin;

return {
Expand Down
12 changes: 1 addition & 11 deletions packages/render/src/frame-app/web-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,7 @@ export function useFrameAppInWebView(
case "pending":
return frameApp;
case "success": {
const frame = frameApp.frame.frame;
const frameUrl = frame.button?.action?.url;

if (!frameUrl) {
return {
status: "error",
error: new Error(
"Frame URL is not provided, please check button.action.url"
),
};
}
const frameUrl = frameApp.frameUrl.toString();

return {
...frameApp,
Expand Down
23 changes: 23 additions & 0 deletions packages/render/src/use-frame-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ export type UseFrameAppReturn =
| {
frame: ParseFramesV2ResultWithFrameworkDetails;
client: FrameClientConfig;
/**
* 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 from manifest.
*/
frameUrl: URL;
status: "success";
/**
* Creates sdk that must be exposed to frame app endpoint
Expand Down Expand Up @@ -302,6 +308,22 @@ export function useFrameApp({
switch (frameResolutionState.status) {
case "success": {
const frame = frameResolutionState.frame;
let frameUrl: URL;

if (frameResolutionState.source instanceof URL) {
frameUrl = frameResolutionState.source;
} else if (typeof frameResolutionState.source === "string") {
frameUrl = new URL(frameResolutionState.source);
} else if (frame.frame.button?.action?.url) {
frameUrl = new URL(frame.frame.button.action.url);
} else {
return {
status: "error",
error: new Error(
"Frame URL is not provided, please check button.action.url"
),
};
}

return {
getEmitter: (endpoint) => ({
Expand Down Expand Up @@ -416,6 +438,7 @@ export function useFrameApp({
}),
status: "success",
frame: frameResolutionState.frame,
frameUrl,
client: clientResolutionState.client,
};
}
Expand Down

0 comments on commit 43fee15

Please sign in to comment.