diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c5d135b4..6999ca024 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 +- [#804](https://github.com/alleslabs/celatone-frontend/pull/804) api v1 - validator info - [#803](https://github.com/alleslabs/celatone-frontend/pull/803) api v1 - validator list - [#799](https://github.com/alleslabs/celatone-frontend/pull/799) Add extra config single denom staking - [#796](https://github.com/alleslabs/celatone-frontend/pull/796) Depositors list in vote details section diff --git a/src/lib/app-provider/env.ts b/src/lib/app-provider/env.ts index bca6cd5ab..310487df5 100644 --- a/src/lib/app-provider/env.ts +++ b/src/lib/app-provider/env.ts @@ -50,6 +50,7 @@ export enum CELATONE_QUERY_KEYS { VALIDATOR_IDENTITY_BY_ADDRESS = "CELATONE_QUERY_VALIDATOR_IDENTITY_BY_ADDRESS", // VALIDATOR VALIDATORS = "CELATONE_QUERY_VALIDATORS", + VALIDATOR_DATA = "CELATONE_QUERY_VALIDATOR_DATA", // FAUCET FAUCET_INFO = "CELATONE_QUERY_FAUCET_INFO", // X/GOV diff --git a/src/lib/services/validator.ts b/src/lib/services/validator.ts index 95e391903..e05125bc3 100644 --- a/src/lib/services/validator.ts +++ b/src/lib/services/validator.ts @@ -84,7 +84,6 @@ const zValidatorsResponse = z total_voting_power: zBig, }) .transform(snakeToCamel); - export type ValidatorsResponse = z.infer; export const getValidators = async ( @@ -108,3 +107,20 @@ export const getValidators = async ( }, }) .then(({ data }) => parseWithError(zValidatorsResponse, data)); + +const zValidatorDataResponse = z + .object({ + info: zValidatorData.nullable(), + self_voting_power: zBig, + total_voting_power: zBig, + }) + .transform(snakeToCamel); +export type ValidatorDataResponse = z.infer; + +export const getValidatorData = async ( + endpoint: string, + validatorAddress: ValidatorAddr +) => + axios + .get(`${endpoint}/${encodeURIComponent(validatorAddress)}/info`) + .then(({ data }) => parseWithError(zValidatorDataResponse, data)); diff --git a/src/lib/services/validatorService.ts b/src/lib/services/validatorService.ts index 3aa7cb99d..9568ded3a 100644 --- a/src/lib/services/validatorService.ts +++ b/src/lib/services/validatorService.ts @@ -12,8 +12,13 @@ import { } from "lib/app-provider"; import type { Nullable, Option, Validator, ValidatorAddr } from "lib/types"; -import type { ValidatorsResponse } from "./validator"; -import { getValidator, getValidators, resolveValIdentity } from "./validator"; +import type { ValidatorDataResponse, ValidatorsResponse } from "./validator"; +import { + getValidator, + getValidatorData, + getValidators, + resolveValIdentity, +} from "./validator"; export const useValidator = ( validatorAddr: ValidatorAddr, @@ -93,3 +98,15 @@ export const useValidators = ( } ); }; + +export const useValidatorData = (validatorAddress: ValidatorAddr) => { + const endpoint = useBaseApiRoute("validators"); + + return useQuery( + [CELATONE_QUERY_KEYS.VALIDATOR_DATA, endpoint, validatorAddress], + async () => getValidatorData(endpoint, validatorAddress), + { + retry: 1, + } + ); +};