Доработа логика генерации apiUrl для тестинг-окружения реферальной системы

This commit is contained in:
kuduzow
2023-01-05 22:15:31 +03:00
parent 38dd89d81a
commit afb57769f6
3 changed files with 17 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.15.27-rc.2",
"version": "0.15.27-rc.3",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -145,7 +145,7 @@ export default class OrionUnit {
this.orionAnalytics = new OrionAnalytics(orionAnalyticsUrl);
this.exchange = new Exchange(this);
this.farmingManager = new FarmingManager(this);
this.referralSystem = new ReferralSystem(`${options?.api ?? customApi}/referral-api`);
this.referralSystem = new ReferralSystem(options?.api ?? customApi, env);
}
get siblings() {

View File

@@ -19,8 +19,8 @@ type SignatureType = {
class ReferralSystem {
private apiUrl: string;
constructor(apiUrl: string) {
this.apiUrl = apiUrl;
constructor(apiUrl: string, env: string) {
this.apiUrl = ReferralSystem.getActualApiUrl(apiUrl, env);
this.getLink = this.getLink.bind(this);
this.getSubscribersList = this.getSubscribersList.bind(this);
@@ -29,6 +29,19 @@ class ReferralSystem {
this.getMyReferral = this.getMyReferral.bind(this);
}
// ресурсы реферальной системы в тестинг окружении имеют вид
// testing.orionprotocol.io/referral-api вместо обычного
// testing.orionprotocol.io/bsc-testnet/referral-api, поэтому лишняя часть вырезается
static getActualApiUrl = (apiUrl: string, env: string) => {
if (env !== 'testing') {
return `${apiUrl}/referral-api`;
}
const { protocol, hostname } = new URL(apiUrl);
return `${protocol}//${hostname}/referral-api`;
};
getLink = (refererAddress: string) => fetchWithValidation(`${this.apiUrl}/referer/view/link`, linkSchema, {
headers: {
'referer-address': refererAddress,