@alephium/web3 0.19.1 → 0.19.2
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.
|
@@ -16,3 +16,4 @@ export declare function prettifyNumber(amount: Number256, decimals: number, conf
|
|
|
16
16
|
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
17
17
|
export declare function convertAlphAmountWithDecimals(amount: string | number): bigint | undefined;
|
|
18
18
|
export declare function number256ToBigint(number: Number256): bigint;
|
|
19
|
+
export declare function number256ToNumber(number: Number256, decimals: number): number;
|
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.number256ToBigint = exports.convertAlphAmountWithDecimals = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
23
|
+
exports.number256ToNumber = exports.number256ToBigint = exports.convertAlphAmountWithDecimals = 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
|
|
@@ -138,7 +138,7 @@ function convertAmountWithDecimals(amount, decimals) {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
exports.convertAmountWithDecimals = convertAmountWithDecimals;
|
|
141
|
-
// E.g. `1.23 ALPH
|
|
141
|
+
// E.g. `1.23` ALPH will be converted to `1230000000000000000`
|
|
142
142
|
function convertAlphAmountWithDecimals(amount) {
|
|
143
143
|
return convertAmountWithDecimals(amount, 18);
|
|
144
144
|
}
|
|
@@ -147,3 +147,7 @@ function number256ToBigint(number) {
|
|
|
147
147
|
return typeof number === 'string' ? BigInt(number) : number;
|
|
148
148
|
}
|
|
149
149
|
exports.number256ToBigint = number256ToBigint;
|
|
150
|
+
function number256ToNumber(number, decimals) {
|
|
151
|
+
return parseFloat(toFixedNumber(number256ToBigint(number), decimals));
|
|
152
|
+
}
|
|
153
|
+
exports.number256ToNumber = number256ToNumber;
|
package/package.json
CHANGED
package/src/utils/number.ts
CHANGED
|
@@ -153,7 +153,7 @@ export function convertAmountWithDecimals(amount: string | number, decimals: num
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
// E.g. `1.23 ALPH
|
|
156
|
+
// E.g. `1.23` ALPH will be converted to `1230000000000000000`
|
|
157
157
|
export function convertAlphAmountWithDecimals(amount: string | number): bigint | undefined {
|
|
158
158
|
return convertAmountWithDecimals(amount, 18)
|
|
159
159
|
}
|
|
@@ -161,3 +161,7 @@ export function convertAlphAmountWithDecimals(amount: string | number): bigint |
|
|
|
161
161
|
export function number256ToBigint(number: Number256): bigint {
|
|
162
162
|
return typeof number === 'string' ? BigInt(number) : number
|
|
163
163
|
}
|
|
164
|
+
|
|
165
|
+
export function number256ToNumber(number: Number256, decimals: number): number {
|
|
166
|
+
return parseFloat(toFixedNumber(number256ToBigint(number), decimals))
|
|
167
|
+
}
|