mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-04-01 02:27:56 +03:00
Merge branch 'main' into OP-2812-show-order-route-path-and-benefits
# Conflicts: # package.json
This commit is contained in:
73
src/services/ReferralSystem/index.ts
Normal file
73
src/services/ReferralSystem/index.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import fetchWithValidation from '../../fetchWithValidation';
|
||||
import distinctAnalyticsSchema from './schemas/distinctAnalyticsSchema';
|
||||
import linkSchema from './schemas/linkSchema';
|
||||
|
||||
type CreateLinkPayloadType = {
|
||||
referer: string;
|
||||
link_option: number;
|
||||
};
|
||||
|
||||
type SubscribePayloadType = {
|
||||
ref_target: string;
|
||||
referral: string;
|
||||
}
|
||||
|
||||
type SignatureType = {
|
||||
signature: string;
|
||||
};
|
||||
|
||||
class ReferralSystem {
|
||||
private apiUrl: string;
|
||||
|
||||
constructor(apiUrl: string) {
|
||||
this.apiUrl = apiUrl;
|
||||
|
||||
this.getLink = this.getLink.bind(this);
|
||||
this.getSubscribersList = this.getSubscribersList.bind(this);
|
||||
this.createReferralLink = this.createReferralLink.bind(this);
|
||||
this.subscribeToReferral = this.subscribeToReferral.bind(this);
|
||||
}
|
||||
|
||||
getLink = (refererAddress: string) => fetchWithValidation(`${this.apiUrl}/view/link`, linkSchema, {
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
});
|
||||
|
||||
getSubscribersList = (refererAddress: string) => fetchWithValidation(
|
||||
`${this.apiUrl}/view/distinct-analytics`,
|
||||
distinctAnalyticsSchema,
|
||||
{
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
createReferralLink = (payload: CreateLinkPayloadType, signature: SignatureType) => fetchWithValidation(
|
||||
`${this.apiUrl}/create`,
|
||||
linkSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
);
|
||||
|
||||
subscribeToReferral = (payload: SubscribePayloadType, signature: SignatureType) => fetchWithValidation(
|
||||
`${this.apiUrl}/subscribe`,
|
||||
linkSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export * as schemas from './schemas';
|
||||
export { ReferralSystem };
|
||||
@@ -0,0 +1,17 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const distinctAnalyticsSchema = z.object({
|
||||
referer: z.string(),
|
||||
|
||||
refs_info: z.array(
|
||||
z.object({
|
||||
referral_address: z.string(),
|
||||
referral_earned_fees: z.number(),
|
||||
referer_earned_fees: z.number(),
|
||||
relative_ref_level: z.number(),
|
||||
timestamp: z.number(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export default distinctAnalyticsSchema;
|
||||
2
src/services/ReferralSystem/schemas/index.ts
Normal file
2
src/services/ReferralSystem/schemas/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as linkSchema } from './linkSchema';
|
||||
export { default as distinctAnalyticsSchema } from './distinctAnalyticsSchema';
|
||||
9
src/services/ReferralSystem/schemas/linkSchema.ts
Normal file
9
src/services/ReferralSystem/schemas/linkSchema.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const linkSchema = z.object({
|
||||
referer: z.string(),
|
||||
ref_link: z.string(),
|
||||
option: z.number(),
|
||||
});
|
||||
|
||||
export default linkSchema;
|
||||
Reference in New Issue
Block a user