Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for hpos store #68

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/stores/useClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const makeUseClientStore = ({ useInterfaceStore, onInit }) => defineStore('clien

useInterfaceStore().$subscribe((_, state) => {
// This could be more efficient by inspecting the contents of mutation
this.isReady = state.isReady
this.isReady = state

if (state.appInfo?.agent_pub_key) {
this.agentKey = state.appInfo.agent_pub_key
Expand Down
59 changes: 50 additions & 9 deletions src/stores/useHoloportAPIStore.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,69 @@
import axios from 'axios'
import { generateSigningKeyPair, setSigningCredentials } from '@holochain/client'
import { AppWebsocket, generateSigningKeyPair, setSigningCredentials } from '@holochain/client'
import { defineStore } from 'pinia'
import { listify } from '../utils'
import { kycLevel2 } from '../services/hbs'

const makeUseHoloportAPIStore = ({ useHolochainStore }) => defineStore('holoportAPI', {
const makeUseHoloportAPIStore = () => defineStore('holoportAPI', {
state: () => ({
client: useHolochainStore().client,
client: null,
// These two values are subscribed to by clientStore
appInfo: useHolochainStore().appInfo,
isReady: useHolochainStore().isReady,
signingCredentials: useHolochainStore().signingCredentials
appInfo: null,
isReady: false,
signingCredentials: null
}),
actions: {
async initialize() {
useHolochainStore().initialize()
try {
const holochainClient = await AppWebsocket.connect(
app_ws_url,
HC_APP_TIMEOUT,
signal => useSignalStore().handleSignal(presentHcSignal(signal))
)

this.client = holochainClient

holochainClient.client.socket.onclose = function(e) {
console.log(
'Socket to Holochain App Interface has closed.',
inspect(e)
)
this.client = null
this.isReady = false
}

this.loadAppInfo()
} catch (e) {
console.error('Holochain connection error ', e)
this.isReady = false
}
},

async loadAppInfo() {
useHolochainStore().loadAppInfo()
try {
const appInfo = await this.client.appInfo({
installed_app_id
})
this.appInfo = appInfo
this.isReady = true

return appInfo
} catch (error) {
console.error('appInfo() returned error.', inspect(error))
}
},

async callZome(args) {
useHolochainStore().callZome(args)
const zomeCallArgs = {
appId: installed_app_id,
roleId: args.role_name,
zomeName: args.zome_name,
fnName: args.fn_name,
payload: args.payload
}

const response = await this.hposHolochainCall({path: 'zome_call', headers: {}, params: zomeCallArgs})
return response
},
setCredentials(cellId) {
this.signingCredentials = new Promise(async (resolve, reject) => {
Expand Down
Loading