From a1447ab4f82d13045a7f8e94142f2d298e09ff0d Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 28 Dec 2018 16:16:24 +0100 Subject: [PATCH] fix: formatUtil - calculating decimal amount returns '0' on exception --- src/utils/formatUtils.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/formatUtils.js b/src/utils/formatUtils.js index f7e48b52..a273959c 100644 --- a/src/utils/formatUtils.js +++ b/src/utils/formatUtils.js @@ -54,6 +54,18 @@ export const hexToString = (hex: string): string => { return str; }; -export const toDecimalAmount = (amount: string, decimals: number): string => new BigNumber(amount).div(10 ** decimals).toString(10); +export const toDecimalAmount = (amount: string | number, decimals: number): string => { + try { + return new BigNumber(amount).div(10 ** decimals).toString(10); + } catch (error) { + return '0'; + } +}; -export const fromDecimalAmount = (amount: string, decimals: number): string => new BigNumber(amount).times(10 ** decimals).toString(10); +export const fromDecimalAmount = (amount: string | number, decimals: number): string => { + try { + return new BigNumber(amount).times(10 ** decimals).toString(10); + } catch (error) { + return '0'; + } +};