diff --git a/CHANGELOG.md b/CHANGELOG.md index e22d1776a..0124b54c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features +- [#816](https://github.com/alleslabs/celatone-frontend/pull/816) api v1 - validator staking provisions - [#815](https://github.com/alleslabs/celatone-frontend/pull/815) api v1 - validator delegators count - [#813](https://github.com/alleslabs/celatone-frontend/pull/813) api v1 - validator historical powers - [#812](https://github.com/alleslabs/celatone-frontend/pull/812) api v1 - validator delegation related txs, proposed blocks diff --git a/src/lib/app-provider/env.ts b/src/lib/app-provider/env.ts index 547ccc360..fd2ad5954 100644 --- a/src/lib/app-provider/env.ts +++ b/src/lib/app-provider/env.ts @@ -55,6 +55,7 @@ export enum CELATONE_QUERY_KEYS { VALIDATOR_DELEGATION_RELATED_TXS = "CELATONE_QUERY_VALIDATOR_DELEGATION_RELATED_TXS", VALIDATOR_PROPOSED_BLOCKS = "CELATONE_QUERY_VALIDATOR_PROPOSED_BLOCKS", VALIDATOR_DELEGATORS = "CELATONE_QUERY_VALIDATOR_DELEGATORS", + VALIDATOR_STAKING_PROVISIONS = "CELATONE_QUERY_VALIDATOR_STAKING_PROVISIONS", // FAUCET FAUCET_INFO = "CELATONE_QUERY_FAUCET_INFO", // X/GOV diff --git a/src/lib/services/validator.ts b/src/lib/services/validator.ts index a8c5cacdf..ded992a9d 100644 --- a/src/lib/services/validator.ts +++ b/src/lib/services/validator.ts @@ -141,6 +141,18 @@ export const getValidators = async ( }) .then(({ data }) => parseWithError(zValidatorsResponse, data)); +const zStakingProvisionsResponse = z.object({ + staking_provisions: zBig, +}); +export type StakingProvisionsResponse = z.infer< + typeof zStakingProvisionsResponse +>; + +export const getValidatorStakingProvisions = async (endpoint: string) => + axios + .get(`${endpoint}/staking-provisions`) + .then(({ data }) => parseWithError(zStakingProvisionsResponse, data)); + const zValidatorDataResponse = z .object({ info: zValidatorData.nullable(), diff --git a/src/lib/services/validatorService.ts b/src/lib/services/validatorService.ts index 07ce218a5..1ba2ecc12 100644 --- a/src/lib/services/validatorService.ts +++ b/src/lib/services/validatorService.ts @@ -14,6 +14,7 @@ import type { Nullable, Option, Validator, ValidatorAddr } from "lib/types"; import type { BlocksResponse } from "./block"; import type { + StakingProvisionsResponse, ValidatorDataResponse, ValidatorDelegationRelatedTxsResponse, ValidatorsResponse, @@ -27,6 +28,7 @@ import { getValidatorDelegators, getValidatorProposedBlocks, getValidators, + getValidatorStakingProvisions, getValidatorUptime, resolveValIdentity, } from "./validator"; @@ -123,6 +125,18 @@ export const useValidators = ( ); }; +export const useValidatorStakingProvisions = () => { + const endpoint = useBaseApiRoute("validators"); + + return useQuery( + [CELATONE_QUERY_KEYS.VALIDATOR_STAKING_PROVISIONS, endpoint], + async () => getValidatorStakingProvisions(endpoint), + { + retry: 1, + } + ); +}; + export const useValidatorData = (validatorAddress: ValidatorAddr) => { const endpoint = useBaseApiRoute("validators");