@dynamic-labs/utils 0.18.100-viem.2 → 0.18.100-viem.20

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,4 +1,175 @@
1
1
 
2
+ ### [0.18.100-viem.20](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.19...v0.18.100-viem.20) (2023-09-25)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * signing messages with backpack ([#3400](https://github.com/dynamic-labs/DynamicAuth/issues/3400)) ([f3231d8](https://github.com/dynamic-labs/DynamicAuth/commit/f3231d82c739ccd40ac9de6a33a0a1dd116145bf))
8
+
9
+ ### [0.18.100-viem.19](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.18...v0.18.100-viem.19) (2023-09-22)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * pass the network param on wallet transfers ([#3307](https://github.com/dynamic-labs/DynamicAuth/issues/3307)) ([#3385](https://github.com/dynamic-labs/DynamicAuth/issues/3385)) ([d003423](https://github.com/dynamic-labs/DynamicAuth/commit/d00342377fe1cd9605f37e54edb647378edd45d5))
15
+
16
+ ### [0.18.100-viem.18](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.17...v0.18.100-viem.18) (2023-09-20)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * show default wallet icon when no image is available ([#3291](https://github.com/dynamic-labs/DynamicAuth/issues/3291)) ([b541d00](https://github.com/dynamic-labs/DynamicAuth/commit/b541d002a0f6ff2e409034341e6e2191d6d3ac7f))
22
+ * display user profile when closing send balance ([#3333](https://github.com/dynamic-labs/DynamicAuth/issues/3333)) ([#3337](https://github.com/dynamic-labs/DynamicAuth/issues/3337)) ([5b3e665](https://github.com/dynamic-labs/DynamicAuth/commit/5b3e665a6ebfc0b46b84c787634d2e27bc4a9270))
23
+ * display sign typed data message for confirmation ([#3328](https://github.com/dynamic-labs/DynamicAuth/issues/3328)) ([2b93473](https://github.com/dynamic-labs/DynamicAuth/commit/2b93473024e277072be32a17c5513168b85d13f9))
24
+ * remove async from getWeb3Provider method in Magic connector ([#3281](https://github.com/dynamic-labs/DynamicAuth/issues/3281)) ([1d949c1](https://github.com/dynamic-labs/DynamicAuth/commit/1d949c18df8d5453f057f61b0c54ac16de1fbb76))
25
+ * fixes unlinking oauth account from multi wallet panel ([#3344](https://github.com/dynamic-labs/DynamicAuth/issues/3344)) ([87d08d6](https://github.com/dynamic-labs/DynamicAuth/commit/87d08d667f7bb82fcbadcf651a99c08acfdabf1e))
26
+ * prevent wallet connect v2 from redirect user to last known wallet after logout ([#3354](https://github.com/dynamic-labs/DynamicAuth/issues/3354)) ([dd39b13](https://github.com/dynamic-labs/DynamicAuth/commit/dd39b136af95667d1bf81586034eee5dc9c385db))
27
+
28
+ ### [0.18.100-viem.17](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.16...v0.18.100-viem.17) (2023-09-11)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * remove react component props from sending to sdk api v18-viem ([#3287](https://github.com/dynamic-labs/DynamicAuth/issues/3287)) ([18e7617](https://github.com/dynamic-labs/DynamicAuth/commit/18e76179b3287cc9ca60efc2771e072bb87667ba)), closes [#3282](https://github.com/dynamic-labs/DynamicAuth/issues/3282)
34
+
35
+ ### [0.18.100-viem.16](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.15...v0.18.100-viem.16) (2023-09-11)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * catch error sending sdkSettings and log warning v18-viem ([#3277](https://github.com/dynamic-labs/DynamicAuth/issues/3277)) ([af86753](https://github.com/dynamic-labs/DynamicAuth/commit/af86753f4b73c0ec4ba981c9ffd47af21fac9d8d)), closes [#3274](https://github.com/dynamic-labs/DynamicAuth/issues/3274)
41
+ * issue where unexpected token would occur when bundlers defined process.env ([#3283](https://github.com/dynamic-labs/DynamicAuth/issues/3283)) ([16110f9](https://github.com/dynamic-labs/DynamicAuth/commit/16110f90f02841104b053365b17343ed80a72018))
42
+ * seprate ls checks for dynamiccontext and wagmi settings v18-viem ([#3279](https://github.com/dynamic-labs/DynamicAuth/issues/3279)) ([e31d85e](https://github.com/dynamic-labs/DynamicAuth/commit/e31d85e576d0fba31616d6aa408316c261f42373)), closes [#3275](https://github.com/dynamic-labs/DynamicAuth/issues/3275)
43
+
44
+ ### [0.18.100-viem.15](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.14...v0.18.100-viem.15) (2023-09-11)
45
+
46
+
47
+ ### Bug Fixes
48
+ * sdkSettings should call once per session ([#3189](https://github.com/dynamic-labs/DynamicAuth/issues/3189)) ([#3265](https://github.com/dynamic-labs/DynamicAuth/issues/3265)) ([f46a692](https://github.com/dynamic-labs/DynamicAuth/commit/f46a6927684caf5962e5b60a9927030a5f7720e2))
49
+ * wallet transition in the bridge ([#3268](https://github.com/dynamic-labs/DynamicAuth/issues/3268)) ([#3271](https://github.com/dynamic-labs/DynamicAuth/issues/3271)) ([95e6d5f](https://github.com/dynamic-labs/DynamicAuth/commit/95e6d5f6ff003ff428795bdd73e2d88da366ed56)), closes [#3243](https://github.com/dynamic-labs/DynamicAuth/issues/3243)
50
+
51
+ ### [0.18.100-viem.14](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.13...v0.18.100-viem.14) (2023-09-05)
52
+
53
+
54
+ ### Features
55
+
56
+ * add onSignedMessage callback ([#3214](https://github.com/dynamic-labs/DynamicAuth/issues/3214)) ([92fd070](https://github.com/dynamic-labs/DynamicAuth/commit/92fd070c8edabce5ed991cfd92b3745c7afb0b43))
57
+
58
+
59
+ ### Bug Fixes
60
+
61
+ * prefer mainnet chain id when connecting with WCv2 ([#3220](https://github.com/dynamic-labs/DynamicAuth/issues/3220)) ([55eb097](https://github.com/dynamic-labs/DynamicAuth/commit/55eb09739f4c8912a9de2198f69cd925923270c4))
62
+
63
+ ### [0.18.100-viem.13](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.12...v0.18.100-viem.13) (2023-09-01)
64
+
65
+
66
+ ### Features
67
+
68
+ * add option to disable the locked wallet view ([#3187](https://github.com/dynamic-labs/DynamicAuth/issues/3187)) ([aa70fb5](https://github.com/dynamic-labs/DynamicAuth/commit/aa70fb52bb185e27fdb311b0e0dd10166a83d60a))
69
+ * migrate starknet version to v5 ([#3198](https://github.com/dynamic-labs/DynamicAuth/issues/3198)) ([e5b24ea](https://github.com/dynamic-labs/DynamicAuth/commit/e5b24ea86ce58f83a539d8ef8adc6fb0c77bd51a))
70
+
71
+
72
+ ### Bug Fixes
73
+
74
+ * show the multi wallet list when opening the auth flow to authenticated users ([#3165](https://github.com/dynamic-labs/DynamicAuth/issues/3165)) ([b7a7110](https://github.com/dynamic-labs/DynamicAuth/commit/b7a71106a730925dc44abbd0e3aedf5ce3f5ca39)), closes [#3134](https://github.com/dynamic-labs/DynamicAuth/issues/3134) [#3152](https://github.com/dynamic-labs/DynamicAuth/issues/3152) [#3168](https://github.com/dynamic-labs/DynamicAuth/issues/3168)
75
+ * sign message for embedded wallet when auth mode is connect only ([#3195](https://github.com/dynamic-labs/DynamicAuth/issues/3195)) ([6cdee66](https://github.com/dynamic-labs/DynamicAuth/commit/6cdee661d45877c3d78744d115a675d114d62091))
76
+ * verify email OTP when email is updated ([#3168](https://github.com/dynamic-labs/DynamicAuth/issues/3168)) ([641eeb6](https://github.com/dynamic-labs/DynamicAuth/commit/641eeb685b0c9d77cc72912f29b137c699c192f0))
77
+
78
+ ### [0.18.100-viem.12](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.11...v0.18.100-viem.12) (2023-08-30)
79
+
80
+
81
+ ### Features
82
+
83
+ * add deepLinkPreference prop ([#3174](https://github.com/dynamic-labs/DynamicAuth/issues/3174)) ([#3177](https://github.com/dynamic-labs/DynamicAuth/issues/3177)) ([d5a4052](https://github.com/dynamic-labs/DynamicAuth/commit/d5a4052ce6547289fff08ba57728af227d334dfa))
84
+
85
+
86
+ ### Bug Fixes
87
+
88
+ * end connector session when unlinking from bridge ([#3120](https://github.com/dynamic-labs/DynamicAuth/issues/3120)) ([#3179](https://github.com/dynamic-labs/DynamicAuth/issues/3179)) ([d1f9898](https://github.com/dynamic-labs/DynamicAuth/commit/d1f9898fd678c9b342afe0dc1ea9ab21914c610f))
89
+ * **bridge:** update address when switching networks ([#3171](https://github.com/dynamic-labs/DynamicAuth/issues/3171)) ([#3181](https://github.com/dynamic-labs/DynamicAuth/issues/3181)) ([0e138e0](https://github.com/dynamic-labs/DynamicAuth/commit/0e138e0f824cda7e67f6ffce3057deb0a92ee7ae))
90
+
91
+ ### [0.18.100-viem.11](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.10...v0.18.100-viem.11) (2023-08-29)
92
+
93
+
94
+ ### Bug Fixes
95
+
96
+ * **bridge:** connect L2 wallet after updating network ([#3164](https://github.com/dynamic-labs/DynamicAuth/issues/3164)) ([b775408](https://github.com/dynamic-labs/DynamicAuth/commit/b775408f98c1436383ae781dffb4a832f86a7d0d))
97
+ * resend magic OTP on back click ([#3123](https://github.com/dynamic-labs/DynamicAuth/issues/3123)) ([#3151](https://github.com/dynamic-labs/DynamicAuth/issues/3151)) ([eee2b0c](https://github.com/dynamic-labs/DynamicAuth/commit/eee2b0c0db0d9538b39c8e6ee76baf36c3479af5))
98
+ * **WagmiConnector:** sync wagmi with wallet connector events ([#3160](https://github.com/dynamic-labs/DynamicAuth/issues/3160)) ([5618903](https://github.com/dynamic-labs/DynamicAuth/commit/561890334f4ae28ffaf40f02d793da75865a0885)), closes [#3149](https://github.com/dynamic-labs/DynamicAuth/issues/3149)
99
+
100
+ ### [0.18.100-viem.10](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.9...v0.18.100-viem.10) (2023-08-25)
101
+
102
+
103
+ ### Bug Fixes
104
+
105
+ * stop calling handleLogOut prematurely ([#3137](https://github.com/dynamic-labs/DynamicAuth/issues/3137)) ([3d029ba](https://github.com/dynamic-labs/DynamicAuth/commit/3d029ba3e34e3cb8a2b976dc5d3fb9ee1356d76c)), closes [#3135](https://github.com/dynamic-labs/DynamicAuth/issues/3135)
106
+
107
+ ### [0.18.100-viem.9](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.8...v0.18.100-viem.9) (2023-08-25)
108
+
109
+
110
+ ### Features
111
+
112
+ * register connection of second wallet in bridge ([3e12cde](https://github.com/dynamic-labs/DynamicAuth/commit/3e12cdece4abd717280aeed442999aef4653e059)), closes [#3113](https://github.com/dynamic-labs/DynamicAuth/issues/3113)
113
+
114
+
115
+ ### Bug Fixes
116
+
117
+ * fix github social linking icon on dark mode ([#3130](https://github.com/dynamic-labs/DynamicAuth/issues/3130)) ([8db8aa7](https://github.com/dynamic-labs/DynamicAuth/commit/8db8aa7b9892f93f6fb6aa7772f99b747fe8f86b)), closes [#3126](https://github.com/dynamic-labs/DynamicAuth/issues/3126)
118
+ * fix issue with detecting oauth window closed before finishing linking ([#3128](https://github.com/dynamic-labs/DynamicAuth/issues/3128)) ([b108bf9](https://github.com/dynamic-labs/DynamicAuth/commit/b108bf9d9b3ca47202ca4a1993f155639fd032a8)), closes [#3124](https://github.com/dynamic-labs/DynamicAuth/issues/3124)
119
+
120
+ ### [0.18.100-viem.8](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.7...v0.18.100-viem.8) (2023-08-24)
121
+
122
+
123
+ ### Bug Fixes
124
+
125
+ * allow overriding contracts on wagmi chains ([#3105](https://github.com/dynamic-labs/DynamicAuth/issues/3105)) ([acee314](https://github.com/dynamic-labs/DynamicAuth/commit/acee3147156c30957bdb690c56cfd10af13dc57f))
126
+ * send wagmi settings only once when DynamicWagmiConnector loads (v18-viem) ([#3109](https://github.com/dynamic-labs/DynamicAuth/issues/3109)) ([a6e2675](https://github.com/dynamic-labs/DynamicAuth/commit/a6e2675c49eab3c40dc9365b20ac2dd9eaf8e4ae)), closes [#3103](https://github.com/dynamic-labs/DynamicAuth/issues/3103)
127
+
128
+ ### [0.18.100-viem.7](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.6...v0.18.100-viem.7) (2023-08-23)
129
+
130
+
131
+ ### Bug Fixes
132
+
133
+ * fix jumping when entering OTP code on IOS ([#3036](https://github.com/dynamic-labs/DynamicAuth/issues/3036)) ([#3094](https://github.com/dynamic-labs/DynamicAuth/issues/3094)) ([093ab9a](https://github.com/dynamic-labs/DynamicAuth/commit/093ab9aae2f8bba99622e1146d1dc54c077ae3cb))
134
+ * log user out when magic session expires ([#3085](https://github.com/dynamic-labs/DynamicAuth/issues/3085)) ([#3088](https://github.com/dynamic-labs/DynamicAuth/issues/3088)) ([d7d125c](https://github.com/dynamic-labs/DynamicAuth/commit/d7d125c93a652f26deeedce534f1e0472ad3377c))
135
+ * improvements to network switching in bridge flow ([#3080](https://github.com/dynamic-labs/DynamicAuth/issues/3080)) ([4137c05](https://github.com/dynamic-labs/DynamicAuth/commit/4137c0599a760d2ec8a6b9a6a5de7cce9987033b))
136
+ * fix could not replace transaction error ([#3058](https://github.com/dynamic-labs/DynamicAuth/issues/3058)) ([b36184e](https://github.com/dynamic-labs/DynamicAuth/commit/b36184e17a268d49bed100e81477df9f5e4b3731)), closes [#3049](https://github.com/dynamic-labs/DynamicAuth/issues/3049)
137
+ * update embedded wallet notice design ([529f90f](https://github.com/dynamic-labs/DynamicAuth/commit/529f90f323f712240dfd964d908b6ea59cacbd19)), closes [#2987](https://github.com/dynamic-labs/DynamicAuth/issues/2987) [#3082](https://github.com/dynamic-labs/DynamicAuth/issues/3082)
138
+
139
+ ### [0.18.100-viem.6](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.5...v0.18.100-viem.6) (2023-08-21)
140
+
141
+
142
+ ### Bug Fixes
143
+
144
+ * detect when user closes oauth window when linking social account ([#3066](https://github.com/dynamic-labs/DynamicAuth/issues/3066)) ([428e9e8](https://github.com/dynamic-labs/DynamicAuth/commit/428e9e81d5473b2de03560f118c61baf3ee9e692))
145
+ * sync connected wallets with wagmi client ([#3073](https://github.com/dynamic-labs/DynamicAuth/issues/3073)) ([bce960d](https://github.com/dynamic-labs/DynamicAuth/commit/bce960d341ff55d3d660a8c34121c4348ca2908b))
146
+
147
+ ### [0.18.100-viem.5](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.4...v0.18.100-viem.5) (2023-08-19)
148
+
149
+
150
+ ### Bug Fixes
151
+
152
+ * ensure social sign in embedded wallets sync correctly with wagmi ([5fdf11d](https://github.com/dynamic-labs/DynamicAuth/commit/5fdf11df19759b6e32b461802c0a32686365d890))
153
+
154
+ ### [0.18.100-viem.4](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.3...v0.18.100-viem.4) (2023-08-17)
155
+
156
+
157
+ ### Bug Fixes
158
+
159
+ * always enable magic connectors when enabled ([#3014](https://github.com/dynamic-labs/DynamicAuth/issues/3014)) ([#3039](https://github.com/dynamic-labs/DynamicAuth/issues/3039)) ([6d4c473](https://github.com/dynamic-labs/DynamicAuth/commit/6d4c4738b92b40c903488c435fdd1bf69dc6c96e))
160
+ * guard against null or undefined provider value when logging in w… ([#3028](https://github.com/dynamic-labs/DynamicAuth/issues/3028)) ([050b62c](https://github.com/dynamic-labs/DynamicAuth/commit/050b62c7c91b6430eb350f7b49fa57260a08a756)), closes [#3021](https://github.com/dynamic-labs/DynamicAuth/issues/3021)
161
+ * issue where walletconnectors are instantiated without walletbook ([#3020](https://github.com/dynamic-labs/DynamicAuth/issues/3020)) ([#3033](https://github.com/dynamic-labs/DynamicAuth/issues/3033)) ([92394aa](https://github.com/dynamic-labs/DynamicAuth/commit/92394aa83cad497d805ac4d4ce8eb35d2b10690c))
162
+ * only use the production api environment of magicLink ([#3024](https://github.com/dynamic-labs/DynamicAuth/issues/3024)) ([25eea74](https://github.com/dynamic-labs/DynamicAuth/commit/25eea7438b0c2cb0279fb70d0be3c16f73b24573))
163
+ * switching network in connected state should update wallets to connect list ([#3038](https://github.com/dynamic-labs/DynamicAuth/issues/3038)) ([22837cb](https://github.com/dynamic-labs/DynamicAuth/commit/22837cb0af3a2dbdd7345b5cf92c23455bdd3cc4))
164
+
165
+ ### [0.18.100-viem.3](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.2...v0.18.100-viem.3) (2023-08-16)
166
+
167
+
168
+ ### Bug Fixes
169
+
170
+ * fix twitter linking ([#2918](https://github.com/dynamic-labs/DynamicAuth/issues/2918)) ([#3003](https://github.com/dynamic-labs/DynamicAuth/issues/3003)) ([8f028dc](https://github.com/dynamic-labs/DynamicAuth/commit/8f028dc91434a44b4f2bcae82ad5f16a27c9e5b1))
171
+ * use ETH currency symbol for STARK chains ([#3005](https://github.com/dynamic-labs/DynamicAuth/issues/3005)) ([#3008](https://github.com/dynamic-labs/DynamicAuth/issues/3008)) ([6f0c66f](https://github.com/dynamic-labs/DynamicAuth/commit/6f0c66f63bbfdbb08d0c504d52565acd90070528))
172
+
2
173
  ### [0.18.100-viem.2](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.100-viem.1...v0.18.100-viem.2) (2023-08-15)
3
174
 
4
175
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "0.18.100-viem.2",
3
+ "version": "0.18.100-viem.20",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -29,6 +29,7 @@
29
29
  "viem": "^1.5.3"
30
30
  },
31
31
  "dependencies": {
32
- "@dynamic-labs/types": "0.18.100-viem.2"
32
+ "@dynamic-labs/logger": "0.18.100-viem.20",
33
+ "@dynamic-labs/types": "0.18.100-viem.20"
33
34
  }
34
35
  }
@@ -2,32 +2,134 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var logger = require('../logger/logger.cjs');
6
+
7
+ /* eslint-disable multiline-comment-style */
8
+ const defaultCancel = () => {
9
+ logger.logger.error("Tried to cancel CancellablePromise without ever assigning it's '_cancel' method");
10
+ };
11
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
12
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
13
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
14
+ *
15
+ * @example
16
+ * // Cancelling this promise
17
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
18
+ * promise.cancel('User cancelled')
19
+ *
20
+ * // Setting up listeners for resolve, cancel and reject
21
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
22
+ * new CancellablePromise(() => {})
23
+ * .then(() => console.log('Promise resolved'))
24
+ * .onCancel(() => console.log('Promise was cancelled'))
25
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
26
+ *
27
+ * // Telling whether catch was cause of cancel or not
28
+ * new CancellablePromise(() => {})
29
+ * .then(() => console.log('Promise resolved'))
30
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
31
+ */
5
32
  class CancellablePromise extends Promise {
33
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
+ internalCancel(reason) {
35
+ defaultCancel();
36
+ }
6
37
  constructor(executor) {
38
+ let superReject = defaultCancel;
39
+ let superResolve = () => { };
7
40
  super((resolve, reject) => {
8
- executor((val) => {
9
- if (this.isCancelled)
10
- return;
11
- resolve(val);
12
- }, (err) => {
13
- if (this.isCancelled)
14
- return;
15
- reject(err);
16
- });
41
+ superReject = reject;
42
+ superResolve = resolve;
43
+ });
44
+ this.internalIsCancelled = false;
45
+ this.isSettled = false;
46
+ executor((value) => {
47
+ if (!this.isCancelled && !this.isSettled)
48
+ superResolve(value);
49
+ this.isSettled = true;
50
+ }, (reason) => {
51
+ if (!this.isCancelled && !this.isSettled)
52
+ superReject(reason);
53
+ this.isSettled = true;
17
54
  });
18
- this._controller = new AbortController();
55
+ this.internalCancel = superReject;
19
56
  }
57
+ /** Whether this CancellablePromise was cancelled. */
20
58
  get isCancelled() {
21
- return this._controller.signal.aborted;
59
+ return this.internalIsCancelled;
22
60
  }
23
- cancel() {
24
- this._controller.abort();
61
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
62
+ * where the reason is the provided argument.
63
+ * @returns The cancelled promise.
64
+ */
65
+ cancel(reason) {
66
+ if (this.isSettled)
67
+ return this;
68
+ this.internalIsCancelled = true;
69
+ this.internalCancel(reason);
70
+ this.isSettled = true;
71
+ return this;
25
72
  }
26
- static fromPromise(promise) {
27
- return new CancellablePromise((resolve, reject) => {
28
- promise.then(resolve).catch(reject);
73
+ internalOnCancel(listener, options) {
74
+ const newPromise = new CancellablePromise((resolve, reject) => {
75
+ this.internalThen(resolve, ({ wasCancelled, reason }) => {
76
+ if (wasCancelled)
77
+ resolve(listener(reason));
78
+ else
79
+ reject(reason);
80
+ }, { ignoreOnCancel: true });
81
+ });
82
+ /** Tie the new promise's cancel to this promise's cancel */
83
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
84
+ newPromise.internalOnCancel((reason) => {
85
+ this.cancel(reason);
86
+ }, { ignoreOnCancel: true });
87
+ }
88
+ return newPromise;
89
+ }
90
+ /** Allows reacting to this CancellablePromise being cancelled */
91
+ onCancel(listener) {
92
+ return this.internalOnCancel(listener);
93
+ }
94
+ internalThen(onFulfilled, onRejected, options) {
95
+ /** Create a catch handler that is undefined if the received callback is undefined */
96
+ const catchHandler = onRejected
97
+ ? (reason) => onRejected({ reason, wasCancelled: this.isCancelled })
98
+ : onRejected;
99
+ // /** Create the CancellablePromise we will returned, associated to the then promise */
100
+ const newPromise = CancellablePromise.fromPromise(super.then(onFulfilled, catchHandler));
101
+ /** Tie the new promise's cancel to this promise's cancel */
102
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
103
+ newPromise.internalOnCancel((reason) => {
104
+ this.cancel(reason);
105
+ }, { ignoreOnCancel: true });
106
+ }
107
+ return newPromise;
108
+ }
109
+ then(onFulfilled, onRejected) {
110
+ return this.internalThen(onFulfilled, onRejected);
111
+ }
112
+ catch(onRejected) {
113
+ return this.then(undefined, onRejected);
114
+ }
115
+ finally(onFinally) {
116
+ return this.then((value) => {
117
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
118
+ return value;
119
+ }, (reason) => {
120
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
121
+ throw reason;
29
122
  });
30
123
  }
124
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
125
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
126
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
127
+ static fromPromise(promise) {
128
+ if ('internalIsCancelled' in promise)
129
+ return promise;
130
+ const newPromise = new CancellablePromise((resolve, reject) => promise.then(resolve, reject));
131
+ return newPromise;
132
+ }
31
133
  }
32
134
 
33
135
  exports.CancellablePromise = CancellablePromise;
@@ -1,9 +1,54 @@
1
1
  type Executor<T> = (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void;
2
+ type CancelListener<TResult = never> = (reason?: unknown) => TResult;
3
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
4
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
5
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
6
+ *
7
+ * @example
8
+ * // Cancelling this promise
9
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
10
+ * promise.cancel('User cancelled')
11
+ *
12
+ * // Setting up listeners for resolve, cancel and reject
13
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
14
+ * new CancellablePromise(() => {})
15
+ * .then(() => console.log('Promise resolved'))
16
+ * .onCancel(() => console.log('Promise was cancelled'))
17
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
18
+ *
19
+ * // Telling whether catch was cause of cancel or not
20
+ * new CancellablePromise(() => {})
21
+ * .then(() => console.log('Promise resolved'))
22
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
23
+ */
2
24
  export declare class CancellablePromise<T> extends Promise<T> {
3
- _controller: AbortController;
25
+ private internalIsCancelled;
26
+ private isSettled;
27
+ private internalCancel;
4
28
  constructor(executor: Executor<T>);
29
+ /** Whether this CancellablePromise was cancelled. */
5
30
  get isCancelled(): boolean;
6
- cancel(): void;
7
- static fromPromise<T>(promise: Promise<T>): CancellablePromise<T>;
31
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
32
+ * where the reason is the provided argument.
33
+ * @returns The cancelled promise.
34
+ */
35
+ cancel(reason?: unknown): this;
36
+ private internalOnCancel;
37
+ /** Allows reacting to this CancellablePromise being cancelled */
38
+ onCancel<TResult = never>(listener: CancelListener<TResult>): CancellablePromise<T | TResult>;
39
+ private internalThen;
40
+ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: {
41
+ reason: unknown;
42
+ wasCancelled: boolean;
43
+ }) => TResult2 | PromiseLike<TResult2>) | null): CancellablePromise<TResult1 | TResult2>;
44
+ catch<TResult = never>(onRejected?: ((reason: {
45
+ reason: unknown;
46
+ wasCancelled: boolean;
47
+ }) => TResult | PromiseLike<TResult>) | null): CancellablePromise<T | TResult>;
48
+ finally(onFinally?: (() => void) | null): CancellablePromise<T>;
49
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
50
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
51
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
52
+ static fromPromise<T>(promise: Promise<T> | CancellablePromise<T>): CancellablePromise<T>;
8
53
  }
9
54
  export {};
@@ -1,29 +1,131 @@
1
+ import { logger } from '../logger/logger.js';
2
+
3
+ /* eslint-disable multiline-comment-style */
4
+ const defaultCancel = () => {
5
+ logger.error("Tried to cancel CancellablePromise without ever assigning it's '_cancel' method");
6
+ };
7
+ /** An extension of Promise that allows you to explicitly cancel a promise with an external reference to it.
8
+ * Cancelling CancellablePromise causes it to reject with reason set to the parameter passed to the cancel method.
9
+ * When CancellablePromise rejects, it provides a boolean to indicate whether it was cancelled, alongside the reason.
10
+ *
11
+ * @example
12
+ * // Cancelling this promise
13
+ * const promise = new CancellablePromise(() => {}).onCancel(console.log)
14
+ * promise.cancel('User cancelled')
15
+ *
16
+ * // Setting up listeners for resolve, cancel and reject
17
+ * // (notice calling catch after onCancel prevents catch from being called by cancellation)
18
+ * new CancellablePromise(() => {})
19
+ * .then(() => console.log('Promise resolved'))
20
+ * .onCancel(() => console.log('Promise was cancelled'))
21
+ * .catch(() => console.log('Promise was rejected but NOT cancelled'))
22
+ *
23
+ * // Telling whether catch was cause of cancel or not
24
+ * new CancellablePromise(() => {})
25
+ * .then(() => console.log('Promise resolved'))
26
+ * .catch(({ reason, wasCancelled }) => console.log('Promise was rejected. Cancelled: ' + wasCancelled))
27
+ */
1
28
  class CancellablePromise extends Promise {
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ internalCancel(reason) {
31
+ defaultCancel();
32
+ }
2
33
  constructor(executor) {
34
+ let superReject = defaultCancel;
35
+ let superResolve = () => { };
3
36
  super((resolve, reject) => {
4
- executor((val) => {
5
- if (this.isCancelled)
6
- return;
7
- resolve(val);
8
- }, (err) => {
9
- if (this.isCancelled)
10
- return;
11
- reject(err);
12
- });
37
+ superReject = reject;
38
+ superResolve = resolve;
39
+ });
40
+ this.internalIsCancelled = false;
41
+ this.isSettled = false;
42
+ executor((value) => {
43
+ if (!this.isCancelled && !this.isSettled)
44
+ superResolve(value);
45
+ this.isSettled = true;
46
+ }, (reason) => {
47
+ if (!this.isCancelled && !this.isSettled)
48
+ superReject(reason);
49
+ this.isSettled = true;
13
50
  });
14
- this._controller = new AbortController();
51
+ this.internalCancel = superReject;
15
52
  }
53
+ /** Whether this CancellablePromise was cancelled. */
16
54
  get isCancelled() {
17
- return this._controller.signal.aborted;
55
+ return this.internalIsCancelled;
18
56
  }
19
- cancel() {
20
- this._controller.abort();
57
+ /** Cancels the promise. This causes the promise to reject with { wasCancelled: true, reason: reason }
58
+ * where the reason is the provided argument.
59
+ * @returns The cancelled promise.
60
+ */
61
+ cancel(reason) {
62
+ if (this.isSettled)
63
+ return this;
64
+ this.internalIsCancelled = true;
65
+ this.internalCancel(reason);
66
+ this.isSettled = true;
67
+ return this;
21
68
  }
22
- static fromPromise(promise) {
23
- return new CancellablePromise((resolve, reject) => {
24
- promise.then(resolve).catch(reject);
69
+ internalOnCancel(listener, options) {
70
+ const newPromise = new CancellablePromise((resolve, reject) => {
71
+ this.internalThen(resolve, ({ wasCancelled, reason }) => {
72
+ if (wasCancelled)
73
+ resolve(listener(reason));
74
+ else
75
+ reject(reason);
76
+ }, { ignoreOnCancel: true });
77
+ });
78
+ /** Tie the new promise's cancel to this promise's cancel */
79
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
80
+ newPromise.internalOnCancel((reason) => {
81
+ this.cancel(reason);
82
+ }, { ignoreOnCancel: true });
83
+ }
84
+ return newPromise;
85
+ }
86
+ /** Allows reacting to this CancellablePromise being cancelled */
87
+ onCancel(listener) {
88
+ return this.internalOnCancel(listener);
89
+ }
90
+ internalThen(onFulfilled, onRejected, options) {
91
+ /** Create a catch handler that is undefined if the received callback is undefined */
92
+ const catchHandler = onRejected
93
+ ? (reason) => onRejected({ reason, wasCancelled: this.isCancelled })
94
+ : onRejected;
95
+ // /** Create the CancellablePromise we will returned, associated to the then promise */
96
+ const newPromise = CancellablePromise.fromPromise(super.then(onFulfilled, catchHandler));
97
+ /** Tie the new promise's cancel to this promise's cancel */
98
+ if (!(options === null || options === void 0 ? void 0 : options.ignoreOnCancel)) {
99
+ newPromise.internalOnCancel((reason) => {
100
+ this.cancel(reason);
101
+ }, { ignoreOnCancel: true });
102
+ }
103
+ return newPromise;
104
+ }
105
+ then(onFulfilled, onRejected) {
106
+ return this.internalThen(onFulfilled, onRejected);
107
+ }
108
+ catch(onRejected) {
109
+ return this.then(undefined, onRejected);
110
+ }
111
+ finally(onFinally) {
112
+ return this.then((value) => {
113
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
114
+ return value;
115
+ }, (reason) => {
116
+ onFinally === null || onFinally === void 0 ? void 0 : onFinally();
117
+ throw reason;
25
118
  });
26
119
  }
120
+ /** Generates a CancellablePromise from a Promise. If a CancellablePromise is passed, it's returned unscathed.
121
+ * WARNING: unless you attach a method to reject the original Promise with the "onCancel" param.
122
+ * cancelling the resulting CancellablePromise does NOT affect the original Promise. */
123
+ static fromPromise(promise) {
124
+ if ('internalIsCancelled' in promise)
125
+ return promise;
126
+ const newPromise = new CancellablePromise((resolve, reject) => promise.then(resolve, reject));
127
+ return newPromise;
128
+ }
27
129
  }
28
130
 
29
131
  export { CancellablePromise };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const bigIntToHex = (value) => {
6
+ if (typeof value !== 'bigint') {
7
+ throw new TypeError('Input must be of type BigInt');
8
+ }
9
+ if (value < 0) {
10
+ throw new RangeError('Negative BigInt values are not supported');
11
+ }
12
+ return `0x${value.toString(16)}`;
13
+ };
14
+
15
+ exports.bigIntToHex = bigIntToHex;
@@ -0,0 +1 @@
1
+ export declare const bigIntToHex: (value: bigint) => `0x${string}`;
@@ -0,0 +1,11 @@
1
+ const bigIntToHex = (value) => {
2
+ if (typeof value !== 'bigint') {
3
+ throw new TypeError('Input must be of type BigInt');
4
+ }
5
+ if (value < 0) {
6
+ throw new RangeError('Negative BigInt values are not supported');
7
+ }
8
+ return `0x${value.toString(16)}`;
9
+ };
10
+
11
+ export { bigIntToHex };
@@ -0,0 +1 @@
1
+ export { bigIntToHex } from './bigIntToHex';
package/src/index.cjs CHANGED
@@ -25,6 +25,9 @@ var isMobile = require('./isMobile.cjs');
25
25
  var localStorageAsync = require('./localStorageAsync.cjs');
26
26
  var bufferToBase64 = require('./bufferToBase64.cjs');
27
27
  var getOrMapViemChain = require('./getOrMapViemChain.cjs');
28
+ var bigIntToHex = require('./bigIntToHex/bigIntToHex.cjs');
29
+ var isBigInt = require('./isBigInt/isBigInt.cjs');
30
+ var last = require('./last.cjs');
28
31
 
29
32
 
30
33
 
@@ -61,3 +64,6 @@ exports.bufferToBase64 = bufferToBase64.bufferToBase64;
61
64
  exports.getChain = getOrMapViemChain.getChain;
62
65
  exports.getOrMapViemChain = getOrMapViemChain.getOrMapViemChain;
63
66
  exports.mapChain = getOrMapViemChain.mapChain;
67
+ exports.bigIntToHex = bigIntToHex.bigIntToHex;
68
+ exports.isBigInt = isBigInt.isBigInt;
69
+ exports.last = last.last;
package/src/index.d.ts CHANGED
@@ -7,3 +7,6 @@ export * from './isMobile';
7
7
  export * from './localStorageAsync';
8
8
  export * from './bufferToBase64';
9
9
  export * from './getOrMapViemChain';
10
+ export * from './bigIntToHex';
11
+ export * from './isBigInt';
12
+ export * from './last';
package/src/index.js CHANGED
@@ -21,3 +21,6 @@ export { isAndroid, isIOS, isIPad, isIPhone, isLegacySafari, isMobile, isSamsung
21
21
  export { getItemAsync, removeItemAsync, setItemAsync } from './localStorageAsync.js';
22
22
  export { bufferToBase64 } from './bufferToBase64.js';
23
23
  export { getChain, getOrMapViemChain, mapChain } from './getOrMapViemChain.js';
24
+ export { bigIntToHex } from './bigIntToHex/bigIntToHex.js';
25
+ export { isBigInt } from './isBigInt/isBigInt.js';
26
+ export { last } from './last.js';
@@ -0,0 +1 @@
1
+ export { isBigInt } from './isBigInt';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isBigInt = (value) => typeof value === 'bigint';
6
+
7
+ exports.isBigInt = isBigInt;
@@ -0,0 +1 @@
1
+ export declare const isBigInt: (value: bigint | unknown) => value is bigint;
@@ -0,0 +1,3 @@
1
+ const isBigInt = (value) => typeof value === 'bigint';
2
+
3
+ export { isBigInt };
package/src/last.cjs ADDED
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Retrieves the last item from an array.
7
+ *
8
+ * @template T - The type of the items in the array.
9
+ * @param {T[]} arr - The array from which to retrieve the last item.
10
+ * @returns {T | undefined} The last item in the array, or undefined if the array is empty.
11
+ *
12
+ * @example
13
+ * const numbers = [1, 2, 3, 4, 5];
14
+ * console.log(last(numbers)); // Outputs: 5
15
+ *
16
+ * const emptyArray: number[] = [];
17
+ * console.log(last(emptyArray)); // Outputs: undefined
18
+ */
19
+ const last = (arr) => arr.length > 0 ? arr[arr.length - 1] : undefined;
20
+
21
+ exports.last = last;
package/src/last.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Retrieves the last item from an array.
3
+ *
4
+ * @template T - The type of the items in the array.
5
+ * @param {T[]} arr - The array from which to retrieve the last item.
6
+ * @returns {T | undefined} The last item in the array, or undefined if the array is empty.
7
+ *
8
+ * @example
9
+ * const numbers = [1, 2, 3, 4, 5];
10
+ * console.log(last(numbers)); // Outputs: 5
11
+ *
12
+ * const emptyArray: number[] = [];
13
+ * console.log(last(emptyArray)); // Outputs: undefined
14
+ */
15
+ export declare const last: <T>(arr: T[]) => T | undefined;
package/src/last.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Retrieves the last item from an array.
3
+ *
4
+ * @template T - The type of the items in the array.
5
+ * @param {T[]} arr - The array from which to retrieve the last item.
6
+ * @returns {T | undefined} The last item in the array, or undefined if the array is empty.
7
+ *
8
+ * @example
9
+ * const numbers = [1, 2, 3, 4, 5];
10
+ * console.log(last(numbers)); // Outputs: 5
11
+ *
12
+ * const emptyArray: number[] = [];
13
+ * console.log(last(emptyArray)); // Outputs: undefined
14
+ */
15
+ const last = (arr) => arr.length > 0 ? arr[arr.length - 1] : undefined;
16
+
17
+ export { last };
@@ -0,0 +1 @@
1
+ export * from './logger';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var logger$1 = require('@dynamic-labs/logger');
6
+
7
+ const logger = new logger$1.Logger('magic');
8
+
9
+ exports.logger = logger;
@@ -0,0 +1,2 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+ export declare const logger: Logger;
@@ -0,0 +1,5 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+
3
+ const logger = new Logger('magic');
4
+
5
+ export { logger };