From 9598284178f2de59af68c194f39a1e7e5fa257c0 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Mon, 28 Oct 2024 07:58:05 +0000 Subject: [PATCH] wip: simplify fromTokenMinimalUnit --- app/util/number/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/util/number/index.js b/app/util/number/index.js index 993f1ef43783..e46e88816d9f 100644 --- a/app/util/number/index.js +++ b/app/util/number/index.js @@ -116,8 +116,14 @@ export function fromWei(value = 0, unit = 'ether') { export function fromTokenMinimalUnit( minimalInput, decimals = 0, - isRounding = true, + _isRounding = true, ) { + const value = new BigNumber( + (isBN(minimalInput) ? minimalInput.toString(10) : minimalInput), + 10, + ) + return value.div(new BigNumber(decimals, 10)).toString(10, decimals); + /* minimalInput = isRounding ? Number(minimalInput) : minimalInput; const prefixedInput = addHexPrefix(minimalInput.toString(16)); let minimal = safeNumberToBN(prefixedInput); @@ -138,6 +144,7 @@ export function fromTokenMinimalUnit( value = '-' + value; } return value; + */ } /** @@ -385,6 +392,9 @@ export function toBN(value) { if (typeof value === 'number' && isNaN(value) || !value || value === 'NaN') { return new BN(0); } + if (isBN(value)) { + return value; + } return value?.startsWith('0x') ? hexToBN(value) : new BN(value || '0');