|
|
|
@ -56,7 +56,12 @@ export const hexToString = (hex: string): string => {
|
|
|
|
|
|
|
|
|
|
export const toDecimalAmount = (amount: string | number, decimals: number): string => {
|
|
|
|
|
try {
|
|
|
|
|
return new BigNumber(amount).div(10 ** decimals).toString(10);
|
|
|
|
|
const bAmount = new BigNumber(amount);
|
|
|
|
|
// BigNumber() returns NaN on non-numeric string
|
|
|
|
|
if (bAmount.isNaN()) {
|
|
|
|
|
throw new Error('Amount is not a number');
|
|
|
|
|
}
|
|
|
|
|
return bAmount.div(10 ** decimals).toString(10);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
|
|
|
@ -64,7 +69,12 @@ export const toDecimalAmount = (amount: string | number, decimals: number): stri
|
|
|
|
|
|
|
|
|
|
export const fromDecimalAmount = (amount: string | number, decimals: number): string => {
|
|
|
|
|
try {
|
|
|
|
|
return new BigNumber(amount).times(10 ** decimals).toString(10);
|
|
|
|
|
const bAmount = new BigNumber(amount);
|
|
|
|
|
// BigNumber() returns NaN on non-numeric string
|
|
|
|
|
if (bAmount.isNaN()) {
|
|
|
|
|
throw new Error('Amount is not a number');
|
|
|
|
|
}
|
|
|
|
|
return bAmount.times(10 ** decimals).toString(10);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return '0';
|
|
|
|
|
}
|
|
|
|
|