@cityofzion/blockchain-service 3.1.10 → 3.1.12
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.
- package/dist/helpers/BSBigNumberHelper.d.ts +23 -10
- package/dist/helpers/BSBigNumberHelper.js +72 -47
- package/dist/interfaces.d.ts +15 -8
- package/dist/types.d.ts +0 -3
- package/package.json +1 -1
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
export declare class BSBigNumber extends BigNumber {
|
|
3
|
+
constructor(value: BigNumber.Value, base?: number);
|
|
4
|
+
static ensureNumber(value: number | string | bigint | undefined): number;
|
|
5
|
+
toBigInt(): bigint;
|
|
6
|
+
protected _wrap(value: BigNumber): this;
|
|
7
|
+
plus(n: BigNumber.Value, base?: number): this;
|
|
8
|
+
minus(n: BigNumber.Value, base?: number): this;
|
|
9
|
+
multipliedBy(n: BigNumber.Value, base?: number): this;
|
|
10
|
+
dividedBy(n: BigNumber.Value, base?: number): this;
|
|
11
|
+
integerValue(roundingMode?: BigNumber.RoundingMode): this;
|
|
12
|
+
}
|
|
13
|
+
export declare class BSBigHumanAmount extends BSBigNumber {
|
|
14
|
+
decimals?: number;
|
|
15
|
+
constructor(value: BigNumber.Value | undefined | null, decimals?: number | string);
|
|
16
|
+
protected _wrap(value: BigNumber): this;
|
|
17
|
+
toFormatted(): string;
|
|
18
|
+
toUnit(): BSBigUnitAmount;
|
|
19
|
+
}
|
|
20
|
+
export declare class BSBigUnitAmount extends BSBigNumber {
|
|
21
|
+
decimals?: number;
|
|
22
|
+
constructor(value: BigNumber.Value | undefined | null, decimals: number | string);
|
|
23
|
+
protected _wrap(value: BigNumber): this;
|
|
24
|
+
toHuman(): BSBigHumanAmount;
|
|
12
25
|
}
|
|
@@ -1,62 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
4
|
};
|
|
10
|
-
var _b, _BSBigNumberHelper_ensureDecimals;
|
|
11
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
6
|
+
exports.BSBigUnitAmount = exports.BSBigHumanAmount = exports.BSBigNumber = void 0;
|
|
13
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
14
|
-
|
|
15
|
-
class
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
const error_1 = require("../error");
|
|
9
|
+
class BSBigNumber extends bignumber_js_1.default {
|
|
10
|
+
constructor(value, base) {
|
|
11
|
+
super(value, base);
|
|
12
|
+
}
|
|
13
|
+
static ensureNumber(value) {
|
|
14
|
+
const bn = new bignumber_js_1.default(value || 0);
|
|
15
|
+
if (bn.isNaN()) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
return bn.toNumber();
|
|
19
|
+
}
|
|
20
|
+
toBigInt() {
|
|
21
|
+
return BigInt(this.toString());
|
|
22
|
+
}
|
|
23
|
+
_wrap(value) {
|
|
24
|
+
return new this.constructor(value);
|
|
25
|
+
}
|
|
26
|
+
plus(n, base) {
|
|
27
|
+
return this._wrap(super.plus(n, base));
|
|
28
|
+
}
|
|
29
|
+
minus(n, base) {
|
|
30
|
+
return this._wrap(super.minus(n, base));
|
|
31
|
+
}
|
|
32
|
+
multipliedBy(n, base) {
|
|
33
|
+
return this._wrap(super.multipliedBy(n, base));
|
|
34
|
+
}
|
|
35
|
+
dividedBy(n, base) {
|
|
36
|
+
return this._wrap(super.dividedBy(n, base));
|
|
37
|
+
}
|
|
38
|
+
integerValue(roundingMode) {
|
|
39
|
+
return this._wrap(super.integerValue(roundingMode));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.BSBigNumber = BSBigNumber;
|
|
43
|
+
class BSBigHumanAmount extends BSBigNumber {
|
|
44
|
+
constructor(value, decimals) {
|
|
36
45
|
if (typeof value === 'string') {
|
|
37
46
|
value = value.replace(/,|\.\.|\.,/g, '.').replace(/^([^.]*\.)(.*)$/, function (_a, b, c) {
|
|
38
47
|
return b + c.replace(/\./g, '');
|
|
39
48
|
});
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (bigValue.isNaN()) {
|
|
44
|
-
return '0';
|
|
45
|
-
}
|
|
46
|
-
const decimals = __classPrivateFieldGet(this, _b, "m", _BSBigNumberHelper_ensureDecimals).call(this, options?.decimals);
|
|
47
|
-
const formattedValue = bigValue.decimalPlaces(decimals, exports.BSBigNumber.ROUND_DOWN);
|
|
48
|
-
return formattedValue.toFixed();
|
|
50
|
+
if (!value || new bignumber_js_1.default(value).isNaN()) {
|
|
51
|
+
value = 0;
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
super(value);
|
|
54
|
+
this.decimals = decimals !== undefined ? BSBigNumber.ensureNumber(decimals) : undefined;
|
|
55
|
+
}
|
|
56
|
+
_wrap(value) {
|
|
57
|
+
return new this.constructor(value, this.decimals);
|
|
58
|
+
}
|
|
59
|
+
toFormatted() {
|
|
60
|
+
return this.decimalPlaces(this.decimals ?? 0, bignumber_js_1.default.ROUND_DOWN).toFixed();
|
|
61
|
+
}
|
|
62
|
+
toUnit() {
|
|
63
|
+
if (typeof this.decimals !== 'number') {
|
|
64
|
+
throw new error_1.BSError('Decimals property is required to convert to Unit', 'DECIMALS_REQUIRED');
|
|
53
65
|
}
|
|
66
|
+
const shifted = this.shiftedBy(this.decimals);
|
|
67
|
+
return new BSBigUnitAmount(shifted, this.decimals);
|
|
54
68
|
}
|
|
55
69
|
}
|
|
56
|
-
exports.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
exports.BSBigHumanAmount = BSBigHumanAmount;
|
|
71
|
+
class BSBigUnitAmount extends BSBigNumber {
|
|
72
|
+
constructor(value, decimals) {
|
|
73
|
+
if (!value || new bignumber_js_1.default(value).isNaN()) {
|
|
74
|
+
value = 0;
|
|
75
|
+
}
|
|
76
|
+
super(value);
|
|
77
|
+
this.decimals = BSBigNumber.ensureNumber(decimals);
|
|
78
|
+
}
|
|
79
|
+
_wrap(value) {
|
|
80
|
+
return new this.constructor(value, this.decimals);
|
|
81
|
+
}
|
|
82
|
+
toHuman() {
|
|
83
|
+
const shifted = this.shiftedBy(-this.decimals);
|
|
84
|
+
return new BSBigHumanAmount(shifted, this.decimals);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.BSBigUnitAmount = BSBigUnitAmount;
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -459,20 +459,27 @@ export interface ITokenService {
|
|
|
459
459
|
validateTokenHash(hash?: string): hash is string;
|
|
460
460
|
isNativeToken(hash: string): boolean;
|
|
461
461
|
}
|
|
462
|
-
export type TWalletConnectServiceRequestMethodParams<N extends string> = {
|
|
462
|
+
export type TWalletConnectServiceRequestMethodParams<N extends string, P = any> = {
|
|
463
463
|
account: TBSAccount<N>;
|
|
464
|
-
params:
|
|
464
|
+
params: P;
|
|
465
|
+
method: string;
|
|
465
466
|
};
|
|
466
|
-
export type
|
|
467
|
-
|
|
467
|
+
export type TWalletConnectServiceMethodHandler<N extends string, P = any> = {
|
|
468
|
+
validate: (params: any) => Promise<P>;
|
|
469
|
+
process: (args: TWalletConnectServiceRequestMethodParams<N, P>) => Promise<any>;
|
|
470
|
+
};
|
|
471
|
+
export type TWalletConnectServiceHandlers<N extends string, P extends Record<string, any> = Record<string, any>> = {
|
|
472
|
+
[K in keyof P]: TWalletConnectServiceMethodHandler<N, P[K]>;
|
|
473
|
+
};
|
|
474
|
+
export interface IWalletConnectService<N extends string, M extends string = string> {
|
|
468
475
|
readonly namespace: string;
|
|
469
476
|
readonly chain: string;
|
|
470
|
-
readonly supportedMethods:
|
|
477
|
+
readonly supportedMethods: M[];
|
|
471
478
|
readonly supportedEvents: string[];
|
|
472
|
-
readonly calculableMethods:
|
|
473
|
-
readonly autoApproveMethods:
|
|
479
|
+
readonly calculableMethods: M[];
|
|
480
|
+
readonly autoApproveMethods: M[];
|
|
481
|
+
handlers: TWalletConnectServiceHandlers<N>;
|
|
474
482
|
calculateRequestFee(args: TWalletConnectServiceRequestMethodParams<N>): Promise<string>;
|
|
475
|
-
[methodName: string]: any | TWalletConnectServiceRequestMethod<N>;
|
|
476
483
|
}
|
|
477
484
|
export interface IBSWithWalletConnect<N extends string> {
|
|
478
485
|
walletConnectService: IWalletConnectService<N>;
|
package/dist/types.d.ts
CHANGED
|
@@ -56,9 +56,6 @@ export type TCryptoCompareEDSHistoryResponse = {
|
|
|
56
56
|
}[];
|
|
57
57
|
};
|
|
58
58
|
export type THexString = `0x${string}`;
|
|
59
|
-
export type TBSBigNumberHelperFormatOptions = {
|
|
60
|
-
decimals?: number | string;
|
|
61
|
-
};
|
|
62
59
|
export type TBSUtilsHelperRetryOptions = {
|
|
63
60
|
retries?: number;
|
|
64
61
|
delay?: number;
|