Skip to content

Commit

Permalink
Update holochainStore for newer client, and other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiecarlton committed Jul 31, 2024
1 parent bf08adb commit a748c12
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 43 deletions.
57 changes: 33 additions & 24 deletions src/components/RegisterHapp.vue
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
<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 />
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
14 changes: 7 additions & 7 deletions src/stores/useClientStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ const makeUseClientStore = ({ useInterfaceStore, onInit, fetchKycLevel }) => def
// This could be more efficient by inspecting the contents of mutation
this.isReady = state.isReady

console.log('^&* useClientStore agent state', state)
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

if (state.appInfo?.agent_pub_key) {
this.agentKey = state.appInfo.agent_pub_key
// 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) {

console.log('^&* useClientStore agent.id', state.agentState?.id)
console.log('^&* useClientStore setting pubkey', state.agentState?.pubkey)

this.agentKey = state.agentState.pubkey
}
})
Expand Down
27 changes: 15 additions & 12 deletions src/stores/useHolochainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ import { hposHolochainCall } from '../services/hpos'

const HC_APP_TIMEOUT = 35_000

const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__";
const isLauncher = () => globalThis.window && __HC_LAUNCHER_ENV__ in globalThis.window;
const getLauncherEnvironment = () => isLauncher() ? globalThis.window[__HC_LAUNCHER_ENV__] : undefined;

const makeUseHolochainStore = ({ installed_app_id, app_ws_url, hc_admin_port }) => defineStore('holochain', {
state: () => ({
client: null,
signingCredentials: 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({
url: app_ws_url,
defaultTimeout: HC_APP_TIMEOUT,
})

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

this.client = holochainClient

Expand All @@ -52,9 +58,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,8 +102,7 @@ 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)
{
if(!this.isLauncher && !this.signingCredentials) {
this.setCredentials(cellId)
}

Expand Down

0 comments on commit a748c12

Please sign in to comment.