Skip to content

Commit

Permalink
fix getPoints interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-babylonlabs committed Sep 17, 2024
1 parent f347a10 commit b202031
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions src/app/api/getPoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { Pagination } from "../types/api";

import { pointsApiWrapper } from "./pointsApiWrapper";

export interface StakerPoints {
interface StakerPointsAPIResponse {
data: StakerPointsAPI[];
}

export interface StakerPointsAPI {
staker_btc_pk: string;
points: number;
}

export interface DelegationPoints {
export interface DelegationPointsAPI {
staking_tx_hash_hex: string;
staker: {
pk: string;
Expand All @@ -24,18 +28,14 @@ export interface DelegationPoints {
expiry_height: number;
}

export interface PaginatedDelegationsPoints {
data: DelegationPoints[];
interface PaginatedDelegationsPointsAPIResponse {
data: DelegationPointsAPI[];
pagination: Pagination;
}

export interface DelegationsPoints {
data: DelegationPoints[];
}

export const getStakersPoints = async (
stakerBtcPks: string[],
): Promise<StakerPoints[]> => {
): Promise<StakerPointsAPI[]> => {
const params = new URLSearchParams();

stakerBtcPks.forEach((pk) => {
Expand All @@ -49,19 +49,21 @@ export const getStakersPoints = async (
params,
);

return response.data;
const responseData: StakerPointsAPIResponse = response.data;
return responseData.data;
};

// Get delegation points by staking transaction hash hex
export const getDelegationPointsByStakingTxHashHexes = async (
stakingTxHashHexes: string[],
): Promise<DelegationsPoints> => {
): Promise<DelegationPointsAPI[]> => {
const response = await pointsApiWrapper(
"POST",
"/v1/points/delegations",
"Error getting delegation points by staking transaction hashes",
{ staking_tx_hash_hex: stakingTxHashHexes },
);

return response.data;
const responseData: PaginatedDelegationsPointsAPIResponse = response.data;
return responseData.data;
};
4 changes: 2 additions & 2 deletions src/app/context/api/DelegationsPointsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface DelegationsPointsProviderProps {
address: string;
}

const MAX_DELEGATION_POINTS_BATCH_SIZE = 60;
const MAX_DELEGATION_POINTS_BATCH_SIZE = 200;
const DelegationsPointsContext = createContext<PointsContextType | undefined>(
undefined,
);
Expand Down Expand Up @@ -68,7 +68,7 @@ export const DelegationsPointsProvider: React.FC<
chunks.map((chunk) => getDelegationPointsByStakingTxHashHexes(chunk)),
);

return results.flatMap((result) => result.data);
return results.flatMap((result) => result);
};

const { data, isLoading, error } = useQuery({
Expand Down

0 comments on commit b202031

Please sign in to comment.