From afb57769f62472bc86f95886c17b11a3e39bf97d Mon Sep 17 00:00:00 2001 From: kuduzow Date: Thu, 5 Jan 2023 22:15:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20apiUrl=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=82=D0=B5=D1=81=D1=82=D0=B8=D0=BD=D0=B3-?= =?UTF-8?q?=D0=BE=D0=BA=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B5=D1=84=D0=B5=D1=80=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/OrionUnit/index.ts | 2 +- src/services/ReferralSystem/index.ts | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b552770..4399845 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/OrionUnit/index.ts b/src/OrionUnit/index.ts index e305cf1..b991580 100644 --- a/src/OrionUnit/index.ts +++ b/src/OrionUnit/index.ts @@ -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() { diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 9f8f8be..4216e52 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -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,