Updated referral methods / schemas

This commit is contained in:
Demid
2023-05-02 12:23:09 +03:00
parent 093bb7b113
commit d417031c14
4 changed files with 25 additions and 13 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.18.22",
"version": "0.18.21-rc0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.18.22",
"version": "0.18.21-rc0",
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.21.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.18.22",
"version": "0.18.21-rc0",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -65,9 +65,9 @@ class ReferralSystem {
});
getMyReferral = (myWalletAddress: string) =>
fetchWithValidation(`${this.apiUrl}/referral/view/link`, linkSchema, {
fetchWithValidation(`${this.apiUrl}/referer/view/link`, linkSchema, {
headers: {
referral: myWalletAddress,
'referer-address': myWalletAddress,
},
});
@@ -166,14 +166,14 @@ class ReferralSystem {
`${this.apiUrl}/referer/ve/rating-table-leaderboard?chain_id=${chainId}`,
ratingSchema,
{
headers: refererAddress !== undefined ? { 'referer-address': refererAddress } : {},
headers: refererAddress !== undefined ? {'referer-address': refererAddress} : {},
},
errorSchema
);
getClamInfo = (refererAddress: string) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/claim-info-with-stats`,
`${this.apiUrl}/referer/view/claim-info-with-stats?&suppress_error=1`,
claimInfoSchema,
{
headers: {
@@ -183,9 +183,21 @@ class ReferralSystem {
errorSchema
);
getAggregatedHistory = (refererAddress: string, chainId: SupportedChainId, itemPerPage: number, page: number) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/aggregated-history?chain_id=${chainId}&n_per_page=${itemPerPage}&page=${page}`,
getAggregatedHistory = (refererAddress: string, chainId: SupportedChainId | undefined, itemPerPage: number, page: number) => {
const queryParams: Record<string, string | number> = {
n_per_page: itemPerPage,
page,
suppress_error: 1
};
if (chainId !== undefined) {
queryParams['chain_id'] = chainId;
}
const queryString = Object.entries(queryParams).map(([k, v]) => `${k}=${v}`).join('&')
return fetchWithValidation(
`${this.apiUrl}/referer/view/aggregated-history?${queryString}`,
aggregatedHistorySchema,
{
headers: {
@@ -194,6 +206,7 @@ class ReferralSystem {
},
errorSchema
);
}
}
export * as schemas from './schemas/index.js';

View File

@@ -2,11 +2,10 @@ import { z } from 'zod';
const aggregatedHistorySchema = z.object({
data: z.array(z.object({
history_type: z.object({
RewardDistribution: z.string()
}),
history_type: z.string(),
chain_type: z.string(),
chain_comp: z.string(),
chain_id: z.number(),
date_unix: z.number(),
date_time_local: z.string(),
date_time_utc: z.string(),