diff --git a/packages/apps/src/Apps.tsx b/packages/apps/src/Apps.tsx index d315df6137..558b787103 100644 --- a/packages/apps/src/Apps.tsx +++ b/packages/apps/src/Apps.tsx @@ -32,11 +32,12 @@ function WarmUp (): React.ReactElement { const { api, isApiReady } = useApi(); const fees = useCall(isApiReady ? api.derive.balances.fees : undefined, []); const indexes = useCall(isApiReady ? api.derive.accounts.indexes : undefined, []); + const registrars = useCall(isApiReady ? api.query.identity?.registrars : undefined, []); const staking = useCall(isApiReady ? api.derive.staking.overview : undefined, []); const [hasValues, setHasValues] = useState(false); useEffect((): void => { - setHasValues(!!fees || !!indexes || !!staking); + setHasValues(!!fees || !!indexes || !!registrars || !!staking); }, []); return ( diff --git a/packages/react-query/src/AccountName.tsx b/packages/react-components/src/AccountName.tsx similarity index 58% rename from packages/react-query/src/AccountName.tsx rename to packages/react-components/src/AccountName.tsx index 161faa7c4c..b7d3586149 100644 --- a/packages/react-query/src/AccountName.tsx +++ b/packages/react-components/src/AccountName.tsx @@ -4,15 +4,23 @@ import { DeriveAccountInfo } from '@polkadot/api-derive/types'; import { BareProps } from '@polkadot/react-api/types'; -import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces'; +import { AccountId, AccountIndex, Address, RegistrarInfo } from '@polkadot/types/interfaces'; import React, { useEffect, useMemo, useState } from 'react'; import styled from 'styled-components'; -import { Badge, Icon } from '@polkadot/react-components'; -import { getAddressName } from '@polkadot/react-components/util'; -import { useCall, useApi } from '@polkadot/react-hooks'; +import { useCall, useAccounts, useApi, useToggle } from '@polkadot/react-hooks'; +import { Option } from '@polkadot/types'; import { useTranslation } from './translate'; +import { getAddressName } from './util'; +import Badge from './Badge'; +import Button from './Button'; +import Dropdown from './Dropdown'; +import Icon from './Icon'; +import Input from './Input'; +import InputAddress from './InputAddress'; +import Modal from './Modal'; +import TxButton from './TxButton'; interface Props extends BareProps { children?: React.ReactNode; @@ -50,7 +58,15 @@ function defaultOrAddr (defaultName = '', _address: AccountId | AccountIndex | A function AccountName ({ children, className, defaultName, label, onClick, override, style, toggle, value, withShort }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); + const { allAccounts } = useAccounts(); + const [isJudgementOpen, toggleJudgement] = useToggle(); + const registrars = useCall[]>(api.query.identity?.registrars, []); const info = useCall(api.derive.accounts.info as any, [value]); + const [accountId, setAccountId] = useState(null); + const [isRegistrar, setIsRegistrar] = useState(false); + const [judgementAccountId, setJudgementAccountId] = useState(null); + const [judgementEnum, setJudgementEnum] = useState(0); + const [registrarIndex, setRegistrarIndex] = useState(-1); const address = useMemo((): string => (value || '').toString(), [value]); const _extractName = (accountId?: AccountId, accountIndex?: AccountIndex): React.ReactNode => { @@ -65,9 +81,43 @@ function AccountName ({ children, className, defaultName, label, onClick, overri const [name, setName] = useState((): React.ReactNode => _extractName()); + useEffect((): void => { + if (allAccounts && registrars) { + setIsRegistrar( + registrars + .map((registrar): string| null => + registrar.isSome + ? registrar.unwrap().account.toString() + : null + ) + .some((regId): boolean => !!regId && allAccounts.includes(regId)) + ); + } + }, [allAccounts, registrars]); + + useEffect((): void => { + if (registrars && judgementAccountId) { + setRegistrarIndex( + registrars + .map((registrar): string| null => + registrar.isSome + ? registrar.unwrap().account.toString() + : null + ) + .indexOf(judgementAccountId) + ); + } else { + setRegistrarIndex(-1); + } + }, [judgementAccountId, registrars]); + useEffect((): void => { const { accountId, accountIndex, identity, nickname } = info || {}; + if (accountId) { + setAccountId(accountId.toString()); + } + if (api.query.identity?.identityOf) { if (identity?.display) { const isGood = identity.judgements.some(([, judgement]): boolean => judgement.isKnownGood || judgement.isReasonable); @@ -120,6 +170,7 @@ function AccountName ({ children, className, defaultName, label, onClick, overri isInline isSmall isTooltip + onClick={isRegistrar ? toggleJudgement : undefined} type={ isGood ? 'green' @@ -148,17 +199,71 @@ function AccountName ({ children, className, defaultName, label, onClick, overri }, [info, toggle]); return ( -
- {label || ''}{override || name}{children} -
+ <> + {isJudgementOpen && ( + + + + + + + + +