2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import AccountModalContainer from '../account-modal-container';
|
2021-04-28 21:53:59 +02:00
|
|
|
import getAccountLink from '../../../../helpers/utils/account-link';
|
2021-02-04 19:15:23 +01:00
|
|
|
import QrView from '../../../ui/qr-code';
|
|
|
|
import EditableLabel from '../../../ui/editable-label';
|
|
|
|
import Button from '../../../ui/button';
|
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-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-27 17:03:18 +02:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: 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-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-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
|
2020-11-12 17:45:54 +01:00
|
|
|
if (keyring?.type?.search('Hardware') !== -1) {
|
2021-02-04 19:15:23 +01:00
|
|
|
exportPrivateKeyFeatureEnabled = false;
|
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)}
|
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"
|
2019-06-27 17:03:18 +02:00
|
|
|
onClick={() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
global.platform.openTab({
|
2021-03-10 18:21:52 +01:00
|
|
|
url: getAccountLink(address, chainId, rpcPrefs),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-06-27 17:03:18 +02:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{rpcPrefs.blockExplorerUrl
|
2020-11-03 00:41:28 +01:00
|
|
|
? this.context.t('blockExplorerView', [
|
|
|
|
rpcPrefs.blockExplorerUrl.match(/^https?:\/\/(.+)/u)[1],
|
|
|
|
])
|
|
|
|
: this.context.t('viewOnEtherscan')}
|
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
|
|
|
}
|
|
|
|
}
|