Skip to content

Commit

Permalink
Cleanup AccountName display (polkadot-js#2166)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr authored and jordy25519 committed Feb 20, 2020
1 parent 2233655 commit 3a6c16b
Showing 1 changed file with 20 additions and 45 deletions.
65 changes: 20 additions & 45 deletions packages/react-components/src/AccountName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ interface Props extends BareProps {
withShort?: boolean;
}

const JUDGEMENT_ENUM = [
{ value: 0, text: 'Unknown' },
{ value: 1, text: 'Fee paid' },
{ value: 2, text: 'Reasonable' },
{ value: 3, text: 'Known good' },
{ value: 4, text: 'Out of date' },
{ value: 5, text: 'Low quality' }
];
const DISPLAY_KEYS = ['display', 'legal', 'email', 'web', 'twitter', 'riot'];
const nameCache: Map<string, [boolean, [React.ReactNode, React.ReactNode | null]]> = new Map();

function defaultOrAddr (defaultName = '', _address: AccountId | AccountIndex | Address | string | Uint8Array, _accountIndex?: AccountIndex | null): [[React.ReactNode, React.ReactNode | null], boolean, boolean] {
Expand Down Expand Up @@ -64,7 +73,7 @@ function AccountName ({ children, className, defaultName, label, onClick, overri
const [accountId, setAccountId] = useState<string | null>(null);
const [isRegistrar, setIsRegistrar] = useState(false);
const [judgementAccountId, setJudgementAccountId] = useState<string | null>(null);
const [judgementEnum, setJudgementEnum] = useState(0);
const [judgementEnum, setJudgementEnum] = useState(2); // Reasonable
const [registrarIndex, setRegistrarIndex] = useState(-1);
const address = useMemo((): string => (value || '').toString(), [value]);

Expand Down Expand Up @@ -154,42 +163,15 @@ function AccountName ({ children, className, defaultName, label, onClick, overri
<td><AddressMini value={identity.parent} /></td>
</tr>
)}
{identity.display && (
<tr>
<td>{t('display')}</td>
<td>{identity.display}</td>
</tr>
)}
{identity.legal && (
<tr>
<td>{t('legal')}</td>
<td>{identity.legal}</td>
</tr>
)}
{identity.email && (
<tr>
<td>{t('email')}</td>
<td>{identity.email}</td>
</tr>
)}
{identity.web && (
<tr>
<td>{t('www')}</td>
<td>{identity.web}</td>
</tr>
)}
{identity.twitter && (
<tr>
<td>{t('twitter')}</td>
<td>{identity.twitter}</td>
</tr>
)}
{identity.riot && (
<tr>
<td>{t('riot')}</td>
<td>{identity.riot}</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>
Expand Down Expand Up @@ -264,14 +246,7 @@ function AccountName ({ children, className, defaultName, label, onClick, overri
<Dropdown
label={t('judgement')}
onChange={setJudgementEnum}
options={[
{ value: 0, text: 'Unknown' },
{ value: 1, text: 'Fee paid' },
{ value: 2, text: 'Reasonable' },
{ value: 3, text: 'Known good' },
{ value: 4, text: 'Out of date' },
{ value: 5, text: 'Low quality' }
]}
options={JUDGEMENT_ENUM}
value={judgementEnum}
/>
</Modal.Content>
Expand Down

0 comments on commit 3a6c16b

Please sign in to comment.