Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wirednkod committed Sep 24, 2024
1 parent 8bc86c1 commit 833072a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 43 deletions.
7 changes: 5 additions & 2 deletions src/contexts/AccountsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface IAccountContext {
selectAccount: (account: InjectedPolkadotAccount | undefined) => void
}

type AccountAddressType = {
address: string
}

const AccountContext = createContext<IAccountContext | undefined>(undefined)

const AccountContextProvider = ({ children }: AccountContextProps) => {
Expand Down Expand Up @@ -50,8 +54,7 @@ const AccountContextProvider = ({ children }: AccountContextProps) => {
useEffect(() => {
if (localStorageAccount) {
const account = accounts.find(
(account: { address: string }) =>
account.address === localStorageAccount,
({ address }: AccountAddressType) => address === localStorageAccount,
)
if (account) {
selectAccount(account)
Expand Down
14 changes: 7 additions & 7 deletions src/contexts/NetworkContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export type SupportedNetworkNames =
| 'kusama-lc'
| NetworksFromConfig
export type ApiType = TypedApi<typeof dot | typeof ksm>
export type PeopleApiType = TypedApi<typeof dotPeople | typeof ksmPeople>
export type PeopleApiType = TypedApi<
typeof dotPeople | typeof ksmPeople | typeof westendPeople
>

export const descriptorName: Record<SupportedNetworkNames, ChainDefinition> = {
polkadot: dot,
Expand All @@ -71,12 +73,10 @@ export interface INetworkContext {
lightClientLoaded: boolean
isLight: boolean
selectNetwork: (network: string, shouldResetAccountAddress?: boolean) => void
client: PolkadotClient | undefined
api: TypedApi<typeof dot | typeof ksm> | undefined
peopleApi:
| TypedApi<typeof dotPeople | typeof ksmPeople | typeof westendPeople>
| undefined
peopleClient: PolkadotClient | undefined
client: PolkadotClient
api: TypedApi<typeof dot | typeof ksm>
peopleApi: PeopleApiType
peopleClient: PolkadotClient
network?: SupportedNetworkNames
peopleNetwork?: SupportedPeopleNetworkNames
assetInfo: AssetType
Expand Down
34 changes: 13 additions & 21 deletions src/hooks/useIdentity.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { useNetwork } from '@/contexts/NetworkContext'
import {
AccountInfoIF,
acceptedJudgement,
notAcceptedJudgement,
} from '@/lib/utils'
import { AccountInfoIF, acceptedJudgement } from '@/lib/utils'
import { DotPeopleQueries, IdentityJudgement } from '@polkadot-api/descriptors'
import { Binary } from 'polkadot-api'
import { useEffect, useState } from 'react'

const getJudgements = (judgements: [number, IdentityJudgement][]) => {
judgements.forEach((j) => {
if (acceptedJudgement.includes(j[1].type)) return true
if (notAcceptedJudgement.includes(j[1].type)) return false
})
return false
}
const getJudgements = (judgements: [number, IdentityJudgement][]) =>
judgements.some(([, j]) => acceptedJudgement.includes(j.type))

const dataToString = (value: number | string | Binary | undefined) =>
typeof value === 'object' ? value.asText() : (value ?? '')
Expand All @@ -36,7 +27,7 @@ const mapRawIdentity = (
legal: dataToString(legal.value),
matrix: dataToString(matrix.value),
twitter: dataToString(twitter.value),
judgement: !!judgements.length || getJudgements(judgements),
judgement: getJudgements(judgements),
}
}

Expand All @@ -46,15 +37,16 @@ export const useIdentity = (address: string | undefined) => {
const { peopleApi } = useNetwork()

useEffect(() => {
const retrieveIdentity = async () => {
if (!address) return
const id = await peopleApi?.query?.Identity.IdentityOf.getValue(address)
setIdentity({
address,
...mapRawIdentity(id),
if (!address || !peopleApi) return

peopleApi.query.Identity.IdentityOf.getValue(address)
.then((id) => {
setIdentity({
address,
...mapRawIdentity(id),
})
})
}
retrieveIdentity()
.catch(console.error)
}, [address, peopleApi])

return identity
Expand Down
6 changes: 0 additions & 6 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,3 @@ export type AccountInfoIF = {
}

export const acceptedJudgement = ['Reasonable', 'FeePaid', 'KnownGood']
export const notAcceptedJudgement = [
'Unknown',
'OutOfDate',
'LowQuality',
'Erroneous',
]
7 changes: 0 additions & 7 deletions src/pages/Delegate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ export const Delegate = () => {
setAmountVisible('0')
}, [api])

useEffect(() => {
if (!address || delegate) return

const res = getDelegateByAddress(address)
setDelegate(res)
}, [address, delegate, getDelegateByAddress])

if (!delegate || !api) return <div>No delegate found</div>

const onChangeAmount = (
Expand Down

0 comments on commit 833072a

Please sign in to comment.