1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 11:46:13 +02:00
metamask-extension/ui/components/app/modals/account-details-modal/account-details-modal.component.js

102 lines
2.9 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';
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,
};
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
};
2020-11-03 00:41:28 +01:00
render() {
const {
selectedIdentity,
chainId,
showExportPrivateKeyModal,
setAccountLabel,
keyrings,
rpcPrefs,
} = 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
2020-11-12 17:45:54 +01:00
if (keyring?.type?.search('Hardware') !== -1) {
exportPrivateKeyFeatureEnabled = false;
}
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)}
/>
<QrView
Qr={{
data: address,
}}
/>
<div className="account-details-modal__divider" />
<Button
type="secondary"
className="account-details-modal__button"
onClick={() => {
const accountLink = getAccountLink(address, chainId, rpcPrefs);
this.context.trackEvent({
category: 'Navigation',
event: 'Clicked Block Explorer Link',
properties: {
link_type: 'Account Tracker',
action: 'Account Details Modal',
block_explorer_domain: getURLHostName(accountLink),
},
});
2020-11-03 00:41:28 +01:00
global.platform.openTab({
url: accountLink,
});
}}
>
{rpcPrefs.blockExplorerUrl
2020-11-03 00:41:28 +01:00
? this.context.t('blockExplorerView', [
rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/u)[1],
])
: this.context.t('viewOnEtherscan')}
</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}
</AccountModalContainer>
);
}
}