|
@@ -6,16 +6,14 @@ import { DeriveAccountInfo, DeriveAccountRegistration } from '@polkadot/api-deri
|
|
import { BareProps } from '@polkadot/react-api/types';
|
|
import { BareProps } from '@polkadot/react-api/types';
|
|
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
|
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
|
|
|
|
|
-import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
+import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
import styled from 'styled-components';
|
|
import styled from 'styled-components';
|
|
import registry from '@polkadot/react-api/typeRegistry';
|
|
import registry from '@polkadot/react-api/typeRegistry';
|
|
-import { useCall, useApi, useRegistrars, useToggle } from '@polkadot/react-hooks';
|
|
|
|
|
|
+import { AccountSidebarToggle } from '@polkadot/app-accounts/Sidebar';
|
|
|
|
+import { useCall, useApi } from '@polkadot/react-hooks';
|
|
import { stringToU8a } from '@polkadot/util';
|
|
import { stringToU8a } from '@polkadot/util';
|
|
|
|
|
|
-import { useTranslation } from './translate';
|
|
|
|
import { getAddressName } from './util';
|
|
import { getAddressName } from './util';
|
|
-import AccountNameJudgement from './AccountNameJudgement';
|
|
|
|
-import AddressMini from './AddressMini';
|
|
|
|
import Badge from './Badge';
|
|
import Badge from './Badge';
|
|
import Icon from './Icon';
|
|
import Icon from './Icon';
|
|
|
|
|
|
@@ -29,9 +27,9 @@ interface Props extends BareProps {
|
|
// this is used by app-account/addresses to toggle editing
|
|
// this is used by app-account/addresses to toggle editing
|
|
toggle?: boolean;
|
|
toggle?: boolean;
|
|
value: AccountId | AccountIndex | Address | string | Uint8Array | null | undefined;
|
|
value: AccountId | AccountIndex | Address | string | Uint8Array | null | undefined;
|
|
|
|
+ withSidebar?: boolean;
|
|
}
|
|
}
|
|
|
|
|
|
-const DISPLAY_KEYS = ['display', 'legal', 'email', 'web', 'twitter', 'riot'];
|
|
|
|
const KNOWN: [AccountId, string][] = [
|
|
const KNOWN: [AccountId, string][] = [
|
|
[registry.createType('AccountId', stringToU8a('modlpy/socie'.padEnd(32, '\0'))), 'Society'],
|
|
[registry.createType('AccountId', stringToU8a('modlpy/socie'.padEnd(32, '\0'))), 'Society'],
|
|
[registry.createType('AccountId', stringToU8a('modlpy/trsry'.padEnd(32, '\0'))), 'Treasury']
|
|
[registry.createType('AccountId', stringToU8a('modlpy/trsry'.padEnd(32, '\0'))), 'Treasury']
|
|
@@ -98,16 +96,14 @@ function extractName (address: string, accountIndex?: AccountIndex, defaultName?
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
-function createIdElem (badgeType: 'green' | 'brown' | 'gray', nameElem: React.ReactNode, infoElem: React.ReactNode, hoverElem?: React.ReactNode, onJudge?: undefined | (() => void)): React.ReactNode {
|
|
|
|
|
|
+function createIdElem (badgeType: 'green' | 'brown' | 'gray', nameElem: React.ReactNode, infoElem: React.ReactNode): React.ReactNode {
|
|
return (
|
|
return (
|
|
<div className='via-identity'>
|
|
<div className='via-identity'>
|
|
<Badge
|
|
<Badge
|
|
- hover={hoverElem}
|
|
|
|
info={infoElem}
|
|
info={infoElem}
|
|
isInline
|
|
isInline
|
|
isSmall
|
|
isSmall
|
|
isTooltip
|
|
isTooltip
|
|
- onClick={onJudge}
|
|
|
|
type={badgeType}
|
|
type={badgeType}
|
|
/>
|
|
/>
|
|
{nameElem}
|
|
{nameElem}
|
|
@@ -115,11 +111,10 @@ function createIdElem (badgeType: 'green' | 'brown' | 'gray', nameElem: React.Re
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
-function extractIdentity (address: string, identity: DeriveAccountRegistration, onJudge: undefined | (() => void), t: (key: string, opts?: object) => string): React.ReactNode {
|
|
|
|
|
|
+function extractIdentity (address: string, identity: DeriveAccountRegistration): React.ReactNode {
|
|
const judgements = identity.judgements.filter(([, judgement]): boolean => !judgement.isFeePaid);
|
|
const judgements = identity.judgements.filter(([, judgement]): boolean => !judgement.isFeePaid);
|
|
const isGood = judgements.some(([, judgement]): boolean => judgement.isKnownGood || judgement.isReasonable);
|
|
const isGood = judgements.some(([, judgement]): boolean => judgement.isKnownGood || judgement.isReasonable);
|
|
const isBad = judgements.some(([, judgement]): boolean => judgement.isErroneous || judgement.isLowQuality);
|
|
const isBad = judgements.some(([, judgement]): boolean => judgement.isErroneous || judgement.isLowQuality);
|
|
- const waitCount = identity.judgements.length - judgements.length;
|
|
|
|
const displayName = isGood
|
|
const displayName = isGood
|
|
? identity.display
|
|
? identity.display
|
|
: (identity.display || '').replace(/[^\x20-\x7E]/g, '');
|
|
: (identity.display || '').replace(/[^\x20-\x7E]/g, '');
|
|
@@ -130,43 +125,6 @@ function extractIdentity (address: string, identity: DeriveAccountRegistration,
|
|
: identity.displayParent.replace(/[^\x20-\x7E]/g, '')
|
|
: identity.displayParent.replace(/[^\x20-\x7E]/g, '')
|
|
)
|
|
)
|
|
: undefined;
|
|
: undefined;
|
|
- const hoverElem = (
|
|
|
|
- <div>
|
|
|
|
- <div>
|
|
|
|
- {
|
|
|
|
- judgements.length
|
|
|
|
- ? (judgements.length === 1
|
|
|
|
- ? t('1 judgement')
|
|
|
|
- : t('{{count}} judgements', { replace: { count: judgements.length } })
|
|
|
|
- )
|
|
|
|
- : t('no judgements')
|
|
|
|
- }{judgements.length ? ': ' : ''}{judgements.map(([, judgement]): string => judgement.toString()).join(', ')}{
|
|
|
|
- waitCount
|
|
|
|
- ? t(' ({{count}} waiting)', { replace: { count: waitCount } })
|
|
|
|
- : ''
|
|
|
|
- }
|
|
|
|
- </div>
|
|
|
|
- <table>
|
|
|
|
- <tbody>
|
|
|
|
- {identity.parent && (
|
|
|
|
- <tr>
|
|
|
|
- <td>{t('parent')}</td>
|
|
|
|
- <td><AddressMini value={identity.parent} /></td>
|
|
|
|
- </tr>
|
|
|
|
- )}
|
|
|
|
- {DISPLAY_KEYS
|
|
|
|
- .filter((key): boolean => !!identity[key as 'web'])
|
|
|
|
- .map((key): React.ReactNode => (
|
|
|
|
- <tr key={key}>
|
|
|
|
- <td>{t(key)}</td>
|
|
|
|
- <td>{identity[key as 'web']}</td>
|
|
|
|
- </tr>
|
|
|
|
- ))
|
|
|
|
- }
|
|
|
|
- </tbody>
|
|
|
|
- </table>
|
|
|
|
- </div>
|
|
|
|
- );
|
|
|
|
const nameElem = displayParent
|
|
const nameElem = displayParent
|
|
? <span className={`name ${isGood && 'isGood'}`}><span className='top'>{displayParent}</span><span className='sub'>/{displayName}</span></span>
|
|
? <span className={`name ${isGood && 'isGood'}`}><span className='top'>{displayParent}</span><span className='sub'>/{displayName}</span></span>
|
|
: <span className={`name ${isGood && 'isGood'}`}>{displayName}</span>;
|
|
: <span className={`name ${isGood && 'isGood'}`}>{displayName}</span>;
|
|
@@ -176,16 +134,14 @@ function extractIdentity (address: string, identity: DeriveAccountRegistration,
|
|
nameCache.set(address, [false, displayParent ? [displayParent, displayName] : [displayName, null]]);
|
|
nameCache.set(address, [false, displayParent ? [displayParent, displayName] : [displayName, null]]);
|
|
displayCache.set(address, createIdElem(badgeType, nameElem, infoElem));
|
|
displayCache.set(address, createIdElem(badgeType, nameElem, infoElem));
|
|
|
|
|
|
- return createIdElem(badgeType, nameElem, infoElem, hoverElem, onJudge);
|
|
|
|
|
|
+ return createIdElem(badgeType, nameElem, infoElem);
|
|
}
|
|
}
|
|
|
|
|
|
-function AccountName ({ children, className, defaultName, label, noLookup, onClick, override, toggle, value }: Props): React.ReactElement<Props> {
|
|
|
|
- const { t } = useTranslation();
|
|
|
|
|
|
+function AccountName ({ children, className, defaultName, label, noLookup, onClick, override, toggle, value, withSidebar }: Props): React.ReactElement<Props> {
|
|
const { api } = useApi();
|
|
const { api } = useApi();
|
|
- const { isRegistrar, registrars } = useRegistrars(noLookup);
|
|
|
|
- const [isJudgementOpen, toggleJudgement] = useToggle();
|
|
|
|
const info = useCall<DeriveAccountInfo>(!noLookup && api.derive.accounts.info, [value]);
|
|
const info = useCall<DeriveAccountInfo>(!noLookup && api.derive.accounts.info, [value]);
|
|
const [name, setName] = useState<React.ReactNode>(() => extractName((value || '').toString(), undefined, defaultName));
|
|
const [name, setName] = useState<React.ReactNode>(() => extractName((value || '').toString(), undefined, defaultName));
|
|
|
|
+ const toggleSidebar = useContext(AccountSidebarToggle);
|
|
|
|
|
|
// set the actual nickname, local name, accountIndex, accountId
|
|
// set the actual nickname, local name, accountIndex, accountId
|
|
useEffect((): void => {
|
|
useEffect((): void => {
|
|
@@ -195,7 +151,7 @@ function AccountName ({ children, className, defaultName, label, noLookup, onCli
|
|
if (api.query.identity?.identityOf) {
|
|
if (api.query.identity?.identityOf) {
|
|
setName(() =>
|
|
setName(() =>
|
|
identity?.display
|
|
identity?.display
|
|
- ? extractIdentity(cacheAddr, identity, isRegistrar ? toggleJudgement : undefined, t)
|
|
|
|
|
|
+ ? extractIdentity(cacheAddr, identity)
|
|
: extractName(cacheAddr, accountIndex)
|
|
: extractName(cacheAddr, accountIndex)
|
|
);
|
|
);
|
|
} else if (nickname) {
|
|
} else if (nickname) {
|
|
@@ -205,32 +161,40 @@ function AccountName ({ children, className, defaultName, label, noLookup, onCli
|
|
} else {
|
|
} else {
|
|
setName(defaultOrAddr(defaultName, cacheAddr, accountIndex));
|
|
setName(defaultOrAddr(defaultName, cacheAddr, accountIndex));
|
|
}
|
|
}
|
|
- }, [api, defaultName, info, isRegistrar, t, toggle, toggleJudgement, value]);
|
|
|
|
|
|
+ }, [api, defaultName, info, toggle, value]);
|
|
|
|
+
|
|
|
|
+ const _onNameEdit = useCallback(
|
|
|
|
+ () => setName(defaultOrAddr(defaultName, (value || '').toString())),
|
|
|
|
+ [defaultName, value]
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const _onToggleSidebar = useCallback(
|
|
|
|
+ () => toggleSidebar && value && toggleSidebar([value.toString(), _onNameEdit]),
|
|
|
|
+ [_onNameEdit, toggleSidebar, value]
|
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
return (
|
|
- <>
|
|
|
|
- {isJudgementOpen && (
|
|
|
|
- <AccountNameJudgement
|
|
|
|
- address={(value || '').toString()}
|
|
|
|
- registrars={registrars}
|
|
|
|
- toggleJudgement={toggleJudgement}
|
|
|
|
- />
|
|
|
|
- )}
|
|
|
|
- <div
|
|
|
|
- className={`ui--AccountName ${className}`}
|
|
|
|
- onClick={
|
|
|
|
- override
|
|
|
|
- ? undefined
|
|
|
|
- : onClick
|
|
|
|
- }
|
|
|
|
- >
|
|
|
|
- {label || ''}{override || name}{children}
|
|
|
|
- </div>
|
|
|
|
- </>
|
|
|
|
|
|
+ <div
|
|
|
|
+ className={`ui--AccountName ${withSidebar && 'withSidebar'} ${className}`}
|
|
|
|
+ onClick={
|
|
|
|
+ withSidebar
|
|
|
|
+ ? _onToggleSidebar
|
|
|
|
+ : onClick
|
|
|
|
+ }
|
|
|
|
+ >
|
|
|
|
+ {label || ''}{override || name}{children}
|
|
|
|
+ </div>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
export default React.memo(styled(AccountName)`
|
|
export default React.memo(styled(AccountName)`
|
|
|
|
+ border: 1px dotted transparent;
|
|
|
|
+
|
|
|
|
+ &.withSidebar:hover {
|
|
|
|
+ border-bottom-color: #333;
|
|
|
|
+ cursor: help !important;
|
|
|
|
+ }
|
|
|
|
+
|
|
.via-identity {
|
|
.via-identity {
|
|
display: inline-block;
|
|
display: inline-block;
|
|
overflow: hidden;
|
|
overflow: hidden;
|