@alephium/web3 0.5.0-rc.20 → 0.5.0-rc.22
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.
|
@@ -15,3 +15,4 @@ export declare function prettifyExactAmount(amount: Number256, decimals: number)
|
|
|
15
15
|
export declare function prettifyNumber(amount: Number256, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
16
16
|
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
17
17
|
export declare function convertAlphAmount(amount: string | number): bigint | undefined;
|
|
18
|
+
export declare function number256ToBigint(number: Number256): bigint;
|
package/dist/src/utils/number.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.convertAlphAmount = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
23
|
+
exports.number256ToBigint = exports.convertAlphAmount = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
24
24
|
// Credits:
|
|
25
25
|
// 1. https://github.com/argentlabs/argent-x/blob/e63affa7f28b27333dca4081a3dcd375bb2da40b/packages/extension/src/shared/utils/number.ts
|
|
26
26
|
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
@@ -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 =
|
|
63
|
+
const number = toFixedNumber(number256ToBigint(amount), decimals);
|
|
64
64
|
if (!(0, exports.isNumeric)(number)) {
|
|
65
65
|
return undefined;
|
|
66
66
|
}
|
|
@@ -142,3 +142,7 @@ function convertAlphAmount(amount) {
|
|
|
142
142
|
return convertAmountWithDecimals(amount, 18);
|
|
143
143
|
}
|
|
144
144
|
exports.convertAlphAmount = convertAlphAmount;
|
|
145
|
+
function number256ToBigint(number) {
|
|
146
|
+
return typeof number === 'string' ? BigInt(number) : number;
|
|
147
|
+
}
|
|
148
|
+
exports.number256ToBigint = number256ToBigint;
|
package/package.json
CHANGED
package/src/utils/number.ts
CHANGED
|
@@ -68,7 +68,7 @@ export function prettifyExactAmount(amount: Number256, decimals: number): string
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export function prettifyNumber(amount: Number256, decimals: number, config: IPrettifyNumberConfig): string | undefined {
|
|
71
|
-
const number =
|
|
71
|
+
const number = toFixedNumber(number256ToBigint(amount), decimals)
|
|
72
72
|
|
|
73
73
|
if (!isNumeric(number)) {
|
|
74
74
|
return undefined
|
|
@@ -156,3 +156,7 @@ export function convertAmountWithDecimals(amount: string | number, decimals: num
|
|
|
156
156
|
export function convertAlphAmount(amount: string | number): bigint | undefined {
|
|
157
157
|
return convertAmountWithDecimals(amount, 18)
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
export function number256ToBigint(number: Number256): bigint {
|
|
161
|
+
return typeof number === 'string' ? BigInt(number) : number
|
|
162
|
+
}
|