Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/react-components/src/IdentityIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { DeriveAccountInfo } from '@polkadot/api-derive/types';
import { IdentityProps } from '@polkadot/react-identicon/types';
import { I18nProps } from './types';

import React, { useContext, useEffect, useState } from 'react';
import { useApi } from '@polkadot/react-hooks';
import { useApi, useCall } from '@polkadot/react-hooks';
import BaseIdentityIcon from '@polkadot/react-identicon';
import uiSettings from '@polkadot/ui-settings';
import { ValidatorsContext } from '@polkadot/react-query';
Expand All @@ -32,10 +33,12 @@ export function getIdentityTheme (systemName: string): 'empty' {
}

function IdentityIcon ({ className, onCopy, prefix, size, style, t, theme, value }: Props): React.ReactElement<Props> {
const { systemName } = useApi();
const { api, systemName } = useApi();
const info = useCall<DeriveAccountInfo>(api.derive.accounts.info as any, [value]);
const { queueAction } = useContext(StatusContext);
const validators = useContext(ValidatorsContext);
const [isValidator, setIsValidator] = useState(false);
const [address, setAddress] = useState(value?.toString());
const thisTheme = theme || getIdentityTheme(systemName);

useEffect((): void => {
Expand All @@ -44,6 +47,12 @@ function IdentityIcon ({ className, onCopy, prefix, size, style, t, theme, value
}
}, [value, validators]);

useEffect((): void => {
if (info) {
setAddress(info.accountId?.toString());
}
}, [info]);

const _onCopy = (account: string): void => {
onCopy && onCopy(account);
queueAction && queueAction({
Expand All @@ -63,7 +72,7 @@ function IdentityIcon ({ className, onCopy, prefix, size, style, t, theme, value
size={size}
style={style}
theme={thisTheme as 'substrate'}
value={value?.toString()}
value={address}
/>
);
}
Expand Down