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

Fix launcher hf #106

Merged
merged 5 commits into from
Aug 1, 2024
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
59 changes: 34 additions & 25 deletions src/components/RegisterHapp.vue
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
<template>

<div v-if="shouldShowRegisterScreen" class="register-screen">
<img v-if="logoUrl" :src="logoUrl" class="logo" />
<h1 class="happ-name">{{ happName }}</h1>
<div class="body">
Please enter the email you registered with and the registration code you received in your email.
</div>
<template v-if="isLoading">
LOADING...
</template>
<template v-else>
<img v-if="logoUrl" :src="logoUrl" class="logo" />
<h1 class="happ-name">{{ happName }}</h1>
<div class="body">
Please enter the email you registered with and the registration code you received in your email.
</div>

<input type="email" id="register-email"
v-model="emailInput"
class="register-input"
data-testid='register-email-input'
placeholder="Enter Email">
<input type="email" id="register-email"
v-model="emailInput"
class="register-input"
data-testid='register-email-input'
placeholder="Enter Email">

<input type="text" id="register-registration-code"
v-model="registrationCode"
class="register-input"
data-testid='registration-code-input'
placeholder="Enter Registration code">
<input type="text" id="register-registration-code"
v-model="registrationCode"
class="register-input"
data-testid='registration-code-input'
placeholder="Enter Registration code">

<div class="buttons">
<button v-if="signOut" class="logout-button" @click="handleLogout">Logout</button>
<Button class='save-button' :color="buttonColor" :disabled="!isValid" :isBusy="isBusy" @click="handleRegister">Submit</Button>
</div>
<div class="buttons">
<button v-if="signOut" class="logout-button" @click="handleLogout">Logout</button>
<Button class='save-button' :color="buttonColor" :disabled="!isValid" :isBusy="isBusy" @click="handleRegister">Submit</Button>
</div>

<div class="help-text">
Don't have a registration code? Please <a href="https://register.holo.host/" target="_blank">register with Holo.</a>
</div>
<div class="help-text">
Don't have a registration code? Please <a href="https://register.holo.host/" target="_blank">register with Holo.</a>
</div>
</template>
</div>

<slot v-else />
</template>

<script>
import Button from './Button.vue'
import { getMembraneProof } from '../utils/registration.hs'
import { getMembraneProof } from '../utils/registration.js'

export default {
name: 'RegisterHapp',
Expand Down Expand Up @@ -92,9 +97,13 @@ export default {
computed: {
isValid () {
// Simple, permissive email validation
const emailIsValid = this.email?.length > 5 && this.email?.includes('@')
const emailIsValid = this.emailInput?.length > 5 && this.emailInput?.includes('@')

return emailIsValid && this.registrationCode?.length > 0
},
isLoading () {
return !this.agentId
},
shouldShowRegisterScreen () {
return !this.isAnonymous && !this.hasMemproofs
},
Expand All @@ -109,7 +118,7 @@ export default {
try {
let memproof = await getMembraneProof({
registration_code: this.registrationCode,
email: this.email,
email: this.emailInput,
membrane_proof_server_url: this.membraneProofServerUrl,
membrane_proof_server_payload: this.membraneProofServerPayload,
agent_id: this.agentId,
Expand Down
10 changes: 8 additions & 2 deletions src/stores/useClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ const makeUseClientStore = ({ useInterfaceStore, onInit, fetchKycLevel }) => def
// This could be more efficient by inspecting the contents of mutation
this.isReady = state.isReady

this.hasMemproofs = state?.agentState?.hasMemproofs

if (state.appInfo?.agent_pub_key) {
this.agentKey = state.appInfo.agent_pub_key
}

// how we know we have memproofs in holo
this.hasMemproofs = state?.agentState?.hasMemproofs

// how we know we have memproofs in holochain (I realize this is not pretty rn)
if (state.appInfo) {
this.hasMemproofs = state.appInfo.status !== 'awaiting_memproofs'
}

// we override here the above here because in the holo case, agentState is in general much more up to date than appInfo
if (state.agentState?.pubkey) {
this.agentKey = state.agentState.pubkey
Expand Down
46 changes: 14 additions & 32 deletions src/stores/useHolochainStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inspect } from 'util'
import { AdminWebsocket, AppWebsocket, generateSigningKeyPair, setSigningCredentials } from '@holochain/client'
import { AppWebsocket } from '@holochain/client'
import { defineStore } from 'pinia'
import { presentHcSignal, listify } from '../utils'
import useIsLoadingStore from './useIsLoadingStore'
Expand All @@ -9,28 +9,32 @@ import { hposHolochainCall } from '../services/hpos'

const HC_APP_TIMEOUT = 35_000

const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port }) => defineStore('holochain', {
const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__";
const isLauncher = () => globalThis.window && __HC_LAUNCHER_ENV__ in globalThis.window;

const makeUseHolochainStore = ({ app_ws_url }) => defineStore('holochain', {
state: () => ({
client: null,
// These two values are subscribed to by clientStore
appInfo: null,
isReady: false,
signingCredentials: null
}),
getters: {
isAnonymous: _ => false, // for compatibility with holo
agentEmail: _ => null, // for compatibility with holo
agentEmail: _ => null, // for compatibility with holo,
isLauncher,
},
actions: {
// BEGIN useInterfaceStore methods

async initialize() {
try {
const holochainClient = await AppWebsocket.connect(
app_ws_url,
HC_APP_TIMEOUT,
signal => useSignalStore().handleSignal(presentHcSignal(signal))
)
const holochainClient = await AppWebsocket.connect({
JettTech marked this conversation as resolved.
Show resolved Hide resolved
url: app_ws_url,
defaultTimeout: HC_APP_TIMEOUT,
})

holochainClient.on('signal', signal => useSignalStore().handleSignal(presentHcSignal(signal)))

this.client = holochainClient

Expand All @@ -52,9 +56,7 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })

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

Expand Down Expand Up @@ -98,13 +100,6 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })
throw new Error(`Couldn't find provisioned cell with role_name ${role_name}`)
}

if( !this.signingCredentials)
{
this.setCredentials(cellId)
}

await this.signingCredentials

let result = null

const cell_id = [new Uint8Array(listify(cellId[0], (_, value) => (Number(value)))), new Uint8Array(listify(cellId[1], (_, value) => (Number(value))))]
Expand All @@ -126,19 +121,6 @@ const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port })

return result
},
setCredentials(cellId) {
this.signingCredentials = new Promise(async (resolve, reject) => {
try {
const adminWs = await AdminWebsocket.connect(`ws:localhost:${hc_admin_port}`)
await adminWs.authorizeSigningCredentials(cellId)
} catch(e) {
console.log(`holochainCallZome error authorizeSigningCredentials AdminWebsocket: ws:localhost:${hc_admin_port}`, e)
reject()
}

resolve()
})
},
async fetchAgentKycLevel(_, __) {
const kycLevel = await hposHolochainCall({path: 'host/kyc_level', headers: {}, params: {}, method: 'get'})
return kycLevel ? (kycLevel === kycLevel2) ? 2 : 1 : null
Expand Down
Loading