aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2019-02-26 02:16:23 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2019-02-26 02:16:23 +0800
commitfdc7eb211340b3af035a7f7c023155a8f1b1675d (patch)
treea36305155083d8762043bb34bb8d7ea188a75b0e
parent65bfdeedc77e51dea28ef643b5ea9d50a8569c81 (diff)
downloadtangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.tar
tangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.tar.gz
tangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.tar.bz2
tangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.tar.lz
tangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.tar.xz
tangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.tar.zst
tangerine-wallet-browser-fdc7eb211340b3af035a7f7c023155a8f1b1675d.zip
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
-rw-r--r--ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js4
-rw-r--r--ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js1
-rw-r--r--ui/app/components/send/send-footer/tests/send-footer-container.test.js8
-rw-r--r--ui/app/components/send/send.utils.js6
-rw-r--r--ui/app/components/send/tests/send-utils.test.js3
-rw-r--r--ui/app/reducers/metamask.js2
6 files changed, 16 insertions, 8 deletions
diff --git a/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js b/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js
index 50cb47178..a187d61a2 100644
--- a/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js
+++ b/ui/app/components/send/send-content/send-gas-row/send-gas-row.container.js
@@ -26,7 +26,7 @@ import {
} from '../../../../ducks/gas.duck'
import { getGasLoadingError, gasFeeIsInError, getGasButtonGroupShown } from './send-gas-row.selectors.js'
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'
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(SendGasRow)
@@ -42,7 +42,7 @@ function mapStateToProps (state) {
const balance = getCurrentEthBalance(state)
const insufficientBalance = !isBalanceSufficient({
- amount: getSendAmount(state),
+ amount: getSelectedToken(state) ? '0x0' : getSendAmount(state),
gasTotal,
balance,
conversionRate,
diff --git a/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js b/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js
index 723c406f7..12e78657b 100644
--- a/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js
+++ b/ui/app/components/send/send-content/send-gas-row/tests/send-gas-row-container.test.js
@@ -35,6 +35,7 @@ proxyquire('../send-gas-row.container.js', {
'../../../../selectors': {
getCurrentEthBalance: (s) => `mockCurrentEthBalance:${s}`,
getAdvancedInlineGasShown: (s) => `mockAdvancedInlineGasShown:${s}`,
+ getSelectedToken: () => false,
},
'../../send.selectors.js': {
getConversionRate: (s) => `mockConversionRate:${s}`,
diff --git a/ui/app/components/send/send-footer/tests/send-footer-container.test.js b/ui/app/components/send/send-footer/tests/send-footer-container.test.js
index cf4c893ee..daefa5103 100644
--- a/ui/app/components/send/send-footer/tests/send-footer-container.test.js
+++ b/ui/app/components/send/send-footer/tests/send-footer-container.test.js
@@ -14,7 +14,9 @@ const actionSpies = {
}
const utilsStubs = {
addressIsNew: sinon.stub().returns(true),
- constructTxParams: sinon.stub().returns('mockConstructedTxParams'),
+ constructTxParams: sinon.stub().returns({
+ value: 'mockAmount',
+ }),
constructUpdatedTx: sinon.stub().returns('mockConstructedUpdatedTxParams'),
}
@@ -115,7 +117,7 @@ describe('send-footer container', () => {
)
assert.deepEqual(
actionSpies.signTokenTx.getCall(0).args,
- [ '0xabc', 'mockTo', 'mockAmount', 'mockConstructedTxParams' ]
+ [ '0xabc', 'mockTo', 'mockAmount', { value: 'mockAmount' } ]
)
})
@@ -143,7 +145,7 @@ describe('send-footer container', () => {
)
assert.deepEqual(
actionSpies.signTx.getCall(0).args,
- [ 'mockConstructedTxParams' ]
+ [ { value: 'mockAmount' } ]
)
})
})
diff --git a/ui/app/components/send/send.utils.js b/ui/app/components/send/send.utils.js
index b2ac41e9c..d78b7736f 100644
--- a/ui/app/components/send/send.utils.js
+++ b/ui/app/components/send/send.utils.js
@@ -234,10 +234,14 @@ async function estimateGas ({
if (to) {
paramsForGasEstimate.to = to
}
+
+ if (!value || value === '0') {
+ paramsForGasEstimate.value = '0xff'
+ }
}
// 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,
multiplierBase: 10,
roundDown: '0',
diff --git a/ui/app/components/send/tests/send-utils.test.js b/ui/app/components/send/tests/send-utils.test.js
index f31e1221b..48fa09392 100644
--- a/ui/app/components/send/tests/send-utils.test.js
+++ b/ui/app/components/send/tests/send-utils.test.js
@@ -316,6 +316,7 @@ describe('send utils', () => {
from: 'mockAddress',
gas: '0x64x0.95',
to: '0xisContract',
+ value: '0xff',
}
beforeEach(() => {
@@ -373,7 +374,7 @@ describe('send utils', () => {
assert.equal(baseMockParams.estimateGasMethod.callCount, 1)
assert.deepEqual(
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')
})
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
index 5a08f2d09..0de56ddbb 100644
--- a/ui/app/reducers/metamask.js
+++ b/ui/app/reducers/metamask.js
@@ -36,7 +36,7 @@ function reduceMetamask (state, action) {
tokenBalance: '0x0',
from: '',
to: '',
- amount: '0x0',
+ amount: '0',
memo: '',
errors: {},
maxModeOn: false,