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 16, 2024
1 parent f347a10 commit fca9067
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.2.44",
"version": "0.2.45",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
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;
};
2 changes: 1 addition & 1 deletion src/app/context/api/DelegationsPointsProvider.tsx
Original file line number Diff line number Diff line change
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 fca9067

Please sign in to comment.