2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-05-19 16:51:47 +02:00
|
|
|
import { getAccountLink } from '@metamask/etherscan-link';
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import AccountModalContainer from '../account-modal-container';
|
|
|
|
import QrView from '../../../ui/qr-code';
|
|
|
|
import EditableLabel from '../../../ui/editable-label';
|
|
|
|
import Button from '../../../ui/button';
|
2021-08-25 00:28:16 +02:00
|
|
|
import { getURLHostName } from '../../../../helpers/utils/util';
|
2021-10-28 01:54:18 +02:00
|
|
|
import { isHardwareKeyring } from '../../../../helpers/utils/hardware';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } from '../../../../../shared/constants/metametrics';
|
2022-08-02 23:56:02 +02:00
|
|
|
import { NETWORKS_ROUTE } from '../../../../helpers/constants/routes';
|
2019-06-27 17:03:18 +02:00
|
|
|
|
|
|
|
export default class AccountDetailsModal extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
selectedIdentity: PropTypes.object,
|
2021-03-10 18:21:52 +01:00
|
|
|
chainId: PropTypes.string,
|
2019-06-27 17:03:18 +02:00
|
|
|
showExportPrivateKeyModal: PropTypes.func,
|
|
|
|
setAccountLabel: PropTypes.func,
|
|
|
|
keyrings: PropTypes.array,
|
|
|
|
rpcPrefs: PropTypes.object,
|
2021-12-16 11:41:55 +01:00
|
|
|
accounts: PropTypes.array,
|
2022-08-02 23:56:02 +02:00
|
|
|
history: PropTypes.object,
|
|
|
|
hideModal: PropTypes.func,
|
|
|
|
blockExplorerLinkText: PropTypes.object,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-27 17:03:18 +02:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-05-19 16:51:47 +02:00
|
|
|
trackEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-27 17:03:18 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2019-06-27 17:03:18 +02:00
|
|
|
const {
|
|
|
|
selectedIdentity,
|
2021-03-10 18:21:52 +01:00
|
|
|
chainId,
|
2019-06-27 17:03:18 +02:00
|
|
|
showExportPrivateKeyModal,
|
|
|
|
setAccountLabel,
|
|
|
|
keyrings,
|
|
|
|
rpcPrefs,
|
2021-12-16 11:41:55 +01:00
|
|
|
accounts,
|
2022-08-02 23:56:02 +02:00
|
|
|
history,
|
|
|
|
hideModal,
|
|
|
|
blockExplorerLinkText,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { name, address } = selectedIdentity;
|
2019-06-27 17:03:18 +02:00
|
|
|
|
|
|
|
const keyring = keyrings.find((kr) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
return kr.accounts.includes(address);
|
|
|
|
});
|
2019-06-27 17:03:18 +02:00
|
|
|
|
2021-12-16 11:41:55 +01:00
|
|
|
const getAccountsNames = (allAccounts, currentName) => {
|
|
|
|
return Object.values(allAccounts)
|
|
|
|
.map((item) => item.name)
|
|
|
|
.filter((itemName) => itemName !== currentName);
|
|
|
|
};
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let exportPrivateKeyFeatureEnabled = true;
|
2019-06-27 17:03:18 +02:00
|
|
|
// This feature is disabled for hardware wallets
|
2021-10-28 01:54:18 +02:00
|
|
|
if (isHardwareKeyring(keyring?.type)) {
|
2021-02-04 19:15:23 +01:00
|
|
|
exportPrivateKeyFeatureEnabled = false;
|
2019-06-27 17:03:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-02 23:56:02 +02:00
|
|
|
const routeToAddBlockExplorerUrl = () => {
|
|
|
|
hideModal();
|
|
|
|
history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const openBlockExplorer = () => {
|
|
|
|
const accountLink = getAccountLink(address, chainId, rpcPrefs);
|
|
|
|
this.context.trackEvent({
|
|
|
|
category: EVENT.CATEGORIES.NAVIGATION,
|
|
|
|
event: 'Clicked Block Explorer Link',
|
|
|
|
properties: {
|
|
|
|
link_type: 'Account Tracker',
|
|
|
|
action: 'Account Details Modal',
|
|
|
|
block_explorer_domain: getURLHostName(accountLink),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
global.platform.openTab({
|
|
|
|
url: accountLink,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-06-27 17:03:18 +02:00
|
|
|
return (
|
2020-08-11 18:07:47 +02:00
|
|
|
<AccountModalContainer className="account-details-modal">
|
2019-06-27 17:03:18 +02:00
|
|
|
<EditableLabel
|
2020-08-11 18:07:47 +02:00
|
|
|
className="account-details-modal__name"
|
2019-06-27 17:03:18 +02:00
|
|
|
defaultValue={name}
|
2020-02-15 21:34:12 +01:00
|
|
|
onSubmit={(label) => setAccountLabel(address, label)}
|
2021-12-16 11:41:55 +01:00
|
|
|
accountsNames={getAccountsNames(accounts, name)}
|
2019-06-27 17:03:18 +02:00
|
|
|
/>
|
|
|
|
|
|
|
|
<QrView
|
|
|
|
Qr={{
|
|
|
|
data: address,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
2020-08-11 18:07:47 +02:00
|
|
|
<div className="account-details-modal__divider" />
|
2019-06-27 17:03:18 +02:00
|
|
|
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
2020-08-11 18:07:47 +02:00
|
|
|
className="account-details-modal__button"
|
2022-08-02 23:56:02 +02:00
|
|
|
onClick={
|
|
|
|
blockExplorerLinkText.firstPart === 'addBlockExplorer'
|
|
|
|
? routeToAddBlockExplorerUrl
|
|
|
|
: openBlockExplorer
|
|
|
|
}
|
2019-06-27 17:03:18 +02:00
|
|
|
>
|
2022-08-02 23:56:02 +02:00
|
|
|
{this.context.t(
|
|
|
|
blockExplorerLinkText.firstPart,
|
|
|
|
blockExplorerLinkText.secondPart === ''
|
|
|
|
? null
|
|
|
|
: [blockExplorerLinkText.secondPart],
|
|
|
|
)}
|
2019-06-27 17:03:18 +02:00
|
|
|
</Button>
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
{exportPrivateKeyFeatureEnabled ? (
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
className="account-details-modal__button"
|
|
|
|
onClick={() => showExportPrivateKeyModal()}
|
|
|
|
>
|
|
|
|
{this.context.t('exportPrivateKey')}
|
|
|
|
</Button>
|
|
|
|
) : null}
|
2019-06-27 17:03:18 +02:00
|
|
|
</AccountModalContainer>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-06-27 17:03:18 +02:00
|
|
|
}
|
|
|
|
}
|