mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-02 06:07:06 +01:00
1304ec7af5
We want to convert NetworkController to TypeScript in order to be able to compare differences in the controller between in this repo and the core repo. To do this, however, we need to convert the dependencies of the controller to TypeScript. As a part of this effort, this commit converts `shared/constants/metametrics` to TypeScript. Note that simple objects have been largely replaced with enums. There are some cases where I even split up some of these objects into multiple enums. Co-authored-by: Mark Stacey <markjstacey@gmail.com>
137 lines
4.0 KiB
JavaScript
137 lines
4.0 KiB
JavaScript
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 {
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventLinkType,
|
|
MetaMetricsEventKeyType,
|
|
MetaMetricsEventName,
|
|
} 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,
|
|
};
|
|
|
|
render() {
|
|
const {
|
|
selectedIdentity,
|
|
chainId,
|
|
showExportPrivateKeyModal,
|
|
setAccountLabel,
|
|
keyrings,
|
|
rpcPrefs,
|
|
history,
|
|
hideModal,
|
|
blockExplorerLinkText,
|
|
} = this.props;
|
|
const { name, address } = selectedIdentity;
|
|
|
|
const keyring = keyrings.find((kr) => {
|
|
return kr.accounts.includes(address);
|
|
});
|
|
|
|
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: MetaMetricsEventCategory.Navigation,
|
|
event: MetaMetricsEventName.ExternalLinkClicked,
|
|
properties: {
|
|
link_type: MetaMetricsEventLinkType.AccountTracker,
|
|
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}
|
|
onSubmit={(label) => setAccountLabel(address, label)}
|
|
accounts={this.props.accounts}
|
|
/>
|
|
|
|
<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,
|
|
])}
|
|
</Button>
|
|
|
|
{exportPrivateKeyFeatureEnabled && (
|
|
<Button
|
|
type="secondary"
|
|
className="account-details-modal__button"
|
|
onClick={() => {
|
|
this.context.trackEvent({
|
|
category: MetaMetricsEventCategory.Accounts,
|
|
event: MetaMetricsEventName.KeyExportSelected,
|
|
properties: {
|
|
key_type: MetaMetricsEventKeyType.Pkey,
|
|
location: 'Account Details Modal',
|
|
},
|
|
});
|
|
showExportPrivateKeyModal();
|
|
}}
|
|
>
|
|
{this.context.t('exportPrivateKey')}
|
|
</Button>
|
|
)}
|
|
</AccountModalContainer>
|
|
);
|
|
}
|
|
}
|