Referral schema / request updates

This commit is contained in:
Demid
2023-04-14 09:34:50 +03:00
parent 23234ae26e
commit ff1725b5fb
6 changed files with 86 additions and 3 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.18.14",
"version": "0.18.16",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.18.14",
"version": "0.18.16",
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.21.0",

View File

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

View File

@@ -8,6 +8,8 @@ import {
rewardsClaimedSchema,
linkSchema,
ratingSchema,
claimInfoSchema,
aggregatedHistorySchema,
} from './schemas/index.js';
type CreateLinkPayloadType = {
@@ -48,6 +50,10 @@ class ReferralSystem {
this.getMiniStats = this.getMiniStats.bind(this);
this.getRewardsMapping = this.getRewardsMapping.bind(this);
this.claimRewards = this.claimRewards.bind(this);
this.getRating = this.getRating.bind(this);
this.getRating = this.getRating.bind(this);
this.getClamInfo = this.getClamInfo.bind(this);
this.getAggregatedHistory = this.getAggregatedHistory.bind(this);
}
getLink = (refererAddress: string) =>
@@ -161,6 +167,30 @@ class ReferralSystem {
{},
errorSchema
);
getClamInfo = (refererAddress: string) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/claim-info-with-stats`,
claimInfoSchema,
{
headers: {
'referer-address': refererAddress,
},
},
errorSchema
);
getAggregatedHistory = (refererAddress: string) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/aggregated-history`,
aggregatedHistorySchema,
{
headers: {
'referer-address': refererAddress,
},
},
errorSchema
);
}
export * as schemas from './schemas/index.js';

View File

@@ -0,0 +1,20 @@
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()
}))
export default aggregatedHistorySchema;

View File

@@ -0,0 +1,31 @@
import { z } from 'zod';
const claimInfoSchema = z.object({
global: z.object({
total_non_accrued: z.number(),
total_non_accrued_orn: z.number(),
total_non_accrued_usd: z.number()
}),
chain_to_reward_info: z.record(
z.string(),
z.object({
total_accrued: z.number(),
total_accrued_orn: z.number(),
total_accrued_usd: z.number(),
total_non_accrued: z.number(),
total_non_accrued_orn: z.number(),
total_non_accrued_usd: z.number(),
total_earned: z.number()
})
),
mini_stats: z.object({
earned_on_referrals_orn: z.number(),
earned_on_referrals_usd: z.number(),
orn_usd: z.number(),
registered_via_link_count: z.number(),
earned_in_a_week_orn: z.number(),
earned_in_a_week_usd: z.number()
}),
});
export default claimInfoSchema;

View File

@@ -6,3 +6,5 @@ export { default as rewardsMappingSchema } from './rewardsMappingSchema.js';
export { default as rewardsClaimedSchema } from './rewardsClaimedSchema.js';
export { default as globalAnalyticsSchema } from './globalAnalyticsSchema.js';
export { default as ratingSchema } from './ratingSchema.js';
export { default as claimInfoSchema } from './claimInfoSchema.js';
export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js';