You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.1 KiB
180 lines
4.1 KiB
7 years ago
|
import React from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
|
import PersistentForm from '../../../lib/persistent-form'
|
||
|
import {
|
||
|
getAmountErrorObject,
|
||
7 years ago
|
getGasFeeErrorObject,
|
||
7 years ago
|
getToAddressForGasUpdate,
|
||
7 years ago
|
doesAmountErrorRequireUpdate,
|
||
|
} from './send.utils'
|
||
|
|
||
7 years ago
|
import SendHeader from './send-header/'
|
||
|
import SendContent from './send-content/'
|
||
|
import SendFooter from './send-footer/'
|
||
7 years ago
|
|
||
|
export default class SendTransactionScreen extends PersistentForm {
|
||
|
|
||
|
static propTypes = {
|
||
|
amount: PropTypes.string,
|
||
|
amountConversionRate: PropTypes.oneOfType([
|
||
|
PropTypes.string,
|
||
|
PropTypes.number,
|
||
|
]),
|
||
7 years ago
|
blockGasLimit: PropTypes.string,
|
||
7 years ago
|
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,
|
||
7 years ago
|
recentBlocks: PropTypes.array,
|
||
7 years ago
|
selectedAddress: PropTypes.string,
|
||
|
selectedToken: PropTypes.object,
|
||
|
tokenBalance: PropTypes.string,
|
||
|
tokenContract: PropTypes.object,
|
||
|
updateAndSetGasTotal: PropTypes.func,
|
||
|
updateSendErrors: PropTypes.func,
|
||
|
updateSendTokenBalance: PropTypes.func,
|
||
|
};
|
||
|
|
||
7 years ago
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
|
};
|
||
|
|
||
7 years ago
|
updateGas ({ to: updatedToAddress, amount: value } = {}) {
|
||
7 years ago
|
const {
|
||
7 years ago
|
amount,
|
||
7 years ago
|
blockGasLimit,
|
||
7 years ago
|
editingTransactionId,
|
||
|
gasLimit,
|
||
|
gasPrice,
|
||
7 years ago
|
recentBlocks,
|
||
7 years ago
|
selectedAddress,
|
||
|
selectedToken = {},
|
||
7 years ago
|
to: currentToAddress,
|
||
7 years ago
|
updateAndSetGasTotal,
|
||
|
} = this.props
|
||
|
|
||
|
updateAndSetGasTotal({
|
||
7 years ago
|
blockGasLimit,
|
||
7 years ago
|
editingTransactionId,
|
||
|
gasLimit,
|
||
|
gasPrice,
|
||
7 years ago
|
recentBlocks,
|
||
7 years ago
|
selectedAddress,
|
||
|
selectedToken,
|
||
7 years ago
|
to: getToAddressForGasUpdate(updatedToAddress, currentToAddress),
|
||
7 years ago
|
value: value || amount,
|
||
7 years ago
|
})
|
||
|
}
|
||
|
|
||
|
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)
|
||
7 years ago
|
|
||
7 years ago
|
const amountErrorRequiresUpdate = doesAmountErrorRequireUpdate({
|
||
|
balance,
|
||
|
gasTotal,
|
||
|
prevBalance,
|
||
|
prevGasTotal,
|
||
|
prevTokenBalance,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
|
})
|
||
|
|
||
|
if (amountErrorRequiresUpdate) {
|
||
|
const amountErrorObject = getAmountErrorObject({
|
||
|
amount,
|
||
|
amountConversionRate,
|
||
7 years ago
|
balance,
|
||
7 years ago
|
conversionRate,
|
||
7 years ago
|
gasTotal,
|
||
7 years ago
|
primaryCurrency,
|
||
7 years ago
|
selectedToken,
|
||
|
tokenBalance,
|
||
|
})
|
||
7 years ago
|
const gasFeeErrorObject = selectedToken
|
||
|
? getGasFeeErrorObject({
|
||
|
amount,
|
||
|
amountConversionRate,
|
||
|
balance,
|
||
|
conversionRate,
|
||
|
gasTotal,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
tokenBalance,
|
||
|
})
|
||
|
: { gasFee: null }
|
||
|
updateSendErrors(Object.assign(amountErrorObject, gasFeeErrorObject))
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
if (!uninitialized) {
|
||
7 years ago
|
|
||
|
if (network !== prevNetwork && network !== 'loading') {
|
||
|
updateSendTokenBalance({
|
||
|
selectedToken,
|
||
|
tokenContract,
|
||
|
address,
|
||
|
})
|
||
|
this.updateGas()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
componentWillMount () {
|
||
7 years ago
|
const {
|
||
7 years ago
|
from: { address },
|
||
7 years ago
|
selectedToken,
|
||
|
tokenContract,
|
||
|
updateSendTokenBalance,
|
||
|
} = this.props
|
||
|
updateSendTokenBalance({
|
||
|
selectedToken,
|
||
|
tokenContract,
|
||
|
address,
|
||
|
})
|
||
7 years ago
|
this.updateGas()
|
||
|
}
|
||
|
|
||
7 years ago
|
componentWillUnmount () {
|
||
|
this.props.resetSendState()
|
||
|
}
|
||
|
|
||
7 years ago
|
render () {
|
||
|
const { history } = this.props
|
||
|
|
||
|
return (
|
||
7 years ago
|
<div className="page-container">
|
||
7 years ago
|
<SendHeader history={history}/>
|
||
7 years ago
|
<SendContent updateGas={(updateData) => this.updateGas(updateData)}/>
|
||
7 years ago
|
<SendFooter history={history}/>
|
||
7 years ago
|
</div>
|
||
7 years ago
|
)
|
||
|
}
|
||
|
|
||
|
}
|