From fca906772aebc84361cf0a302fa86e169e037877 Mon Sep 17 00:00:00 2001 From: jeremy-babylonchain Date: Mon, 16 Sep 2024 23:22:22 +0700 Subject: [PATCH] fix getPoints interface --- package.json | 2 +- src/app/api/getPoints.ts | 26 ++++++++++--------- .../context/api/DelegationsPointsProvider.tsx | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index d656786a..b1ad054c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-staking", - "version": "0.2.44", + "version": "0.2.45", "private": true, "scripts": { "dev": "next dev", diff --git a/src/app/api/getPoints.ts b/src/app/api/getPoints.ts index 6619885e..49ea86cb 100644 --- a/src/app/api/getPoints.ts +++ b/src/app/api/getPoints.ts @@ -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; @@ -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 => { +): Promise => { const params = new URLSearchParams(); stakerBtcPks.forEach((pk) => { @@ -49,13 +49,14 @@ 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 => { +): Promise => { const response = await pointsApiWrapper( "POST", "/v1/points/delegations", @@ -63,5 +64,6 @@ export const getDelegationPointsByStakingTxHashHexes = async ( { staking_tx_hash_hex: stakingTxHashHexes }, ); - return response.data; + const responseData: PaginatedDelegationsPointsAPIResponse = response.data; + return responseData.data; }; diff --git a/src/app/context/api/DelegationsPointsProvider.tsx b/src/app/context/api/DelegationsPointsProvider.tsx index 6b058d04..2ae8ffe9 100644 --- a/src/app/context/api/DelegationsPointsProvider.tsx +++ b/src/app/context/api/DelegationsPointsProvider.tsx @@ -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({