@talismn/util 0.1.7 → 0.1.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @talismn/util
2
2
 
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 3068bd60: feat: stale balances and exponential rpc backoff
8
+
3
9
  ## 0.1.7
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,15 @@
1
+ /**
2
+ * In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
3
+ * resolved or rejected at a later point in time, typically by code outside of the current function scope.
4
+ *
5
+ * This pattern is often used when dealing with asynchronous operations that involve multiple steps or when
6
+ * the result of an operation cannot be immediately determined.
7
+ */
8
+ export declare function Deferred<T>(): {
9
+ promise: Promise<T>;
10
+ resolve: (value: T | PromiseLike<T>) => void;
11
+ reject: (reason?: any) => void;
12
+ isPending: () => boolean;
13
+ isResolved: () => boolean;
14
+ isRejected: () => boolean;
15
+ };
@@ -3,6 +3,7 @@ export * from "./FunctionPropertyNames";
3
3
  export * from "./blake2Concat";
4
4
  export * from "./classNames";
5
5
  export * from "./decodeAnyAddress";
6
+ export * from "./deferred";
6
7
  export * from "./encodeAnyAddress";
7
8
  export * from "./formatDecimals";
8
9
  export * from "./getBase64ImageUrl";
@@ -57,6 +57,41 @@ function decodeAnyAddress(encoded, ignoreChecksum, ss58Format) {
57
57
  }
58
58
  }
59
59
 
