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

Rollback hpos store #69

Merged
merged 3 commits into from
Sep 26, 2023
Merged
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
69 changes: 68 additions & 1 deletion src/stores/useHolochainStore.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { inspect } from 'util'
import axios from 'axios'
import { AdminWebsocket, AppWebsocket, generateSigningKeyPair, setSigningCredentials } from '@holochain/client'
import { defineStore } from 'pinia'
import { presentHcSignal, listify } from '../utils'
import useIsLoadingStore from './useIsLoadingStore'
import useSignalStore from './useSignalStore'
import { kycLevel2 } from '../services/hbs'

const HC_APP_TIMEOUT = 35_000

Expand Down Expand Up @@ -104,6 +106,18 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, is_hpos_served, h

return result
},
async zomeCall(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) => {
try {
Expand All @@ -117,8 +131,61 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, is_hpos_served, h
resolve()
})
},
async hposHolochainCall({
path,
headers: userHeaders = {},
params,
method = 'post',
}) {
const axiosConfig = {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
}

const HPOS_API_URL = `${window.location.protocol}//${window.location.host}`
const pathPrefix = '/holochain-api/v1/'
const fullUrl = `${HPOS_API_URL}${pathPrefix}${path}`

const authToken = localStorage.getItem('authToken')

const headers = {
'X-Hpos-Auth-Token': authToken,
...axiosConfig.headers,
...userHeaders
}

let response

switch (method) {
case 'get':
response = await axios.get(fullUrl, { params, headers })
return response.data

case 'post':
response = await axios.post(fullUrl, params, { headers })
return response.data

case 'put':
response = await axios.put(fullUrl, params, { headers })
return response.data

case 'delete':
response = await axios.delete(fullUrl, { params, headers })
return response.data

default:
throw new Error(`No case in hposCall for ${method} method`)
}
},
async loadAgentKycLevel(_, __) {
return null // raw holochain doesn't have a mechanism for fetching agent's kyc level
if( !is_hpos_served) {
return null // raw holochain doesn't have a mechanism for retrieving agent's kyc
}

const kycLevel = await this.hposHolochainCall({path: 'kyc', headers: {}, params: {}, method: 'get'})
return kycLevel ? (kycLevel === kycLevel2) ? 2 : 1 : null
},
}
})
Expand Down
104 changes: 0 additions & 104 deletions src/stores/useHoloportAPIStore.js

This file was deleted.

Loading