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-07-06 19:48:49 +02:00
|
|
|
import { conversionUtil } from '../../../shared/modules/conversion.utils';
|
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-06-10 19:49:14 +02:00
|
|
|
nativeCurrency: PropTypes.string.isRequired,
|
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-07-20 18:29:38 +02:00
|
|
|
const { fromAccount } = this.props;
|
2021-02-04 19:15:23 +01:00
|
|
|
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 = () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
2021-07-20 18:29:38 +02:00
|
|
|
conversionRate,
|
|
|
|
nativeCurrency,
|
2020-11-03 00:41:28 +01:00
|
|
|
fromAccount: { balance },
|
2021-07-20 18:29:38 +02:00
|
|
|
} = this.props;
|
|
|
|
const { t } = this.context;
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-06-10 19:49:14 +02:00
|
|
|
const nativeCurrencyBalance = conversionUtil(balance, {
|
2020-02-19 19:24:16 +01:00
|
|
|
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">
|
2021-06-10 19:49:14 +02:00
|
|
|
{`${nativeCurrencyBalance} ${nativeCurrency}`}
|
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
|
2021-10-05 21:20:42 +02:00
|
|
|
type="secondary"
|
2020-02-19 19:24:16 +01:00
|
|
|
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
|
2021-10-05 21:20:42 +02:00
|
|
|
type="primary"
|
2020-02-19 19:24:16 +01:00
|
|
|
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
|
|
|
}
|