Skip to content

Conversation

@cprussin
Copy link
Collaborator

Summary

Adds an endpoint to the staking app to return a stake summary per account.

Rationale

This is required to calculate Fogo flames

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

@cprussin cprussin requested a review from a team as a code owner March 31, 2025 21:44
@vercel
Copy link

vercel bot commented Mar 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 5, 2025 5:00am
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 5, 2025 5:00am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2025 5:00am
component-library ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2025 5:00am
entropy-debugger ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2025 5:00am
proposals ⬜️ Ignored (Inspect) Visit Preview Apr 5, 2025 5:00am

Comment on lines 1127 to 1129
// Safe because `min(1)` guarantees that `data` is nonempty
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Buffer.from(data[0]!, "base64"),
Copy link
Contributor

@keyvankhademi keyvankhademi Mar 31, 2025

Choose a reason for hiding this comment

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

nit: can we use an if to avoid having !?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case we actually want ! because the min(1) line from Zod already guarantees the length, but can't encode that in the type. I generally prefer letting Zod verify this kind of thing since it will generate nice consistent error messages, but it requires the ! to avoid having a second null check at runtime. In this case since it's so many accounts, it's not huge but it is actually a relevant optimization.

I usually wrap this kind of thing into a nonEmptyArray Zod helper which returns [T, ...T[]] instead of T[] which typescript can then guarantee is nonempty...

@cprussin cprussin force-pushed the cprussin/add-staking-endpoint-to-return-positions-by-wallet branch from 9bbc2ed to 3d461e5 Compare April 5, 2025 04:55
@cprussin cprussin merged commit 84446fa into main Apr 5, 2025
9 checks passed
@cprussin cprussin deleted the cprussin/add-staking-endpoint-to-return-positions-by-wallet branch April 5, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants