|
|
@ -1,11 +1,13 @@ |
|
|
|
import React, { Component } from 'react' |
|
|
|
import React, { Component } from 'react' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import ConfirmPageContainer, { ConfirmDetailRow } from '../../confirm-page-container' |
|
|
|
import ConfirmPageContainer, { ConfirmDetailRow } from '../../confirm-page-container' |
|
|
|
import { formatCurrency, getHexGasTotal } from '../../../helpers/confirm-transaction/util' |
|
|
|
import { formatCurrency } from '../../../helpers/confirm-transaction/util' |
|
|
|
import { isBalanceSufficient } from '../../send_/send.utils' |
|
|
|
import { isBalanceSufficient } from '../../send_/send.utils' |
|
|
|
import { DEFAULT_ROUTE } from '../../../routes' |
|
|
|
import { DEFAULT_ROUTE } from '../../../routes' |
|
|
|
import { conversionGreaterThan } from '../../../conversion-util' |
|
|
|
import { |
|
|
|
import { MIN_GAS_LIMIT_DEC } from '../../send_/send.constants' |
|
|
|
INSUFFICIENT_FUNDS_ERROR_KEY, |
|
|
|
|
|
|
|
TRANSACTION_ERROR_KEY, |
|
|
|
|
|
|
|
} from '../../../constants/error-keys' |
|
|
|
|
|
|
|
|
|
|
|
export default class ConfirmTransactionBase extends Component { |
|
|
|
export default class ConfirmTransactionBase extends Component { |
|
|
|
static contextTypes = { |
|
|
|
static contextTypes = { |
|
|
@ -13,57 +15,58 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static propTypes = { |
|
|
|
static propTypes = { |
|
|
|
|
|
|
|
// react-router props
|
|
|
|
match: PropTypes.object, |
|
|
|
match: PropTypes.object, |
|
|
|
history: PropTypes.object, |
|
|
|
history: PropTypes.object, |
|
|
|
// Redux props
|
|
|
|
// Redux props
|
|
|
|
txData: PropTypes.object, |
|
|
|
balance: PropTypes.string, |
|
|
|
tokenData: PropTypes.object, |
|
|
|
cancelTransaction: PropTypes.func, |
|
|
|
methodData: PropTypes.object, |
|
|
|
clearConfirmTransaction: PropTypes.func, |
|
|
|
tokenProps: PropTypes.object, |
|
|
|
clearSend: PropTypes.func, |
|
|
|
isTxReprice: PropTypes.bool, |
|
|
|
conversionRate: PropTypes.number, |
|
|
|
nonce: PropTypes.string, |
|
|
|
currentCurrency: PropTypes.string, |
|
|
|
fromName: PropTypes.string, |
|
|
|
editTransaction: PropTypes.func, |
|
|
|
fromAddress: PropTypes.string, |
|
|
|
|
|
|
|
toName: PropTypes.string, |
|
|
|
|
|
|
|
toAddress: PropTypes.string, |
|
|
|
|
|
|
|
transactionStatus: PropTypes.string, |
|
|
|
|
|
|
|
ethTransactionAmount: PropTypes.string, |
|
|
|
ethTransactionAmount: PropTypes.string, |
|
|
|
ethTransactionFee: PropTypes.string, |
|
|
|
ethTransactionFee: PropTypes.string, |
|
|
|
ethTransactionTotal: PropTypes.string, |
|
|
|
ethTransactionTotal: PropTypes.string, |
|
|
|
fiatTransactionAmount: PropTypes.string, |
|
|
|
fiatTransactionAmount: PropTypes.string, |
|
|
|
fiatTransactionFee: PropTypes.string, |
|
|
|
fiatTransactionFee: PropTypes.string, |
|
|
|
fiatTransactionTotal: PropTypes.string, |
|
|
|
fiatTransactionTotal: PropTypes.string, |
|
|
|
|
|
|
|
fromAddress: PropTypes.string, |
|
|
|
|
|
|
|
fromName: PropTypes.string, |
|
|
|
hexGasTotal: PropTypes.string, |
|
|
|
hexGasTotal: PropTypes.string, |
|
|
|
balance: PropTypes.string, |
|
|
|
isTxReprice: PropTypes.bool, |
|
|
|
currentCurrency: PropTypes.string, |
|
|
|
methodData: PropTypes.object, |
|
|
|
conversionRate: PropTypes.number, |
|
|
|
nonce: PropTypes.string, |
|
|
|
clearConfirmTransaction: PropTypes.func, |
|
|
|
|
|
|
|
cancelTransaction: PropTypes.func, |
|
|
|
|
|
|
|
clearSend: PropTypes.func, |
|
|
|
|
|
|
|
sendTransaction: PropTypes.func, |
|
|
|
sendTransaction: PropTypes.func, |
|
|
|
editTransaction: PropTypes.func, |
|
|
|
|
|
|
|
showCustomizeGasModal: PropTypes.func, |
|
|
|
showCustomizeGasModal: PropTypes.func, |
|
|
|
updateGasAndCalculate: PropTypes.func, |
|
|
|
|
|
|
|
showTransactionConfirmedModal: PropTypes.func, |
|
|
|
showTransactionConfirmedModal: PropTypes.func, |
|
|
|
|
|
|
|
toAddress: PropTypes.string, |
|
|
|
|
|
|
|
tokenData: PropTypes.object, |
|
|
|
|
|
|
|
tokenProps: PropTypes.object, |
|
|
|
|
|
|
|
toName: PropTypes.string, |
|
|
|
|
|
|
|
transactionStatus: PropTypes.string, |
|
|
|
|
|
|
|
txData: PropTypes.object, |
|
|
|
// Component props
|
|
|
|
// Component props
|
|
|
|
action: PropTypes.string, |
|
|
|
action: PropTypes.string, |
|
|
|
hideDetails: PropTypes.bool, |
|
|
|
|
|
|
|
hideData: PropTypes.bool, |
|
|
|
|
|
|
|
detailsComponent: PropTypes.node, |
|
|
|
|
|
|
|
dataComponent: PropTypes.node, |
|
|
|
|
|
|
|
summaryComponent: PropTypes.node, |
|
|
|
|
|
|
|
contentComponent: PropTypes.node, |
|
|
|
contentComponent: PropTypes.node, |
|
|
|
title: PropTypes.string, |
|
|
|
dataComponent: PropTypes.node, |
|
|
|
subtitle: PropTypes.string, |
|
|
|
detailsComponent: PropTypes.node, |
|
|
|
hideSubtitle: PropTypes.bool, |
|
|
|
errorKey: PropTypes.string, |
|
|
|
valid: PropTypes.bool, |
|
|
|
|
|
|
|
errorMessage: PropTypes.string, |
|
|
|
errorMessage: PropTypes.string, |
|
|
|
warning: PropTypes.string, |
|
|
|
hideData: PropTypes.bool, |
|
|
|
|
|
|
|
hideDetails: PropTypes.bool, |
|
|
|
|
|
|
|
hideSubtitle: PropTypes.bool, |
|
|
|
identiconAddress: PropTypes.string, |
|
|
|
identiconAddress: PropTypes.string, |
|
|
|
|
|
|
|
onCancel: PropTypes.func, |
|
|
|
onEdit: PropTypes.func, |
|
|
|
onEdit: PropTypes.func, |
|
|
|
onEditGas: PropTypes.func, |
|
|
|
onEditGas: PropTypes.func, |
|
|
|
onCancel: PropTypes.func, |
|
|
|
|
|
|
|
onSubmit: PropTypes.func, |
|
|
|
onSubmit: PropTypes.func, |
|
|
|
|
|
|
|
subtitle: PropTypes.string, |
|
|
|
|
|
|
|
summaryComponent: PropTypes.node, |
|
|
|
|
|
|
|
title: PropTypes.string, |
|
|
|
|
|
|
|
valid: PropTypes.bool, |
|
|
|
|
|
|
|
warning: PropTypes.string, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate () { |
|
|
|
componentDidUpdate () { |
|
|
@ -86,9 +89,7 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getError () { |
|
|
|
getErrorKey () { |
|
|
|
const INSUFFICIENT_FUNDS_ERROR = this.context.t('insufficientFunds') |
|
|
|
|
|
|
|
const TRANSACTION_ERROR = this.context.t('transactionError') |
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
|
balance, |
|
|
|
balance, |
|
|
|
conversionRate, |
|
|
|
conversionRate, |
|
|
@ -111,68 +112,14 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
if (insufficientBalance) { |
|
|
|
if (insufficientBalance) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
valid: false, |
|
|
|
valid: false, |
|
|
|
errorMessage: INSUFFICIENT_FUNDS_ERROR, |
|
|
|
errorKey: INSUFFICIENT_FUNDS_ERROR_KEY, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (simulationFails) { |
|
|
|
if (simulationFails) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
valid: false, |
|
|
|
valid: false, |
|
|
|
errorMessage: TRANSACTION_ERROR, |
|
|
|
errorKey: TRANSACTION_ERROR_KEY, |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
valid: true, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validateEditGas ({ gasLimit, gasPrice }) { |
|
|
|
|
|
|
|
const { t } = this.context |
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
balance, |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
txData: { |
|
|
|
|
|
|
|
txParams: { |
|
|
|
|
|
|
|
value: amount, |
|
|
|
|
|
|
|
} = {}, |
|
|
|
|
|
|
|
} = {}, |
|
|
|
|
|
|
|
} = this.props |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const INSUFFICIENT_FUNDS_ERROR = t('insufficientFunds') |
|
|
|
|
|
|
|
const GAS_LIMIT_TOO_LOW_ERROR = t('gasLimitTooLow') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const gasTotal = getHexGasTotal({ gasLimit, gasPrice }) |
|
|
|
|
|
|
|
const hasSufficientBalance = isBalanceSufficient({ |
|
|
|
|
|
|
|
amount, |
|
|
|
|
|
|
|
gasTotal, |
|
|
|
|
|
|
|
balance, |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasSufficientBalance) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
valid: false, |
|
|
|
|
|
|
|
errorMessage: INSUFFICIENT_FUNDS_ERROR, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const gasLimitTooLow = gasLimit && conversionGreaterThan( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
value: MIN_GAS_LIMIT_DEC, |
|
|
|
|
|
|
|
fromNumericBase: 'dec', |
|
|
|
|
|
|
|
conversionRate, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
value: gasLimit, |
|
|
|
|
|
|
|
fromNumericBase: 'hex', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gasLimitTooLow) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
valid: false, |
|
|
|
|
|
|
|
errorMessage: GAS_LIMIT_TOO_LOW_ERROR, |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -182,16 +129,12 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleEditGas () { |
|
|
|
handleEditGas () { |
|
|
|
const { onEditGas, showCustomizeGasModal, txData, updateGasAndCalculate } = this.props |
|
|
|
const { onEditGas, showCustomizeGasModal } = this.props |
|
|
|
|
|
|
|
|
|
|
|
if (onEditGas) { |
|
|
|
if (onEditGas) { |
|
|
|
onEditGas() |
|
|
|
onEditGas() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
showCustomizeGasModal({ |
|
|
|
showCustomizeGasModal() |
|
|
|
txData, |
|
|
|
|
|
|
|
onSubmit: txData => updateGasAndCalculate(txData), |
|
|
|
|
|
|
|
validate: ({ gasLimit, gasPrice }) => this.validateEditGas({ gasLimit, gasPrice }), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -328,7 +271,8 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
ethTransactionAmount, |
|
|
|
ethTransactionAmount, |
|
|
|
fiatTransactionAmount, |
|
|
|
fiatTransactionAmount, |
|
|
|
valid: propsValid, |
|
|
|
valid: propsValid, |
|
|
|
errorMessage: propsErrorMessage, |
|
|
|
errorMessage, |
|
|
|
|
|
|
|
errorKey: propsErrorKey, |
|
|
|
currentCurrency, |
|
|
|
currentCurrency, |
|
|
|
action, |
|
|
|
action, |
|
|
|
title, |
|
|
|
title, |
|
|
@ -344,7 +288,7 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
|
|
|
|
|
|
|
|
const { name } = methodData |
|
|
|
const { name } = methodData |
|
|
|
const fiatConvertedAmount = formatCurrency(fiatTransactionAmount, currentCurrency) |
|
|
|
const fiatConvertedAmount = formatCurrency(fiatTransactionAmount, currentCurrency) |
|
|
|
const { valid, errorMessage } = this.getError() |
|
|
|
const { valid, errorKey } = this.getErrorKey() |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<ConfirmPageContainer |
|
|
|
<ConfirmPageContainer |
|
|
@ -363,7 +307,8 @@ export default class ConfirmTransactionBase extends Component { |
|
|
|
contentComponent={contentComponent} |
|
|
|
contentComponent={contentComponent} |
|
|
|
nonce={nonce} |
|
|
|
nonce={nonce} |
|
|
|
identiconAddress={identiconAddress} |
|
|
|
identiconAddress={identiconAddress} |
|
|
|
errorMessage={propsErrorMessage || errorMessage} |
|
|
|
errorMessage={errorMessage} |
|
|
|
|
|
|
|
errorKey={propsErrorKey || errorKey} |
|
|
|
warning={warning} |
|
|
|
warning={warning} |
|
|
|
valid={propsValid || valid} |
|
|
|
valid={propsValid || valid} |
|
|
|
onEdit={() => this.handleEdit()} |
|
|
|
onEdit={() => this.handleEdit()} |
|
|
|