mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
Merge pull request #179 from orionprotocol/feat/OP-4344-invite-code
Add referral invite code
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@orionprotocol/sdk",
|
"name": "@orionprotocol/sdk",
|
||||||
"version": "0.19.70",
|
"version": "0.19.70-rc3",
|
||||||
"description": "Orion Protocol SDK",
|
"description": "Orion Protocol SDK",
|
||||||
"main": "./lib/index.cjs",
|
"main": "./lib/index.cjs",
|
||||||
"module": "./lib/index.js",
|
"module": "./lib/index.js",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {fetchWithValidation} from 'simple-typed-fetch';
|
import { fetchWithValidation } from 'simple-typed-fetch';
|
||||||
import {
|
import {
|
||||||
errorSchema,
|
errorSchema,
|
||||||
miniStatsSchema,
|
miniStatsSchema,
|
||||||
@@ -10,9 +10,10 @@ import {
|
|||||||
ratingSchema,
|
ratingSchema,
|
||||||
claimInfoSchema,
|
claimInfoSchema,
|
||||||
aggregatedHistorySchema,
|
aggregatedHistorySchema,
|
||||||
|
inviteCodeLinkSchema,
|
||||||
|
contractsAddressesSchema,
|
||||||
} from './schemas/index.js';
|
} from './schemas/index.js';
|
||||||
import {SupportedChainId} from "../../types.js";
|
import type { SupportedChainId } from '../../types.js';
|
||||||
import contractsAddressesSchema from './schemas/contractsAddressesSchema.js';
|
|
||||||
|
|
||||||
type CreateLinkPayloadType = {
|
type CreateLinkPayloadType = {
|
||||||
referer: string
|
referer: string
|
||||||
@@ -24,6 +25,12 @@ type ClaimRewardsPayload = {
|
|||||||
chain_id: number
|
chain_id: number
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type SubmitInviteCodekWithLinkPayload = {
|
||||||
|
inviteCode: string
|
||||||
|
referer: string
|
||||||
|
linkOption: number
|
||||||
|
};
|
||||||
|
|
||||||
type SubscribePayloadType = {
|
type SubscribePayloadType = {
|
||||||
ref_target: string
|
ref_target: string
|
||||||
referral: string
|
referral: string
|
||||||
@@ -34,7 +41,7 @@ type SignatureType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class ReferralSystem {
|
class ReferralSystem {
|
||||||
private readonly apiUrl: string;
|
private readonly apiUrl: string
|
||||||
|
|
||||||
get api() {
|
get api() {
|
||||||
return this.apiUrl;
|
return this.apiUrl;
|
||||||
@@ -48,6 +55,8 @@ class ReferralSystem {
|
|||||||
this.createReferralLink = this.createReferralLink.bind(this);
|
this.createReferralLink = this.createReferralLink.bind(this);
|
||||||
this.subscribeToReferral = this.subscribeToReferral.bind(this);
|
this.subscribeToReferral = this.subscribeToReferral.bind(this);
|
||||||
this.getMyReferral = this.getMyReferral.bind(this);
|
this.getMyReferral = this.getMyReferral.bind(this);
|
||||||
|
this.getMyInviteCodeAndLink = this.getMyInviteCodeAndLink.bind(this);
|
||||||
|
this.submitInviteCodeWithLink = this.submitInviteCodeWithLink.bind(this);
|
||||||
this.getGlobalAnalytics = this.getGlobalAnalytics.bind(this);
|
this.getGlobalAnalytics = this.getGlobalAnalytics.bind(this);
|
||||||
this.getMiniStats = this.getMiniStats.bind(this);
|
this.getMiniStats = this.getMiniStats.bind(this);
|
||||||
this.getRewardsMapping = this.getRewardsMapping.bind(this);
|
this.getRewardsMapping = this.getRewardsMapping.bind(this);
|
||||||
@@ -73,6 +82,40 @@ class ReferralSystem {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
getMyInviteCodeAndLink = (refererAddress: string, suppressError = false) =>
|
||||||
|
fetchWithValidation(
|
||||||
|
`${this.apiUrl}/referer/invite/status2?suppress_error=${Number(
|
||||||
|
suppressError
|
||||||
|
)}`,
|
||||||
|
inviteCodeLinkSchema,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'referer-address': refererAddress,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
submitInviteCodeWithLink = ({
|
||||||
|
inviteCode,
|
||||||
|
referer,
|
||||||
|
linkOption,
|
||||||
|
}: SubmitInviteCodekWithLinkPayload) =>
|
||||||
|
fetchWithValidation(
|
||||||
|
`${this.apiUrl}/referer/invite/submit-code2`,
|
||||||
|
inviteCodeLinkSchema,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
'invite-code': inviteCode,
|
||||||
|
},
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
referer,
|
||||||
|
link_option: linkOption,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
getDistinctAnalytics = (refererAddress: string) =>
|
getDistinctAnalytics = (refererAddress: string) =>
|
||||||
fetchWithValidation(
|
fetchWithValidation(
|
||||||
`${this.apiUrl}/referer/view/distinct-analytics`,
|
`${this.apiUrl}/referer/view/distinct-analytics`,
|
||||||
@@ -130,13 +173,11 @@ class ReferralSystem {
|
|||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({payload, signature}),
|
body: JSON.stringify({ payload, signature }),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
createReferralLink = (
|
createReferralLink = (payload: CreateLinkPayloadType) =>
|
||||||
payload: CreateLinkPayloadType
|
|
||||||
) =>
|
|
||||||
fetchWithValidation(`${this.apiUrl}/referer/create2`, linkSchema, {
|
fetchWithValidation(`${this.apiUrl}/referer/create2`, linkSchema, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
@@ -145,9 +186,7 @@ class ReferralSystem {
|
|||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
subscribeToReferral = (
|
subscribeToReferral = (payload: SubscribePayloadType) =>
|
||||||
payload: SubscribePayloadType
|
|
||||||
) =>
|
|
||||||
fetchWithValidation(
|
fetchWithValidation(
|
||||||
`${this.apiUrl}/referer/subscribe2`,
|
`${this.apiUrl}/referer/subscribe2`,
|
||||||
linkSchema,
|
linkSchema,
|
||||||
@@ -166,7 +205,10 @@ class ReferralSystem {
|
|||||||
`${this.apiUrl}/referer/ve/rating-table-leaderboard?chain_id=${chainId}`,
|
`${this.apiUrl}/referer/ve/rating-table-leaderboard?chain_id=${chainId}`,
|
||||||
ratingSchema,
|
ratingSchema,
|
||||||
{
|
{
|
||||||
headers: refererAddress !== undefined ? {'referer-address': refererAddress} : {},
|
headers:
|
||||||
|
refererAddress !== undefined
|
||||||
|
? { 'referer-address': refererAddress }
|
||||||
|
: {},
|
||||||
},
|
},
|
||||||
errorSchema
|
errorSchema
|
||||||
);
|
);
|
||||||
@@ -201,7 +243,7 @@ class ReferralSystem {
|
|||||||
const queryParams: Record<string, string | number> = {
|
const queryParams: Record<string, string | number> = {
|
||||||
n_per_page: itemPerPage,
|
n_per_page: itemPerPage,
|
||||||
page,
|
page,
|
||||||
suppress_error: 1
|
suppress_error: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (chainId !== undefined) {
|
if (chainId !== undefined) {
|
||||||
@@ -212,7 +254,9 @@ class ReferralSystem {
|
|||||||
queryParams['history_filter'] = encodeURIComponent(types.join(','));
|
queryParams['history_filter'] = encodeURIComponent(types.join(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryString = Object.entries(queryParams).map(([k, v]) => `${k}=${v}`).join('&')
|
const queryString = Object.entries(queryParams)
|
||||||
|
.map(([k, v]) => `${k}=${v}`)
|
||||||
|
.join('&');
|
||||||
|
|
||||||
return fetchWithValidation(
|
return fetchWithValidation(
|
||||||
`${this.apiUrl}/referer/view/aggregated-history?${queryString}`,
|
`${this.apiUrl}/referer/view/aggregated-history?${queryString}`,
|
||||||
@@ -224,8 +268,8 @@ class ReferralSystem {
|
|||||||
},
|
},
|
||||||
errorSchema
|
errorSchema
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export * as schemas from './schemas/index.js';
|
export * as schemas from './schemas/index.js';
|
||||||
export {ReferralSystem};
|
export { ReferralSystem };
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ export { default as ratingSchema } from './ratingSchema.js';
|
|||||||
export { default as claimInfoSchema } from './claimInfoSchema.js';
|
export { default as claimInfoSchema } from './claimInfoSchema.js';
|
||||||
export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js';
|
export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js';
|
||||||
export { default as contractsAddressesSchema } from './contractsAddressesSchema.js';
|
export { default as contractsAddressesSchema } from './contractsAddressesSchema.js';
|
||||||
|
export { default as inviteCodeLinkSchema } from './inviteCodeLinkSchema.js';
|
||||||
|
|||||||
24
src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts
Normal file
24
src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
const inviteCodeLinkSchema = z.object({
|
||||||
|
link: z
|
||||||
|
.object({
|
||||||
|
referer: z.string(),
|
||||||
|
ref_link: z.string(),
|
||||||
|
option: z.number(),
|
||||||
|
})
|
||||||
|
.nullable(),
|
||||||
|
invite: z
|
||||||
|
.object({
|
||||||
|
code: z.string(),
|
||||||
|
data: z.null(),
|
||||||
|
limits: z.object({
|
||||||
|
tag: z.string(),
|
||||||
|
max_invites: z.number(),
|
||||||
|
max_ref_depth: z.number(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default inviteCodeLinkSchema;
|
||||||
Reference in New Issue
Block a user