Skip to content

Commit

Permalink
fix: get by identity (#6284)
Browse files Browse the repository at this point in the history
  • Loading branch information
septs authored May 19, 2022
1 parent 65050ec commit 6ea16e7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/web3-providers/src/NextID/kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@ export class NextIDStorageAPI implements NextIDBaseAPI.Storage {
identity: string,
pluginId: string,
): Promise<Result<T, string>> {
const response = await fetchJSON<{
interface Proof {
platform: NextIDPlatform
identity: string
content: Record<string, T>
}
interface Response {
persona: string
proofs: Array<{
platform: NextIDPlatform
identity: string
content: Record<string, T>
}>
}>(urlcat(BASE_URL, '/v1/kv', { persona: personaPublicKey }))
proofs: Proof[]
}
const response = await fetchJSON<Response>(urlcat(BASE_URL, '/v1/kv', { persona: personaPublicKey }))
if (!response.ok) return Err('User not found')

const data =
response.val.proofs?.filter((x) => x.identity === identity.toLowerCase() && x.platform === platform) ?? []
if (!data.length) return Err('Not found')
return Ok(data[0].content[pluginId])
const proofs = (response.val.proofs ?? [])
.filter((x) => x.platform === platform)
.filter((x) => x.identity === identity.toLowerCase())
if (!proofs.length) return Err('Not found')
return Ok(proofs[0].content[pluginId])
}
async get<T>(personaPublicKey: string): Promise<Result<T, string>> {
return fetchJSON(urlcat(BASE_URL, '/v1/kv', { persona: personaPublicKey }))
Expand Down

0 comments on commit 6ea16e7

Please sign in to comment.