-
Notifications
You must be signed in to change notification settings - Fork 88
feat: support abi & api #5641
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
base: feat/prime-rank-card
Are you sure you want to change the base?
feat: support abi & api #5641
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { VError } from 'libs/errors'; | ||
| import type { ChainId } from 'types'; | ||
| import { restService } from 'utilities'; | ||
| import type { Address } from 'viem'; | ||
|
|
||
| export interface PrimeCurrentCycle { | ||
| cycleIndex: number; | ||
| status: string; | ||
| startsAt: Date; | ||
| endsAt: Date; | ||
| anchorBlockNum: string | null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No |
||
| mintLimitUsed: number; | ||
| } | ||
|
|
||
| export interface PrimePendingRewardTokenTotal { | ||
| rewardTokenAddress: Address; | ||
| totalPendingUsdCents: string; | ||
| totalPendingMantissa: string; | ||
| } | ||
|
|
||
| export interface PrimePendingRewardPool { | ||
| blockNumber: string; | ||
| computedAt: Date; | ||
| primeHolderCount: number; | ||
| totalPendingUsdCents: string; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to add "Usd" into the name (the repo considers that dollars are the the only on-crypto currency used). |
||
| byRewardToken: PrimePendingRewardTokenTotal[]; | ||
| } | ||
|
|
||
| export interface GetPrimeCurrentCycleInput { | ||
| chainId: ChainId; | ||
| } | ||
|
|
||
| export interface GetPrimeCurrentCycleOutput { | ||
| cycle: PrimeCurrentCycle | null; | ||
| pendingPool: PrimePendingRewardPool | null; | ||
| } | ||
|
|
||
| interface PrimeCurrentCycleResponse { | ||
| cycleIndex: number; | ||
| status: string; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, let's use an enum. |
||
| startsAt: string; | ||
| endsAt: string; | ||
| anchorBlockNum: string | null; | ||
| mintLimitUsed: number; | ||
| } | ||
|
|
||
| interface PrimePendingRewardPoolResponse { | ||
| blockNumber: string; | ||
| computedAt: string; | ||
| primeHolderCount: number; | ||
| totalPendingUsdCents: string; | ||
| byRewardToken: PrimePendingRewardTokenTotal[]; | ||
| } | ||
|
|
||
| interface GetPrimeCurrentCycleResponse { | ||
| cycle: PrimeCurrentCycleResponse | null; | ||
| pendingPool: PrimePendingRewardPoolResponse | null; | ||
| } | ||
|
|
||
| export const getPrimeCurrentCycle = async ({ | ||
| chainId, | ||
| }: GetPrimeCurrentCycleInput): Promise<GetPrimeCurrentCycleOutput> => { | ||
| const response = await restService<GetPrimeCurrentCycleResponse>({ | ||
| endpoint: '/prime/cycle/current', | ||
| method: 'GET', | ||
| params: { chainId }, | ||
| }); | ||
|
|
||
| const payload = response.data; | ||
|
|
||
| if (payload && 'error' in payload) { | ||
| throw new VError({ | ||
| type: 'unexpected', | ||
| code: 'somethingWentWrong', | ||
| data: { exception: payload.error }, | ||
| }); | ||
| } | ||
|
|
||
| if (!payload) { | ||
| throw new VError({ type: 'unexpected', code: 'somethingWentWrong' }); | ||
| } | ||
|
|
||
| return { | ||
| 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, | ||
|
Comment on lines
+84
to
+96
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use |
||
| }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { type QueryObserverOptions, useQuery } from '@tanstack/react-query'; | ||
|
|
||
| import FunctionKey from 'constants/functionKey'; | ||
| import { useChainId } from 'libs/wallet'; | ||
|
|
||
| import { | ||
| type GetPrimeCurrentCycleInput, | ||
| type GetPrimeCurrentCycleOutput, | ||
| getPrimeCurrentCycle, | ||
| } from '.'; | ||
|
|
||
| type Options = QueryObserverOptions< | ||
| GetPrimeCurrentCycleOutput, | ||
| Error, | ||
| GetPrimeCurrentCycleOutput, | ||
| GetPrimeCurrentCycleOutput, | ||
| [FunctionKey.GET_PRIME_CURRENT_CYCLE, GetPrimeCurrentCycleInput] | ||
| >; | ||
|
|
||
| export const useGetPrimeCurrentCycle = (options?: Partial<Options>) => { | ||
| const { chainId } = useChainId(); | ||
|
|
||
| return useQuery({ | ||
| queryKey: [FunctionKey.GET_PRIME_CURRENT_CYCLE, { chainId }], | ||
| queryFn: () => getPrimeCurrentCycle({ chainId }), | ||
| ...options, | ||
| }); | ||
| }; |
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.
This should be an enum so we can list all the possible statuses.