import React, { useCallback, useState } from 'react';
import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import Popover from '../../ui/popover/popover.component';
import {
setAccountDetailsAddress,
clearAccountDetails,
hideWarning,
} from '../../../store/actions';
import {
AvatarAccount,
AvatarAccountSize,
AvatarAccountVariant,
ButtonIcon,
IconName,
PopoverHeader,
Text,
} from '../../component-library';
import Box from '../../ui/box/box';
import { getMetaMaskAccountsOrdered } from '../../../selectors';
import { useI18nContext } from '../../../hooks/useI18nContext';
import {
AlignItems,
JustifyContent,
TextVariant,
Size,
Display,
FlexDirection,
} from '../../../helpers/constants/design-system';
import { AddressCopyButton } from '../address-copy-button';
import { AccountDetailsDisplay } from './account-details-display';
import { AccountDetailsAuthenticate } from './account-details-authenticate';
import { AccountDetailsKey } from './account-details-key';
export const AccountDetails = ({ address }) => {
const dispatch = useDispatch();
const t = useI18nContext();
const useBlockie = useSelector((state) => state.metamask.useBlockie);
const accounts = useSelector(getMetaMaskAccountsOrdered);
const { name } = accounts.find((account) => account.address === address);
const [attemptingExport, setAttemptingExport] = useState(false);
// This is only populated when the user properly authenticates
const privateKey = useSelector(
(state) => state.appState.accountDetail.privateKey,
);
const onClose = useCallback(() => {
dispatch(setAccountDetailsAddress(''));
dispatch(clearAccountDetails());
dispatch(hideWarning());
}, [dispatch]);
const avatar = (
);
return (
{
dispatch(hideWarning());
setAttemptingExport(false);
}}
iconName={IconName.ArrowLeft}
size={Size.SM}
/>
}
>
{t('showPrivateKey')}
) : (
{avatar}
)
}
onClose={onClose}
>
{attemptingExport ? (
<>
{avatar}
{name}
{privateKey ? (
) : (
)}
>
) : (
setAttemptingExport(true)}
/>
)}
);
};
AccountDetails.propTypes = {
address: PropTypes.string,
};