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,