2018-04-27 21:03:00 +02:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import PersistentForm from '../../../lib/persistent-form'
|
|
|
|
import {
|
|
|
|
getAmountErrorObject,
|
2018-06-29 19:19:40 +02:00
|
|
|
getGasFeeErrorObject,
|
2018-06-18 18:37:01 +02:00
|
|
|
getToAddressForGasUpdate,
|
2018-04-27 21:03:00 +02:00
|
|
|
doesAmountErrorRequireUpdate,
|
|
|
|
} from './send.utils'
|
|
|
|
|
2018-05-15 14:29:23 +02:00
|
|
|
import SendHeader from './send-header/'
|
|
|
|
import SendContent from './send-content/'
|
|
|
|
import SendFooter from './send-footer/'
|
2018-04-27 21:03:00 +02:00
|
|
|
|
|
|
|
export default class SendTransactionScreen extends PersistentForm {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
amount: PropTypes.string,
|
|
|
|
amountConversionRate: PropTypes.oneOfType([
|
|
|
|
PropTypes.string,
|
|
|
|
PropTypes.number,
|
|
|
|
]),
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit: PropTypes.string,
|
2018-04-27 21:03:00 +02:00
|
|
|
conversionRate: PropTypes.number,
|
|
|
|
editingTransactionId: PropTypes.string,
|
|
|
|
from: PropTypes.object,
|
|
|
|
gasLimit: PropTypes.string,
|
|
|
|
gasPrice: PropTypes.string,
|
|
|
|
gasTotal: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
|
|
|
network: PropTypes.string,
|
|
|
|
primaryCurrency: PropTypes.string,
|
2018-05-22 10:10:06 +02:00
|
|
|
recentBlocks: PropTypes.array,
|
2018-04-27 21:03:00 +02:00
|
|
|
selectedAddress: PropTypes.string,
|
|
|
|
selectedToken: PropTypes.object,
|
|
|
|
tokenBalance: PropTypes.string,
|
|
|
|
tokenContract: PropTypes.object,
|
|
|
|
updateAndSetGasTotal: PropTypes.func,
|
|
|
|
updateSendErrors: PropTypes.func,
|
|
|
|
updateSendTokenBalance: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
2018-06-18 18:37:01 +02:00
|
|
|
updateGas ({ to: updatedToAddress, amount: value } = {}) {
|
2018-04-27 21:03:00 +02:00
|
|
|
const {
|
2018-05-23 18:43:25 +02:00
|
|
|
amount,
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit,
|
2018-04-27 21:03:00 +02:00
|
|
|
editingTransactionId,
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
2018-05-22 10:10:06 +02:00
|
|
|
recentBlocks,
|
2018-04-27 21:03:00 +02:00
|
|
|
selectedAddress,
|
|
|
|
selectedToken = {},
|
2018-06-18 18:37:01 +02:00
|
|
|
to: currentToAddress,
|
2018-04-27 21:03:00 +02:00
|
|
|
updateAndSetGasTotal,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
updateAndSetGasTotal({
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit,
|
2018-04-27 21:03:00 +02:00
|
|
|
editingTransactionId,
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
2018-05-22 10:10:06 +02:00
|
|
|
recentBlocks,
|
2018-04-27 21:03:00 +02:00
|
|
|
selectedAddress,
|
|
|
|
selectedToken,
|
2018-06-18 18:37:01 +02:00
|
|
|
to: getToAddressForGasUpdate(updatedToAddress, currentToAddress),
|
2018-06-15 23:36:52 +02:00
|
|
|
value: value || amount,
|
2018-04-27 21:03:00 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const {
|
|
|
|
amount,
|
|
|
|
amountConversionRate,
|
|
|
|
conversionRate,
|
|
|
|
from: { address, balance },
|
|
|
|
gasTotal,
|
|
|
|
network,
|
|
|
|
primaryCurrency,
|
|
|
|
selectedToken,
|
|
|
|
tokenBalance,
|
|
|
|
updateSendErrors,
|
|
|
|
updateSendTokenBalance,
|
|
|
|
tokenContract,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const {
|
|
|
|
from: { balance: prevBalance },
|
|
|
|
gasTotal: prevGasTotal,
|
|
|
|
tokenBalance: prevTokenBalance,
|
|
|
|
network: prevNetwork,
|
|
|
|
} = prevProps
|
|
|
|
|
|
|
|
const uninitialized = [prevBalance, prevGasTotal].every(n => n === null)
|
2018-05-24 21:57:33 +02:00
|
|
|
|
2018-05-30 18:40:30 +02:00
|
|
|
const amountErrorRequiresUpdate = doesAmountErrorRequireUpdate({
|
|
|
|
balance,
|
|
|
|
gasTotal,
|
|
|
|
prevBalance,
|
|
|
|
prevGasTotal,
|
|
|
|
prevTokenBalance,
|
|
|
|
selectedToken,
|
|
|
|
tokenBalance,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (amountErrorRequiresUpdate) {
|
|
|
|
const amountErrorObject = getAmountErrorObject({
|
|
|
|
amount,
|
|
|
|
amountConversionRate,
|
2018-04-27 21:03:00 +02:00
|
|
|
balance,
|
2018-05-30 18:40:30 +02:00
|
|
|
conversionRate,
|
2018-04-27 21:03:00 +02:00
|
|
|
gasTotal,
|
2018-05-30 18:40:30 +02:00
|
|
|
primaryCurrency,
|
2018-04-27 21:03:00 +02:00
|
|
|
selectedToken,
|
|
|
|
tokenBalance,
|
|
|
|
})
|
2018-06-29 19:19:40 +02:00
|
|
|
const gasFeeErrorObject = selectedToken
|
|
|
|
? getGasFeeErrorObject({
|
|
|
|
amount,
|
|
|
|
amountConversionRate,
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
gasTotal,
|
|
|
|
primaryCurrency,
|
|
|
|
selectedToken,
|
|
|
|
tokenBalance,
|
|
|
|
})
|
|
|
|
: { gasFee: null }
|
|
|
|
updateSendErrors(Object.assign(amountErrorObject, gasFeeErrorObject))
|
2018-05-30 18:40:30 +02:00
|
|
|
}
|
2018-04-27 21:03:00 +02:00
|
|
|
|
2018-05-30 18:40:30 +02:00
|
|
|
if (!uninitialized) {
|
2018-04-27 21:03:00 +02:00
|
|
|
|
|
|
|
if (network !== prevNetwork && network !== 'loading') {
|
|
|
|
updateSendTokenBalance({
|
|
|
|
selectedToken,
|
|
|
|
tokenContract,
|
|
|
|
address,
|
|
|
|
})
|
|
|
|
this.updateGas()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount () {
|
2018-05-23 21:26:13 +02:00
|
|
|
const {
|
2018-05-24 21:57:33 +02:00
|
|
|
from: { address },
|
2018-05-23 21:26:13 +02:00
|
|
|
selectedToken,
|
|
|
|
tokenContract,
|
|
|
|
updateSendTokenBalance,
|
|
|
|
} = this.props
|
|
|
|
updateSendTokenBalance({
|
|
|
|
selectedToken,
|
|
|
|
tokenContract,
|
|
|
|
address,
|
|
|
|
})
|
2018-04-27 21:03:00 +02:00
|
|
|
this.updateGas()
|
|
|
|
}
|
|
|
|
|
2018-06-29 19:19:40 +02:00
|
|
|
componentWillUnmount () {
|
|
|
|
this.props.resetSendState()
|
|
|
|
}
|
|
|
|
|
2018-04-27 21:03:00 +02:00
|
|
|
render () {
|
|
|
|
const { history } = this.props
|
|
|
|
|
|
|
|
return (
|
2018-05-01 04:42:57 +02:00
|
|
|
<div className="page-container">
|
2018-04-30 17:30:51 +02:00
|
|
|
<SendHeader history={history}/>
|
2018-05-23 18:43:25 +02:00
|
|
|
<SendContent updateGas={(updateData) => this.updateGas(updateData)}/>
|
2018-04-27 21:03:00 +02:00
|
|
|
<SendFooter history={history}/>
|
2018-05-01 04:42:57 +02:00
|
|
|
</div>
|
2018-04-27 21:03:00 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|