2018-06-23 08:52:45 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-11-05 16:13:48 +01:00
|
|
|
import ConfirmTransactionBase from '../confirm-transaction-base'
|
|
|
|
import ConfirmApproveContent from './confirm-approve-content'
|
|
|
|
import { getCustomTxParamsData } from './confirm-approve.util'
|
|
|
|
import {
|
|
|
|
calcTokenAmount,
|
|
|
|
} from '../../helpers/utils/token-util'
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
export default class ConfirmApprove extends Component {
|
2019-11-05 16:13:48 +01:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
static propTypes = {
|
2019-11-05 16:13:48 +01:00
|
|
|
tokenAddress: PropTypes.string,
|
|
|
|
toAddress: PropTypes.string,
|
2018-07-14 22:47:07 +02:00
|
|
|
tokenAmount: PropTypes.number,
|
2018-07-15 08:36:42 +02:00
|
|
|
tokenSymbol: PropTypes.string,
|
2019-11-05 16:13:48 +01:00
|
|
|
fiatTransactionTotal: PropTypes.string,
|
|
|
|
ethTransactionTotal: PropTypes.string,
|
|
|
|
contractExchangeRate: PropTypes.number,
|
|
|
|
conversionRate: PropTypes.number,
|
|
|
|
currentCurrency: PropTypes.string,
|
|
|
|
showCustomizeGasModal: PropTypes.func,
|
|
|
|
showEditApprovalPermissionModal: PropTypes.func,
|
|
|
|
origin: PropTypes.string,
|
|
|
|
siteImage: PropTypes.string,
|
|
|
|
tokenTrackerBalance: PropTypes.string,
|
|
|
|
data: PropTypes.string,
|
|
|
|
decimals: PropTypes.number,
|
|
|
|
txData: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
tokenAmount: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
customPermissionAmount: '',
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const { tokenAmount } = this.props
|
|
|
|
|
|
|
|
if (tokenAmount !== prevProps.tokenAmount) {
|
|
|
|
this.setState({ customPermissionAmount: tokenAmount })
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2019-11-05 16:13:48 +01:00
|
|
|
const {
|
|
|
|
toAddress,
|
|
|
|
tokenAddress,
|
|
|
|
tokenSymbol,
|
|
|
|
tokenAmount,
|
|
|
|
showCustomizeGasModal,
|
|
|
|
showEditApprovalPermissionModal,
|
|
|
|
origin,
|
|
|
|
siteImage,
|
|
|
|
tokenTrackerBalance,
|
|
|
|
data,
|
|
|
|
decimals,
|
|
|
|
txData,
|
2019-11-19 14:41:28 +01:00
|
|
|
currentCurrency,
|
2019-11-05 16:13:48 +01:00
|
|
|
ethTransactionTotal,
|
|
|
|
fiatTransactionTotal,
|
|
|
|
...restProps
|
|
|
|
} = this.props
|
|
|
|
const { customPermissionAmount } = this.state
|
|
|
|
|
|
|
|
const tokensText = `${tokenAmount} ${tokenSymbol}`
|
|
|
|
|
|
|
|
const tokenBalance = tokenTrackerBalance
|
|
|
|
? Number(calcTokenAmount(tokenTrackerBalance, decimals)).toPrecision(9)
|
|
|
|
: ''
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
return (
|
2019-11-05 16:13:48 +01:00
|
|
|
<ConfirmTransactionBase
|
|
|
|
toAddress={toAddress}
|
|
|
|
identiconAddress={tokenAddress}
|
2019-11-19 00:23:41 +01:00
|
|
|
showAccountInHeader
|
2019-11-05 16:13:48 +01:00
|
|
|
title={tokensText}
|
2019-12-03 17:35:44 +01:00
|
|
|
contentComponent={(
|
|
|
|
<ConfirmApproveContent
|
|
|
|
siteImage={siteImage}
|
|
|
|
tokenAddress={tokenAddress}
|
|
|
|
setCustomAmount={(newAmount) => {
|
|
|
|
this.setState({ customPermissionAmount: newAmount })
|
|
|
|
}}
|
|
|
|
customTokenAmount={String(customPermissionAmount)}
|
|
|
|
tokenAmount={String(tokenAmount)}
|
|
|
|
origin={origin}
|
|
|
|
tokenSymbol={tokenSymbol}
|
|
|
|
tokenBalance={tokenBalance}
|
|
|
|
showCustomizeGasModal={() => showCustomizeGasModal(txData)}
|
|
|
|
showEditApprovalPermissionModal={showEditApprovalPermissionModal}
|
|
|
|
data={data}
|
|
|
|
toAddress={toAddress}
|
|
|
|
currentCurrency={currentCurrency}
|
|
|
|
ethTransactionTotal={ethTransactionTotal}
|
|
|
|
fiatTransactionTotal={fiatTransactionTotal}
|
|
|
|
/>
|
|
|
|
)}
|
2019-11-19 00:23:41 +01:00
|
|
|
hideSenderToRecipient
|
2019-11-05 16:13:48 +01:00
|
|
|
customTxParamsData={customPermissionAmount
|
|
|
|
? getCustomTxParamsData(data, { customPermissionAmount, tokenAmount, decimals })
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
{...restProps}
|
2018-06-23 08:52:45 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|