2023-05-03 19:09:13 +02:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import {
|
|
|
|
setAccountDetailsAddress,
|
|
|
|
clearAccountDetails,
|
|
|
|
hideWarning,
|
|
|
|
} from '../../../store/actions';
|
|
|
|
import {
|
|
|
|
AvatarAccount,
|
|
|
|
AvatarAccountSize,
|
|
|
|
AvatarAccountVariant,
|
2023-07-05 14:57:02 +02:00
|
|
|
Modal,
|
|
|
|
ModalContent,
|
|
|
|
ModalHeader,
|
|
|
|
ModalOverlay,
|
2023-07-04 17:17:05 +02:00
|
|
|
Box,
|
2023-05-03 19:09:13 +02:00
|
|
|
} from '../../component-library';
|
2023-07-14 19:59:30 +02:00
|
|
|
import { Text } from '../../component-library/text/deprecated';
|
2023-05-03 19:09:13 +02:00
|
|
|
import { getMetaMaskAccountsOrdered } from '../../../selectors';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
|
|
import {
|
|
|
|
AlignItems,
|
|
|
|
TextVariant,
|
2023-06-28 17:03:50 +02:00
|
|
|
Display,
|
|
|
|
FlexDirection,
|
2023-05-03 19:09:13 +02:00
|
|
|
} 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 = (
|
|
|
|
<AvatarAccount
|
|
|
|
variant={
|
|
|
|
useBlockie
|
|
|
|
? AvatarAccountVariant.Blockies
|
|
|
|
: AvatarAccountVariant.Jazzicon
|
|
|
|
}
|
|
|
|
address={address}
|
|
|
|
size={AvatarAccountSize.Lg}
|
2023-07-05 14:57:02 +02:00
|
|
|
style={{ margin: '0 auto' }}
|
2023-05-03 19:09:13 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2023-07-05 14:57:02 +02:00
|
|
|
<Modal isOpen onClose={onClose}>
|
|
|
|
<ModalOverlay />
|
|
|
|
<ModalContent>
|
|
|
|
<ModalHeader
|
|
|
|
onClose={onClose}
|
|
|
|
onBack={
|
|
|
|
attemptingExport
|
|
|
|
? () => {
|
2023-05-08 16:03:34 +02:00
|
|
|
dispatch(hideWarning());
|
|
|
|
setAttemptingExport(false);
|
2023-07-05 14:57:02 +02:00
|
|
|
}
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{attemptingExport ? t('showPrivateKey') : avatar}
|
|
|
|
</ModalHeader>
|
|
|
|
{attemptingExport ? (
|
|
|
|
<>
|
|
|
|
<Box
|
|
|
|
display={Display.Flex}
|
|
|
|
alignItems={AlignItems.center}
|
|
|
|
flexDirection={FlexDirection.Column}
|
|
|
|
>
|
|
|
|
{avatar}
|
|
|
|
<Text
|
|
|
|
marginTop={2}
|
|
|
|
marginBottom={2}
|
|
|
|
variant={TextVariant.bodyLgMedium}
|
|
|
|
style={{ wordBreak: 'break-word' }}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Text>
|
|
|
|
<AddressCopyButton address={address} shorten />
|
|
|
|
</Box>
|
|
|
|
{privateKey ? (
|
|
|
|
<AccountDetailsKey
|
|
|
|
accountName={name}
|
|
|
|
onClose={onClose}
|
|
|
|
privateKey={privateKey}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<AccountDetailsAuthenticate
|
|
|
|
address={address}
|
|
|
|
onCancel={onClose}
|
2023-05-03 19:09:13 +02:00
|
|
|
/>
|
2023-07-05 14:57:02 +02:00
|
|
|
)}
|
|
|
|
</>
|
2023-05-03 19:09:13 +02:00
|
|
|
) : (
|
2023-07-05 14:57:02 +02:00
|
|
|
<AccountDetailsDisplay
|
|
|
|
accounts={accounts}
|
|
|
|
accountName={name}
|
|
|
|
address={address}
|
|
|
|
onExportClick={() => setAttemptingExport(true)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</ModalContent>
|
|
|
|
</Modal>
|
2023-05-03 19:09:13 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AccountDetails.propTypes = {
|
|
|
|
address: PropTypes.string,
|
|
|
|
};
|