Skip to content

Commit

Permalink
feat: added state object to FrameValidationData (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia authored Mar 5, 2024
1 parent 760775a commit 3f76991
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/cyan-paws-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@coinbase/onchainkit': patch
---

- **feat**: added `state` type support for `FrameData` and `FrameValidationData`. By @zizzamia #216
- **fix**: update Neynar frame validation type. By @Flickque #212
22 changes: 22 additions & 0 deletions site/docs/pages/frame/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ type FrameButtonMetadata =
};
```

## `FrameData`

```ts
interface FrameData {
buttonIndex: number;
castId: {
fid: number;
hash: string;
};
inputText: string;
fid: number;
messageHash: string;
network: number;
state: string;
timestamp: number;
url: string;
}
```

## `FrameImageMetadata`

```ts
Expand Down Expand Up @@ -97,6 +116,9 @@ interface FrameValidationData {
liked: boolean; // Indicates if the viewer clicking the frame liked the cast
raw: NeynarFrameValidationInternalModel;
recasted: boolean; // Indicates if the viewer clicking the frame recasted the cast
state: {
serialized: string; // Serialized state (e.g. JSON) passed to the frame server
};
valid: boolean; // Indicates if the frame is valid
}
```
Expand Down
11 changes: 6 additions & 5 deletions src/frame/getFrameMessage.integ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ describe('getFrameMessage integration tests', () => {
it('frame message should decode properly', async () => {
const body = {
untrustedData: {
buttonIndex: 1,
castId: { fid: 194519, hash: '0x3d7c0dac1dd0ee588eb58d07105b14786cfca976' },
fid: 194519,
url: 'https://frame-demo.vercel.app/2',
messageHash: '0x7099de8afb08984d53f56a02b28d0f96097bfd82',
timestamp: 1706559790000,
inputText: '',
messageHash: '0x7099de8afb08984d53f56a02b28d0f96097bfd82',
network: 1,
buttonIndex: 1,
castId: { fid: 194519, hash: '0x3d7c0dac1dd0ee588eb58d07105b14786cfca976' },
url: 'https://frame-demo.vercel.app/2',
state: '',
timestamp: 1706559790000,
},
trustedData: {
messageBytes:
Expand Down
2 changes: 2 additions & 0 deletions src/frame/getFrameMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('getFrameValidatedMessage', () => {
fid: 0,
network: 0,
messageHash: '0xthisisnotreal',
state: '',
timestamp: 0,
url: 'https://localhost:3000',
},
Expand All @@ -75,6 +76,7 @@ describe('getFrameValidatedMessage', () => {
fid: 0,
network: 0,
messageHash: '0xthisisnotreal',
state: '',
timestamp: 0,
url: 'https://localhost:3000',
},
Expand Down
5 changes: 4 additions & 1 deletion src/frame/getMockFrameRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function getMockFrameRequest(
...request,
mockFrameData: {
button: request.untrustedData.buttonIndex,
input: request.untrustedData.inputText,
following: !!options?.following,
input: request.untrustedData.inputText,
interactor: {
fid: options?.interactor?.fid || 0,
custody_address: options?.interactor?.custody_address || '0xnotarealaddress',
Expand All @@ -28,6 +28,9 @@ function getMockFrameRequest(
},
liked: !!options?.liked,
recasted: !!options?.recasted,
state: {
serialized: request.untrustedData.state || '',
},
valid: true,
raw: {
valid: true,
Expand Down
4 changes: 4 additions & 0 deletions src/frame/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface FrameData {
fid: number;
messageHash: string;
network: number;
state: string;
timestamp: number;
url: string;
}
Expand Down Expand Up @@ -51,6 +52,9 @@ export interface FrameValidationData {
liked: boolean; // Indicates if the viewer clicking the frame liked the cast
raw: NeynarFrameValidationInternalModel;
recasted: boolean; // Indicates if the viewer clicking the frame recasted the cast
state: {
serialized: string; // Serialized state (e.g. JSON) passed to the frame server
};
valid: boolean; // Indicates if the frame is valid
}

Expand Down
3 changes: 3 additions & 0 deletions src/utils/neynar/frame/neynarFrameModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export function convertToNeynarResponseModel(data: any): FrameValidationData | u
liked: cast?.viewer_context?.liked,
raw: neynarResponse,
recasted: cast?.viewer_context?.recasted,
state: {
serialized: action?.state?.serialized || '',
},
valid: neynarResponse.valid,
};
}
4 changes: 2 additions & 2 deletions src/utils/neynar/frame/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ export interface NeynarFrameValidationInternalModel {
action_type: string;
}[];
input: {
text: string;
text?: string;
};
state: {
serialized: string;
serialized?: string;
};
post_url: string;
frames_url: string;
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.9.8';
export const version = '0.9.9';

0 comments on commit 3f76991

Please sign in to comment.