feat: support abi & api#5641
Conversation
|
bf5d385 to
4b14711
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds 10 new
Confidence Score: 4/5The new query layer is additive and not yet wired into any UI, so the practical blast radius is low on this branch. Most of the 10 new query modules are well-structured and follow established conventions. The
Important Files Changed
Reviews (1): Last reviewed commit: "feat: support abi & api" | Re-trigger Greptile |
| queryKey: [ | ||
| FunctionKey.GET_PRIME_USER_PENDING_REWARDS, | ||
| { chainId, accountAddress: accountAddress as Address }, | ||
| ], |
There was a problem hiding this comment.
Unsafe
as Address cast embeds undefined into the query key
accountAddress is Address | undefined, but the cast to Address makes the query key's TypeScript type claim it is always a valid address. When the hook is disabled (because accountAddress is undefined), the key is { ..., accountAddress: undefined } even though the type says Address. This can cause silent cache-key mismatches if downstream code ever inspects or matches these keys. The same pattern appears in useGetPrimeUserCycleRewards.ts. A safe fallback avoids the assertion entirely.
| queryKey: [ | |
| FunctionKey.GET_PRIME_USER_PENDING_REWARDS, | |
| { chainId, accountAddress: accountAddress as Address }, | |
| ], | |
| queryKey: [ | |
| FunctionKey.GET_PRIME_USER_PENDING_REWARDS, | |
| { chainId, accountAddress: accountAddress ?? ('' as Address) }, | |
| ], |
| return useQuery({ | ||
| queryKey: [ | ||
| FunctionKey.GET_PRIME_USER_CYCLE_REWARDS, | ||
| { chainId, cycleIndex, accountAddress: accountAddress as Address }, |
There was a problem hiding this comment.
Same unsafe
as Address cast in query key
accountAddress can be undefined here too (it is typed Address | undefined in the hook input), yet it is cast to Address in the query key. When the hook is disabled, the serialised key silently contains undefined while the type asserts Address.
| { chainId, cycleIndex, accountAddress: accountAddress as Address }, | |
| { chainId, cycleIndex, accountAddress: accountAddress ?? ('' as Address) }, |
9bfb2b4 to
b2440a8
Compare
4b14711 to
c4b0ea7
Compare
| cycle: payload.cycle | ||
| ? { | ||
| ...payload.cycle, | ||
| startsAt: new Date(payload.cycle.startsAt), | ||
| endsAt: new Date(payload.cycle.endsAt), | ||
| } | ||
| : null, | ||
| pendingPool: payload.pendingPool | ||
| ? { | ||
| ...payload.pendingPool, | ||
| computedAt: new Date(payload.pendingPool.computedAt), | ||
| } | ||
| : null, |
There was a problem hiding this comment.
Let's not use null in the frontend repo, but rather undefined. null has many many issues: https://craftbettersoftware.com/p/stop-using-null-its-a-bad-practice
|
|
||
| export interface PrimeCurrentCycle { | ||
| cycleIndex: number; | ||
| status: string; |
There was a problem hiding this comment.
This should be an enum so we can list all the possible statuses.
| blockNumber: string; | ||
| computedAt: Date; | ||
| primeHolderCount: number; | ||
| totalPendingUsdCents: string; |
There was a problem hiding this comment.
You don't need to add "Usd" into the name (the repo considers that dollars are the the only on-crypto currency used).
| export interface PrimeFinalizedCycle { | ||
| cycleIndex: number; | ||
| startsAt: Date; | ||
| endsAt: Date; | ||
| mintLimitUsed: number; | ||
| totalRewardPoolUsdCents: string | null; | ||
| finalizedAt: Date | null; | ||
| } |
There was a problem hiding this comment.
The type for defining cycles is defined in multiple places.
I recommend creating a shared type that can live in side the root types file (apps/evm/src/types/index.ts) and that contains all the optional properties to define the various states of a cycle (past, current, etc..).
|
|
||
| interface PrimeCurrentCycleResponse { | ||
| cycleIndex: number; | ||
| status: string; |
There was a problem hiding this comment.
Same thing here, let's use an enum.
| } | ||
|
|
||
| export interface GetPrimePastCycleOutput { | ||
| cycle: PrimePastCycle | null; |
| }; | ||
| }; | ||
|
|
||
| export const getPrimePastCycle = async ({ |
There was a problem hiding this comment.
For simplicity and to follow the same naming logic as getPrimeUserCycleRewards, I'd name this function getPrimeCycle (and propagate the change onto the related types and hook).
| getPrimeUserCycleRewards({ chainId, cycleIndex, ...params }), | ||
| ), | ||
| ...options, | ||
| enabled: (options?.enabled === undefined || options?.enabled) && !!accountAddress, |
There was a problem hiding this comment.
Since we are fetching past data, we don't need to refetch it every 5 minutes (which is what React Query will do by default). You can pass the following options to prevent the query from being refetched this session"
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
staleTime: Number.POSITIVE_INFINITY,
gcTime: Number.POSITIVE_INFINITY,| return useQuery({ | ||
| queryKey: [FunctionKey.GET_PRIME_PAST_CYCLE, params], | ||
| queryFn: () => getPrimePastCycle(params), | ||
| ...options, |
There was a problem hiding this comment.
Since we are fetching past data, we don't need to refetch it every 5 minutes (which is what React Query will do by default). You can pass the following options to prevent the query from being refetched this session"
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
staleTime: Number.POSITIVE_INFINITY,
gcTime: Number.POSITIVE_INFINITY,There was a problem hiding this comment.
To follow the codebase practice of adding a suffix with the unit, I'd rename this: TOP_500_GAP_THRESHOLD_XVS_TOKENS.
Jira ticket(s)
VPD-1337
Changes