diff --git a/src/services/hbs.js b/src/services/hbs.js index 34d6fa6..4dcbc7a 100644 --- a/src/services/hbs.js +++ b/src/services/hbs.js @@ -1,27 +1,29 @@ import axios from 'axios' -import { AUTH_SERVICE_URL, AUTH_SERVICE_VERSION } from '../utils/hbsConfiguration' +import { authServiceUrl, authServiceVersion } from '../utils/hbsConfiguration' import { httpCall } from '../utils/httpProvider' export const kycLevel1 = 'holo_kyc_1' export const kycLevel2 = 'holo_kyc_2' -async function authCall(args) { +async function authCall(args, envirionment, hbsServicePort) { return httpCall({ - serviceUrl: AUTH_SERVICE_URL, - version: AUTH_SERVICE_VERSION, + serviceUrl: authServiceUrl(envirionment), + version: authServiceVersion(hbsServicePort), method: 'post', ...args }) } -export async function authenticateAgent(payload, signature) { +export async function authenticateAgent(payload, signature, envirionment, hbsServicePort) { try { const result = await authCall({ params: payload, endpoint: 'holo-client', headers: { 'X-Signature': signature - } + }, + envirionment, + hbsServicePort }) return result.data @@ -34,8 +36,8 @@ export async function authenticateAgent(payload, signature) { } } -export async function loadAgentKycLevel(payload, signature) { - const authResult = await authenticateAgent(payload, signature) +export async function loadAgentKycLevel(payload, signature, envirionment, hbsServicePort) { + const authResult = await authenticateAgent(payload, signature, envirionment, hbsServicePort) return (authResult && authResult.kyc) ? (authResult.kyc === kycLevel2) ? 2 : 1 : null } \ No newline at end of file diff --git a/src/stores/useClientStore.js b/src/stores/useClientStore.js index c1d66d9..e3936e2 100644 --- a/src/stores/useClientStore.js +++ b/src/stores/useClientStore.js @@ -48,8 +48,8 @@ const makeUseClientStore = ({ useInterfaceStore, onInit }) => defineStore('clien return result }, - async getKycLevel() { - const kycLevel = await useInterfaceStore().getKycLevel() + async getKycLevel(envirionment, hbsServicePort) { + const kycLevel = await useInterfaceStore().getKycLevel(envirionment, hbsServicePort) this.agentKyc = kycLevel return kycLevel } diff --git a/src/stores/useHoloStore.js b/src/stores/useHoloStore.js index 61fb6e0..a1ad897 100644 --- a/src/stores/useHoloStore.js +++ b/src/stores/useHoloStore.js @@ -102,7 +102,7 @@ const makeUseHoloStore = ({ connectionArgs, MockWebSdk }) => defineStore('holo', this.appInfo = await client.appInfo() return this.appInfo }, - async getKycLevel() { + async getKycLevel(envirionment, hbsServicePort) { const payload = { "email": this.agentEmail, "timestamp": Date.now() - (30 * 1000), // Subtract 30 sec to prevent "future" timestamp error from API @@ -110,7 +110,7 @@ const makeUseHoloStore = ({ connectionArgs, MockWebSdk }) => defineStore('holo', } const { _, signature } = await client.signPayload(payload) - const kycLevel = await loadAgentKycLevel(payload, signature) + const kycLevel = await loadAgentKycLevel(payload, signature, envirionment, hbsServicePort) this.kycLevel = kycLevel return kycLevel } diff --git a/src/stores/useHolochainStore.js b/src/stores/useHolochainStore.js index 6c89c4f..3eb11d2 100644 --- a/src/stores/useHolochainStore.js +++ b/src/stores/useHolochainStore.js @@ -117,7 +117,7 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, is_hpos_served, h resolve() }) }, - async getKycLevel() { + async getKycLevel(_, _) { return null // raw holochain doesn't have a mechanism for fetching agent's kyc level }, } diff --git a/src/stores/useHoloportAPIStore.js b/src/stores/useHoloportAPIStore.js index bf82e7e..eacb950 100644 --- a/src/stores/useHoloportAPIStore.js +++ b/src/stores/useHoloportAPIStore.js @@ -94,7 +94,7 @@ const makeUseHoloportAPIStore = ({ useHolochainStore }) => defineStore('holoport throw new Error(`No case in hposCall for ${method} method`) } }, - async getKycLevel() { + async getKycLevel(_, _) { const kycLevel = await this.hposHolochainCall({path: 'kyc', headers: {}, params: {}, method: 'get'}) return kycLevel ? (kycLevel === kycLevel2) ? 2 : 1 : null }, diff --git a/src/utils/hbsConfiguration.js b/src/utils/hbsConfiguration.js index 5dbde0d..f17dd4c 100644 --- a/src/utils/hbsConfiguration.js +++ b/src/utils/hbsConfiguration.js @@ -30,17 +30,19 @@ const HbsServiceURL = (service, key, port) => { [Environment.qa]: 'v1', [Environment.production]: 'v1' } - const CONFIG_ENVIRONMENT = ( import.meta.env ) ? import.meta.env.VITE_ENV : process.env.VUE_ENV - const HBS_SERVICE_PORT = ( import.meta.env ) ? import.meta.env.VITE_OPS_SERVICE_PORT : process.env.VUE_OPS_SERVICE_PORT - export const AUTH_SERVICE_URL = HbsServiceURL( - 'auth', - CONFIG_ENVIRONMENT || Environment.localNoBackend, - HBS_SERVICE_PORT || '3003' - ) - - export const AUTH_SERVICE_VERSION = CONFIG_ENVIRONMENT - ? AuthServiceVersion[CONFIG_ENVIRONMENT] + export const authServiceVersion = function(envirionment) { + return (envirionment) + ? AuthServiceVersion[envirionment] : AuthServiceVersion[Environment.local] + } + + export const authServiceUrl = function(envirionment, hbsServicePort) { + return HbsServiceURL( + 'auth', + envirionment || Environment.localNoBackend, + hbsServicePort || '3003' + ) + } \ No newline at end of file