diff --git a/packages/page-accounts/src/Sidebar/Sidebar.tsx b/packages/page-accounts/src/Sidebar/Sidebar.tsx index d0366091c3..517ed129cb 100644 --- a/packages/page-accounts/src/Sidebar/Sidebar.tsx +++ b/packages/page-accounts/src/Sidebar/Sidebar.tsx @@ -24,7 +24,7 @@ interface Props { function Sidebar ({ address, className = '', onClose, onUpdateName }: Props): React.ReactElement { const { t } = useTranslation(); - const { flags, identity, isEditingName, isEditingTags, meta, name, onForgetAddress, onSaveName, onSaveTags, setName, setTags, tags, toggleIsEditingName, toggleIsEditingTags } = useAccountInfo(address); + const { accountIndex, flags, identity, isEditingName, isEditingTags, meta, name, onForgetAddress, onSaveName, onSaveTags, setName, setTags, tags, toggleIsEditingName, toggleIsEditingTags } = useAccountInfo(address); const [isHoveringButton, toggleIsHoveringButton] = useToggle(); const [isTransferOpen, toggleIsTransferOpen] = useToggle(); @@ -61,6 +61,11 @@ function Sidebar ({ address, className = '', onClose, onUpdateName }: Props): Re
{address}
+ {accountIndex && ( +
+ {accountIndex} +
+ )} { - const { accountIndex: anAccountIndex, identity, nickname } = accountInfo || {}; + const { accountIndex, identity, nickname } = accountInfo || {}; + const newIndex = accountIndex?.toString(); - if (anAccountIndex && accountIndex !== anAccountIndex.toString()) { - setAccountIndex(anAccountIndex.toString()); - } + setAccountIndex((oldIndex) => + oldIndex !== newIndex + ? newIndex + : oldIndex + ); let name; @@ -97,7 +100,7 @@ export default function useAccountInfo (value: string | null, isContract = false } else { setIdentity(undefined); } - }, [accountIndex, accountInfo, api]); + }, [accountInfo, api]); useEffect((): void => { if (value) {