2021-02-04 19:15:23 +01:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Identicon from '../../../components/ui/identicon';
|
|
|
|
import { addressSummary } from '../../../helpers/utils/util';
|
|
|
|
import { formatCurrency } from '../../../helpers/utils/confirm-tx.util';
|
2021-04-17 00:00:18 +02:00
|
|
|
import { ConfirmPageContainerWarning } from '../../../components/app/confirm-page-container/confirm-page-container-content';
|
|
|
|
import Typography from '../../../components/ui/typography';
|
|
|
|
import {
|
|
|
|
TYPOGRAPHY,
|
|
|
|
FONT_WEIGHT,
|
|
|
|
BLOCK_SIZES,
|
|
|
|
JUSTIFY_CONTENT,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import Box from '../../../components/ui/box';
|
|
|
|
import Button from '../../../components/ui/button';
|
2019-11-05 16:13:48 +01:00
|
|
|
|
|
|
|
export default class ConfirmApproveContent extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-05 16:13:48 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
2020-01-29 19:16:38 +01:00
|
|
|
decimals: PropTypes.number,
|
2019-11-05 16:13:48 +01:00
|
|
|
tokenAmount: PropTypes.string,
|
|
|
|
customTokenAmount: PropTypes.string,
|
|
|
|
tokenSymbol: PropTypes.string,
|
|
|
|
siteImage: PropTypes.string,
|
|
|
|
showCustomizeGasModal: PropTypes.func,
|
|
|
|
showEditApprovalPermissionModal: PropTypes.func,
|
|
|
|
origin: PropTypes.string,
|
|
|
|
setCustomAmount: PropTypes.func,
|
|
|
|
tokenBalance: PropTypes.string,
|
|
|
|
data: PropTypes.string,
|
|
|
|
toAddress: PropTypes.string,
|
2019-11-19 14:41:28 +01:00
|
|
|
currentCurrency: PropTypes.string,
|
2021-01-28 07:44:04 +01:00
|
|
|
nativeCurrency: PropTypes.string,
|
2019-11-05 16:13:48 +01:00
|
|
|
fiatTransactionTotal: PropTypes.string,
|
|
|
|
ethTransactionTotal: PropTypes.string,
|
2021-04-17 00:00:18 +02:00
|
|
|
useNonceField: PropTypes.bool,
|
|
|
|
customNonceValue: PropTypes.string,
|
|
|
|
updateCustomNonce: PropTypes.func,
|
|
|
|
getNextNonce: PropTypes.func,
|
|
|
|
nextNonce: PropTypes.number,
|
|
|
|
showCustomizeNonceModal: PropTypes.func,
|
|
|
|
warning: PropTypes.string,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-05 16:13:48 +01:00
|
|
|
|
|
|
|
state = {
|
|
|
|
showFullTxDetails: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-05 16:13:48 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderApproveContentCard({
|
2021-04-17 00:00:18 +02:00
|
|
|
showHeader = true,
|
2019-11-05 16:13:48 +01:00
|
|
|
symbol,
|
|
|
|
title,
|
|
|
|
showEdit,
|
|
|
|
onEditClick,
|
|
|
|
content,
|
|
|
|
footer,
|
|
|
|
noBorder,
|
|
|
|
}) {
|
2021-04-17 00:00:18 +02:00
|
|
|
const { t } = this.context;
|
2019-11-05 16:13:48 +01:00
|
|
|
return (
|
2019-12-03 17:35:44 +01:00
|
|
|
<div
|
|
|
|
className={classnames({
|
|
|
|
'confirm-approve-content__card': !noBorder,
|
|
|
|
'confirm-approve-content__card--no-border': noBorder,
|
|
|
|
})}
|
|
|
|
>
|
2021-04-17 00:00:18 +02:00
|
|
|
{showHeader && (
|
|
|
|
<div className="confirm-approve-content__card-header">
|
|
|
|
<div className="confirm-approve-content__card-header__symbol">
|
|
|
|
{symbol}
|
2019-12-03 17:35:44 +01:00
|
|
|
</div>
|
2021-04-17 00:00:18 +02:00
|
|
|
<div className="confirm-approve-content__card-header__title">
|
|
|
|
{title}
|
|
|
|
</div>
|
|
|
|
{showEdit && (
|
|
|
|
<Box width={BLOCK_SIZES.ONE_SIXTH}>
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
className="confirm-approve-content__small-blue-text"
|
|
|
|
onClick={() => onEditClick()}
|
|
|
|
>
|
|
|
|
{t('edit')}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="confirm-approve-content__card-content">{content}</div>
|
|
|
|
{footer}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-05 16:13:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Add "Learn Why" with link to the feeAssociatedRequest text
|
2020-11-03 00:41:28 +01:00
|
|
|
renderTransactionDetailsContent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2019-11-05 16:13:48 +01:00
|
|
|
const {
|
2019-11-19 14:41:28 +01:00
|
|
|
currentCurrency,
|
2021-01-28 07:44:04 +01:00
|
|
|
nativeCurrency,
|
2019-11-05 16:13:48 +01:00
|
|
|
ethTransactionTotal,
|
|
|
|
fiatTransactionTotal,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-11-05 16:13:48 +01:00
|
|
|
return (
|
|
|
|
<div className="confirm-approve-content__transaction-details-content">
|
|
|
|
<div className="confirm-approve-content__small-text">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('feeAssociatedRequest')}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__transaction-details-content__fee">
|
|
|
|
<div className="confirm-approve-content__transaction-details-content__primary-fee">
|
2020-11-03 00:41:28 +01:00
|
|
|
{formatCurrency(fiatTransactionTotal, currentCurrency)}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__transaction-details-content__secondary-fee">
|
2021-01-28 07:44:04 +01:00
|
|
|
{`${ethTransactionTotal} ${nativeCurrency}`}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-05 16:13:48 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderPermissionContent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
customTokenAmount,
|
|
|
|
tokenAmount,
|
|
|
|
tokenSymbol,
|
|
|
|
origin,
|
|
|
|
toAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
2019-11-05 16:13:48 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex-column">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="confirm-approve-content__small-text">
|
|
|
|
{t('accessAndSpendNotice', [origin])}
|
|
|
|
</div>
|
2019-11-05 16:13:48 +01:00
|
|
|
<div className="flex-row">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="confirm-approve-content__label">
|
|
|
|
{t('amountWithColon')}
|
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__medium-text">
|
|
|
|
{`${Number(customTokenAmount || tokenAmount)} ${tokenSymbol}`}
|
|
|
|
</div>
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
<div className="flex-row">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="confirm-approve-content__label">
|
|
|
|
{t('toWithColon')}
|
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__medium-text">
|
|
|
|
{addressSummary(toAddress)}
|
|
|
|
</div>
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-05 16:13:48 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
renderDataContent() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
|
|
|
const { data } = this.props;
|
2019-11-05 16:13:48 +01:00
|
|
|
return (
|
|
|
|
<div className="flex-column">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="confirm-approve-content__small-text">
|
|
|
|
{t('functionApprove')}
|
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__small-text confirm-approve-content__data__data-block">
|
|
|
|
{data}
|
|
|
|
</div>
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-05 16:13:48 +01:00
|
|
|
}
|
|
|
|
|
2021-04-17 00:00:18 +02:00
|
|
|
renderCustomNonceContent() {
|
|
|
|
const { t } = this.context;
|
|
|
|
const {
|
|
|
|
useNonceField,
|
|
|
|
customNonceValue,
|
|
|
|
updateCustomNonce,
|
|
|
|
getNextNonce,
|
|
|
|
nextNonce,
|
|
|
|
showCustomizeNonceModal,
|
|
|
|
} = this.props;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{useNonceField && (
|
|
|
|
<div className="confirm-approve-content__custom-nonce-content">
|
|
|
|
<Box
|
|
|
|
className="confirm-approve-content__custom-nonce-header"
|
|
|
|
justifyContent={JUSTIFY_CONTENT.FLEX_START}
|
|
|
|
>
|
|
|
|
<Typography
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
fontWeight={FONT_WEIGHT.NORMAL}
|
|
|
|
>
|
|
|
|
{t('nonce')}
|
|
|
|
</Typography>
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
className="confirm-approve-content__custom-nonce-edit"
|
|
|
|
onClick={() =>
|
|
|
|
showCustomizeNonceModal({
|
|
|
|
nextNonce,
|
|
|
|
customNonceValue,
|
|
|
|
updateCustomNonce,
|
|
|
|
getNextNonce,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{t('edit')}
|
|
|
|
</Button>
|
|
|
|
</Box>
|
|
|
|
<Typography
|
|
|
|
className="confirm-approve-content__custom-nonce-value"
|
|
|
|
variant={TYPOGRAPHY.H6}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{customNonceValue || nextNonce}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { t } = this.context;
|
2019-11-05 16:13:48 +01:00
|
|
|
const {
|
2020-01-29 19:16:38 +01:00
|
|
|
decimals,
|
2019-11-05 16:13:48 +01:00
|
|
|
siteImage,
|
|
|
|
tokenAmount,
|
|
|
|
customTokenAmount,
|
|
|
|
origin,
|
|
|
|
tokenSymbol,
|
|
|
|
showCustomizeGasModal,
|
|
|
|
showEditApprovalPermissionModal,
|
|
|
|
setCustomAmount,
|
|
|
|
tokenBalance,
|
2021-04-17 00:00:18 +02:00
|
|
|
useNonceField,
|
|
|
|
warning,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { showFullTxDetails } = this.state;
|
2019-11-05 16:13:48 +01:00
|
|
|
|
|
|
|
return (
|
2019-12-03 17:35:44 +01:00
|
|
|
<div
|
|
|
|
className={classnames('confirm-approve-content', {
|
|
|
|
'confirm-approve-content--full': showFullTxDetails,
|
|
|
|
})}
|
|
|
|
>
|
2021-04-17 00:00:18 +02:00
|
|
|
{warning && (
|
|
|
|
<div className="confirm-approve-content__custom-nonce-warning">
|
|
|
|
<ConfirmPageContainerWarning warning={warning} />
|
|
|
|
</div>
|
|
|
|
)}
|
2019-11-05 16:13:48 +01:00
|
|
|
<div className="confirm-approve-content__identicon-wrapper">
|
|
|
|
<Identicon
|
|
|
|
className="confirm-approve-content__identicon"
|
|
|
|
diameter={48}
|
|
|
|
address={origin}
|
|
|
|
image={siteImage}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__title">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('allowOriginSpendToken', [origin, tokenSymbol])}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__description">
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('trustSiteApprovePermission', [origin, tokenSymbol])}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="confirm-approve-content__edit-submission-button-container">
|
2019-11-05 16:13:48 +01:00
|
|
|
<div
|
|
|
|
className="confirm-approve-content__medium-link-text cursor-pointer"
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={() =>
|
|
|
|
showEditApprovalPermissionModal({
|
|
|
|
customTokenAmount,
|
|
|
|
decimals,
|
|
|
|
origin,
|
|
|
|
setCustomAmount,
|
|
|
|
tokenAmount,
|
|
|
|
tokenSymbol,
|
|
|
|
tokenBalance,
|
|
|
|
})
|
|
|
|
}
|
2019-11-05 16:13:48 +01:00
|
|
|
>
|
2020-11-03 00:41:28 +01:00
|
|
|
{t('editPermission')}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__card-wrapper">
|
|
|
|
{this.renderApproveContentCard({
|
|
|
|
symbol: <i className="fa fa-tag" />,
|
|
|
|
title: 'Transaction Fee',
|
|
|
|
showEdit: true,
|
|
|
|
onEditClick: showCustomizeGasModal,
|
|
|
|
content: this.renderTransactionDetailsContent(),
|
2021-04-17 00:00:18 +02:00
|
|
|
noBorder: useNonceField || !showFullTxDetails,
|
|
|
|
footer: !useNonceField && (
|
2019-12-03 17:35:44 +01:00
|
|
|
<div
|
|
|
|
className="confirm-approve-content__view-full-tx-button-wrapper"
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={() =>
|
|
|
|
this.setState({
|
|
|
|
showFullTxDetails: !this.state.showFullTxDetails,
|
|
|
|
})
|
|
|
|
}
|
2019-12-03 17:35:44 +01:00
|
|
|
>
|
|
|
|
<div className="confirm-approve-content__view-full-tx-button cursor-pointer">
|
|
|
|
<div className="confirm-approve-content__small-blue-text">
|
|
|
|
View full transaction details
|
|
|
|
</div>
|
2020-04-01 22:38:19 +02:00
|
|
|
<i
|
|
|
|
className={classnames({
|
|
|
|
'fa fa-caret-up': showFullTxDetails,
|
|
|
|
'fa fa-caret-down': !showFullTxDetails,
|
|
|
|
})}
|
2019-12-03 17:35:44 +01:00
|
|
|
/>
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-03 17:35:44 +01:00
|
|
|
),
|
2019-11-05 16:13:48 +01:00
|
|
|
})}
|
2021-04-17 00:00:18 +02:00
|
|
|
{useNonceField &&
|
|
|
|
this.renderApproveContentCard({
|
|
|
|
showHeader: false,
|
|
|
|
content: this.renderCustomNonceContent(),
|
|
|
|
useNonceField,
|
|
|
|
noBorder: !showFullTxDetails,
|
|
|
|
footer: (
|
|
|
|
<div
|
|
|
|
className="confirm-approve-content__view-full-tx-button-wrapper"
|
|
|
|
onClick={() =>
|
|
|
|
this.setState({
|
|
|
|
showFullTxDetails: !this.state.showFullTxDetails,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div className="confirm-approve-content__view-full-tx-button cursor-pointer">
|
|
|
|
<div className="confirm-approve-content__small-blue-text">
|
|
|
|
View full transaction details
|
|
|
|
</div>
|
|
|
|
<i
|
|
|
|
className={classnames({
|
|
|
|
'fa fa-caret-up': showFullTxDetails,
|
|
|
|
'fa fa-caret-down': !showFullTxDetails,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
),
|
|
|
|
})}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
{showFullTxDetails ? (
|
|
|
|
<div className="confirm-approve-content__full-tx-content">
|
|
|
|
<div className="confirm-approve-content__permission">
|
|
|
|
{this.renderApproveContentCard({
|
2020-11-11 16:38:15 +01:00
|
|
|
symbol: <img src="/images/user-check.svg" alt="" />,
|
2020-11-03 00:41:28 +01:00
|
|
|
title: 'Permission',
|
|
|
|
content: this.renderPermissionContent(),
|
|
|
|
showEdit: true,
|
|
|
|
onEditClick: () =>
|
|
|
|
showEditApprovalPermissionModal({
|
|
|
|
customTokenAmount,
|
|
|
|
decimals,
|
|
|
|
origin,
|
|
|
|
setCustomAmount,
|
|
|
|
tokenAmount,
|
|
|
|
tokenSymbol,
|
|
|
|
tokenBalance,
|
|
|
|
}),
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<div className="confirm-approve-content__data">
|
|
|
|
{this.renderApproveContentCard({
|
|
|
|
symbol: <i className="fa fa-file" />,
|
|
|
|
title: 'Data',
|
|
|
|
content: this.renderDataContent(),
|
|
|
|
noBorder: true,
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2019-11-05 16:13:48 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-05 16:13:48 +01:00
|
|
|
}
|
|
|
|
}
|