Skip to content

Commit

Permalink
identity
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Sep 22, 2024
1 parent 38dbc03 commit dd4a7f9
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 104 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"graphql-ws": "^5.16.0",
"polkadot-api": "^1.2.0",
"polkadot-api": "^1.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^5.1.0",
Expand Down
79 changes: 42 additions & 37 deletions packages/ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 32 additions & 11 deletions packages/ui/src/hooks/useIdentity.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
import { useEffect, useState } from 'react'
import { DeriveAccountInfo, DeriveAccountRegistration } from '@polkadot/api-derive/types'
import { useIdenityApi } from './useIdentityApi'
import { FixedSizeBinary, TypedApi } from 'polkadot-api'
import { dotPpl, IdentityData } from '@polkadot-api/descriptors'

export const useIdentity = (address?: string) => {
const { api } = useIdenityApi()
const [identity, setIdentity] = useState<DeriveAccountRegistration | null>(null)
const [identity, setIdentity] = useState<Record<string, any> | null>(null)

useEffect(() => {
if (!api || !address) {
return
}

let unsubscribe: () => void

api.derive.accounts
.info(address, (info: DeriveAccountInfo) => {
setIdentity(info.identity)
const unsub = (api as TypedApi<typeof dotPpl>).query.Identity.IdentityOf.watchValue(
address,
'best'
).subscribe((val) => {
const id: Record<string, any> = { judgements: [] }
val?.[0].judgements.forEach(([, judgement]) => {
id.judgements.push(judgement.type)
})
.then((unsub) => {
unsubscribe = unsub
Object.entries(val?.[0]?.info || {}).forEach(([key, value]) => {
if ((value as IdentityData)?.type !== 'None') {
// console.log('key', JSONprint(key));
// console.log('value', JSONprint(value));
const text = (value as IdentityData)?.value as FixedSizeBinary<2> | undefined
if (text) {
id[key] = text.asText()
}
}
})
.catch((e) => console.error(e))

return () => unsubscribe && unsubscribe()
setIdentity(id)
})

// api.derive.accounts
// .info(address, (info: DeriveAccountInfo) => {
// setIdentity(info.identity)
// })
// .then((unsub) => {
// unsubscribe = unsub
// })
// .catch((e) => console.error(e))

return () => unsub && unsub.unsubscribe()
}, [address, api])

return identity
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/utils/getDisplayArgs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { GenericCall } from '@polkadot/types'
import { AnyTuple } from '@polkadot/types/types'
import { Transaction } from 'polkadot-api'

export const getDisplayArgs = (call: GenericCall<AnyTuple> | false | undefined) =>
export const getDisplayArgs = (call: Transaction<any, any, any, any> | false | undefined) =>
call && call.toHuman().args
Loading

0 comments on commit dd4a7f9

Please sign in to comment.