From 6ee86ae57ed1168e908565a0c5026f903729f11b Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Wed, 15 Mar 2023 15:26:35 +0100 Subject: [PATCH] display discord identity in profile sidebar (#9185) * display discord identity in profile sidebar * use common discord key --- packages/page-accounts/src/Sidebar/Identity.tsx | 9 +++++++++ packages/page-accounts/src/modals/IdentityMain.tsx | 6 +++--- packages/react-hooks/src/types.ts | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/page-accounts/src/Sidebar/Identity.tsx b/packages/page-accounts/src/Sidebar/Identity.tsx index 40a4bfabee..5b08a40545 100644 --- a/packages/page-accounts/src/Sidebar/Identity.tsx +++ b/packages/page-accounts/src/Sidebar/Identity.tsx @@ -7,6 +7,7 @@ import React, { useMemo } from 'react'; import { AddressMini, AvatarItem, Expander, IconLink } from '@polkadot/react-components'; import { useApi, useRegistrars, useSubidentities, useToggle } from '@polkadot/react-hooks'; +import { AddressIdentityOtherDiscordKey } from '@polkadot/react-hooks/types'; import { isHex } from '@polkadot/util'; import { useTranslation } from '../translate.js'; @@ -138,6 +139,14 @@ function Identity ({ address, identity }: Props): React.ReactElement | nu )} + {identity.other && AddressIdentityOtherDiscordKey in identity.other && ( +
+
{t('discord')}
+
+ {identity.other[AddressIdentityOtherDiscordKey]} +
+
+ )} {identity.riot && (
{t('riot')}
diff --git a/packages/page-accounts/src/modals/IdentityMain.tsx b/packages/page-accounts/src/modals/IdentityMain.tsx index be8a930a6a..3ce97fcac3 100644 --- a/packages/page-accounts/src/modals/IdentityMain.tsx +++ b/packages/page-accounts/src/modals/IdentityMain.tsx @@ -10,6 +10,7 @@ import { ApiPromise } from '@polkadot/api'; import { Input, InputBalance, Modal, Toggle, TxButton } from '@polkadot/react-components'; import { getAddressMeta } from '@polkadot/react-components/util'; import { useApi, useCall } from '@polkadot/react-hooks'; +import { AddressIdentityOtherDiscordKey } from '@polkadot/react-hooks/types'; import { u8aToString } from '@polkadot/util'; import { useTranslation } from '../translate.js'; @@ -33,7 +34,6 @@ interface ValueState { } const WHITESPACE = [' ', '\t']; -const ADDITIONAL_FIELD_DISCORD = 'Discord'; function setData (data: Data, setActive: null | ((isActive: boolean) => void), setVal: (val: string) => void): void { if (data.isRaw) { @@ -96,7 +96,7 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React setData(info.legal, setHasLegal, setValLegal); setData(info.riot, setHasRiot, setValRiot); setData(info.twitter, setHasTwitter, setValTwitter); - const infoDiscord = setAdditionalFieldData(api, info, ADDITIONAL_FIELD_DISCORD, setHasDiscord, setValDiscord); + const infoDiscord = setAdditionalFieldData(api, info, AddressIdentityOtherDiscordKey, setHasDiscord, setValDiscord); setData(info.web, setHasWeb, setValWeb); @@ -124,7 +124,7 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React setInfo({ info: { additional: [ - (okDiscord && hasDiscord ? [{ raw: ADDITIONAL_FIELD_DISCORD }, { raw: valDiscord }] : null) + (okDiscord && hasDiscord ? [{ raw: AddressIdentityOtherDiscordKey }, { raw: valDiscord }] : null) ].filter((item) => !!item), display: { [okDisplay ? 'raw' : 'none']: valDisplay || null }, email: { [okEmail && hasEmail ? 'raw' : 'none']: okEmail && hasEmail ? valEmail : null }, diff --git a/packages/react-hooks/src/types.ts b/packages/react-hooks/src/types.ts index 0333845257..3f3270adde 100644 --- a/packages/react-hooks/src/types.ts +++ b/packages/react-hooks/src/types.ts @@ -104,6 +104,8 @@ export interface AddressFlags extends DeriveAccountFlags { isNominator: boolean; } +export const AddressIdentityOtherDiscordKey = 'Discord'; + export interface AddressIdentity extends DeriveAccountRegistration { isExistent: boolean; isKnownGood: boolean;