Commit 61d6556a authored by Noah Zinsmeister's avatar Noah Zinsmeister Committed by GitHub

fix rounding issue (#445)

parent ecd71753
...@@ -221,6 +221,7 @@ export async function getTokenAllowance(address, tokenAddress, spenderAddress, l ...@@ -221,6 +221,7 @@ export async function getTokenAllowance(address, tokenAddress, spenderAddress, l
return getContract(tokenAddress, ERC20_ABI, library).allowance(address, spenderAddress) return getContract(tokenAddress, ERC20_ABI, library).allowance(address, spenderAddress)
} }
//
// amount must be a BigNumber, {base,display}Decimals must be Numbers // amount must be a BigNumber, {base,display}Decimals must be Numbers
export function amountFormatter(amount, baseDecimals = 18, displayDecimals = 3, useLessThan = true) { export function amountFormatter(amount, baseDecimals = 18, displayDecimals = 3, useLessThan = true) {
if (baseDecimals > 18 || displayDecimals > 18 || displayDecimals > baseDecimals) { if (baseDecimals > 18 || displayDecimals > 18 || displayDecimals > baseDecimals) {
...@@ -261,10 +262,8 @@ export function amountFormatter(amount, baseDecimals = 18, displayDecimals = 3, ...@@ -261,10 +262,8 @@ export function amountFormatter(amount, baseDecimals = 18, displayDecimals = 3,
// if there is a decimal portion // if there is a decimal portion
else { else {
const [wholeComponent, decimalComponent] = stringAmount.split('.') const [wholeComponent, decimalComponent] = stringAmount.split('.')
const roundUpAmount = minimumDisplayAmount.div(ethers.constants.Two)
const roundedDecimalComponent = ethers.utils const roundedDecimalComponent = ethers.utils
.bigNumberify(decimalComponent.padEnd(baseDecimals, '0')) .bigNumberify(decimalComponent.padEnd(baseDecimals, '0'))
.add(roundUpAmount)
.toString() .toString()
.padStart(baseDecimals, '0') .padStart(baseDecimals, '0')
.substring(0, displayDecimals) .substring(0, displayDecimals)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment