mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Remove unused props, prevent redundant gas update (#7769)
These unused props weren't being caught by ESLint because this component extended another, which I guess made it difficult for the React plugin to determine what was unused. The `componentWillUpdate` logic was moved into `componentDidUpdate` so that it would be picked up by ESLint. Also it seemed like a sensible place for it to go. Having three redundant gas updates as part of the same lifecycle function seemed too far, so I ensured it's only called once.
This commit is contained in:
parent
728026d1f7
commit
f20e028cde
@ -19,6 +19,7 @@ import EnsInput from './send-content/add-recipient/ens-input'
|
|||||||
export default class SendTransactionScreen extends PersistentForm {
|
export default class SendTransactionScreen extends PersistentForm {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
addressBook: PropTypes.arrayOf(PropTypes.object),
|
||||||
amount: PropTypes.string,
|
amount: PropTypes.string,
|
||||||
amountConversionRate: PropTypes.oneOfType([
|
amountConversionRate: PropTypes.oneOfType([
|
||||||
PropTypes.string,
|
PropTypes.string,
|
||||||
@ -32,6 +33,7 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
gasLimit: PropTypes.string,
|
gasLimit: PropTypes.string,
|
||||||
gasPrice: PropTypes.string,
|
gasPrice: PropTypes.string,
|
||||||
gasTotal: PropTypes.string,
|
gasTotal: PropTypes.string,
|
||||||
|
hasHexData: PropTypes.bool,
|
||||||
history: PropTypes.object,
|
history: PropTypes.object,
|
||||||
network: PropTypes.string,
|
network: PropTypes.string,
|
||||||
primaryCurrency: PropTypes.string,
|
primaryCurrency: PropTypes.string,
|
||||||
@ -45,7 +47,6 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
tokens: PropTypes.array,
|
tokens: PropTypes.array,
|
||||||
tokenBalance: PropTypes.string,
|
tokenBalance: PropTypes.string,
|
||||||
tokenContract: PropTypes.object,
|
tokenContract: PropTypes.object,
|
||||||
updateAndSetGasTotal: PropTypes.func,
|
|
||||||
updateAndSetGasLimit: PropTypes.func.isRequired,
|
updateAndSetGasLimit: PropTypes.func.isRequired,
|
||||||
updateSendEnsResolution: PropTypes.func.isRequired,
|
updateSendEnsResolution: PropTypes.func.isRequired,
|
||||||
updateSendEnsResolutionError: PropTypes.func.isRequired,
|
updateSendEnsResolutionError: PropTypes.func.isRequired,
|
||||||
@ -56,8 +57,6 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
scanQrCode: PropTypes.func.isRequired,
|
scanQrCode: PropTypes.func.isRequired,
|
||||||
qrCodeDetected: PropTypes.func.isRequired,
|
qrCodeDetected: PropTypes.func.isRequired,
|
||||||
qrCodeData: PropTypes.object,
|
qrCodeData: PropTypes.object,
|
||||||
ensResolution: PropTypes.string,
|
|
||||||
ensResolutionError: PropTypes.string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
@ -76,21 +75,6 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
this.dValidate = debounce(this.validate, 1000)
|
this.dValidate = debounce(this.validate, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
UNSAFE_componentWillReceiveProps (nextProps) {
|
|
||||||
if (nextProps.qrCodeData) {
|
|
||||||
if (nextProps.qrCodeData.type === 'address') {
|
|
||||||
const scannedAddress = nextProps.qrCodeData.values.address.toLowerCase()
|
|
||||||
const currentAddress = this.props.to && this.props.to.toLowerCase()
|
|
||||||
if (currentAddress !== scannedAddress) {
|
|
||||||
this.props.updateSendTo(scannedAddress)
|
|
||||||
this.updateGas({ to: scannedAddress })
|
|
||||||
// Clean up QR code data after handling
|
|
||||||
this.props.qrCodeDetected(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate (prevProps) {
|
componentDidUpdate (prevProps) {
|
||||||
const {
|
const {
|
||||||
amount,
|
amount,
|
||||||
@ -103,20 +87,25 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
selectedToken,
|
selectedToken,
|
||||||
tokenBalance,
|
tokenBalance,
|
||||||
updateSendErrors,
|
updateSendErrors,
|
||||||
|
updateSendTo,
|
||||||
updateSendTokenBalance,
|
updateSendTokenBalance,
|
||||||
tokenContract,
|
tokenContract,
|
||||||
to,
|
to,
|
||||||
toNickname,
|
toNickname,
|
||||||
addressBook,
|
addressBook,
|
||||||
updateToNicknameIfNecessary,
|
updateToNicknameIfNecessary,
|
||||||
|
qrCodeData,
|
||||||
|
qrCodeDetected,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
|
let updateGas = false
|
||||||
const {
|
const {
|
||||||
from: { balance: prevBalance },
|
from: { balance: prevBalance },
|
||||||
gasTotal: prevGasTotal,
|
gasTotal: prevGasTotal,
|
||||||
tokenBalance: prevTokenBalance,
|
tokenBalance: prevTokenBalance,
|
||||||
network: prevNetwork,
|
network: prevNetwork,
|
||||||
selectedToken: prevSelectedToken,
|
selectedToken: prevSelectedToken,
|
||||||
|
to: prevTo,
|
||||||
} = prevProps
|
} = prevProps
|
||||||
|
|
||||||
const uninitialized = [prevBalance, prevGasTotal].every(n => n === null)
|
const uninitialized = [prevBalance, prevGasTotal].every(n => n === null)
|
||||||
@ -164,7 +153,7 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
address,
|
address,
|
||||||
})
|
})
|
||||||
updateToNicknameIfNecessary(to, toNickname, addressBook)
|
updateToNicknameIfNecessary(to, toNickname, addressBook)
|
||||||
this.updateGas()
|
updateGas = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +162,29 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
|
|
||||||
if (selectedTokenAddress && prevTokenAddress !== selectedTokenAddress) {
|
if (selectedTokenAddress && prevTokenAddress !== selectedTokenAddress) {
|
||||||
this.updateSendToken()
|
this.updateSendToken()
|
||||||
this.updateGas()
|
updateGas = true
|
||||||
|
}
|
||||||
|
|
||||||
|
let scannedAddress
|
||||||
|
if (qrCodeData) {
|
||||||
|
if (qrCodeData.type === 'address') {
|
||||||
|
scannedAddress = qrCodeData.values.address.toLowerCase()
|
||||||
|
const currentAddress = prevTo && prevTo.toLowerCase()
|
||||||
|
if (currentAddress !== scannedAddress) {
|
||||||
|
updateSendTo(scannedAddress)
|
||||||
|
updateGas = true
|
||||||
|
// Clean up QR code data after handling
|
||||||
|
qrCodeDetected(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateGas) {
|
||||||
|
if (scannedAddress) {
|
||||||
|
this.updateGas({ to: scannedAddress })
|
||||||
|
} else {
|
||||||
|
this.updateGas()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ import {
|
|||||||
getSendToNickname,
|
getSendToNickname,
|
||||||
getTokenBalance,
|
getTokenBalance,
|
||||||
getQrCodeData,
|
getQrCodeData,
|
||||||
getSendEnsResolution,
|
|
||||||
getSendEnsResolutionError,
|
|
||||||
} from './send.selectors'
|
} from './send.selectors'
|
||||||
import {
|
import {
|
||||||
getSelectedAddress,
|
getSelectedAddress,
|
||||||
@ -67,8 +65,6 @@ function mapStateToProps (state) {
|
|||||||
blockGasLimit: getBlockGasLimit(state),
|
blockGasLimit: getBlockGasLimit(state),
|
||||||
conversionRate: getConversionRate(state),
|
conversionRate: getConversionRate(state),
|
||||||
editingTransactionId: getSendEditingTransactionId(state),
|
editingTransactionId: getSendEditingTransactionId(state),
|
||||||
ensResolution: getSendEnsResolution(state),
|
|
||||||
ensResolutionError: getSendEnsResolutionError(state),
|
|
||||||
from: getSendFromObject(state),
|
from: getSendFromObject(state),
|
||||||
gasLimit: getGasLimit(state),
|
gasLimit: getGasLimit(state),
|
||||||
gasPrice: getGasPrice(state),
|
gasPrice: getGasPrice(state),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user