Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass original frame app url to view #540

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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's button action definition.
*/
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
Loading