Skip to content
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

feat: api validator staking provisions #816

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading