Skip to content

Commit

Permalink
Add hbs store and move hbs functionality from holo store (#92)
Browse files Browse the repository at this point in the history
* add hbs store and move hbs functionality from holo store

* rename useHBSStore to useHbsStore
  • Loading branch information
Paterick authored Mar 13, 2024
1 parent e96acdc commit 26d2d31
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
40 changes: 40 additions & 0 deletions src/stores/useHbsStore.js
Original file line number Diff line number Diff line change
@@ -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
30 changes: 2 additions & 28 deletions src/stores/useHoloStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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,
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 26d2d31

Please sign in to comment.