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

fix: Refactor Farcaster typing to be explicit #37

Merged
merged 3 commits into from
Jan 29, 2024

Conversation

robpolak
Copy link
Contributor

@robpolak robpolak commented Jan 29, 2024

What changed? Why?

  1. Be more explicit on our Farcaster request / response types.
    2. Decided against importing the Farcaster types from @farcaster/hub-nodejs as the object types were more complex and could confuse consumers. Extract + simplify the interface.
  2. Added a farcaster message verification integration test.

Notes to reviewers

How has it been tested?

 yarn test
 PASS  src/utils/neynar/user/neynarUserFunctions.test.ts
 PASS  src/core/getFrameValidatedMessage.test.ts
 PASS  src/core/getFrameMetadata.test.ts
 PASS  src/core/getFrameAccountAddress.test.ts

Test Suites: 4 passed, 4 total
Tests:       8 passed, 8 total
Snapshots:   0 total
Time:        1.876 s, estimated 2 s
Ran all test suites.

❯ yarn test:integration         
 PASS  src/utils/neynar/neynar.integ.ts
 PASS  src/core/farcaster.integ.ts

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        2.399 s
Ran all test suites.

@robpolak robpolak changed the title Refactor farcaster typing to be explicit fix: Refactor Farcaster typing to be explicit Jan 29, 2024
@@ -18,9 +19,9 @@ export function getHubClient(): HubRpcClient {
*
* @param body The JSON received by server on frame callback
*/
async function getFrameValidatedMessage(body: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question should we keep this as getFrameValidatedMessage or have getFrameMessage.
As now we are returing isValid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should is data more correct than message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree and agree .. pr updated

};
}

export interface FrameValidationResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a tagged union, like:

type FrameValidationResponse =
  | { isValid: true, data: FrameData }
  | { isValid: false, data: undefined }

Then if isValid is true the typechecker should know that data is defined and vice-versa

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is pretty cool

Copy link
Contributor

@Zizzamia Zizzamia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!!!
I am going to merge and then release a 0.2.0 version at 5pm PST.
With explicit call on this breaking changes.

@Zizzamia Zizzamia merged commit c0e35a0 into main Jan 29, 2024
5 checks passed
@Zizzamia Zizzamia deleted the robpolak/refactor-farcaster-types branch January 29, 2024 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants