import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import UrlIcon from '../../../components/ui/url-icon'; import { addressSummary } from '../../../helpers/utils/util'; import { formatCurrency } from '../../../helpers/utils/confirm-tx.util'; 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'; export default class ConfirmApproveContent extends Component { static contextTypes = { t: PropTypes.func, }; static propTypes = { decimals: PropTypes.number, 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, currentCurrency: PropTypes.string, nativeCurrency: PropTypes.string, fiatTransactionTotal: PropTypes.string, ethTransactionTotal: PropTypes.string, useNonceField: PropTypes.bool, customNonceValue: PropTypes.string, updateCustomNonce: PropTypes.func, getNextNonce: PropTypes.func, nextNonce: PropTypes.number, showCustomizeNonceModal: PropTypes.func, warning: PropTypes.string, }; state = { showFullTxDetails: false, }; renderApproveContentCard({ showHeader = true, symbol, title, showEdit, onEditClick, content, footer, noBorder, }) { const { t } = this.context; return (
{showHeader && (
{symbol}
{title}
{showEdit && ( )}
)}
{content}
{footer}
); } // TODO: Add "Learn Why" with link to the feeAssociatedRequest text renderTransactionDetailsContent() { const { t } = this.context; const { currentCurrency, nativeCurrency, ethTransactionTotal, fiatTransactionTotal, } = this.props; return (
{t('feeAssociatedRequest')}
{formatCurrency(fiatTransactionTotal, currentCurrency)}
{`${ethTransactionTotal} ${nativeCurrency}`}
); } renderPermissionContent() { const { t } = this.context; const { customTokenAmount, tokenAmount, tokenSymbol, origin, toAddress, } = this.props; return (
{t('accessAndSpendNotice', [origin])}
{t('amountWithColon')}
{`${Number(customTokenAmount || tokenAmount)} ${tokenSymbol}`}
{t('toWithColon')}
{addressSummary(toAddress)}
); } renderDataContent() { const { t } = this.context; const { data } = this.props; return (
{t('functionApprove')}
{data}
); } renderCustomNonceContent() { const { t } = this.context; const { useNonceField, customNonceValue, updateCustomNonce, getNextNonce, nextNonce, showCustomizeNonceModal, } = this.props; return ( <> {useNonceField && (
{t('nonce')} {customNonceValue || nextNonce}
)} ); } render() { const { t } = this.context; const { decimals, siteImage, tokenAmount, customTokenAmount, origin, tokenSymbol, showCustomizeGasModal, showEditApprovalPermissionModal, setCustomAmount, tokenBalance, useNonceField, warning, } = this.props; const { showFullTxDetails } = this.state; return (
{warning && (
)}
{t('allowOriginSpendToken', [origin, tokenSymbol])}
{t('trustSiteApprovePermission', [origin, tokenSymbol])}
showEditApprovalPermissionModal({ customTokenAmount, decimals, origin, setCustomAmount, tokenAmount, tokenSymbol, tokenBalance, }) } > {t('editPermission')}
{this.renderApproveContentCard({ symbol: , title: 'Transaction Fee', showEdit: true, onEditClick: showCustomizeGasModal, content: this.renderTransactionDetailsContent(), noBorder: useNonceField || !showFullTxDetails, footer: !useNonceField && (
this.setState({ showFullTxDetails: !this.state.showFullTxDetails, }) } >
View full transaction details
), })} {useNonceField && this.renderApproveContentCard({ showHeader: false, content: this.renderCustomNonceContent(), useNonceField, noBorder: !showFullTxDetails, footer: (
this.setState({ showFullTxDetails: !this.state.showFullTxDetails, }) } >
View full transaction details
), })}
{showFullTxDetails ? (
{this.renderApproveContentCard({ symbol: , title: 'Permission', content: this.renderPermissionContent(), showEdit: true, onEditClick: () => showEditApprovalPermissionModal({ customTokenAmount, decimals, origin, setCustomAmount, tokenAmount, tokenSymbol, tokenBalance, }), })}
{this.renderApproveContentCard({ symbol: , title: 'Data', content: this.renderDataContent(), noBorder: true, })}
) : null}
); } }