mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 21:00:13 +01:00
59a1746afc
The custom spend limit was previously not validated. It did have a minimum of zero set, but this didn't have any affect (that minimum is used for form constraint validation, and this field wasn't in a form). The field was never checked to ensure the contents didn't exceed the maximum. The field is now checked for values that exceed the maximum, and invalid values in general (including negative values). The parameters to the `showEditApprovalPermissionModal` were also alphabetized to make them easier to read. In the course of doing this, I noticed that the origin was missing from one of the calls. This was responsible for the modal saying "Spend limit requested by undefined" when clicking "Edit" under the transaction details. This has been fixed.
116 lines
3.2 KiB
JavaScript
116 lines
3.2 KiB
JavaScript
import React, { Component } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
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'
|
|
|
|
export default class ConfirmApprove extends Component {
|
|
static contextTypes = {
|
|
t: PropTypes.func,
|
|
}
|
|
|
|
static propTypes = {
|
|
tokenAddress: PropTypes.string,
|
|
toAddress: PropTypes.string,
|
|
tokenAmount: PropTypes.string,
|
|
tokenSymbol: PropTypes.string,
|
|
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 })
|
|
}
|
|
}
|
|
|
|
render () {
|
|
const {
|
|
toAddress,
|
|
tokenAddress,
|
|
tokenSymbol,
|
|
tokenAmount,
|
|
showCustomizeGasModal,
|
|
showEditApprovalPermissionModal,
|
|
origin,
|
|
siteImage,
|
|
tokenTrackerBalance,
|
|
data,
|
|
decimals,
|
|
txData,
|
|
currentCurrency,
|
|
ethTransactionTotal,
|
|
fiatTransactionTotal,
|
|
...restProps
|
|
} = this.props
|
|
const { customPermissionAmount } = this.state
|
|
|
|
const tokensText = `${Number(tokenAmount)} ${tokenSymbol}`
|
|
|
|
const tokenBalance = tokenTrackerBalance
|
|
? calcTokenAmount(tokenTrackerBalance, decimals).toString(10)
|
|
: ''
|
|
|
|
const customData = customPermissionAmount
|
|
? getCustomTxParamsData(data, { customPermissionAmount, decimals })
|
|
: null
|
|
|
|
return (
|
|
<ConfirmTransactionBase
|
|
toAddress={toAddress}
|
|
identiconAddress={tokenAddress}
|
|
showAccountInHeader
|
|
title={tokensText}
|
|
contentComponent={(
|
|
<ConfirmApproveContent
|
|
decimals={decimals}
|
|
siteImage={siteImage}
|
|
setCustomAmount={(newAmount) => {
|
|
this.setState({ customPermissionAmount: newAmount })
|
|
}}
|
|
customTokenAmount={String(customPermissionAmount)}
|
|
tokenAmount={tokenAmount}
|
|
origin={origin}
|
|
tokenSymbol={tokenSymbol}
|
|
tokenBalance={tokenBalance}
|
|
showCustomizeGasModal={() => showCustomizeGasModal(txData)}
|
|
showEditApprovalPermissionModal={showEditApprovalPermissionModal}
|
|
data={customData || data}
|
|
toAddress={toAddress}
|
|
currentCurrency={currentCurrency}
|
|
ethTransactionTotal={ethTransactionTotal}
|
|
fiatTransactionTotal={fiatTransactionTotal}
|
|
/>
|
|
)}
|
|
hideSenderToRecipient
|
|
customTxParamsData={customData}
|
|
{...restProps}
|
|
/>
|
|
)
|
|
}
|
|
}
|