From 26d2d314de9ba0e09b30ff9f7bac6f6dff302c72 Mon Sep 17 00:00:00 2001 From: Patrick Winfield Date: Wed, 13 Mar 2024 15:09:10 -0600 Subject: [PATCH] Add hbs store and move hbs functionality from holo store (#92) * add hbs store and move hbs functionality from holo store * rename useHBSStore to useHbsStore --- src/stores/useHbsStore.js | 40 ++++++++++++++++++++++++++++++++++++++ src/stores/useHoloStore.js | 30 ++-------------------------- 2 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 src/stores/useHbsStore.js diff --git a/src/stores/useHbsStore.js b/src/stores/useHbsStore.js new file mode 100644 index 0000000..e7290b6 --- /dev/null +++ b/src/stores/useHbsStore.js @@ -0,0 +1,40 @@ +import { defineStore } from 'pinia' +import { fetchAgentKycLevel, registrationFetchJurisdictions } from '../services/hbs' + +const makeUseHbsStore = ({ useHoloStore }) => { + return defineStore('hbs', { + state: () => ({ + kycLevel: null, + jurisdictions: [] + }), + getters: { + agentKycLevel: state => state.kycLevel, + hbsJurisdictions: state => state.jurisdictions + }, + actions: { + async loadAgentKycLevel(environment, hbsServicePort) { + const payload = { + "email": useHoloStore().agentEmail, + "timestamp": Date.now() - (30 * 1000), // Subtract 30 sec to prevent "future" timestamp error from API + "pubKey": useHoloStore().agentId + } + + const { _, signature } = await await useHoloStore().signPayload(payload) + const kycLevel = await fetchAgentKycLevel(payload, signature, environment, hbsServicePort) + this.kycLevel = kycLevel + return kycLevel + }, + async loadJurisdictions(environment, hbsServicePort) { + try { + registrationFetchJurisdictions(environment, hbsServicePort).then((jurisdictions) => { + this.jurisdictions = jurisdictions.data + }) + } catch (e) { + console.error(`Error fetching jurisdictions: ${e}`) + } + } + } + }) +} + +export default makeUseHbsStore \ No newline at end of file diff --git a/src/stores/useHoloStore.js b/src/stores/useHoloStore.js index dca1fb7..f40bb66 100644 --- a/src/stores/useHoloStore.js +++ b/src/stores/useHoloStore.js @@ -2,7 +2,6 @@ import WebSdk from '@holo-host/web-sdk' import { defineStore } from 'pinia' import useIsLoadingStore from './useIsLoadingStore' import useSignalStore from './useSignalStore' -import { fetchAgentKycLevel, registrationFetchJurisdictions } from '../services/hbs' const msgpack = require('@msgpack/msgpack') @@ -16,9 +15,7 @@ const makeUseHoloStore = ({ connectionArgs, MockWebSdk }) => defineStore('holo', isAuthFormOpen: false, // These two values are subscribed to by clientStore isReady: false, - appInfo: null, - kycLevel: null, - jurisdictions: [] + appInfo: null }), getters: { isAnonymous: state => state.agentState && state.agentState.isAnonymous, @@ -27,9 +24,7 @@ const makeUseHoloStore = ({ connectionArgs, MockWebSdk }) => defineStore('holo', error: state => state.agentState && !state.agentState.isAvailable && (state.connectionError || state.agentState.unrecoverableError), agentKey: (state) => state.appInfo?.agent_pub_key, agentId: state => state.agentState?.id, - agentEmail: state => state.agentState?.email, - agentKycLevel: state => state.kycLevel, - hbsJurisdictions: state => state.jurisdictions + agentEmail: state => state.agentState?.email }, actions: { async initialize() { @@ -106,27 +101,6 @@ const makeUseHoloStore = ({ connectionArgs, MockWebSdk }) => defineStore('holo', this.appInfo = await client.appInfo() return this.appInfo }, - async loadAgentKycLevel(environment, hbsServicePort) { - const payload = { - "email": this.agentEmail, - "timestamp": Date.now() - (30 * 1000), // Subtract 30 sec to prevent "future" timestamp error from API - "pubKey": this.agentId - } - - const { _, signature } = await client.signPayload(payload) - const kycLevel = await fetchAgentKycLevel(payload, signature, environment, hbsServicePort) - this.kycLevel = kycLevel - return kycLevel - }, - async loadJurisdictions(environment, hbsServicePort) { - try { - registrationFetchJurisdictions(environment, hbsServicePort).then((jurisdictions) => { - this.jurisdictions = jurisdictions.data - }) - } catch (e) { - console.error(`Error fetching jurisdictions: ${e}`) - } - }, async signPayload(payload) { return client.signPayload(payload) }