-
Notifications
You must be signed in to change notification settings - Fork 145
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
Feat: Better Handling of FrameButton post actions #1053
Merged
Zizzamia
merged 8 commits into
coinbase:main
from
brendan-defi:feat/frame-post-button-handling
Aug 15, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
29c0fa3
updated FrameButtonMetadata to allow custom postUrl
brendan-defi 6c31bf7
updated logic to handle post-button postUrl setting
brendan-defi d5a61f2
addressed linter formatting issues
brendan-defi fe98b0d
added test for multiple buttons with custom s
brendan-defi 17419c9
created utility function for setting Button metadata
brendan-defi b661c40
added additional tests
brendan-defi 86be7fc
implement setFrameMetadataButtons for button metadata
brendan-defi d471806
addressed linter and formatter issues
brendan-defi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,126 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { setFrameMetadataButtons } from './setFrameMetadataButtons'; | ||
|
||
describe('setFrameMetadataButtons', () => { | ||
it('should return no button metadata', () => { | ||
const testMetadata = { | ||
'fc:frame': 'vNext', | ||
}; | ||
setFrameMetadataButtons(testMetadata, undefined); | ||
|
||
expect(testMetadata).toEqual({ | ||
'fc:frame': 'vNext', | ||
}); | ||
}); | ||
|
||
it('should return the correct metadata', () => { | ||
const testMetadata = { | ||
'fc:frame': 'vNext', | ||
}; | ||
setFrameMetadataButtons(testMetadata, [ | ||
{ label: 'button1', action: 'post' }, | ||
{ label: 'button2', action: 'post_redirect' }, | ||
{ label: 'button3' }, | ||
]); | ||
|
||
expect(testMetadata).toEqual({ | ||
'fc:frame': 'vNext', | ||
'fc:frame:button:1': 'button1', | ||
'fc:frame:button:1:action': 'post', | ||
'fc:frame:button:2': 'button2', | ||
'fc:frame:button:2:action': 'post_redirect', | ||
'fc:frame:button:3': 'button3', | ||
}); | ||
}); | ||
|
||
it('should return the correct metadata for button with action tx and target', () => { | ||
const testMetadata = { 'fc:frame': 'vNext' }; | ||
setFrameMetadataButtons(testMetadata, [ | ||
{ | ||
label: 'Button1', | ||
action: 'tx', | ||
target: 'https://zizzamia.xyz/api/frame/tx', | ||
}, | ||
]); | ||
|
||
expect(testMetadata).toEqual({ | ||
'fc:frame': 'vNext', | ||
'fc:frame:button:1': 'Button1', | ||
'fc:frame:button:1:action': 'tx', | ||
'fc:frame:button:1:target': 'https://zizzamia.xyz/api/frame/tx', | ||
}); | ||
}); | ||
|
||
it('should return the correct metadata for button with action post and post_url', () => { | ||
const testMetadata = { 'fc:frame': 'vNext' }; | ||
setFrameMetadataButtons(testMetadata, [ | ||
{ | ||
label: 'Button1', | ||
action: 'post', | ||
postUrl: 'https://zizzamia.xyz/api/frame/post_url', | ||
}, | ||
]); | ||
|
||
expect(testMetadata).toEqual({ | ||
'fc:frame': 'vNext', | ||
'fc:frame:button:1': 'Button1', | ||
'fc:frame:button:1:action': 'post', | ||
'fc:frame:button:1:post_url': 'https://zizzamia.xyz/api/frame/post_url', | ||
}); | ||
}); | ||
|
||
it('should return the correct metadata for buttons with action tx and custom targets', () => { | ||
const testMetadata = { 'fc:frame': 'vNext' }; | ||
setFrameMetadataButtons(testMetadata, [ | ||
{ | ||
label: 'Button1', | ||
action: 'tx', | ||
target: 'https://zizzamia.xyz/api/frame/tx?queryParam=XXX', | ||
}, | ||
{ | ||
label: 'Button2', | ||
action: 'tx', | ||
target: 'https://zizzamia.xyz/api/frame/tx?queryParam=YYY', | ||
}, | ||
]); | ||
|
||
expect(testMetadata).toEqual({ | ||
'fc:frame': 'vNext', | ||
'fc:frame:button:1': 'Button1', | ||
'fc:frame:button:1:action': 'tx', | ||
'fc:frame:button:1:target': | ||
'https://zizzamia.xyz/api/frame/tx?queryParam=XXX', | ||
'fc:frame:button:2': 'Button2', | ||
'fc:frame:button:2:action': 'tx', | ||
'fc:frame:button:2:target': | ||
'https://zizzamia.xyz/api/frame/tx?queryParam=YYY', | ||
}); | ||
}); | ||
|
||
it('should return the correct metadata for buttons with action post and custom post_urls', () => { | ||
const testMetadata = { 'fc:frame': 'vNext' }; | ||
setFrameMetadataButtons(testMetadata, [ | ||
{ | ||
label: 'Button1', | ||
action: 'post', | ||
postUrl: 'https://zizzamia.xyz/api/frame/post-url?queryParam=XXX', | ||
}, | ||
{ | ||
label: 'Button2', | ||
action: 'post', | ||
postUrl: 'https://zizzamia.xyz/api/frame/post-url?queryParam=YYY', | ||
}, | ||
]); | ||
expect(testMetadata).toEqual({ | ||
'fc:frame': 'vNext', | ||
'fc:frame:button:1': 'Button1', | ||
'fc:frame:button:1:action': 'post', | ||
'fc:frame:button:1:post_url': | ||
'https://zizzamia.xyz/api/frame/post-url?queryParam=XXX', | ||
'fc:frame:button:2': 'Button2', | ||
'fc:frame:button:2:action': 'post', | ||
'fc:frame:button:2:post_url': | ||
'https://zizzamia.xyz/api/frame/post-url?queryParam=YYY', | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
import type { FrameMetadataType } from '../types'; | ||
|
||
export function setFrameMetadataButtons( | ||
metadata: Record<string, string>, | ||
buttons: FrameMetadataType['buttons'], | ||
) { | ||
if (!buttons) { | ||
return; | ||
} | ||
|
||
buttons.forEach((button, index) => { | ||
metadata[`fc:frame:button:${index + 1}`] = button.label; | ||
if (button.action) { | ||
metadata[`fc:frame:button:${index + 1}:action`] = button.action; | ||
} | ||
if (button.target) { | ||
metadata[`fc:frame:button:${index + 1}:target`] = button.target; | ||
} | ||
if ( | ||
button.action && | ||
(button.action === 'tx' || button.action === 'post') && | ||
button.postUrl | ||
) { | ||
metadata[`fc:frame:button:${index + 1}:post_url`] = button.postUrl; | ||
} | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this part of the Frame Spec? And where is this writtend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per Button Actions, we are told that a
post
should send an HTTP request to the button'spost_url
.But as currently configured,
getFrameMetadata
does not set afc:frame:button:[id]:post_url
property for post actions, only tx actions:The above change to
FrameButtonMetadata
is required for strict type-checking of thegetFrameMetadata
logic.