Skip to content

Commit

Permalink
Merge pull request #804 from alleslabs/feat/cfe-358-api-validator-info
Browse files Browse the repository at this point in the history
[after #803] Feat/cfe 358 api validator info
  • Loading branch information
evilpeach committed Mar 5, 2024
2 parents 0ea8e79 + b5b6aff commit 295e72e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/lib/services/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const zValidatorsResponse = z
total_voting_power: zBig,
})
.transform(snakeToCamel);

export type ValidatorsResponse = z.infer<typeof zValidatorsResponse>;

export const getValidators = async (
Expand All @@ -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<typeof zValidatorDataResponse>;

export const getValidatorData = async (
endpoint: string,
validatorAddress: ValidatorAddr
) =>
axios
.get(`${endpoint}/${encodeURIComponent(validatorAddress)}/info`)
.then(({ data }) => parseWithError(zValidatorDataResponse, data));
21 changes: 19 additions & 2 deletions src/lib/services/validatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -93,3 +98,15 @@ export const useValidators = (
}
);
};

export const useValidatorData = (validatorAddress: ValidatorAddr) => {
const endpoint = useBaseApiRoute("validators");

return useQuery<ValidatorDataResponse>(
[CELATONE_QUERY_KEYS.VALIDATOR_DATA, endpoint, validatorAddress],
async () => getValidatorData(endpoint, validatorAddress),
{
retry: 1,
}
);
};

0 comments on commit 295e72e

Please sign in to comment.