60
+ /**
61
+ * In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
62
+ * resolved or rejected at a later point in time, typically by code outside of the current function scope.
63
+ *
64
+ * This pattern is often used when dealing with asynchronous operations that involve multiple steps or when
65
+ * the result of an operation cannot be immediately determined.
66
+ */
67
+ function Deferred() {
68
+ let resolve;
69
+ let reject;
70
+ let isPending = true;
71
+ let isResolved = false;
72
+ let isRejected = false;
73
+ const promise = new Promise((innerResolve, innerReject) => {
74
+ resolve = value => {
75
+ isPending = false;
76
+ isResolved = true;
77
+ innerResolve(value);
78
+ };
79
+ reject = reason => {
80
+ isPending = false;
81
+ isRejected = true;
82
+ innerReject(reason);
83
+ };
84
+ });
85
+ return {
86
+ promise,
87
+ resolve,
88
+ reject,
89
+ isPending: () => isPending,
90
+ isResolved: () => isResolved,
91
+ isRejected: () => isRejected
92
+ };
93
+ }
94
+
60
95
  function encodeAnyAddress(key, ss58Format) {
61
96
  try {
62
97
  return keyring.encodeAddress(key, ss58Format);
@@ -136,9 +171,9 @@ function isArrayOf(array, func) {
136
171
 
137
172
  function planckToTokens(planck, tokenDecimals) {
138
173
  if (typeof planck !== "string" || typeof tokenDecimals !== "number") return;
139
- const base = new BigNumber__default["default"](10);
140
- const exponent = new BigNumber__default["default"](tokenDecimals).negated();
141
- const multiplier = base.pow(exponent);
174
+ const base = 10;
175
+ const exponent = -1 * tokenDecimals;
176
+ const multiplier = base ** exponent;
142
177
  return new BigNumber__default["default"](planck).multipliedBy(multiplier).toString(10);
143
178
  }
144
179
 
@@ -148,9 +183,9 @@ const throwAfter = (ms, reason) => new Promise((_, reject) => setTimeout(() => r
148
183
 
149
184
  function tokensToPlanck(tokens, tokenDecimals) {
150
185
  if (typeof tokens !== "string" || typeof tokenDecimals !== "number") return;
151
- const base = new BigNumber__default["default"](10);
152
- const exponent = new BigNumber__default["default"](tokenDecimals);
153
- const multiplier = base.pow(exponent);
186
+ const base = 10;
187
+ const exponent = tokenDecimals;
188
+ const multiplier = base ** exponent;
154
189
  return new BigNumber__default["default"](tokens).multipliedBy(multiplier).toString(10);
155
190
  }
156
191
 
@@ -160,6 +195,7 @@ function twox64Concat(input) {
160
195
  }
161
196
 
162
197
  exports.BigMath = BigMath;
198
+ exports.Deferred = Deferred;
163
199
  exports.MAX_DECIMALS_FORMAT = MAX_DECIMALS_FORMAT;
164
200
  exports.blake2Concat = blake2Concat;
165
201
  exports.classNames = classNames;
@@ -57,6 +57,41 @@ function decodeAnyAddress(encoded, ignoreChecksum, ss58Format) {
57
57
  }
58
58
  }
59
59
 
60
+ /**
61
+ * In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
62
+ * resolved or rejected at a later point in time, typically by code outside of the current function scope.
63
+ *
64
+ * This pattern is often used when dealing with asynchronous operations that involve multiple steps or when
65
+ * the result of an operation cannot be immediately determined.
66
+ */
67
+ function Deferred() {
68
+ let resolve;
69
+ let reject;
70
+ let isPending = true;
71
+ let isResolved = false;
72
+ let isRejected = false;
73
+ const promise = new Promise((innerResolve, innerReject) => {
74
+ resolve = value => {
75
+ isPending = false;
76
+ isResolved = true;
77
+ innerResolve(value);
78
+ };
79
+ reject = reason => {
80
+ isPending = false;
81
+ isRejected = true;
82
+ innerReject(reason);
83
+ };
84
+ });
85
+ return {
86
+ promise,
87
+ resolve,
88
+ reject,
89
+ isPending: () => isPending,
90
+ isResolved: () => isResolved,
91
+ isRejected: () => isRejected
92
+ };
93
+ }
94
+
60
95
  function encodeAnyAddress(key, ss58Format) {
61
96
  try {
62
97
  return keyring.encodeAddress(key, ss58Format);
@@ -136,9 +171,9 @@ function isArrayOf(array, func) {
136
171
 
137
172
  function planckToTokens(planck, tokenDecimals) {
138
173
  if (typeof planck !== "string" || typeof tokenDecimals !== "number") return;
139
- const base = new BigNumber__default["default"](10);
140
- const exponent = new BigNumber__default["default"](tokenDecimals).negated();
141
- const multiplier = base.pow(exponent);
174
+ const base = 10;
175
+ const exponent = -1 * tokenDecimals;
176
+ const multiplier = base ** exponent;
142
177
  return new BigNumber__default["default"](planck).multipliedBy(multiplier).toString(10);
143
178
  }
144
179
 
@@ -148,9 +183,9 @@ const throwAfter = (ms, reason) => new Promise((_, reject) => setTimeout(() => r
148
183
 
149
184
  function tokensToPlanck(tokens, tokenDecimals) {
150
185
  if (typeof tokens !== "string" || typeof tokenDecimals !== "number") return;
151
- const base = new BigNumber__default["default"](10);
152
- const exponent = new BigNumber__default["default"](tokenDecimals);
153
- const multiplier = base.pow(exponent);
186
+ const base = 10;
187
+ const exponent = tokenDecimals;
188
+ const multiplier = base ** exponent;
154
189
  return new BigNumber__default["default"](tokens).multipliedBy(multiplier).toString(10);
155
190
  }
156
191
 
@@ -160,6 +195,7 @@ function twox64Concat(input) {
160
195
  }
161
196
 
162
197
  exports.BigMath = BigMath;
198
+ exports.Deferred = Deferred;
163
199
  exports.MAX_DECIMALS_FORMAT = MAX_DECIMALS_FORMAT;
164
200
  exports.blake2Concat = blake2Concat;
165
201
  exports.classNames = classNames;
@@ -49,6 +49,41 @@ function decodeAnyAddress(encoded, ignoreChecksum, ss58Format) {
49
49
  }
50
50
  }
51
51
 
52
+ /**
53
+ * In TypeScript, a deferred promise refers to a pattern that involves creating a promise that can be
54
+ * resolved or rejected at a later point in time, typically by code outside of the current function scope.
55
+ *
56
+ * This pattern is often used when dealing with asynchronous operations that involve multiple steps or when
57
+ * the result of an operation cannot be immediately determined.
58
+ */
59
+ function Deferred() {
60
+ let resolve;
61
+ let reject;
62
+ let isPending = true;
63
+ let isResolved = false;
64
+ let isRejected = false;
65
+ const promise = new Promise((innerResolve, innerReject) => {
66
+ resolve = value => {
67
+ isPending = false;
68
+ isResolved = true;
69
+ innerResolve(value);
70
+ };
71
+ reject = reason => {
72
+ isPending = false;
73
+ isRejected = true;
74
+ innerReject(reason);
75
+ };
76
+ });
77
+ return {
78
+ promise,
79
+ resolve,
80
+ reject,
81
+ isPending: () => isPending,
82
+ isResolved: () => isResolved,
83
+ isRejected: () => isRejected
84
+ };
85
+ }
86
+
52
87
  function encodeAnyAddress(key, ss58Format) {
53
88
  try {
54
89
  return encodeAddress(key, ss58Format);
@@ -128,9 +163,9 @@ function isArrayOf(array, func) {
128
163
 
129
164
  function planckToTokens(planck, tokenDecimals) {
130
165
  if (typeof planck !== "string" || typeof tokenDecimals !== "number") return;
131
- const base = new BigNumber(10);
132
- const exponent = new BigNumber(tokenDecimals).negated();
133
- const multiplier = base.pow(exponent);
166
+ const base = 10;
167
+ const exponent = -1 * tokenDecimals;
168
+ const multiplier = base ** exponent;
134
169
  return new BigNumber(planck).multipliedBy(multiplier).toString(10);
135
170
  }
136
171
 
@@ -140,9 +175,9 @@ const throwAfter = (ms, reason) => new Promise((_, reject) => setTimeout(() => r
140
175
 
141
176
  function tokensToPlanck(tokens, tokenDecimals) {
142
177
  if (typeof tokens !== "string" || typeof tokenDecimals !== "number") return;
143
- const base = new BigNumber(10);
144
- const exponent = new BigNumber(tokenDecimals);
145
- const multiplier = base.pow(exponent);
178
+ const base = 10;
179
+ const exponent = tokenDecimals;
180
+ const multiplier = base ** exponent;
146
181
  return new BigNumber(tokens).multipliedBy(multiplier).toString(10);
147
182
  }
148
183
 
@@ -151,4 +186,4 @@ function twox64Concat(input) {
151
186
  return u8aToHex(u8aConcat(xxhashAsU8a(input, bitLength), u8aToU8a(input)));
152
187
  }
153
188
 
154
- export { BigMath, MAX_DECIMALS_FORMAT, blake2Concat, classNames, decodeAnyAddress, encodeAnyAddress, formatDecimals, getBase64ImageUrl, hasOwnProperty, isArrayOf, planckToTokens, sleep, throwAfter, tokensToPlanck, twox64Concat };
189
+ export { BigMath, Deferred, MAX_DECIMALS_FORMAT, blake2Concat, classNames, decodeAnyAddress, encodeAnyAddress, formatDecimals, getBase64ImageUrl, hasOwnProperty, isArrayOf, planckToTokens, sleep, throwAfter, tokensToPlanck, twox64Concat };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/util",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "UNLICENSED",
@@ -18,7 +18,7 @@
18
18
  "/dist"
19
19
  ],
20
20
  "engines": {
21
- "node": ">=14"
21
+ "node": ">=18"
22
22
  },
23
23
  "scripts": {
24
24
  "test": "jest",
@@ -26,12 +26,12 @@
26
26
  "clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
27
27
  },
28
28
  "dependencies": {
29
- "bignumber.js": "^9.1.0"
29
+ "bignumber.js": "^9.1.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@polkadot/keyring": "^10.1.7",
33
- "@polkadot/util": "^10.1.7",
34
- "@polkadot/util-crypto": "^10.1.7",
32
+ "@polkadot/keyring": "^11.1.1",
33
+ "@polkadot/util": "^11.1.1",
34
+ "@polkadot/util-crypto": "^11.1.1",
35
35
  "@talismn/eslint-config": "^0.0.1",
36
36
  "@talismn/tsconfig": "^0.0.2",
37
37
  "@types/jest": "^27.5.1",
@@ -41,9 +41,9 @@
41
41
  "typescript": "^4.6.4"
42
42
  },
43
43
  "peerDependencies": {
44
- "@polkadot/keyring": "10.x",
45
- "@polkadot/util": "10.x",
46
- "@polkadot/util-crypto": "^10.x"
44
+ "@polkadot/keyring": "11.x",
45
+ "@polkadot/util": "11.x",
46
+ "@polkadot/util-crypto": "^11.x"
47
47
  },
48
48
  "eslintConfig": {
49
49
  "root": true,