You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
257 lines
7.2 KiB
257 lines
7.2 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
5 years ago
|
|
||
4 years ago
|
import AccountListItem from '../../components/app/account-list-item';
|
||
|
import Button from '../../components/ui/button';
|
||
|
import Identicon from '../../components/ui/identicon';
|
||
5 years ago
|
|
||
4 years ago
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../shared/constants/app';
|
||
|
import { getEnvironmentType } from '../../../app/scripts/lib/util';
|
||
4 years ago
|
import { conversionUtil } from '../../helpers/utils/conversion-util';
|
||
5 years ago
|
|
||
|
export default class ConfirmEncryptionPublicKey extends Component {
|
||
|
static contextTypes = {
|
||
|
t: PropTypes.func.isRequired,
|
||
|
metricsEvent: PropTypes.func.isRequired,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
static propTypes = {
|
||
5 years ago
|
fromAccount: PropTypes.shape({
|
||
|
address: PropTypes.string.isRequired,
|
||
|
balance: PropTypes.string,
|
||
|
name: PropTypes.string,
|
||
|
}).isRequired,
|
||
5 years ago
|
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,
|
||
5 years ago
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
state = {
|
||
5 years ago
|
fromAccount: this.props.fromAccount,
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
componentDidMount = () => {
|
||
4 years ago
|
if (
|
||
|
getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
|
||
|
) {
|
||
4 years ago
|
window.addEventListener('beforeunload', this._beforeUnload);
|
||
5 years ago
|
}
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
componentWillUnmount = () => {
|
||
4 years ago
|
this._removeBeforeUnload();
|
||
|
};
|
||
5 years ago
|
|
||
5 years ago
|
_beforeUnload = async (event) => {
|
||
|
const {
|
||
|
clearConfirmTransaction,
|
||
|
cancelEncryptionPublicKey,
|
||
|
txData,
|
||
4 years ago
|
} = this.props;
|
||
|
const { metricsEvent } = this.context;
|
||
|
await cancelEncryptionPublicKey(txData, event);
|
||
5 years ago
|
metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Messages',
|
||
|
action: 'Encryption public key Request',
|
||
|
name: 'Cancel Via Notification Close',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
clearConfirmTransaction();
|
||
|
};
|
||
5 years ago
|
|
||
|
_removeBeforeUnload = () => {
|
||
4 years ago
|
if (
|
||
|
getEnvironmentType(window.location.href) === ENVIRONMENT_TYPE_NOTIFICATION
|
||
|
) {
|
||
4 years ago
|
window.removeEventListener('beforeunload', this._beforeUnload);
|
||
5 years ago
|
}
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
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">
|
||
4 years ago
|
{this.context.t('encryptionPublicKeyRequest')}
|
||
5 years ago
|
</div>
|
||
|
|
||
|
<div className="request-encryption-public-key__header__tip-container">
|
||
|
<div className="request-encryption-public-key__header__tip" />
|
||
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
renderAccount = () => {
|
||
4 years ago
|
const { fromAccount } = this.state;
|
||
|
const { t } = this.context;
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__account">
|
||
|
<div className="request-encryption-public-key__account-text">
|
||
4 years ago
|
{`${t('account')}:`}
|
||
5 years ago
|
</div>
|
||
|
|
||
|
<div className="request-encryption-public-key__account-item">
|
||
4 years ago
|
<AccountListItem account={fromAccount} />
|
||
5 years ago
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
renderBalance = () => {
|
||
4 years ago
|
const { conversionRate } = this.props;
|
||
|
const { t } = this.context;
|
||
4 years ago
|
const {
|
||
|
fromAccount: { balance },
|
||
4 years ago
|
} = this.state;
|
||
5 years ago
|
|
||
|
const balanceInEther = conversionUtil(balance, {
|
||
|
fromNumericBase: 'hex',
|
||
|
toNumericBase: 'dec',
|
||
|
fromDenomination: 'WEI',
|
||
|
numberOfDecimals: 6,
|
||
|
conversionRate,
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__balance">
|
||
|
<div className="request-encryption-public-key__balance-text">
|
||
4 years ago
|
{`${t('balance')}:`}
|
||
5 years ago
|
</div>
|
||
|
<div className="request-encryption-public-key__balance-value">
|
||
4 years ago
|
{`${balanceInEther} ETH`}
|
||
5 years ago
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
renderRequestIcon = () => {
|
||
4 years ago
|
const { requesterAddress } = this.props;
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__request-icon">
|
||
4 years ago
|
<Identicon diameter={40} address={requesterAddress} />
|
||
5 years ago
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
renderAccountInfo = () => {
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__account-info">
|
||
4 years ago
|
{this.renderAccount()}
|
||
|
{this.renderRequestIcon()}
|
||
|
{this.renderBalance()}
|
||
5 years ago
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
renderBody = () => {
|
||
4 years ago
|
const { domainMetadata, txData } = this.props;
|
||
|
const { t } = this.context;
|
||
5 years ago
|
|
||
4 years ago
|
const originMetadata = domainMetadata[txData.origin];
|
||
|
const notice = t('encryptionPublicKeyNotice', [txData.origin]);
|
||
4 years ago
|
const name = originMetadata?.hostname || txData.origin;
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__body">
|
||
4 years ago
|
{this.renderAccountInfo()}
|
||
|
<div className="request-encryption-public-key__visual">
|
||
5 years ago
|
<section>
|
||
4 years ago
|
{originMetadata?.icon ? (
|
||
5 years ago
|
<img
|
||
|
className="request-encryption-public-key__visual-identicon"
|
||
4 years ago
|
src={originMetadata.icon}
|
||
4 years ago
|
alt=""
|
||
5 years ago
|
/>
|
||
|
) : (
|
||
|
<i className="request-encryption-public-key__visual-identicon--default">
|
||
4 years ago
|
{name.charAt(0).toUpperCase()}
|
||
5 years ago
|
</i>
|
||
|
)}
|
||
4 years ago
|
<div className="request-encryption-public-key__notice">
|
||
|
{notice}
|
||
5 years ago
|
</div>
|
||
|
</section>
|
||
|
</div>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
renderFooter = () => {
|
||
5 years ago
|
const {
|
||
|
cancelEncryptionPublicKey,
|
||
|
clearConfirmTransaction,
|
||
|
encryptionPublicKey,
|
||
|
history,
|
||
|
mostRecentOverviewPage,
|
||
|
txData,
|
||
4 years ago
|
} = this.props;
|
||
|
const { t, metricsEvent } = this.context;
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__footer">
|
||
|
<Button
|
||
|
type="default"
|
||
|
large
|
||
|
className="request-encryption-public-key__footer__cancel-button"
|
||
|
onClick={async (event) => {
|
||
4 years ago
|
this._removeBeforeUnload();
|
||
|
await cancelEncryptionPublicKey(txData, event);
|
||
5 years ago
|
metricsEvent({
|
||
5 years ago
|
eventOpts: {
|
||
|
category: 'Messages',
|
||
|
action: 'Encryption public key Request',
|
||
|
name: 'Cancel',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
clearConfirmTransaction();
|
||
|
history.push(mostRecentOverviewPage);
|
||
5 years ago
|
}}
|
||
|
>
|
||
4 years ago
|
{this.context.t('cancel')}
|
||
5 years ago
|
</Button>
|
||
|
<Button
|
||
|
type="secondary"
|
||
|
large
|
||
|
className="request-encryption-public-key__footer__sign-button"
|
||
|
onClick={async (event) => {
|
||
4 years ago
|
this._removeBeforeUnload();
|
||
|
await encryptionPublicKey(txData, event);
|
||
5 years ago
|
this.context.metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Messages',
|
||
|
action: 'Encryption public key Request',
|
||
|
name: 'Confirm',
|
||
|
},
|
||
4 years ago
|
});
|
||
|
clearConfirmTransaction();
|
||
|
history.push(mostRecentOverviewPage);
|
||
5 years ago
|
}}
|
||
|
>
|
||
4 years ago
|
{t('provide')}
|
||
5 years ago
|
</Button>
|
||
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
|
||
|
render = () => {
|
||
|
return (
|
||
|
<div className="request-encryption-public-key__container">
|
||
4 years ago
|
{this.renderHeader()}
|
||
|
{this.renderBody()}
|
||
|
{this.renderFooter()}
|
||
5 years ago
|
</div>
|
||
4 years ago
|
);
|
||
|
};
|
||
5 years ago
|
}
|