mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-27 04:46:10 +01:00
Move getTaxBN and bnMultiplyByFraction to util.js
This commit is contained in:
parent
dc72c4cc91
commit
cd351e8aef
@ -10,12 +10,14 @@ const BN = ethUtil.BN
|
|||||||
const hexToBn = require('../../app/scripts/lib/hex-to-bn')
|
const hexToBn = require('../../app/scripts/lib/hex-to-bn')
|
||||||
const numericBalance = require('./util').numericBalance
|
const numericBalance = require('./util').numericBalance
|
||||||
const addressSummary = require('./util').addressSummary
|
const addressSummary = require('./util').addressSummary
|
||||||
|
const bnMultiplyByFraction = require('./util').bnMultiplyByFraction
|
||||||
const isHex = require('./util').isHex
|
const isHex = require('./util').isHex
|
||||||
const EthBalance = require('./components/eth-balance')
|
const EthBalance = require('./components/eth-balance')
|
||||||
const EnsInput = require('./components/ens-input')
|
const EnsInput = require('./components/ens-input')
|
||||||
const FiatValue = require('./components/fiat-value.js')
|
const FiatValue = require('./components/fiat-value.js')
|
||||||
const GasTooltip = require('./components/gas-tooltip.js')
|
const GasTooltip = require('./components/gas-tooltip.js')
|
||||||
const { getSelectedIdentity } = require('./selectors')
|
const { getSelectedIdentity } = require('./selectors')
|
||||||
|
const getTxFeeBn = require('./util').getTxFeeBn
|
||||||
|
|
||||||
const ARAGON = '960b236A07cf122663c4303350609A66A7B288C0'
|
const ARAGON = '960b236A07cf122663c4303350609A66A7B288C0'
|
||||||
|
|
||||||
@ -67,7 +69,6 @@ function SendTransactionScreen () {
|
|||||||
this.back = this.back.bind(this)
|
this.back = this.back.bind(this)
|
||||||
this.back = this.back.bind(this)
|
this.back = this.back.bind(this)
|
||||||
this.closeTooltip = this.closeTooltip.bind(this)
|
this.closeTooltip = this.closeTooltip.bind(this)
|
||||||
this.getTxFeeBn = this.getTxFeeBn.bind(this)
|
|
||||||
this.onSubmit = this.onSubmit.bind(this)
|
this.onSubmit = this.onSubmit.bind(this)
|
||||||
this.onSubmit = this.onSubmit.bind(this)
|
this.onSubmit = this.onSubmit.bind(this)
|
||||||
this.recipientDidChange = this.recipientDidChange.bind(this)
|
this.recipientDidChange = this.recipientDidChange.bind(this)
|
||||||
@ -76,28 +77,6 @@ function SendTransactionScreen () {
|
|||||||
this.toggleTooltip = this.toggleTooltip.bind(this)
|
this.toggleTooltip = this.toggleTooltip.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.bnMultiplyByFraction = function (targetBN, numerator, denominator) {
|
|
||||||
const numBN = new BN(numerator)
|
|
||||||
const denomBN = new BN(denominator)
|
|
||||||
return targetBN.mul(numBN).div(denomBN)
|
|
||||||
}
|
|
||||||
|
|
||||||
SendTransactionScreen.prototype.getTxFeeBn = function (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16)) {
|
|
||||||
const { blockGasLimit } = this.props;
|
|
||||||
const gasBn = hexToBn(gas)
|
|
||||||
const gasLimit = new BN(parseInt(blockGasLimit))
|
|
||||||
const safeGasLimit = this.bnMultiplyByFraction(gasLimit, 19, 20).toString(10)
|
|
||||||
|
|
||||||
|
|
||||||
// Gas Price
|
|
||||||
const gasPriceBn = hexToBn(gasPrice)
|
|
||||||
const txFeeBn = gasBn.mul(gasPriceBn)
|
|
||||||
|
|
||||||
const fiatMultiplier = hexToBn((1000000000).toString(16))
|
|
||||||
const txFeeAsFiatBn = txFeeBn.mul(fiatMultiplier)
|
|
||||||
return txFeeAsFiatBn;
|
|
||||||
}
|
|
||||||
|
|
||||||
SendTransactionScreen.prototype.render = function () {
|
SendTransactionScreen.prototype.render = function () {
|
||||||
this.persistentFormParentId = 'send-tx-form'
|
this.persistentFormParentId = 'send-tx-form'
|
||||||
|
|
||||||
@ -113,6 +92,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
} = props
|
} = props
|
||||||
|
const { blockGasLimit } = this.state
|
||||||
|
|
||||||
console.log({ selectedIdentity, identities })
|
console.log({ selectedIdentity, identities })
|
||||||
console.log("SendTransactionScreen state:", this.state)
|
console.log("SendTransactionScreen state:", this.state)
|
||||||
@ -265,7 +245,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
h('div.large-input.send-screen-gas-input', {}, [
|
h('div.large-input.send-screen-gas-input', {}, [
|
||||||
currentCurrency === 'USD'
|
currentCurrency === 'USD'
|
||||||
? h(FiatValue, {
|
? h(FiatValue, {
|
||||||
value: this.getTxFeeBn(this.state.newTx.gas.toString(16), this.state.newTx.gasPrice.toString(16)).toString(16),
|
value: getTxFeeBn(this.state.newTx.gas.toString(16), this.state.newTx.gasPrice.toString(16), blockGasLimit).toString(16),
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
style: {
|
style: {
|
||||||
@ -276,7 +256,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
: h(EthBalance, {
|
: h(EthBalance, {
|
||||||
value: this.getTxFeeBn(this.state.newTx.gas.toString(16), this.state.newTx.gasPrice.toString(16)).toString(16),
|
value: getTxFeeBn(this.state.newTx.gas.toString(16), this.state.newTx.gasPrice.toString(16), blockGasLimit).toString(16),
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
showFiat: false,
|
showFiat: false,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
const hexToBn = require('../../app/scripts/lib/hex-to-bn')
|
||||||
const vreme = new (require('vreme'))()
|
const vreme = new (require('vreme'))()
|
||||||
|
|
||||||
// formatData :: ( date: <Unix Timestamp> ) -> String
|
// formatData :: ( date: <Unix Timestamp> ) -> String
|
||||||
@ -43,6 +44,8 @@ module.exports = {
|
|||||||
bnTable: bnTable,
|
bnTable: bnTable,
|
||||||
isHex: isHex,
|
isHex: isHex,
|
||||||
formatDate,
|
formatDate,
|
||||||
|
bnMultiplyByFraction,
|
||||||
|
getTxFeeBn,
|
||||||
}
|
}
|
||||||
|
|
||||||
function valuesFor (obj) {
|
function valuesFor (obj) {
|
||||||
@ -222,3 +225,24 @@ function readableDate (ms) {
|
|||||||
function isHex (str) {
|
function isHex (str) {
|
||||||
return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/))
|
return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bnMultiplyByFraction (targetBN, numerator, denominator) {
|
||||||
|
const numBN = new ethUtil.BN(numerator)
|
||||||
|
const denomBN = new ethUtil.BN(denominator)
|
||||||
|
return targetBN.mul(numBN).div(denomBN)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimit) {
|
||||||
|
const gasBn = hexToBn(gas)
|
||||||
|
const gasLimit = new ethUtil.BN(parseInt(blockGasLimit))
|
||||||
|
const safeGasLimit = bnMultiplyByFraction(gasLimit, 19, 20).toString(10)
|
||||||
|
|
||||||
|
// Gas Price
|
||||||
|
const gasPriceBn = hexToBn(gasPrice)
|
||||||
|
const txFeeBn = gasBn.mul(gasPriceBn)
|
||||||
|
|
||||||
|
const fiatMultiplier = hexToBn((1000000000).toString(16))
|
||||||
|
const txFeeAsFiatBn = txFeeBn.mul(fiatMultiplier)
|
||||||
|
|
||||||
|
return txFeeAsFiatBn;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user