mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix gas estimation when sending to contracts (#6195)
* Fix gas estimation when sending to contracts * Fix calculating of balance sufficiency and tx params when sending token transaction
This commit is contained in:
parent
65bfdeedc7
commit
fdc7eb2113
@ -26,7 +26,7 @@ import {
|
|||||||
} from '../../../../ducks/gas.duck'
|
} from '../../../../ducks/gas.duck'
|
||||||
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
|
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
|
||||||
import { showModal, setGasPrice, setGasLimit, setGasTotal } from '../../../../actions'
|
import { showModal, setGasPrice, setGasLimit, setGasTotal } from '../../../../actions'
|
||||||
import { getAdvancedInlineGasShown, getCurrentEthBalance } from '../../../../selectors'
|
import { getAdvancedInlineGasShown, getCurrentEthBalance, getSelectedToken } from '../../../../selectors'
|
||||||
import SendGasRow from './send-gas-row.component'
|
import SendGasRow from './send-gas-row.component'
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(SendGasRow)
|
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(SendGasRow)
|
||||||
@ -42,7 +42,7 @@ function mapStateToProps (state) {
|
|||||||
const balance = getCurrentEthBalance(state)
|
const balance = getCurrentEthBalance(state)
|
||||||
|
|
||||||
const insufficientBalance = !isBalanceSufficient({
|
const insufficientBalance = !isBalanceSufficient({
|
||||||
amount: getSendAmount(state),
|
amount: getSelectedToken(state) ? '0x0' : getSendAmount(state),
|
||||||
gasTotal,
|
gasTotal,
|
||||||
balance,
|
balance,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
|
@ -35,6 +35,7 @@ proxyquire('../send-gas-row.container.js', {
|
|||||||
'../../../../selectors': {
|
'../../../../selectors': {
|
||||||
getCurrentEthBalance: (s) => `mockCurrentEthBalance:${s}`,
|
getCurrentEthBalance: (s) => `mockCurrentEthBalance:${s}`,
|
||||||
getAdvancedInlineGasShown: (s) => `mockAdvancedInlineGasShown:${s}`,
|
getAdvancedInlineGasShown: (s) => `mockAdvancedInlineGasShown:${s}`,
|
||||||
|
getSelectedToken: () => false,
|
||||||
},
|
},
|
||||||
'../../send.selectors.js': {
|
'../../send.selectors.js': {
|
||||||
getConversionRate: (s) => `mockConversionRate:${s}`,
|
getConversionRate: (s) => `mockConversionRate:${s}`,
|
||||||
|
@ -14,7 +14,9 @@ const actionSpies = {
|
|||||||
}
|
}
|
||||||
const utilsStubs = {
|
const utilsStubs = {
|
||||||
addressIsNew: sinon.stub().returns(true),
|
addressIsNew: sinon.stub().returns(true),
|
||||||
constructTxParams: sinon.stub().returns('mockConstructedTxParams'),
|
constructTxParams: sinon.stub().returns({
|
||||||
|
value: 'mockAmount',
|
||||||
|
}),
|
||||||
constructUpdatedTx: sinon.stub().returns('mockConstructedUpdatedTxParams'),
|
constructUpdatedTx: sinon.stub().returns('mockConstructedUpdatedTxParams'),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +117,7 @@ describe('send-footer container', () => {
|
|||||||
)
|
)
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
actionSpies.signTokenTx.getCall(0).args,
|
actionSpies.signTokenTx.getCall(0).args,
|
||||||
[ '0xabc', 'mockTo', 'mockAmount', 'mockConstructedTxParams' ]
|
[ '0xabc', 'mockTo', 'mockAmount', { value: 'mockAmount' } ]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -143,7 +145,7 @@ describe('send-footer container', () => {
|
|||||||
)
|
)
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
actionSpies.signTx.getCall(0).args,
|
actionSpies.signTx.getCall(0).args,
|
||||||
[ 'mockConstructedTxParams' ]
|
[ { value: 'mockAmount' } ]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -234,10 +234,14 @@ async function estimateGas ({
|
|||||||
if (to) {
|
if (to) {
|
||||||
paramsForGasEstimate.to = to
|
paramsForGasEstimate.to = to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!value || value === '0') {
|
||||||
|
paramsForGasEstimate.value = '0xff'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not, fall back to block gasLimit
|
// if not, fall back to block gasLimit
|
||||||
paramsForGasEstimate.gas = ethUtil.addHexPrefix(multiplyCurrencies(blockGasLimit, 0.95, {
|
paramsForGasEstimate.gas = ethUtil.addHexPrefix(multiplyCurrencies(blockGasLimit || '0x5208', 0.95, {
|
||||||
multiplicandBase: 16,
|
multiplicandBase: 16,
|
||||||
multiplierBase: 10,
|
multiplierBase: 10,
|
||||||
roundDown: '0',
|
roundDown: '0',
|
||||||
|
@ -316,6 +316,7 @@ describe('send utils', () => {
|
|||||||
from: 'mockAddress',
|
from: 'mockAddress',
|
||||||
gas: '0x64x0.95',
|
gas: '0x64x0.95',
|
||||||
to: '0xisContract',
|
to: '0xisContract',
|
||||||
|
value: '0xff',
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -373,7 +374,7 @@ describe('send utils', () => {
|
|||||||
assert.equal(baseMockParams.estimateGasMethod.callCount, 1)
|
assert.equal(baseMockParams.estimateGasMethod.callCount, 1)
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
baseMockParams.estimateGasMethod.getCall(0).args[0],
|
baseMockParams.estimateGasMethod.getCall(0).args[0],
|
||||||
{ gasPrice: undefined, value: undefined, data, from: baseExpectedCall.from, gas: baseExpectedCall.gas},
|
{ gasPrice: undefined, value: '0xff', data, from: baseExpectedCall.from, gas: baseExpectedCall.gas},
|
||||||
)
|
)
|
||||||
assert.equal(result, '0xabc16')
|
assert.equal(result, '0xabc16')
|
||||||
})
|
})
|
||||||
|
@ -36,7 +36,7 @@ function reduceMetamask (state, action) {
|
|||||||
tokenBalance: '0x0',
|
tokenBalance: '0x0',
|
||||||
from: '',
|
from: '',
|
||||||
to: '',
|
to: '',
|
||||||
amount: '0x0',
|
amount: '0',
|
||||||
memo: '',
|
memo: '',
|
||||||
errors: {},
|
errors: {},
|
||||||
maxModeOn: false,
|
maxModeOn: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user