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

Account for button post_url in frameInfo #33

Merged
merged 7 commits into from
May 2, 2024
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/rude-chefs-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@open-frames/proxy-types": patch
---

add button result type
5 changes: 5 additions & 0 deletions .changeset/tricky-eyes-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@open-frames/proxy": patch
---

account for button post_url in frameInfo
6 changes: 2 additions & 4 deletions packages/server/src/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ const testCases = [
'of:button:1:target': EXPECTED_FRAME_POST_URL,
'of:button:1:post_url': EXPECTED_FRAME_TX_POST_URL,
},
frameInfo: {
ogImage: EXPECTED_FRAME_IMAGE,
expectedFrameInfo: {
acceptedClients: {
xmtp: EXPECTED_FRAME_XMTP_VERSION,
lens: '2',
Expand All @@ -200,13 +199,12 @@ const testCases = [
alt: EXPECTED_IMAGE_ALT,
},
postUrl: EXPECTED_FRAME_POST_URL,
state: EXPECTED_FRAME_STATE,
buttons: {
'1': {
action: 'tx',
label: 'button-1',
target: EXPECTED_FRAME_POST_URL,
post_url: EXPECTED_FRAME_TX_POST_URL,
postUrl: EXPECTED_FRAME_TX_POST_URL,
},
},
},
Expand Down
13 changes: 11 additions & 2 deletions packages/server/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { OpenFrameButton, OpenFrameImage, OpenFrameResult, TransactionResponse } from '@open-frames/proxy-types';
import type {
OpenFrameButton,
OpenFrameButtonResult,
OpenFrameImage,
OpenFrameResult,
TransactionResponse,
} from '@open-frames/proxy-types';
import { load } from 'cheerio';

import { ALLOWED_ACTIONS, FRAMES_PREFIXES, TAG_PREFIXES } from './constants.js';
Expand Down Expand Up @@ -110,7 +116,7 @@ function updateFrameButton(frameInfo: DeepPartial<OpenFrameResult>, key: string,
return;
}
frameInfo.buttons = frameInfo.buttons || {};
const button = frameInfo.buttons[buttonIndex] || {};
const button = (frameInfo.buttons[buttonIndex] as OpenFrameButtonResult) || {};
if (maybeField) {
const field = maybeField as keyof OpenFrameButton;
if (field === 'action' && isAllowedAction(value)) {
Expand All @@ -119,6 +125,9 @@ function updateFrameButton(frameInfo: DeepPartial<OpenFrameResult>, key: string,
if (field === 'target') {
button.target = value;
}
if (field === 'post_url') {
button.postUrl = value;
}
} else {
button.label = value;
}
Expand Down
24 changes: 23 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export type OpenFrameButton =
action: 'link' | 'mint';
target: string;
label: string;
post_url: never;
}
| {
action: 'post' | 'post_redirect';
target?: string;
label: string;
post_url?: string;
}
| {
action: 'tx';
Expand All @@ -27,6 +29,26 @@ export type OpenFrameButton =
post_url: string;
};

export type OpenFrameButtonResult =
| {
action: 'link' | 'mint';
target: string;
label: string;
postUrl: never;
}
| {
action: 'post' | 'post_redirect';
target?: string;
label: string;
postUrl?: string;
}
| {
action: 'tx';
target: string;
label: string;
postUrl: string;
};

export type TextInput = {
content: string;
};
Expand All @@ -38,7 +60,7 @@ export type OpenFrameResult = {
image: OpenFrameImage;
postUrl?: string;
textInput?: TextInput;
buttons?: { [k: string]: OpenFrameButton };
buttons?: { [k: string]: OpenFrameButtonResult };
ogImage: string;
state?: string;
};
Expand Down
Loading