Updated referral methods and schemas

This commit is contained in:
Demid
2023-05-01 04:39:31 +03:00
parent 3564159dfb
commit 093bb7b113
2 changed files with 33 additions and 28 deletions

View File

@@ -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};

View File

@@ -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;