2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
import AccountListItem from '../../components/app/account-list-item';
|
|
|
|
import Button from '../../components/ui/button';
|
|
|
|
import Identicon from '../../components/ui/identicon';
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../shared/constants/app';
|
|
|
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { conversionUtil } from '../../helpers/utils/conversion-util';
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
export default class ConfirmEncryptionPublicKey extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func.isRequired,
|
|
|
|
metricsEvent: PropTypes.func.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
|
|
|
balance: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
}).isRequired,
|
2020-02-19 19:24:16 +01:00
|
|
|
clearConfirmTransaction: PropTypes.func.isRequired,
|
|
|
|
cancelEncryptionPublicKey: PropTypes.func.isRequired,
|
|
|
|
encryptionPublicKey: PropTypes.func.isRequired,
|
|
|
|
conversionRate: PropTypes.number,
|
|
|
|
history: PropTypes.object.isRequired,
|
|
|
|
requesterAddress: PropTypes.string,
|
|
|
|
txData: PropTypes.object,
|
|
|
|
domainMetadata: PropTypes.object,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
state = {
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount: this.props.fromAccount,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
componentDidMount = () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
window.addEventListener('beforeunload', this._beforeUnload);
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
componentWillUnmount = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2020-06-16 16:40:00 +02:00
|
|
|
_beforeUnload = async (event) => {
|
|
|
|
const {
|
|
|
|
clearConfirmTransaction,
|
|
|
|
cancelEncryptionPublicKey,
|
|
|
|
txData,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { metricsEvent } = this.context;
|
|
|
|
await cancelEncryptionPublicKey(txData, event);
|
2020-02-19 19:24:16 +01:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Messages',
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
name: 'Cancel Via Notification Close',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
clearConfirmTransaction();
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
_removeBeforeUnload = () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
window.removeEventListener('beforeunload', this._beforeUnload);
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderHeader = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__header">
|
|
|
|
<div className="request-encryption-public-key__header-background" />
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__header__text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('encryptionPublicKeyRequest')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__header__tip-container">
|
|
|
|
<div className="request-encryption-public-key__header__tip" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderAccount = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { fromAccount } = this.state;
|
|
|
|
const { t } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__account">
|
|
|
|
<div className="request-encryption-public-key__account-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('account')}:`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="request-encryption-public-key__account-item">
|
2020-11-03 00:41:28 +01:00
|
|
|
<AccountListItem account={fromAccount} />
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderBalance = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { conversionRate } = this.props;
|
|
|
|
const { t } = this.context;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
fromAccount: { balance },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.state;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
const balanceInEther = conversionUtil(balance, {
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
toNumericBase: 'dec',
|
|
|
|
fromDenomination: 'WEI',
|
|
|
|
numberOfDecimals: 6,
|
|
|
|
conversionRate,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__balance">
|
|
|
|
<div className="request-encryption-public-key__balance-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${t('balance')}:`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
<div className="request-encryption-public-key__balance-value">
|
2020-11-03 00:41:28 +01:00
|
|
|
{`${balanceInEther} ETH`}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderRequestIcon = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { requesterAddress } = this.props;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__request-icon">
|
2020-11-03 00:41:28 +01:00
|
|
|
<Identicon diameter={40} address={requesterAddress} />
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderAccountInfo = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__account-info">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAccount()}
|
|
|
|
{this.renderRequestIcon()}
|
|
|
|
{this.renderBalance()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderBody = () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { domainMetadata, txData } = this.props;
|
|
|
|
const { t } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const originMetadata = domainMetadata[txData.origin];
|
|
|
|
const notice = t('encryptionPublicKeyNotice', [txData.origin]);
|
2021-02-22 17:20:42 +01:00
|
|
|
const name = originMetadata?.hostname || txData.origin;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__body">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderAccountInfo()}
|
|
|
|
<div className="request-encryption-public-key__visual">
|
2020-02-19 19:24:16 +01:00
|
|
|
<section>
|
2021-01-13 02:52:58 +01:00
|
|
|
{originMetadata?.icon ? (
|
2020-02-19 19:24:16 +01:00
|
|
|
<img
|
|
|
|
className="request-encryption-public-key__visual-identicon"
|
2021-01-13 02:52:58 +01:00
|
|
|
src={originMetadata.icon}
|
2020-11-11 16:38:15 +01:00
|
|
|
alt=""
|
2020-02-19 19:24:16 +01:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<i className="request-encryption-public-key__visual-identicon--default">
|
2021-01-13 02:52:58 +01:00
|
|
|
{name.charAt(0).toUpperCase()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</i>
|
|
|
|
)}
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="request-encryption-public-key__notice">
|
|
|
|
{notice}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
renderFooter = () => {
|
2020-06-01 19:54:32 +02:00
|
|
|
const {
|
|
|
|
cancelEncryptionPublicKey,
|
|
|
|
clearConfirmTransaction,
|
|
|
|
encryptionPublicKey,
|
|
|
|
history,
|
|
|
|
mostRecentOverviewPage,
|
|
|
|
txData,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { t, metricsEvent } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__footer">
|
|
|
|
<Button
|
|
|
|
type="default"
|
|
|
|
large
|
|
|
|
className="request-encryption-public-key__footer__cancel-button"
|
|
|
|
onClick={async (event) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
|
|
|
await cancelEncryptionPublicKey(txData, event);
|
2020-06-16 16:40:00 +02:00
|
|
|
metricsEvent({
|
2020-02-19 19:24:16 +01:00
|
|
|
eventOpts: {
|
|
|
|
category: 'Messages',
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
name: 'Cancel',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(mostRecentOverviewPage);
|
2020-02-19 19:24:16 +01:00
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.context.t('cancel')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
large
|
|
|
|
className="request-encryption-public-key__footer__sign-button"
|
|
|
|
onClick={async (event) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
this._removeBeforeUnload();
|
|
|
|
await encryptionPublicKey(txData, event);
|
2020-02-19 19:24:16 +01:00
|
|
|
this.context.metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Messages',
|
|
|
|
action: 'Encryption public key Request',
|
|
|
|
name: 'Confirm',
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
clearConfirmTransaction();
|
|
|
|
history.push(mostRecentOverviewPage);
|
2020-02-19 19:24:16 +01:00
|
|
|
}}
|
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('provide')}
|
2020-02-19 19:24:16 +01:00
|
|
|
</Button>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
|
|
|
|
render = () => {
|
|
|
|
return (
|
|
|
|
<div className="request-encryption-public-key__container">
|
2020-11-03 00:41:28 +01:00
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderBody()}
|
|
|
|
{this.renderFooter()}
|
2020-02-19 19:24:16 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|