1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 22:24:27 +01:00
metamask-extension/ui/components/app/modals/account-details-modal/account-details-modal.component.js

145 lines
4.2 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { getAccountLink } from '@metamask/etherscan-link';
import AccountModalContainer from '../account-modal-container';
import QrView from '../../../ui/qr-code';
import EditableLabel from '../../../ui/editable-label';
import Button from '../../../ui/button';
import { getURLHostName } from '../../../../helpers/utils/util';
import { isHardwareKeyring } from '../../../../helpers/utils/hardware';
import {
EVENT,
EVENT_NAMES,
} from '../../../../../shared/constants/metametrics';
import { NETWORKS_ROUTE } from '../../../../helpers/constants/routes';
export default class AccountDetailsModal extends Component {
static propTypes = {
selectedIdentity: PropTypes.object,
chainId: PropTypes.string,
showExportPrivateKeyModal: PropTypes.func,
setAccountLabel: PropTypes.func,
keyrings: PropTypes.array,
rpcPrefs: PropTypes.object,
accounts: PropTypes.array,
history: PropTypes.object,
hideModal: PropTypes.func,
blockExplorerLinkText: PropTypes.object,
};
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
};
2020-11-03 00:41:28 +01:00
render() {
const {
selectedIdentity,
chainId,
showExportPrivateKeyModal,
setAccountLabel,
keyrings,
rpcPrefs,
accounts,
history,
hideModal,
blockExplorerLinkText,
} = this.props;
const { name, address } = selectedIdentity;
const keyring = keyrings.find((kr) => {
return kr.accounts.includes(address);
});
const getAccountsNames = (allAccounts, currentName) => {
return Object.values(allAccounts)
.map((item) => item.name)
.filter((itemName) => itemName !== currentName);
};
let exportPrivateKeyFeatureEnabled = true;
// This feature is disabled for hardware wallets
if (isHardwareKeyring(keyring?.type)) {
exportPrivateKeyFeatureEnabled = false;
}
const routeToAddBlockExplorerUrl = () => {
hideModal();
history.push(`${NETWORKS_ROUTE}#blockExplorerUrl`);
};
const openBlockExplorer = () => {
const accountLink = getAccountLink(address, chainId, rpcPrefs);
this.context.trackEvent({
category: EVENT.CATEGORIES.NAVIGATION,
event: EVENT_NAMES.EXTERNAL_LINK_CLICKED,
properties: {
link_type: EVENT.EXTERNAL_LINK_TYPES.ACCOUNT_TRACKER,
location: 'Account Details Modal',
url_domain: getURLHostName(accountLink),
},
});
global.platform.openTab({
url: accountLink,
});
};
return (
<AccountModalContainer className="account-details-modal">
<EditableLabel
className="account-details-modal__name"
defaultValue={name}
2020-02-15 21:34:12 +01:00
onSubmit={(label) => setAccountLabel(address, label)}
accountsNames={getAccountsNames(accounts, name)}
/>
<QrView
Qr={{
data: address,
}}
/>
<div className="account-details-modal__divider" />
<Button
type="secondary"
className="account-details-modal__button"
onClick={
blockExplorerLinkText.firstPart === 'addBlockExplorer'
? routeToAddBlockExplorerUrl
: openBlockExplorer
}
>
{this.context.t(
blockExplorerLinkText.firstPart,
blockExplorerLinkText.secondPart === ''
? null
: [blockExplorerLinkText.secondPart],
)}
</Button>
2020-11-03 00:41:28 +01:00
{exportPrivateKeyFeatureEnabled ? (
<Button
type="secondary"
className="account-details-modal__button"
onClick={() => {
this.context.trackEvent({
category: EVENT.CATEGORIES.ACCOUNTS,
event: EVENT_NAMES.KEY_EXPORT_SELECTED,
properties: {
key_type: EVENT.KEY_TYPES.PKEY,
location: 'Account Details Modal',
},
});
showExportPrivateKeyModal();
}}
2020-11-03 00:41:28 +01:00
>
{this.context.t('exportPrivateKey')}
</Button>
) : null}
</AccountModalContainer>
);
}
}