Skip to content

Commit 4d1234c

Browse files
committed
completed weProfileApi to use profileStore
1 parent 0338edc commit 4d1234c

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

web/src/api/weProfilesApi.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
import { AppWebsocket, CellId } from '@holochain/client'
22
import { WeServices } from '@lightningrodlabs/we-applet'
3-
import { ObjectFlags } from 'typescript'
4-
import { PROFILES_ZOME_NAME } from '../holochainConfig'
53
import { Profile, WhoAmIOutput } from '../types'
64
import { AgentPubKeyB64, UpdateInput } from '../types/shared'
7-
import callZome from './callZome'
85
import { WireRecord } from './hdkCrud'
6+
import { get } from 'svelte/store'
97

10-
const ZOME_FN_NAMES = {
11-
CREATE_WHOAMI: 'create_whoami',
12-
CREATE_IMPORTED_PROFILE: 'create_imported_profile',
13-
UPDATE_WHOAMI: 'update_whoami',
14-
WHOAMI: 'whoami',
15-
FETCH_AGENTS: 'fetch_agents',
16-
FETCH_AGENT_ADDRESS: 'fetch_agent_address',
17-
}
188
function weToAcornProfile(weProfile: WeProfile): Profile {
199
let acornProfile: Profile
2010
Object.keys(weProfile.fields).forEach((key) => {
@@ -40,8 +30,7 @@ function acornToWeProfile(acornProfile: Profile, nickname: string): WeProfile {
4030
return weProfile
4131
}
4232
async function getMyNickname(weServices: WeServices): Promise<string> {
43-
let myWeProfile: WeProfile
44-
(await weServices.profilesStore.fetchMyProfile()).subscribe((profile) => {myWeProfile = profile})
33+
let myWeProfile = get(await weServices.profilesStore.fetchMyProfile());
4534
return myWeProfile.nickname
4635
}
4736
export interface WeProfile {
@@ -84,8 +73,7 @@ const WeProfilesApi = (appWebsocket: AppWebsocket, weServices: WeServices) => {
8473
}
8574
},
8675
whoami: async (cellId: CellId): Promise<WhoAmIOutput> => {
87-
let myWeProfile
88-
(await weServices.profilesStore.fetchMyProfile()).subscribe((profile) => {myWeProfile = profile})
76+
let myWeProfile = get(await weServices.profilesStore.fetchMyProfile());
8977
return {
9078
actionHash: null,
9179
entryHash: null,
@@ -95,22 +83,12 @@ const WeProfilesApi = (appWebsocket: AppWebsocket, weServices: WeServices) => {
9583
}
9684
},
9785
fetchAgents: async (cellId: CellId): Promise<Array<Profile>> => {
98-
return callZome(
99-
appWebsocket,
100-
cellId,
101-
PROFILES_ZOME_NAME,
102-
ZOME_FN_NAMES.FETCH_AGENTS,
103-
null
104-
)
86+
let profiles: Array<Profile> = get(await weServices.profilesStore.fetchAllProfiles()).values().map((weProfile) => weToAcornProfile(weProfile));
87+
return profiles
10588
},
10689
fetchAgentAddress: async (cellId: CellId): Promise<AgentPubKeyB64> => {
107-
return callZome(
108-
appWebsocket,
109-
cellId,
110-
PROFILES_ZOME_NAME,
111-
ZOME_FN_NAMES.FETCH_AGENT_ADDRESS,
112-
null
113-
)
90+
// is this an alright way to convert the byte array to string?
91+
return new TextDecoder().decode(weServices.profilesStore.myAgentPubKey)
11492
},
11593
}
11694
}

0 commit comments

Comments
 (0)