add support for multiple decimals in fee

This commit is contained in:
Roman Storm 2020-03-30 23:20:36 -07:00
parent 37ced4e77f
commit 7efc2acc36
No known key found for this signature in database
GPG Key ID: 522F2A785F34E71F

View File

@ -114,7 +114,9 @@ function fromDecimals(value, decimals) {
function isEnoughFee({ gas, gasPrices, currency, amount, refund, ethPrices, fee }) { function isEnoughFee({ gas, gasPrices, currency, amount, refund, ethPrices, fee }) {
const { decimals } = mixers[`netId${netId}`][currency] const { decimals } = mixers[`netId${netId}`][currency]
const feePercent = toBN(fromDecimals(amount, decimals)).mul(toBN(relayerServiceFee * 10)).div(toBN('1000')) const decimalsPoint = Math.floor(relayerServiceFee) === relayerServiceFee ? 0 : relayerServiceFee.toString().split('.')[1].length
const roundDecimal = 10 ** decimalsPoint
const feePercent = toBN(fromDecimals(amount, decimals)).mul(toBN(relayerServiceFee * roundDecimal)).div(toBN(roundDecimal * 100))
const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(gas)) const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(gas))
let desiredFee let desiredFee
switch (currency) { switch (currency) {