diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 41061bc..3572fe5 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -1,4 +1,4 @@ -import { fetchWithValidation } from 'simple-typed-fetch'; +import {fetchWithValidation} from 'simple-typed-fetch'; import { errorSchema, miniStatsSchema, @@ -11,6 +11,7 @@ import { claimInfoSchema, aggregatedHistorySchema, } from './schemas/index.js'; +import {SupportedChainId} from "../../types.js"; type CreateLinkPayloadType = { referer: string @@ -127,7 +128,7 @@ class ReferralSystem { 'Content-type': 'application/json', }, method: 'POST', - body: JSON.stringify({ payload, signature }), + body: JSON.stringify({payload, signature}), } ); @@ -140,7 +141,7 @@ class ReferralSystem { 'Content-type': 'application/json', }, method: 'POST', - body: JSON.stringify({ payload, signature }), + body: JSON.stringify({payload, signature}), }); subscribeToReferral = ( @@ -155,19 +156,17 @@ class ReferralSystem { 'Content-type': 'application/json', }, method: 'POST', - body: JSON.stringify({ payload, signature }), + body: JSON.stringify({payload, signature}), }, errorSchema ); - getRating = (refererAddress: string) => + getRating = (refererAddress: string | undefined, chainId: SupportedChainId) => fetchWithValidation( - `${this.apiUrl}/referer/ve/rating-table-leaderboard`, + `${this.apiUrl}/referer/ve/rating-table-leaderboard?chain_id=${chainId}`, ratingSchema, { - headers: { - 'referer-address': refererAddress, - }, + headers: refererAddress !== undefined ? { 'referer-address': refererAddress } : {}, }, errorSchema ); @@ -184,9 +183,9 @@ class ReferralSystem { errorSchema ); - getAggregatedHistory = (refererAddress: string) => + getAggregatedHistory = (refererAddress: string, chainId: SupportedChainId, itemPerPage: number, page: number) => fetchWithValidation( - `${this.apiUrl}/referer/view/aggregated-history`, + `${this.apiUrl}/referer/view/aggregated-history?chain_id=${chainId}&n_per_page=${itemPerPage}&page=${page}`, aggregatedHistorySchema, { headers: { @@ -198,4 +197,4 @@ class ReferralSystem { } export * as schemas from './schemas/index.js'; -export { ReferralSystem }; +export {ReferralSystem}; diff --git a/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts b/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts index 648e2d9..8a94b6e 100644 --- a/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts +++ b/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts @@ -1,20 +1,26 @@ import { z } from 'zod'; -const aggregatedHistorySchema = z.array(z.object({ - history_type: z.object({ - RewardDistribution: z.string() - }), - chain_type: z.string(), - chain_comp: z.string(), - date_unix: z.number(), - date_time_local: z.string(), - date_time_utc: z.string(), - amount_orn: z.string(), - amount_orn_fmt: z.number(), - amount_usd: z.string(), - amount_usd_fmt: z.number(), - orn_price: z.string(), - orn_price_fmt: z.number() -})) +const aggregatedHistorySchema = z.object({ + data: z.array(z.object({ + history_type: z.object({ + RewardDistribution: z.string() + }), + chain_type: z.string(), + chain_comp: z.string(), + date_unix: z.number(), + date_time_local: z.string(), + date_time_utc: z.string(), + amount_orn: z.string(), + amount_orn_fmt: z.number(), + amount_usd: z.string(), + amount_usd_fmt: z.number(), + orn_price: z.string(), + orn_price_fmt: z.number() + })), + pagination_info: z.object({ + c_page: z.number(), + t_pages: z.number() + }) +}) export default aggregatedHistorySchema;