mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-10-22 19:26:13 +02:00
Fix gasPrice range
This commit is contained in:
parent
229d95956b
commit
c400f7c0f6
@ -384,3 +384,15 @@ ConfigManager.prototype.createShapeShiftTx = function (depositAddress, depositTy
|
|||||||
}
|
}
|
||||||
this.setData(data)
|
this.setData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigManager.prototype.getGasMultiplier = function () {
|
||||||
|
var data = this.getData()
|
||||||
|
return ('gasMultiplier' in data) && data.gasMultiplier
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigManager.prototype.setGasMultiplier = function (gasMultiplier) {
|
||||||
|
var data = this.getData()
|
||||||
|
|
||||||
|
data.gasMultiplier = gasMultiplier
|
||||||
|
this.setData(data)
|
||||||
|
}
|
||||||
|
@ -26,10 +26,10 @@ function IdManagement (opts) {
|
|||||||
|
|
||||||
this.signTx = function (txParams) {
|
this.signTx = function (txParams) {
|
||||||
// calculate gas with custom gas multiplier
|
// calculate gas with custom gas multiplier
|
||||||
var gasMultiplier = txParams.gasMultiplier || 1
|
var gasMultiplier = this.configManager.getGasMultiplier() || 1
|
||||||
delete txParams.gasMultiplier
|
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16)
|
||||||
var gasPrice = parseFloat(new BN(ethUtil.stripHexPrefix(txParams.gasPrice), 16).toString()) * gasMultiplier
|
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100)).div(new BN(100, 10))
|
||||||
txParams.gasPrice = ethUtil.intToHex(parseInt(gasPrice))
|
txParams.gasPrice = ethUtil.intToHex(gasPrice.toNumber())
|
||||||
// normalize values
|
// normalize values
|
||||||
|
|
||||||
txParams.to = ethUtil.addHexPrefix(txParams.to)
|
txParams.to = ethUtil.addHexPrefix(txParams.to)
|
||||||
|
@ -112,6 +112,8 @@ IdentityStore.prototype.getState = function () {
|
|||||||
currentFiat: configManager.getCurrentFiat(),
|
currentFiat: configManager.getCurrentFiat(),
|
||||||
conversionRate: configManager.getConversionRate(),
|
conversionRate: configManager.getConversionRate(),
|
||||||
conversionDate: configManager.getConversionDate(),
|
conversionDate: configManager.getConversionDate(),
|
||||||
|
gasMultiplier: configManager.getGasMultiplier(),
|
||||||
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +213,7 @@ IdentityStore.prototype.exportAccount = function (address, cb) {
|
|||||||
// comes from dapp via zero-client hooked-wallet provider
|
// comes from dapp via zero-client hooked-wallet provider
|
||||||
IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDoneCb, cb) {
|
IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDoneCb, cb) {
|
||||||
const configManager = this.configManager
|
const configManager = this.configManager
|
||||||
|
|
||||||
var self = this
|
var self = this
|
||||||
// create txData obj with parameters and meta data
|
// create txData obj with parameters and meta data
|
||||||
var time = (new Date()).getTime()
|
var time = (new Date()).getTime()
|
||||||
@ -222,6 +225,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone
|
|||||||
txParams: txParams,
|
txParams: txParams,
|
||||||
time: time,
|
time: time,
|
||||||
status: 'unconfirmed',
|
status: 'unconfirmed',
|
||||||
|
gasMultiplier: configManager.getGasMultiplier() || 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('addUnconfirmedTransaction:', txData)
|
console.log('addUnconfirmedTransaction:', txData)
|
||||||
|
@ -55,6 +55,7 @@ module.exports = class MetamaskController {
|
|||||||
agreeToEthWarning: this.agreeToEthWarning.bind(this),
|
agreeToEthWarning: this.agreeToEthWarning.bind(this),
|
||||||
setTOSHash: this.setTOSHash.bind(this),
|
setTOSHash: this.setTOSHash.bind(this),
|
||||||
checkTOSChange: this.checkTOSChange.bind(this),
|
checkTOSChange: this.checkTOSChange.bind(this),
|
||||||
|
setGasMultiplier: this.setGasMultiplier.bind(this),
|
||||||
|
|
||||||
// forward directly to idStore
|
// forward directly to idStore
|
||||||
createNewVault: idStore.createNewVault.bind(idStore),
|
createNewVault: idStore.createNewVault.bind(idStore),
|
||||||
@ -377,4 +378,8 @@ module.exports = class MetamaskController {
|
|||||||
createShapeShiftTx (depositAddress, depositType) {
|
createShapeShiftTx (depositAddress, depositType) {
|
||||||
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
this.configManager.createShapeShiftTx(depositAddress, depositType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGasMultiplier (gasMultiplier) {
|
||||||
|
this.configManager.setGasMultiplier(gasMultiplier)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,10 +277,10 @@ function signMsg (msgData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function signTx (txData) {
|
function signTx (txData) {
|
||||||
|
_accountManager.setGasMultiplier(txData.gasMultiplier)
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
web3.eth.sendTransaction(txData, (err, data) => {
|
web3.eth.sendTransaction(txData, (err, data) => {
|
||||||
dispatch(actions.hideLoadingIndication())
|
dispatch(actions.hideLoadingIndication())
|
||||||
|
|
||||||
if (err) return dispatch(actions.displayWarning(err.message))
|
if (err) return dispatch(actions.displayWarning(err.message))
|
||||||
dispatch(actions.hideWarning())
|
dispatch(actions.hideWarning())
|
||||||
dispatch(actions.goHome())
|
dispatch(actions.goHome())
|
||||||
|
@ -29,10 +29,10 @@ PTXP.render = function () {
|
|||||||
var account = props.accounts[address]
|
var account = props.accounts[address]
|
||||||
var balance = account ? account.balance : '0x0'
|
var balance = account ? account.balance : '0x0'
|
||||||
|
|
||||||
var gasMultiplier = txParams.gasMultiplier
|
var gasMultiplier = txData.gasMultiplier
|
||||||
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txData.estimatedGas), 16)
|
var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txData.estimatedGas), 16)
|
||||||
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
|
var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
|
||||||
gasPrice = new BN(parseFloat(gasPrice.toString()) * gasMultiplier)
|
gasPrice = gasPrice.mul(new BN(gasMultiplier * 100)).div(new BN(100, 10))
|
||||||
var txFee = gasCost.mul(gasPrice)
|
var txFee = gasCost.mul(gasPrice)
|
||||||
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
|
var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
|
||||||
var maxCost = txValue.add(txFee)
|
var maxCost = txValue.add(txFee)
|
||||||
|
@ -10,8 +10,9 @@ function RangeSlider () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RangeSlider.prototype.render = function () {
|
RangeSlider.prototype.render = function () {
|
||||||
|
const state = this.state || {}
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const onChange = props.onChange || function () {}
|
const onInput = props.onInput || function () {}
|
||||||
const name = props.name
|
const name = props.name
|
||||||
const {
|
const {
|
||||||
min = 0,
|
min = 0,
|
||||||
@ -33,8 +34,8 @@ RangeSlider.prototype.render = function () {
|
|||||||
max: max,
|
max: max,
|
||||||
step: increment,
|
step: increment,
|
||||||
style: range,
|
style: range,
|
||||||
defaultValue: defaultValue,
|
value: state.value || defaultValue,
|
||||||
onChange: mirrorInput ? this.mirrorInputs.bind(this, name) : onChange,
|
onChange: mirrorInput ? this.mirrorInputs.bind(this, name) : onInput,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Mirrored input for range
|
// Mirrored input for range
|
||||||
@ -43,7 +44,7 @@ RangeSlider.prototype.render = function () {
|
|||||||
name: `${name}Mirror`,
|
name: `${name}Mirror`,
|
||||||
min: min,
|
min: min,
|
||||||
max: max,
|
max: max,
|
||||||
defaultValue: defaultValue,
|
value: state.value || defaultValue,
|
||||||
step: increment,
|
step: increment,
|
||||||
style: input,
|
style: input,
|
||||||
onChange: this.mirrorInputs.bind(this, `${name}Mirror`),
|
onChange: this.mirrorInputs.bind(this, `${name}Mirror`),
|
||||||
@ -52,12 +53,6 @@ RangeSlider.prototype.render = function () {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeSlider.prototype.mirrorInputs = function (active) {
|
RangeSlider.prototype.mirrorInputs = function (active, event) {
|
||||||
var range = document.querySelector(`input[name="${this.props.name}"]`)
|
this.setState({value: event.target.value})
|
||||||
var inputMirror = document.querySelector(`input[name="${this.props.name}Mirror"]`)
|
|
||||||
if (active === this.props.name) {
|
|
||||||
inputMirror.value = range.value
|
|
||||||
} else {
|
|
||||||
range.value = inputMirror.value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -319,10 +319,11 @@ SendTransactionScreen.prototype.onSubmit = function (gasPrice) {
|
|||||||
var txParams = {
|
var txParams = {
|
||||||
from: this.props.address,
|
from: this.props.address,
|
||||||
value: '0x' + value.toString(16),
|
value: '0x' + value.toString(16),
|
||||||
|
gasMultiplier: gasMultiplier * 0.01,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipient) txParams.to = ethUtil.addHexPrefix(recipient)
|
if (recipient) txParams.to = ethUtil.addHexPrefix(recipient)
|
||||||
if (txData) txParams.data = txData
|
if (txData) txParams.data = txData
|
||||||
txParams.gasMultiplier = gasMultiplier * 0.01
|
|
||||||
this.props.dispatch(actions.signTx(txParams))
|
this.props.dispatch(actions.signTx(txParams))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user