Skip to content

Commit

Permalink
Merge pull request #33 from open-frames/dj/post-url
Browse files Browse the repository at this point in the history
Account for button post_url in frameInfo
  • Loading branch information
daria-github authored May 2, 2024
2 parents d2b6b2e + 91dd6df commit c164bdf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
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

0 comments on commit c164bdf

Please sign in to comment.