From 7efc2acc36f4628b55d2fdf5b360ae5501425b4f Mon Sep 17 00:00:00 2001 From: Roman Storm Date: Mon, 30 Mar 2020 23:20:36 -0700 Subject: [PATCH] add support for multiple decimals in fee --- src/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index d788a30..f00a0dd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -114,7 +114,9 @@ function fromDecimals(value, decimals) { function isEnoughFee({ gas, gasPrices, currency, amount, refund, ethPrices, fee }) { 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)) let desiredFee switch (currency) {