2018-04-26 18:38:38 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2019-04-17 21:15:13 +02:00
|
|
|
import PageContainerFooter from '../../../components/ui/page-container/page-container-footer'
|
2020-06-01 19:54:32 +02:00
|
|
|
import { CONFIRM_TRANSACTION_ROUTE } from '../../../helpers/constants/routes'
|
2018-04-26 18:38:38 +02:00
|
|
|
|
|
|
|
export default class SendFooter extends Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
2018-04-27 02:38:14 +02:00
|
|
|
addToAddressBookIfNew: PropTypes.func,
|
2018-04-26 18:38:38 +02:00
|
|
|
amount: PropTypes.string,
|
2018-07-17 00:50:26 +02:00
|
|
|
data: PropTypes.string,
|
2018-04-26 18:38:38 +02:00
|
|
|
clearSend: PropTypes.func,
|
|
|
|
editingTransactionId: PropTypes.string,
|
|
|
|
from: PropTypes.object,
|
|
|
|
gasLimit: PropTypes.string,
|
|
|
|
gasPrice: PropTypes.string,
|
|
|
|
gasTotal: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
2018-05-25 02:53:54 +02:00
|
|
|
inError: PropTypes.bool,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: PropTypes.object,
|
2018-04-27 02:38:14 +02:00
|
|
|
sign: PropTypes.func,
|
2018-04-26 18:38:38 +02:00
|
|
|
to: PropTypes.string,
|
|
|
|
toAccounts: PropTypes.array,
|
|
|
|
tokenBalance: PropTypes.string,
|
|
|
|
unapprovedTxs: PropTypes.object,
|
2018-04-27 02:38:14 +02:00
|
|
|
update: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
sendErrors: PropTypes.object,
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasEstimateType: PropTypes.string,
|
2020-01-10 15:23:54 +01:00
|
|
|
gasIsLoading: PropTypes.bool,
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
2018-11-20 01:06:34 +01:00
|
|
|
}
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2018-07-02 04:09:28 +02:00
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-03-05 16:45:01 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2020-01-07 21:10:44 +01:00
|
|
|
}
|
2018-07-02 04:09:28 +02:00
|
|
|
|
2018-05-07 14:03:20 +02:00
|
|
|
onCancel () {
|
2020-06-01 19:54:32 +02:00
|
|
|
const { clearSend, history, mostRecentOverviewPage } = this.props
|
|
|
|
clearSend()
|
|
|
|
history.push(mostRecentOverviewPage)
|
2018-05-07 14:03:20 +02:00
|
|
|
}
|
|
|
|
|
2020-04-29 06:59:49 +02:00
|
|
|
async onSubmit (event) {
|
2018-04-26 18:38:38 +02:00
|
|
|
event.preventDefault()
|
|
|
|
const {
|
|
|
|
addToAddressBookIfNew,
|
|
|
|
amount,
|
2018-07-17 00:50:26 +02:00
|
|
|
data,
|
2018-04-26 18:38:38 +02:00
|
|
|
editingTransactionId,
|
2019-12-03 21:50:55 +01:00
|
|
|
from: { address: from },
|
2018-04-26 18:38:38 +02:00
|
|
|
gasLimit: gas,
|
|
|
|
gasPrice,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-26 18:38:38 +02:00
|
|
|
sign,
|
|
|
|
to,
|
|
|
|
unapprovedTxs,
|
|
|
|
// updateTx,
|
|
|
|
update,
|
|
|
|
toAccounts,
|
2018-06-23 08:52:45 +02:00
|
|
|
history,
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasEstimateType,
|
2018-04-26 18:38:38 +02:00
|
|
|
} = this.props
|
2019-03-05 16:45:01 +01:00
|
|
|
const { metricsEvent } = this.context
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2018-05-07 14:03:20 +02:00
|
|
|
// Should not be needed because submit should be disabled if there are errors.
|
2018-04-26 18:38:38 +02:00
|
|
|
// const noErrors = !amountError && toError === null
|
|
|
|
|
|
|
|
// if (!noErrors) {
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO: add nickname functionality
|
2020-04-29 06:59:49 +02:00
|
|
|
await addToAddressBookIfNew(to, toAccounts)
|
2018-06-23 08:52:45 +02:00
|
|
|
const promise = editingTransactionId
|
2018-04-26 18:38:38 +02:00
|
|
|
? update({
|
|
|
|
amount,
|
2018-07-17 00:50:26 +02:00
|
|
|
data,
|
2018-04-27 02:38:14 +02:00
|
|
|
editingTransactionId,
|
|
|
|
from,
|
2018-04-26 18:38:38 +02:00
|
|
|
gas,
|
|
|
|
gasPrice,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-27 02:38:14 +02:00
|
|
|
to,
|
2018-04-26 18:38:38 +02:00
|
|
|
unapprovedTxs,
|
|
|
|
})
|
2020-05-29 19:46:10 +02:00
|
|
|
: sign({ data, sendToken, to, amount, from, gas, gasPrice })
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
Promise.resolve(promise)
|
2019-03-05 16:45:01 +01:00
|
|
|
.then(() => {
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Complete',
|
|
|
|
},
|
2019-04-05 06:02:47 +02:00
|
|
|
customVariables: {
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasChanged: gasEstimateType,
|
2019-04-05 06:02:47 +02:00
|
|
|
},
|
2019-03-05 16:45:01 +01:00
|
|
|
})
|
|
|
|
history.push(CONFIRM_TRANSACTION_ROUTE)
|
|
|
|
})
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 02:53:54 +02:00
|
|
|
formShouldBeDisabled () {
|
2020-05-29 19:46:10 +02:00
|
|
|
const { data, inError, sendToken, tokenBalance, gasTotal, to, gasLimit, gasIsLoading } = this.props
|
|
|
|
const missingTokenBalance = sendToken && !tokenBalance
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
const gasLimitTooLow = gasLimit < 5208 // 5208 is hex value of 21000, minimum gas limit
|
2020-01-10 15:23:54 +01:00
|
|
|
const shouldBeDisabled = inError || !gasTotal || missingTokenBalance || !(data || to) || gasLimitTooLow || gasIsLoading
|
2019-03-05 16:45:01 +01:00
|
|
|
return shouldBeDisabled
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
const { inError, sendErrors } = this.props
|
|
|
|
const { metricsEvent } = this.context
|
|
|
|
if (!prevProps.inError && inError) {
|
2020-02-15 21:34:12 +01:00
|
|
|
const errorField = Object.keys(sendErrors).find((key) => sendErrors[key])
|
2019-03-05 16:45:01 +01:00
|
|
|
const errorMessage = sendErrors[errorField]
|
|
|
|
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Error',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
errorField,
|
|
|
|
errorMessage,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-05-25 02:53:54 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 18:38:38 +02:00
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<PageContainerFooter
|
2018-05-07 14:03:20 +02:00
|
|
|
onCancel={() => this.onCancel()}
|
2020-02-15 21:34:12 +01:00
|
|
|
onSubmit={(e) => this.onSubmit(e)}
|
2018-05-25 02:53:54 +02:00
|
|
|
disabled={this.formShouldBeDisabled()}
|
2018-04-26 18:38:38 +02:00
|
|
|
/>
|
2018-04-27 02:38:14 +02:00
|
|
|
)
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|