@hairy/ether-lib 1.11.0 → 1.13.0
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/index.cjs +3 -22
- package/dist/index.d.ts +15 -14
- package/dist/index.global.js +8 -27
- package/dist/index.js +4 -21
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -30,11 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Bignumber: () => import_utils.Bignumber,
|
|
34
33
|
Errors: () => Errors,
|
|
35
34
|
formatEther: () => formatEther,
|
|
36
35
|
idprefix: () => idprefix,
|
|
37
|
-
subscribeForTransaction: () => subscribeForTransaction,
|
|
38
36
|
wait: () => wait
|
|
39
37
|
});
|
|
40
38
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -74,7 +72,7 @@ var import_utils = require("@hairy/utils");
|
|
|
74
72
|
var import_ethers2 = require("ethers");
|
|
75
73
|
function formatEther(value = "0", options = {}) {
|
|
76
74
|
const { separator = false, decimals, delimiters = false, rounding, zeromove = true } = options;
|
|
77
|
-
const number = (0, import_ethers2.formatEther)((0, import_utils.
|
|
75
|
+
const number = (0, import_ethers2.formatEther)((0, import_utils.BigNum)((0, import_utils.numerfix)(value)).toFixed(0));
|
|
78
76
|
const groupSeparator = separator === false ? "" : ",";
|
|
79
77
|
return (0, import_utils.formatNumeric)(number, {
|
|
80
78
|
format: { groupSeparator, ...options.format },
|
|
@@ -86,24 +84,8 @@ function formatEther(value = "0", options = {}) {
|
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
// src/wait.ts
|
|
89
|
-
var import_ethers3 = require("ethers");
|
|
90
87
|
var import_mitt = __toESM(require("mitt"), 1);
|
|
91
88
|
var emitter = (0, import_mitt.default)();
|
|
92
|
-
for (const Response of [import_ethers3.TransactionResponse, import_ethers3.ContractTransactionResponse]) {
|
|
93
|
-
const waitForTransaction = Response.prototype.wait;
|
|
94
|
-
Response.prototype._wait = waitForTransaction;
|
|
95
|
-
Response.prototype.wait = async function(...args) {
|
|
96
|
-
try {
|
|
97
|
-
emitter.emit("before");
|
|
98
|
-
const receipt = await waitForTransaction.call(this, ...args);
|
|
99
|
-
emitter.emit("after", receipt);
|
|
100
|
-
return receipt;
|
|
101
|
-
} catch (error) {
|
|
102
|
-
emitter.emit("error", error);
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
89
|
async function wait(transaction) {
|
|
108
90
|
try {
|
|
109
91
|
emitter.emit("before");
|
|
@@ -115,17 +97,16 @@ async function wait(transaction) {
|
|
|
115
97
|
emitter.emit("after", receipt);
|
|
116
98
|
return receipt;
|
|
117
99
|
} catch (error) {
|
|
100
|
+
emitter.emit("after", null);
|
|
118
101
|
emitter.emit("error", error);
|
|
119
102
|
throw error;
|
|
120
103
|
}
|
|
121
104
|
}
|
|
122
|
-
|
|
105
|
+
wait.subscribe = emitter.on.bind(emitter);
|
|
123
106
|
// Annotate the CommonJS export names for ESM import in node:
|
|
124
107
|
0 && (module.exports = {
|
|
125
|
-
Bignumber,
|
|
126
108
|
Errors,
|
|
127
109
|
formatEther,
|
|
128
110
|
idprefix,
|
|
129
|
-
subscribeForTransaction,
|
|
130
111
|
wait
|
|
131
112
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Delimiter, Bignumber, Numberish } from '@hairy/utils';
|
|
2
|
-
export { Bignumber } from '@hairy/utils';
|
|
3
2
|
import * as mitt from 'mitt';
|
|
4
3
|
import { TransactionResponse, ContractTransactionResponse, TransactionReceipt } from 'ethers';
|
|
5
4
|
|
|
@@ -39,17 +38,19 @@ declare function formatEther(value?: Numberish, options?: FormatEtherOptions): s
|
|
|
39
38
|
|
|
40
39
|
type GenericTransactionResponse = TransactionResponse | ContractTransactionResponse | Promise<TransactionResponse | ContractTransactionResponse> | (() => TransactionResponse | ContractTransactionResponse) | (() => Promise<TransactionResponse | ContractTransactionResponse>);
|
|
41
40
|
declare function wait(transaction: GenericTransactionResponse): Promise<any>;
|
|
42
|
-
declare
|
|
43
|
-
|
|
44
|
-
before:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
41
|
+
declare namespace wait {
|
|
42
|
+
var subscribe: {
|
|
43
|
+
<Key extends "before" | "after" | "error">(type: Key, handler: mitt.Handler<{
|
|
44
|
+
before: void;
|
|
45
|
+
after: TransactionReceipt | null;
|
|
46
|
+
error: Error;
|
|
47
|
+
}[Key]>): void;
|
|
48
|
+
(type: "*", handler: mitt.WildcardHandler<{
|
|
49
|
+
before: void;
|
|
50
|
+
after: TransactionReceipt | null;
|
|
51
|
+
error: Error;
|
|
52
|
+
}>): void;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
54
55
|
|
|
55
|
-
export { Errors, type FormatEtherOptions, type GenericTransactionResponse, formatEther, idprefix,
|
|
56
|
+
export { Errors, type FormatEtherOptions, type GenericTransactionResponse, formatEther, idprefix, wait };
|
package/dist/index.global.js
CHANGED
|
@@ -80,22 +80,20 @@
|
|
|
80
80
|
m: { v: 10 ** 6, d: 7, n: "m" },
|
|
81
81
|
k: { v: 10 ** 3, d: 4, n: "k" }
|
|
82
82
|
};
|
|
83
|
-
function
|
|
83
|
+
function BigNum(num = "0") {
|
|
84
84
|
return new import_bignumber.default(numerfix(num));
|
|
85
85
|
}
|
|
86
86
|
function gte(num, n) {
|
|
87
|
-
return
|
|
87
|
+
return BigNum(num).gte(BigNum(n));
|
|
88
88
|
}
|
|
89
89
|
function lt(num, n) {
|
|
90
|
-
return
|
|
90
|
+
return BigNum(num).lt(BigNum(n));
|
|
91
91
|
}
|
|
92
92
|
function zeromove(value) {
|
|
93
93
|
return value.toString().replace(/\.?0+$/, "");
|
|
94
94
|
}
|
|
95
95
|
function numerfix(value) {
|
|
96
96
|
const _isNaN = Number.isNaN(Number(value)) || value.toString() === "NaN";
|
|
97
|
-
if (_isNaN)
|
|
98
|
-
console.warn(`numerfix(${value}): value is not the correct value. To ensure the normal operation of the program, it will be converted to zero`);
|
|
99
97
|
return _isNaN ? "0" : String(value);
|
|
100
98
|
}
|
|
101
99
|
function parseNumeric(num, delimiters = ["t", "b", "m"]) {
|
|
@@ -107,7 +105,7 @@
|
|
|
107
105
|
];
|
|
108
106
|
let options;
|
|
109
107
|
for (const analy of mappings) {
|
|
110
|
-
const opts = analy && analy(
|
|
108
|
+
const opts = analy && analy(BigNum(num).toFixed(0));
|
|
111
109
|
opts && (options = opts);
|
|
112
110
|
}
|
|
113
111
|
return options || { v: 1, d: 0, n: "" };
|
|
@@ -120,7 +118,7 @@
|
|
|
120
118
|
decimals = 2
|
|
121
119
|
} = options || {};
|
|
122
120
|
const config = parseNumeric(value, delimiters || []);
|
|
123
|
-
let number =
|
|
121
|
+
let number = BigNum(value).div(config.v).toFormat(decimals, rounding, {
|
|
124
122
|
decimalSeparator: ".",
|
|
125
123
|
groupSeparator: ",",
|
|
126
124
|
groupSize: 3,
|
|
@@ -137,7 +135,7 @@
|
|
|
137
135
|
var import_ethers2 = __toESM(require_ethers(), 1);
|
|
138
136
|
function formatEther(value = "0", options = {}) {
|
|
139
137
|
const { separator = false, decimals, delimiters = false, rounding, zeromove: zeromove2 = true } = options;
|
|
140
|
-
const number = (0, import_ethers2.formatEther)(
|
|
138
|
+
const number = (0, import_ethers2.formatEther)(BigNum(numerfix(value)).toFixed(0));
|
|
141
139
|
const groupSeparator = separator === false ? "" : ",";
|
|
142
140
|
return formatNumeric(number, {
|
|
143
141
|
format: { groupSeparator, ...options.format },
|
|
@@ -148,9 +146,6 @@
|
|
|
148
146
|
});
|
|
149
147
|
}
|
|
150
148
|
|
|
151
|
-
// src/wait.ts
|
|
152
|
-
var import_ethers3 = __toESM(require_ethers(), 1);
|
|
153
|
-
|
|
154
149
|
// ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
155
150
|
function mitt_default(n) {
|
|
156
151
|
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
@@ -171,21 +166,6 @@
|
|
|
171
166
|
|
|
172
167
|
// src/wait.ts
|
|
173
168
|
var emitter = mitt_default();
|
|
174
|
-
for (const Response of [import_ethers3.TransactionResponse, import_ethers3.ContractTransactionResponse]) {
|
|
175
|
-
const waitForTransaction = Response.prototype.wait;
|
|
176
|
-
Response.prototype._wait = waitForTransaction;
|
|
177
|
-
Response.prototype.wait = async function(...args) {
|
|
178
|
-
try {
|
|
179
|
-
emitter.emit("before");
|
|
180
|
-
const receipt = await waitForTransaction.call(this, ...args);
|
|
181
|
-
emitter.emit("after", receipt);
|
|
182
|
-
return receipt;
|
|
183
|
-
} catch (error) {
|
|
184
|
-
emitter.emit("error", error);
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
169
|
async function wait(transaction) {
|
|
190
170
|
try {
|
|
191
171
|
emitter.emit("before");
|
|
@@ -197,9 +177,10 @@
|
|
|
197
177
|
emitter.emit("after", receipt);
|
|
198
178
|
return receipt;
|
|
199
179
|
} catch (error) {
|
|
180
|
+
emitter.emit("after", null);
|
|
200
181
|
emitter.emit("error", error);
|
|
201
182
|
throw error;
|
|
202
183
|
}
|
|
203
184
|
}
|
|
204
|
-
|
|
185
|
+
wait.subscribe = emitter.on.bind(emitter);
|
|
205
186
|
})();
|
package/dist/index.js
CHANGED
|
@@ -29,11 +29,11 @@ function idprefix(errorCallString) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// src/number.ts
|
|
32
|
-
import {
|
|
32
|
+
import { BigNum, formatNumeric, numerfix } from "@hairy/utils";
|
|
33
33
|
import { formatEther as _formatEther } from "ethers";
|
|
34
34
|
function formatEther(value = "0", options = {}) {
|
|
35
35
|
const { separator = false, decimals, delimiters = false, rounding, zeromove = true } = options;
|
|
36
|
-
const number = _formatEther(
|
|
36
|
+
const number = _formatEther(BigNum(numerfix(value)).toFixed(0));
|
|
37
37
|
const groupSeparator = separator === false ? "" : ",";
|
|
38
38
|
return formatNumeric(number, {
|
|
39
39
|
format: { groupSeparator, ...options.format },
|
|
@@ -45,24 +45,8 @@ function formatEther(value = "0", options = {}) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// src/wait.ts
|
|
48
|
-
import { ContractTransactionResponse, TransactionResponse } from "ethers";
|
|
49
48
|
import mitt from "mitt";
|
|
50
49
|
var emitter = mitt();
|
|
51
|
-
for (const Response of [TransactionResponse, ContractTransactionResponse]) {
|
|
52
|
-
const waitForTransaction = Response.prototype.wait;
|
|
53
|
-
Response.prototype._wait = waitForTransaction;
|
|
54
|
-
Response.prototype.wait = async function(...args) {
|
|
55
|
-
try {
|
|
56
|
-
emitter.emit("before");
|
|
57
|
-
const receipt = await waitForTransaction.call(this, ...args);
|
|
58
|
-
emitter.emit("after", receipt);
|
|
59
|
-
return receipt;
|
|
60
|
-
} catch (error) {
|
|
61
|
-
emitter.emit("error", error);
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
50
|
async function wait(transaction) {
|
|
67
51
|
try {
|
|
68
52
|
emitter.emit("before");
|
|
@@ -74,16 +58,15 @@ async function wait(transaction) {
|
|
|
74
58
|
emitter.emit("after", receipt);
|
|
75
59
|
return receipt;
|
|
76
60
|
} catch (error) {
|
|
61
|
+
emitter.emit("after", null);
|
|
77
62
|
emitter.emit("error", error);
|
|
78
63
|
throw error;
|
|
79
64
|
}
|
|
80
65
|
}
|
|
81
|
-
|
|
66
|
+
wait.subscribe = emitter.on.bind(emitter);
|
|
82
67
|
export {
|
|
83
|
-
Bignumber,
|
|
84
68
|
Errors,
|
|
85
69
|
formatEther,
|
|
86
70
|
idprefix,
|
|
87
|
-
subscribeForTransaction,
|
|
88
71
|
wait
|
|
89
72
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/ether-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.0",
|
|
5
5
|
"description": "Library for ether",
|
|
6
6
|
"author": "Hairyf <wwu710632@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"mitt": "^3.0.1",
|
|
29
|
-
"@hairy/utils": "1.
|
|
29
|
+
"@hairy/utils": "1.13.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"ethers": "^6"
|