Skip to content

Commit

Permalink
Merge pull request #816 from alleslabs/feat/cfe-362-api-staking-provi…
Browse files Browse the repository at this point in the history
…sions

feat: api validator staking provisions
  • Loading branch information
songwongtp committed Mar 8, 2024
2 parents fb36447 + bcebb50 commit dd1a721
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 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

- [#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
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 @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/lib/services/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
14 changes: 14 additions & 0 deletions src/lib/services/validatorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { Nullable, Option, Validator, ValidatorAddr } from "lib/types";

import type { BlocksResponse } from "./block";
import type {
StakingProvisionsResponse,
ValidatorDataResponse,
ValidatorDelegationRelatedTxsResponse,
ValidatorsResponse,
Expand All @@ -27,6 +28,7 @@ import {
getValidatorDelegators,
getValidatorProposedBlocks,
getValidators,
getValidatorStakingProvisions,
getValidatorUptime,
resolveValIdentity,
} from "./validator";
Expand Down Expand Up @@ -123,6 +125,18 @@ export const useValidators = (
);
};

export const useValidatorStakingProvisions = () => {
const endpoint = useBaseApiRoute("validators");

return useQuery<StakingProvisionsResponse>(
[CELATONE_QUERY_KEYS.VALIDATOR_STAKING_PROVISIONS, endpoint],
async () => getValidatorStakingProvisions(endpoint),
{
retry: 1,
}
);
};

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

Expand Down

0 comments on commit dd1a721

Please sign in to comment.