@alephium/web3 0.5.0-rc.19 → 0.5.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Number256 } from '..';
|
|
1
2
|
export declare const isNumeric: (numToCheck: any) => boolean;
|
|
2
3
|
export interface IPrettifyNumberConfig {
|
|
3
4
|
minDecimalPlaces: number;
|
|
@@ -8,9 +9,9 @@ export interface IPrettifyNumberConfig {
|
|
|
8
9
|
decimalPlacesWhenZero: number;
|
|
9
10
|
}
|
|
10
11
|
export declare const prettifyNumberConfig: Record<string, IPrettifyNumberConfig>;
|
|
11
|
-
export declare function prettifyAttoAlphAmount(amount:
|
|
12
|
-
export declare function prettifyTokenAmount(amount:
|
|
13
|
-
export declare function prettifyExactAmount(amount:
|
|
14
|
-
export declare function prettifyNumber(amount:
|
|
12
|
+
export declare function prettifyAttoAlphAmount(amount: Number256): string | undefined;
|
|
13
|
+
export declare function prettifyTokenAmount(amount: Number256, decimals: number): string | undefined;
|
|
14
|
+
export declare function prettifyExactAmount(amount: Number256, decimals: number): string | undefined;
|
|
15
|
+
export declare function prettifyNumber(amount: Number256, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
15
16
|
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
16
17
|
export declare function convertAlphAmount(amount: string | number): bigint | undefined;
|
package/dist/src/utils/number.js
CHANGED
|
@@ -60,7 +60,7 @@ function prettifyExactAmount(amount, decimals) {
|
|
|
60
60
|
}
|
|
61
61
|
exports.prettifyExactAmount = prettifyExactAmount;
|
|
62
62
|
function prettifyNumber(amount, decimals, config) {
|
|
63
|
-
const number = toFixedNumber(amount, decimals);
|
|
63
|
+
const number = typeof amount === 'string' ? amount : toFixedNumber(amount, decimals);
|
|
64
64
|
if (!(0, exports.isNumeric)(number)) {
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
package/package.json
CHANGED
package/src/utils/number.ts
CHANGED
|
@@ -21,6 +21,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
21
21
|
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
22
22
|
|
|
23
23
|
import BigNumber from 'bignumber.js'
|
|
24
|
+
import { Number256 } from '..'
|
|
24
25
|
|
|
25
26
|
export const isNumeric = (numToCheck: any): boolean => !isNaN(parseFloat(numToCheck)) && isFinite(numToCheck)
|
|
26
27
|
|
|
@@ -54,20 +55,20 @@ export const prettifyNumberConfig: Record<string, IPrettifyNumberConfig> = {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
export function prettifyAttoAlphAmount(amount:
|
|
58
|
+
export function prettifyAttoAlphAmount(amount: Number256): string | undefined {
|
|
58
59
|
return prettifyNumber(amount, 18, prettifyNumberConfig.ALPH)
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
export function prettifyTokenAmount(amount:
|
|
62
|
+
export function prettifyTokenAmount(amount: Number256, decimals: number): string | undefined {
|
|
62
63
|
return prettifyNumber(amount, decimals, prettifyNumberConfig.TOKEN)
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
export function prettifyExactAmount(amount:
|
|
66
|
+
export function prettifyExactAmount(amount: Number256, decimals: number): string | undefined {
|
|
66
67
|
return prettifyNumber(amount, decimals, prettifyNumberConfig.Exact)
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
export function prettifyNumber(amount:
|
|
70
|
-
const number = toFixedNumber(amount, decimals)
|
|
70
|
+
export function prettifyNumber(amount: Number256, decimals: number, config: IPrettifyNumberConfig): string | undefined {
|
|
71
|
+
const number = typeof amount === 'string' ? amount : toFixedNumber(amount, decimals)
|
|
71
72
|
|
|
72
73
|
if (!isNumeric(number)) {
|
|
73
74
|
return undefined
|