-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update
getFrameMetadata
to the latest Frame APIs (#43)
- Loading branch information
Showing
3 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@coinbase/onchainkit': minor | ||
--- | ||
|
||
- **feat** update `getFrameMetadata` to the latest [Frame APIs](https://warpcast.com/v/0x24295a0a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
type FrameMetadataResponse = { | ||
buttons: string[]; | ||
type Button = { | ||
label: string; | ||
action?: 'post' | 'post_redirect'; | ||
}; | ||
|
||
type FrameMetadata = { | ||
buttons: [Button, ...Button[]]; | ||
image: string; | ||
post_url: string; | ||
refresh_period?: number; | ||
}; | ||
|
||
type FrameMetadataResponse = Record<string, string>; | ||
|
||
/** | ||
* This function generates the metadata for a Farcaster Frame. | ||
* @param buttons: An array of button names. | ||
* @param buttons: The buttons to use for the frame. | ||
* @param image: The image to use for the frame. | ||
* @param post_url: The URL to post the frame to. | ||
* @param refresh_period: The refresh period for the image used. | ||
* @returns The metadata for the frame. | ||
*/ | ||
export const getFrameMetadata = function ({ buttons, image, post_url }: FrameMetadataResponse) { | ||
export const getFrameMetadata = function ({ | ||
buttons, | ||
image, | ||
post_url, | ||
refresh_period, | ||
}: FrameMetadata): FrameMetadataResponse { | ||
const metadata: Record<string, string> = { | ||
'fc:frame': 'vNext', | ||
}; | ||
buttons.forEach((button, index) => { | ||
metadata[`fc:frame:button:${index + 1}`] = button; | ||
metadata[`fc:frame:button:${index + 1}`] = button.label; | ||
if (button.action) { | ||
metadata[`fc:frame:button:${index + 1}:action`] = button.action; | ||
} | ||
}); | ||
metadata['fc:frame:image'] = image; | ||
metadata['fc:frame:post_url'] = post_url; | ||
if (refresh_period) { | ||
metadata['fc:frame:refresh_period'] = refresh_period.toString(); | ||
} | ||
return metadata; | ||
}; |