mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-30 20:28:09 +00:00
fix: formatUtil - calculating decimal amount returns '0' on exception
This commit is contained in:
parent
be9cd4fef0
commit
a1447ab4f8
@ -54,6 +54,18 @@ export const hexToString = (hex: string): string => {
|
|||||||
return str;
|
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';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user