@gluwa/connect-kit 0.1.0-next.2 → 0.2.0-next.1
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 +12 -0
- package/dist/chunk-DDA6FP6U.js +7 -0
- package/dist/credit-connect.d.ts +16 -0
- package/dist/credit-connect.js +414 -0
- package/dist/index.css +561 -0
- package/dist/index.d.ts +37 -26
- package/dist/index.js +336 -1068
- package/dist/package.json +23 -6
- package/package.json +17 -5
- package/src/ConnectKitProvider.tsx +81 -26
- package/src/ConnectModal.scss +2 -2
- package/src/ConnectModal.tsx +48 -43
- package/src/api/account.ts +21 -0
- package/src/api/balance.ts +10 -0
- package/src/api/chain.ts +17 -0
- package/src/api/contract.ts +33 -0
- package/src/api/transaction.ts +12 -0
- package/src/components/QRFrame.tsx +2 -2
- package/src/core/config.ts +83 -0
- package/src/credit-connect.ts +2 -0
- package/src/creditConnectConnector.ts +176 -159
- package/src/events/account.ts +49 -0
- package/src/hooks/useWCState.ts +24 -9
- package/src/hooks/useWagmiConnect.ts +13 -8
- package/src/index.ts +33 -2
- package/src/types.ts +9 -0
- package/src/utils/platform.ts +1 -4
- package/src/views/CreditWalletView.tsx +4 -2
- package/src/views/MetaMaskView.tsx +4 -2
- package/src/views/SwitchChainView.tsx +9 -4
- package/tsup.config.ts +6 -2
package/dist/index.js
CHANGED
|
@@ -1,625 +1,158 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
inset: 0;
|
|
21
|
-
background: rgba(0, 0, 0, 0.6);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.ck-modal {
|
|
25
|
-
position: relative;
|
|
26
|
-
display: flex;
|
|
27
|
-
width: 1120px;
|
|
28
|
-
height: 620px;
|
|
29
|
-
border-radius: 16px;
|
|
30
|
-
overflow: hidden;
|
|
31
|
-
background: #1a1a1a;
|
|
32
|
-
color: #fff;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.ck-pane {
|
|
36
|
-
display: flex;
|
|
37
|
-
flex-direction: column;
|
|
38
|
-
padding: 24px;
|
|
39
|
-
width: 560px;
|
|
40
|
-
flex-shrink: 0;
|
|
41
|
-
box-sizing: border-box;
|
|
42
|
-
}
|
|
43
|
-
.ck-pane--selector {
|
|
44
|
-
border-right: 1px solid rgba(255, 255, 255, 0.08);
|
|
45
|
-
}
|
|
46
|
-
.ck-pane--detail {
|
|
47
|
-
padding-inline: 20px;
|
|
48
|
-
overflow: hidden;
|
|
49
|
-
min-height: 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.ck-pane__header {
|
|
53
|
-
display: flex;
|
|
54
|
-
align-items: center;
|
|
55
|
-
gap: 8px;
|
|
56
|
-
margin-bottom: 20px;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.ck-pane__title {
|
|
60
|
-
flex: 1;
|
|
61
|
-
font-size: 16px;
|
|
62
|
-
font-weight: 600;
|
|
63
|
-
margin: 0;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.ck-pane__body {
|
|
67
|
-
flex: 1;
|
|
68
|
-
display: flex;
|
|
69
|
-
flex-direction: column;
|
|
70
|
-
min-height: 0;
|
|
71
|
-
overflow: hidden;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
.ck-pane__footer {
|
|
75
|
-
margin-top: auto;
|
|
76
|
-
padding-top: 16px;
|
|
77
|
-
text-align: center;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.ck-btn-close,
|
|
81
|
-
.ck-btn-back {
|
|
82
|
-
position: relative;
|
|
83
|
-
width: 28px;
|
|
84
|
-
height: 28px;
|
|
85
|
-
background: none;
|
|
86
|
-
border: none;
|
|
87
|
-
cursor: pointer;
|
|
88
|
-
padding: 0;
|
|
89
|
-
border-radius: 50%;
|
|
90
|
-
flex-shrink: 0;
|
|
91
|
-
display: flex;
|
|
92
|
-
align-items: center;
|
|
93
|
-
justify-content: center;
|
|
94
|
-
}
|
|
95
|
-
.ck-btn-close:hover,
|
|
96
|
-
.ck-btn-back:hover {
|
|
97
|
-
background: rgba(255, 255, 255, 0.08);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
.ck-btn-close::before, .ck-btn-close::after {
|
|
101
|
-
content: "";
|
|
102
|
-
position: absolute;
|
|
103
|
-
width: 14px;
|
|
104
|
-
height: 2px;
|
|
105
|
-
background: rgba(255, 255, 255, 0.7);
|
|
106
|
-
border-radius: 1px;
|
|
107
|
-
}
|
|
108
|
-
.ck-btn-close::before {
|
|
109
|
-
transform: rotate(45deg);
|
|
110
|
-
}
|
|
111
|
-
.ck-btn-close::after {
|
|
112
|
-
transform: rotate(-45deg);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.ck-btn-back::before {
|
|
116
|
-
content: "";
|
|
117
|
-
position: absolute;
|
|
118
|
-
width: 8px;
|
|
119
|
-
height: 8px;
|
|
120
|
-
border-left: 2px solid rgba(255, 255, 255, 0.7);
|
|
121
|
-
border-bottom: 2px solid rgba(255, 255, 255, 0.7);
|
|
122
|
-
transform: rotate(45deg) translate(1px, -1px);
|
|
123
|
-
border-radius: 1px;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.ck-btn-primary {
|
|
127
|
-
display: inline-flex;
|
|
128
|
-
align-items: center;
|
|
129
|
-
justify-content: center;
|
|
130
|
-
padding: 8px 16px;
|
|
131
|
-
border-radius: 8px;
|
|
132
|
-
font-size: 14px;
|
|
133
|
-
font-weight: 600;
|
|
134
|
-
text-decoration: none;
|
|
135
|
-
cursor: pointer;
|
|
136
|
-
white-space: nowrap;
|
|
137
|
-
color: #fff;
|
|
138
|
-
background: rgba(255, 255, 255, 0.15);
|
|
139
|
-
border: none;
|
|
140
|
-
}
|
|
141
|
-
.ck-btn-primary:hover {
|
|
142
|
-
background: rgba(255, 255, 255, 0.22);
|
|
143
|
-
}
|
|
144
|
-
.ck-btn-primary:disabled {
|
|
145
|
-
opacity: 0.6;
|
|
146
|
-
cursor: not-allowed;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
.ck-btn-secondary {
|
|
150
|
-
display: inline-flex;
|
|
151
|
-
align-items: center;
|
|
152
|
-
justify-content: center;
|
|
153
|
-
padding: 8px 16px;
|
|
154
|
-
border-radius: 8px;
|
|
155
|
-
font-size: 14px;
|
|
156
|
-
font-weight: 500;
|
|
157
|
-
cursor: pointer;
|
|
158
|
-
white-space: nowrap;
|
|
159
|
-
color: rgba(255, 255, 255, 0.75);
|
|
160
|
-
background: transparent;
|
|
161
|
-
border: 1px solid rgba(255, 255, 255, 0.18);
|
|
162
|
-
}
|
|
163
|
-
.ck-btn-secondary:hover {
|
|
164
|
-
color: #fff;
|
|
165
|
-
border-color: rgba(255, 255, 255, 0.32);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
.ck-view__actions {
|
|
169
|
-
display: flex;
|
|
170
|
-
flex-direction: column;
|
|
171
|
-
gap: 8px;
|
|
172
|
-
width: 100%;
|
|
173
|
-
margin-top: 16px;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.ck-view__caption--error {
|
|
177
|
-
color: #ff8080;
|
|
178
|
-
margin-top: 8px;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
.ck-connector-list {
|
|
182
|
-
display: flex;
|
|
183
|
-
flex-direction: column;
|
|
184
|
-
gap: 8px;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
.ck-connector-item {
|
|
188
|
-
display: flex;
|
|
189
|
-
align-items: center;
|
|
190
|
-
gap: 12px;
|
|
191
|
-
width: 100%;
|
|
192
|
-
padding: 12px 16px;
|
|
193
|
-
border: none;
|
|
194
|
-
border-radius: 12px;
|
|
195
|
-
cursor: pointer;
|
|
196
|
-
text-align: left;
|
|
197
|
-
color: #fff;
|
|
198
|
-
background: rgba(255, 255, 255, 0.05);
|
|
199
|
-
transition: background 0.15s;
|
|
200
|
-
}
|
|
201
|
-
.ck-connector-item:hover:not(:disabled) {
|
|
202
|
-
background: rgba(255, 255, 255, 0.08);
|
|
203
|
-
}
|
|
204
|
-
.ck-connector-item.is-active {
|
|
205
|
-
background: #3b82f6;
|
|
206
|
-
}
|
|
207
|
-
.ck-connector-item:disabled {
|
|
208
|
-
opacity: 0.5;
|
|
209
|
-
cursor: not-allowed;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
.ck-connector-item__icon {
|
|
213
|
-
width: 32px;
|
|
214
|
-
height: 32px;
|
|
215
|
-
border-radius: 8px;
|
|
216
|
-
flex-shrink: 0;
|
|
217
|
-
background: rgba(255, 255, 255, 0.1);
|
|
218
|
-
display: block;
|
|
219
|
-
object-fit: cover;
|
|
220
|
-
}
|
|
221
|
-
.ck-connector-item__icon[src] {
|
|
222
|
-
background: none;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
.ck-connector-item__label {
|
|
226
|
-
flex: 1;
|
|
227
|
-
font-size: 14px;
|
|
228
|
-
font-weight: 500;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
.ck-connector-item__badge {
|
|
232
|
-
font-size: 11px;
|
|
233
|
-
font-weight: 600;
|
|
234
|
-
padding: 2px 6px;
|
|
235
|
-
border-radius: 4px;
|
|
236
|
-
background: rgba(255, 255, 255, 0.15);
|
|
237
|
-
color: rgba(255, 255, 255, 0.8);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
.ck-divider {
|
|
241
|
-
display: flex;
|
|
242
|
-
align-items: center;
|
|
243
|
-
gap: 8px;
|
|
244
|
-
color: rgba(255, 255, 255, 0.3);
|
|
245
|
-
font-size: 12px;
|
|
246
|
-
margin: 4px 0;
|
|
247
|
-
}
|
|
248
|
-
.ck-divider::before, .ck-divider::after {
|
|
249
|
-
content: "";
|
|
250
|
-
flex: 1;
|
|
251
|
-
height: 1px;
|
|
252
|
-
background: rgba(255, 255, 255, 0.1);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
.ck-link-no-wallet {
|
|
256
|
-
font-size: 13px;
|
|
257
|
-
text-decoration: none;
|
|
258
|
-
color: rgba(255, 255, 255, 0.5);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
.ck-view {
|
|
262
|
-
display: flex;
|
|
263
|
-
flex-direction: column;
|
|
264
|
-
align-items: center;
|
|
265
|
-
flex: 1;
|
|
266
|
-
}
|
|
267
|
-
.ck-view--idle {
|
|
268
|
-
justify-content: center;
|
|
269
|
-
text-align: center;
|
|
270
|
-
gap: 12px;
|
|
271
|
-
}
|
|
272
|
-
.ck-view--qr {
|
|
273
|
-
gap: 16px;
|
|
274
|
-
}
|
|
275
|
-
.ck-view--extension {
|
|
276
|
-
justify-content: center;
|
|
277
|
-
align-items: center;
|
|
278
|
-
gap: 12px;
|
|
279
|
-
text-align: center;
|
|
280
|
-
}
|
|
281
|
-
.ck-view--wallet-list {
|
|
282
|
-
align-items: stretch;
|
|
283
|
-
gap: 12px;
|
|
284
|
-
height: 100%;
|
|
285
|
-
overflow: hidden;
|
|
286
|
-
width: 100%;
|
|
287
|
-
box-sizing: border-box;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
.ck-view__illustration {
|
|
291
|
-
width: 180px;
|
|
292
|
-
height: auto;
|
|
293
|
-
display: block;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.ck-view__wallet-icon {
|
|
297
|
-
width: 64px;
|
|
298
|
-
height: 64px;
|
|
299
|
-
border-radius: 16px;
|
|
300
|
-
background: rgba(255, 255, 255, 0.1);
|
|
301
|
-
}
|
|
302
|
-
.ck-view__title {
|
|
303
|
-
font-size: 18px;
|
|
304
|
-
font-weight: 600;
|
|
305
|
-
margin: 0;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
.ck-view__description,
|
|
309
|
-
.ck-view__caption {
|
|
310
|
-
font-size: 13px;
|
|
311
|
-
opacity: 0.6;
|
|
312
|
-
margin: 0;
|
|
313
|
-
text-align: center;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
.ck-qr-frame {
|
|
317
|
-
width: 216px;
|
|
318
|
-
height: 216px;
|
|
319
|
-
border-radius: 16px;
|
|
320
|
-
display: flex;
|
|
321
|
-
align-items: center;
|
|
322
|
-
justify-content: center;
|
|
323
|
-
background: #fff;
|
|
324
|
-
overflow: hidden;
|
|
325
|
-
flex-shrink: 0;
|
|
326
|
-
}
|
|
327
|
-
.ck-qr-frame--loading {
|
|
328
|
-
background: rgba(255, 255, 255, 0.05);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
.ck-qr-spinner,
|
|
332
|
-
.ck-spinner {
|
|
333
|
-
width: 32px;
|
|
334
|
-
height: 32px;
|
|
335
|
-
border: 3px solid rgba(255, 255, 255, 0.15);
|
|
336
|
-
border-top-color: rgba(255, 255, 255, 0.6);
|
|
337
|
-
border-radius: 50%;
|
|
338
|
-
animation: ck-spin 0.8s linear infinite;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
@keyframes ck-spin {
|
|
342
|
-
to {
|
|
343
|
-
transform: rotate(360deg);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
.ck-copy-link {
|
|
347
|
-
background: none;
|
|
348
|
-
border: none;
|
|
349
|
-
cursor: pointer;
|
|
350
|
-
font-size: 13px;
|
|
351
|
-
color: #fff;
|
|
352
|
-
opacity: 0.5;
|
|
353
|
-
display: flex;
|
|
354
|
-
align-items: center;
|
|
355
|
-
gap: 4px;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
.ck-download-card {
|
|
359
|
-
display: flex;
|
|
360
|
-
align-items: center;
|
|
361
|
-
justify-content: space-between;
|
|
362
|
-
width: 100%;
|
|
363
|
-
padding: 14px 16px;
|
|
364
|
-
border-radius: 12px;
|
|
365
|
-
background: rgba(255, 255, 255, 0.05);
|
|
366
|
-
margin-top: auto;
|
|
367
|
-
gap: 12px;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
.ck-download-card__text {
|
|
371
|
-
display: flex;
|
|
372
|
-
flex-direction: column;
|
|
373
|
-
gap: 2px;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
.ck-download-card__title {
|
|
377
|
-
font-size: 14px;
|
|
378
|
-
font-weight: 500;
|
|
379
|
-
margin: 0;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
.ck-download-card__sub {
|
|
383
|
-
font-size: 12px;
|
|
384
|
-
opacity: 0.5;
|
|
385
|
-
margin: 0;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
.ck-all-wallets-btn {
|
|
389
|
-
display: flex;
|
|
390
|
-
align-items: center;
|
|
391
|
-
gap: 12px;
|
|
392
|
-
width: 100%;
|
|
393
|
-
padding: 14px 16px;
|
|
394
|
-
border: none;
|
|
395
|
-
border-radius: 12px;
|
|
396
|
-
background: rgba(255, 255, 255, 0.05);
|
|
397
|
-
color: #fff;
|
|
398
|
-
cursor: pointer;
|
|
399
|
-
margin-top: auto;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
.ck-all-wallets-btn__icon {
|
|
403
|
-
width: 32px;
|
|
404
|
-
height: 32px;
|
|
405
|
-
border-radius: 8px;
|
|
406
|
-
background: rgba(255, 255, 255, 0.1);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
.ck-all-wallets-btn__label {
|
|
410
|
-
flex: 1;
|
|
411
|
-
font-size: 14px;
|
|
412
|
-
font-weight: 500;
|
|
413
|
-
text-align: left;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
.ck-all-wallets-btn__count {
|
|
417
|
-
font-size: 12px;
|
|
418
|
-
opacity: 0.5;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
.ck-wallet-search {
|
|
422
|
-
display: flex;
|
|
423
|
-
align-items: center;
|
|
424
|
-
gap: 8px;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
.ck-wallet-search__input {
|
|
428
|
-
flex: 1;
|
|
429
|
-
padding: 10px 14px;
|
|
430
|
-
border-radius: 10px;
|
|
431
|
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
432
|
-
background: rgba(255, 255, 255, 0.05);
|
|
433
|
-
font-size: 14px;
|
|
434
|
-
outline: none;
|
|
435
|
-
color: #fff;
|
|
436
|
-
}
|
|
437
|
-
.ck-wallet-search__input::placeholder {
|
|
438
|
-
color: rgba(255, 255, 255, 0.35);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
.ck-wc-filter {
|
|
442
|
-
display: flex;
|
|
443
|
-
align-items: center;
|
|
444
|
-
gap: 6px;
|
|
445
|
-
flex-shrink: 0;
|
|
446
|
-
border: none;
|
|
447
|
-
background: none;
|
|
448
|
-
cursor: pointer;
|
|
449
|
-
padding: 0;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
.ck-wc-filter__icon {
|
|
453
|
-
width: 20px;
|
|
454
|
-
height: 20px;
|
|
455
|
-
border-radius: 4px;
|
|
456
|
-
display: block;
|
|
457
|
-
opacity: 0.5;
|
|
458
|
-
}
|
|
459
|
-
.ck-wc-filter.is-active .ck-wc-filter__icon {
|
|
460
|
-
opacity: 1;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
.ck-wc-filter__track {
|
|
464
|
-
position: relative;
|
|
465
|
-
width: 36px;
|
|
466
|
-
height: 20px;
|
|
467
|
-
border-radius: 10px;
|
|
468
|
-
background: rgba(255, 255, 255, 0.15);
|
|
469
|
-
transition: background 0.2s;
|
|
470
|
-
}
|
|
471
|
-
.ck-wc-filter.is-active .ck-wc-filter__track {
|
|
472
|
-
background: #3b82f6;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
.ck-wc-filter__thumb {
|
|
476
|
-
position: absolute;
|
|
477
|
-
top: 2px;
|
|
478
|
-
left: 2px;
|
|
479
|
-
width: 16px;
|
|
480
|
-
height: 16px;
|
|
481
|
-
border-radius: 50%;
|
|
482
|
-
background: #fff;
|
|
483
|
-
transition: transform 0.2s;
|
|
484
|
-
}
|
|
485
|
-
.ck-wc-filter.is-active .ck-wc-filter__thumb {
|
|
486
|
-
transform: translateX(16px);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
.ck-wallet-grid-scroll {
|
|
490
|
-
flex: 1;
|
|
491
|
-
min-height: 0;
|
|
492
|
-
width: 520px;
|
|
493
|
-
overflow-x: hidden;
|
|
494
|
-
overflow-y: auto;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
.ck-wallet-grid {
|
|
498
|
-
display: grid;
|
|
499
|
-
grid-template-columns: repeat(4, minmax(0, 1fr));
|
|
500
|
-
grid-auto-rows: max-content;
|
|
501
|
-
gap: 8px;
|
|
502
|
-
list-style: none;
|
|
503
|
-
margin: 0;
|
|
504
|
-
padding: 0;
|
|
505
|
-
width: 100%;
|
|
506
|
-
box-sizing: border-box;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
.ck-wallet-grid__item {
|
|
510
|
-
display: flex;
|
|
511
|
-
flex-direction: column;
|
|
512
|
-
align-items: center;
|
|
513
|
-
gap: 6px;
|
|
514
|
-
padding: 10px 4px;
|
|
515
|
-
width: 100%;
|
|
516
|
-
background: none;
|
|
517
|
-
border: none;
|
|
518
|
-
border-radius: 10px;
|
|
519
|
-
cursor: pointer;
|
|
520
|
-
color: #fff;
|
|
521
|
-
box-sizing: border-box;
|
|
522
|
-
}
|
|
523
|
-
.ck-wallet-grid__item:hover {
|
|
524
|
-
background: rgba(255, 255, 255, 0.05);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
.ck-wallet-grid__icon {
|
|
528
|
-
width: 48px;
|
|
529
|
-
height: 48px;
|
|
530
|
-
border-radius: 12px;
|
|
531
|
-
flex-shrink: 0;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
.ck-wallet-grid__icon-placeholder {
|
|
535
|
-
width: 48px;
|
|
536
|
-
height: 48px;
|
|
537
|
-
border-radius: 12px;
|
|
538
|
-
flex-shrink: 0;
|
|
539
|
-
background: rgba(255, 255, 255, 0.1);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
.ck-wallet-grid__name {
|
|
543
|
-
display: flex;
|
|
544
|
-
align-items: center;
|
|
545
|
-
justify-content: center;
|
|
546
|
-
gap: 3px;
|
|
547
|
-
width: 100%;
|
|
548
|
-
min-width: 0;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
.ck-wallet-grid__name-text {
|
|
552
|
-
flex: 1;
|
|
553
|
-
min-width: 0;
|
|
554
|
-
font-size: 11px;
|
|
555
|
-
overflow: hidden;
|
|
556
|
-
text-overflow: ellipsis;
|
|
557
|
-
white-space: nowrap;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
.ck-wallet-grid__wc-badge {
|
|
561
|
-
width: 10px;
|
|
562
|
-
height: 10px;
|
|
563
|
-
border-radius: 2px;
|
|
564
|
-
flex-shrink: 0;
|
|
565
|
-
opacity: 0.7;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
.ck-wallet-list-loading,
|
|
569
|
-
.ck-wallet-list-empty {
|
|
570
|
-
display: flex;
|
|
571
|
-
align-items: center;
|
|
572
|
-
justify-content: center;
|
|
573
|
-
padding: 32px;
|
|
574
|
-
opacity: 0.4;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
.ck-mobile-only {
|
|
578
|
-
display: none;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
@media (max-width: 1120px) {
|
|
582
|
-
.ck-root {
|
|
583
|
-
align-items: flex-end;
|
|
584
|
-
}
|
|
585
|
-
.ck-modal {
|
|
586
|
-
flex-direction: column;
|
|
587
|
-
width: 100%;
|
|
588
|
-
height: auto;
|
|
589
|
-
max-height: 90dvh;
|
|
590
|
-
border-radius: 20px 20px 0 0;
|
|
591
|
-
animation: ck-slide-up 0.28s cubic-bezier(0.32, 0.72, 0, 1);
|
|
592
|
-
overflow-y: auto;
|
|
2
|
+
import {
|
|
3
|
+
__name
|
|
4
|
+
} from "./chunk-DDA6FP6U.js";
|
|
5
|
+
|
|
6
|
+
// src/api/contract.ts
|
|
7
|
+
import { readContract as wagmiReadContract, writeContract as wagmiWriteContract } from "@wagmi/core";
|
|
8
|
+
|
|
9
|
+
// src/core/config.ts
|
|
10
|
+
import { createConfig, createStorage } from "wagmi";
|
|
11
|
+
import { metaMask, walletConnect, injected } from "wagmi/connectors";
|
|
12
|
+
var SLOT_KEY = Symbol.for("@gluwa/connect-kit:slot");
|
|
13
|
+
var getSlot = /* @__PURE__ */ __name(() => {
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
if (!g[SLOT_KEY]) {
|
|
16
|
+
g[SLOT_KEY] = {
|
|
17
|
+
config: null,
|
|
18
|
+
kitConfig: null
|
|
19
|
+
};
|
|
593
20
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
21
|
+
return g[SLOT_KEY];
|
|
22
|
+
}, "getSlot");
|
|
23
|
+
var initConfig = /* @__PURE__ */ __name((kitConfig) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const slot = getSlot();
|
|
26
|
+
if (slot.config) {
|
|
27
|
+
if (slot.kitConfig !== kitConfig) {
|
|
28
|
+
console.warn("[connect-kit] initConfig called again with a different kitConfig \u2014 new chains/transports ignored. Call resetConfig() first to re-init.");
|
|
600
29
|
}
|
|
30
|
+
return slot.config;
|
|
601
31
|
}
|
|
602
|
-
|
|
603
|
-
|
|
32
|
+
const connectors = [];
|
|
33
|
+
if (kitConfig.wcProjectId) {
|
|
34
|
+
connectors.push(walletConnect({
|
|
35
|
+
projectId: kitConfig.wcProjectId,
|
|
36
|
+
showQrModal: false
|
|
37
|
+
}));
|
|
604
38
|
}
|
|
605
|
-
.
|
|
606
|
-
|
|
39
|
+
connectors.push(metaMask({
|
|
40
|
+
storage: {
|
|
41
|
+
enabled: true
|
|
42
|
+
}
|
|
43
|
+
}), injected({
|
|
44
|
+
shimDisconnect: false
|
|
45
|
+
}));
|
|
46
|
+
if ((_a = kitConfig.extraConnectors) == null ? void 0 : _a.length) {
|
|
47
|
+
connectors.push(...kitConfig.extraConnectors);
|
|
607
48
|
}
|
|
608
|
-
|
|
609
|
-
.
|
|
610
|
-
|
|
611
|
-
|
|
49
|
+
const isBrowser = typeof window !== "undefined";
|
|
50
|
+
slot.config = createConfig({
|
|
51
|
+
ssr: true,
|
|
52
|
+
chains: kitConfig.chains,
|
|
53
|
+
connectors,
|
|
54
|
+
transports: kitConfig.transports,
|
|
55
|
+
storage: isBrowser ? createStorage({
|
|
56
|
+
storage: window.localStorage
|
|
57
|
+
}) : void 0
|
|
58
|
+
});
|
|
59
|
+
slot.kitConfig = kitConfig;
|
|
60
|
+
return slot.config;
|
|
61
|
+
}, "initConfig");
|
|
62
|
+
var getConfig = /* @__PURE__ */ __name(() => {
|
|
63
|
+
const slot = getSlot();
|
|
64
|
+
if (!slot.config) {
|
|
65
|
+
throw new Error("ConnectKit config not initialized. Make sure ConnectKitProvider is mounted.");
|
|
612
66
|
}
|
|
613
|
-
.
|
|
614
|
-
|
|
67
|
+
return slot.config;
|
|
68
|
+
}, "getConfig");
|
|
69
|
+
var getKitConfig = /* @__PURE__ */ __name(() => {
|
|
70
|
+
const slot = getSlot();
|
|
71
|
+
if (!slot.kitConfig) {
|
|
72
|
+
throw new Error("ConnectKit config not initialized. Make sure ConnectKitProvider is mounted.");
|
|
615
73
|
}
|
|
616
|
-
.
|
|
617
|
-
|
|
74
|
+
return slot.kitConfig;
|
|
75
|
+
}, "getKitConfig");
|
|
76
|
+
|
|
77
|
+
// src/api/contract.ts
|
|
78
|
+
function readContract(parameters) {
|
|
79
|
+
return wagmiReadContract(getConfig(), parameters);
|
|
80
|
+
}
|
|
81
|
+
__name(readContract, "readContract");
|
|
82
|
+
function writeContract(parameters) {
|
|
83
|
+
return wagmiWriteContract(getConfig(), parameters);
|
|
84
|
+
}
|
|
85
|
+
__name(writeContract, "writeContract");
|
|
86
|
+
|
|
87
|
+
// src/api/balance.ts
|
|
88
|
+
import { getBalance as wagmiGetBalance } from "@wagmi/core";
|
|
89
|
+
var getBalance = /* @__PURE__ */ __name((params) => {
|
|
90
|
+
return wagmiGetBalance(getConfig(), params);
|
|
91
|
+
}, "getBalance");
|
|
92
|
+
|
|
93
|
+
// src/api/chain.ts
|
|
94
|
+
import { switchChain as wagmiSwitchChain, getPublicClient as wagmiGetPublicClient } from "@wagmi/core";
|
|
95
|
+
var switchChain = /* @__PURE__ */ __name((params) => {
|
|
96
|
+
return wagmiSwitchChain(getConfig(), params);
|
|
97
|
+
}, "switchChain");
|
|
98
|
+
var getPublicClient = /* @__PURE__ */ __name((params) => {
|
|
99
|
+
return wagmiGetPublicClient(getConfig(), params);
|
|
100
|
+
}, "getPublicClient");
|
|
101
|
+
|
|
102
|
+
// src/api/transaction.ts
|
|
103
|
+
import { waitForTransactionReceipt as wagmiWaitForTransactionReceipt } from "@wagmi/core";
|
|
104
|
+
var waitForTransactionReceipt = /* @__PURE__ */ __name((params) => {
|
|
105
|
+
return wagmiWaitForTransactionReceipt(getConfig(), params);
|
|
106
|
+
}, "waitForTransactionReceipt");
|
|
107
|
+
|
|
108
|
+
// src/api/account.ts
|
|
109
|
+
import { getAccount as wagmiGetAccount, signMessage as wagmiSignMessage, signTypedData as wagmiSignTypedData } from "@wagmi/core";
|
|
110
|
+
var getAccount = /* @__PURE__ */ __name(() => {
|
|
111
|
+
return wagmiGetAccount(getConfig());
|
|
112
|
+
}, "getAccount");
|
|
113
|
+
var signMessage = /* @__PURE__ */ __name((params) => {
|
|
114
|
+
return wagmiSignMessage(getConfig(), params);
|
|
115
|
+
}, "signMessage");
|
|
116
|
+
var signTypedData = /* @__PURE__ */ __name((params) => {
|
|
117
|
+
return wagmiSignTypedData(getConfig(), params);
|
|
118
|
+
}, "signTypedData");
|
|
119
|
+
|
|
120
|
+
// src/events/account.ts
|
|
121
|
+
import { watchAccount as wagmiWatchAccount, watchConnections as wagmiWatchConnections, reconnect as wagmiReconnect, disconnect as wagmiDisconnect } from "@wagmi/core";
|
|
122
|
+
var watchAccount = /* @__PURE__ */ __name((params) => {
|
|
123
|
+
return wagmiWatchAccount(getConfig(), params);
|
|
124
|
+
}, "watchAccount");
|
|
125
|
+
var watchConnections = /* @__PURE__ */ __name((params) => {
|
|
126
|
+
return wagmiWatchConnections(getConfig(), params);
|
|
127
|
+
}, "watchConnections");
|
|
128
|
+
var reconnect = /* @__PURE__ */ __name(() => {
|
|
129
|
+
return wagmiReconnect(getConfig());
|
|
130
|
+
}, "reconnect");
|
|
131
|
+
var disconnectAll = /* @__PURE__ */ __name(async (onLog) => {
|
|
132
|
+
const config = getConfig();
|
|
133
|
+
const results = await Promise.allSettled(config.connectors.map((connector) => wagmiDisconnect(config, {
|
|
134
|
+
connector
|
|
135
|
+
}).then(() => connector.id)));
|
|
136
|
+
const errors = [];
|
|
137
|
+
results.forEach((result, idx) => {
|
|
138
|
+
if (result.status === "rejected") {
|
|
139
|
+
const error = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
|
|
140
|
+
const connectorId = config.connectors[idx].id;
|
|
141
|
+
errors.push({
|
|
142
|
+
connectorId,
|
|
143
|
+
error
|
|
144
|
+
});
|
|
145
|
+
onLog == null ? void 0 : onLog(`[connect-kit] disconnect failed for "${connectorId}": ${error.message}`, error);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (errors.length === config.connectors.length && errors.length > 0) {
|
|
149
|
+
const messages = errors.map((e) => `${e.connectorId}: ${e.error.message}`).join("; ");
|
|
150
|
+
throw new Error(`All disconnects failed \u2014 ${messages}`);
|
|
618
151
|
}
|
|
619
|
-
}
|
|
620
|
-
document.head.appendChild(document.createElement("style")).appendChild(document.createTextNode(css));
|
|
152
|
+
}, "disconnectAll");
|
|
621
153
|
|
|
622
154
|
// src/ConnectModal.tsx
|
|
155
|
+
import { useState as useState3, useEffect as useEffect6, useCallback as useCallback3, useMemo as useMemo4 } from "react";
|
|
623
156
|
import { useAccount, useConfig as useConfig2, useDisconnect } from "wagmi";
|
|
624
157
|
|
|
625
158
|
// assets/creditwallet.png
|
|
@@ -667,7 +200,7 @@ var isMobileDevice = /* @__PURE__ */ __name(() => {
|
|
|
667
200
|
}, "isMobileDevice");
|
|
668
201
|
var tryOpenDeepLink = /* @__PURE__ */ __name((uri, deepLinkBase2) => {
|
|
669
202
|
const sep = deepLinkBase2.endsWith("/") ? "" : "/";
|
|
670
|
-
window.location.
|
|
203
|
+
window.location.replace(`${deepLinkBase2}${sep}wc?uri=${encodeURIComponent(uri)}`);
|
|
671
204
|
}, "tryOpenDeepLink");
|
|
672
205
|
var detectMetaMaskExtension = /* @__PURE__ */ __name(() => {
|
|
673
206
|
var _a;
|
|
@@ -680,7 +213,12 @@ import { useConnect, useConfig } from "wagmi";
|
|
|
680
213
|
var hasMetaMaskKeyword = /* @__PURE__ */ __name((value) => value.toLowerCase().includes("metamask"), "hasMetaMaskKeyword");
|
|
681
214
|
var hasWalletConnectKeyword = /* @__PURE__ */ __name((value) => value.toLowerCase().includes("walletconnect"), "hasWalletConnectKeyword");
|
|
682
215
|
var isMetaMaskConnector = /* @__PURE__ */ __name((connector) => {
|
|
683
|
-
if (connector.id === "
|
|
216
|
+
if (connector.id === "metaMaskSDK") return true;
|
|
217
|
+
if (connector.id === "injected") {
|
|
218
|
+
if (typeof window === "undefined") return false;
|
|
219
|
+
const eth = window.ethereum;
|
|
220
|
+
return (eth == null ? void 0 : eth.isMetaMask) === true;
|
|
221
|
+
}
|
|
684
222
|
if (hasMetaMaskKeyword(connector.id) || hasMetaMaskKeyword(connector.name)) return true;
|
|
685
223
|
if (connector.rdns) {
|
|
686
224
|
const rdnsList = Array.isArray(connector.rdns) ? connector.rdns : [
|
|
@@ -711,6 +249,7 @@ var resolveWagmiConnector = /* @__PURE__ */ __name((connectors, connectorId) =>
|
|
|
711
249
|
var useWagmiConnect = /* @__PURE__ */ __name(({ onConnect, onError, onQrUri }) => {
|
|
712
250
|
const config = useConfig();
|
|
713
251
|
const pendingConnectorId = useRef(null);
|
|
252
|
+
const attemptCounter = useRef(0);
|
|
714
253
|
const onConnectRef = useRef(onConnect);
|
|
715
254
|
const onErrorRef = useRef(onError);
|
|
716
255
|
const onQrUriRef = useRef(onQrUri);
|
|
@@ -752,12 +291,13 @@ var useWagmiConnect = /* @__PURE__ */ __name(({ onConnect, onError, onQrUri }) =
|
|
|
752
291
|
return;
|
|
753
292
|
}
|
|
754
293
|
onQrUriRef.current(null);
|
|
294
|
+
const attemptId = ++attemptCounter.current;
|
|
755
295
|
pendingConnectorId.current = connectorId;
|
|
756
296
|
connectAsync({
|
|
757
297
|
connector
|
|
758
298
|
}).then((result) => {
|
|
759
299
|
var _a;
|
|
760
|
-
if (
|
|
300
|
+
if (attemptCounter.current !== attemptId) return;
|
|
761
301
|
const address = (_a = result.accounts) == null ? void 0 : _a[0];
|
|
762
302
|
if (!address) {
|
|
763
303
|
throw new Error("Connected but no account returned");
|
|
@@ -768,7 +308,7 @@ var useWagmiConnect = /* @__PURE__ */ __name(({ onConnect, onError, onQrUri }) =
|
|
|
768
308
|
connectorId
|
|
769
309
|
});
|
|
770
310
|
}).catch((error) => {
|
|
771
|
-
if (
|
|
311
|
+
if (attemptCounter.current !== attemptId) return;
|
|
772
312
|
pendingConnectorId.current = null;
|
|
773
313
|
onErrorRef.current(error, connectorId);
|
|
774
314
|
});
|
|
@@ -777,6 +317,7 @@ var useWagmiConnect = /* @__PURE__ */ __name(({ onConnect, onError, onQrUri }) =
|
|
|
777
317
|
connectAsync
|
|
778
318
|
]);
|
|
779
319
|
const cancelConnect = useCallback(() => {
|
|
320
|
+
attemptCounter.current += 1;
|
|
780
321
|
pendingConnectorId.current = null;
|
|
781
322
|
onQrUriRef.current(null);
|
|
782
323
|
reset();
|
|
@@ -791,18 +332,21 @@ var useWagmiConnect = /* @__PURE__ */ __name(({ onConnect, onError, onQrUri }) =
|
|
|
791
332
|
}, "useWagmiConnect");
|
|
792
333
|
|
|
793
334
|
// src/hooks/useWCState.ts
|
|
794
|
-
import { useState, useRef as useRef2, useCallback as useCallback2 } from "react";
|
|
795
|
-
var fetchWCWalletList = /* @__PURE__ */ __name(async (projectId) => {
|
|
335
|
+
import { useState, useRef as useRef2, useCallback as useCallback2, useEffect as useEffect2 } from "react";
|
|
336
|
+
var fetchWCWalletList = /* @__PURE__ */ __name(async (projectId, signal) => {
|
|
796
337
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
797
338
|
const all = [];
|
|
798
339
|
let page = 1;
|
|
799
340
|
const entries = 100;
|
|
800
341
|
while (page <= 10) {
|
|
342
|
+
if (signal == null ? void 0 : signal.aborted) throw new DOMException("Aborted", "AbortError");
|
|
801
343
|
const url = new URL("https://explorer-api.walletconnect.com/v3/wallets");
|
|
802
344
|
url.searchParams.set("projectId", projectId);
|
|
803
345
|
url.searchParams.set("entries", String(entries));
|
|
804
346
|
url.searchParams.set("page", String(page));
|
|
805
|
-
const res = await fetch(url.toString()
|
|
347
|
+
const res = await fetch(url.toString(), {
|
|
348
|
+
signal
|
|
349
|
+
});
|
|
806
350
|
if (!res.ok) throw new Error(`Failed to fetch wallet list: ${res.status}`);
|
|
807
351
|
const json = await res.json();
|
|
808
352
|
const listings = Object.values((_a = json.listings) != null ? _a : {});
|
|
@@ -833,17 +377,32 @@ var useWCState = /* @__PURE__ */ __name(() => {
|
|
|
833
377
|
const [filterActive, setFilterActive] = useState(false);
|
|
834
378
|
const [selectedWallet, setSelectedWallet] = useState(null);
|
|
835
379
|
const loadedRef = useRef2(false);
|
|
380
|
+
const abortControllerRef = useRef2(null);
|
|
381
|
+
const isMountedRef = useRef2(true);
|
|
382
|
+
useEffect2(() => {
|
|
383
|
+
isMountedRef.current = true;
|
|
384
|
+
return () => {
|
|
385
|
+
var _a;
|
|
386
|
+
isMountedRef.current = false;
|
|
387
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
388
|
+
abortControllerRef.current = null;
|
|
389
|
+
};
|
|
390
|
+
}, []);
|
|
836
391
|
const loadWalletList = useCallback2(async (projectId) => {
|
|
837
392
|
if (loadedRef.current) return;
|
|
838
393
|
loadedRef.current = true;
|
|
394
|
+
const controller = new AbortController();
|
|
395
|
+
abortControllerRef.current = controller;
|
|
839
396
|
setWalletListLoading(true);
|
|
840
397
|
try {
|
|
841
|
-
const list = await fetchWCWalletList(projectId);
|
|
842
|
-
setWalletList(list);
|
|
843
|
-
} catch {
|
|
844
|
-
|
|
398
|
+
const list = await fetchWCWalletList(projectId, controller.signal);
|
|
399
|
+
if (isMountedRef.current) setWalletList(list);
|
|
400
|
+
} catch (err) {
|
|
401
|
+
const isAbort = err instanceof DOMException && err.name === "AbortError";
|
|
402
|
+
if (!isAbort) loadedRef.current = false;
|
|
845
403
|
} finally {
|
|
846
|
-
setWalletListLoading(false);
|
|
404
|
+
if (isMountedRef.current) setWalletListLoading(false);
|
|
405
|
+
if (abortControllerRef.current === controller) abortControllerRef.current = null;
|
|
847
406
|
}
|
|
848
407
|
}, []);
|
|
849
408
|
const onShowList = useCallback2(() => setSubView("list"), []);
|
|
@@ -913,7 +472,7 @@ var IdleView = /* @__PURE__ */ __name(() => /* @__PURE__ */ React.createElement(
|
|
|
913
472
|
}, "Choose a wallet on the left to start connecting.")), "IdleView");
|
|
914
473
|
|
|
915
474
|
// src/views/CreditWalletView.tsx
|
|
916
|
-
import { useEffect as
|
|
475
|
+
import { useEffect as useEffect3, useMemo, useRef as useRef3 } from "react";
|
|
917
476
|
|
|
918
477
|
// src/components/QRFrame.tsx
|
|
919
478
|
import { QRCodeSVG } from "qrcode.react";
|
|
@@ -925,8 +484,8 @@ var QRFrame = /* @__PURE__ */ __name(({ qrUri, logoUrl }) => /* @__PURE__ */ Rea
|
|
|
925
484
|
level: "H",
|
|
926
485
|
imageSettings: logoUrl ? {
|
|
927
486
|
src: logoUrl,
|
|
928
|
-
width:
|
|
929
|
-
height:
|
|
487
|
+
width: 50,
|
|
488
|
+
height: 50,
|
|
930
489
|
excavate: true
|
|
931
490
|
} : void 0
|
|
932
491
|
}) : /* @__PURE__ */ React.createElement("div", {
|
|
@@ -939,7 +498,9 @@ var CopyLinkButton = /* @__PURE__ */ __name(({ qrUri }) => {
|
|
|
939
498
|
type: "button",
|
|
940
499
|
className: "ck-copy-link",
|
|
941
500
|
onClick: /* @__PURE__ */ __name(() => {
|
|
942
|
-
|
|
501
|
+
var _a;
|
|
502
|
+
(_a = navigator.clipboard) == null ? void 0 : _a.writeText(qrUri).catch(() => {
|
|
503
|
+
});
|
|
943
504
|
}, "onClick")
|
|
944
505
|
}, "Copy link");
|
|
945
506
|
}, "CopyLinkButton");
|
|
@@ -948,8 +509,10 @@ var CopyLinkButton = /* @__PURE__ */ __name(({ qrUri }) => {
|
|
|
948
509
|
var CreditWalletView = /* @__PURE__ */ __name(({ connectorId, qrUri }) => {
|
|
949
510
|
const { downloadUrl: downloadUrl2, logoUrl, deepLinkBase: deepLinkBase2 } = CONNECTOR_META[connectorId];
|
|
950
511
|
const isMobile = useMemo(() => isMobileDevice(), []);
|
|
951
|
-
|
|
952
|
-
|
|
512
|
+
const hasRedirectedRef = useRef3(false);
|
|
513
|
+
useEffect3(() => {
|
|
514
|
+
if (isMobile && qrUri && deepLinkBase2 && !hasRedirectedRef.current) {
|
|
515
|
+
hasRedirectedRef.current = true;
|
|
953
516
|
tryOpenDeepLink(qrUri, deepLinkBase2);
|
|
954
517
|
}
|
|
955
518
|
}, [
|
|
@@ -986,12 +549,14 @@ var CreditWalletView = /* @__PURE__ */ __name(({ connectorId, qrUri }) => {
|
|
|
986
549
|
}, "CreditWalletView");
|
|
987
550
|
|
|
988
551
|
// src/views/MetaMaskView.tsx
|
|
989
|
-
import { useEffect as
|
|
552
|
+
import { useEffect as useEffect4, useMemo as useMemo2, useRef as useRef4 } from "react";
|
|
990
553
|
var { downloadUrl, deepLinkBase } = CONNECTOR_META.METAMASK;
|
|
991
554
|
var MetaMaskView = /* @__PURE__ */ __name(({ qrUri, hasExtension, logoUrl }) => {
|
|
992
555
|
const isMobile = useMemo2(() => isMobileDevice(), []);
|
|
993
|
-
|
|
994
|
-
|
|
556
|
+
const hasRedirectedRef = useRef4(false);
|
|
557
|
+
useEffect4(() => {
|
|
558
|
+
if (isMobile && qrUri && deepLinkBase && !hasRedirectedRef.current) {
|
|
559
|
+
hasRedirectedRef.current = true;
|
|
995
560
|
tryOpenDeepLink(qrUri, deepLinkBase);
|
|
996
561
|
}
|
|
997
562
|
}, [
|
|
@@ -1205,11 +770,18 @@ var WalletQRView = /* @__PURE__ */ __name(({ wallet, qrUri }) => {
|
|
|
1205
770
|
}, "WalletQRView");
|
|
1206
771
|
|
|
1207
772
|
// src/views/SwitchChainView.tsx
|
|
1208
|
-
import { useState as useState2 } from "react";
|
|
773
|
+
import { useEffect as useEffect5, useRef as useRef5, useState as useState2 } from "react";
|
|
1209
774
|
import { useSwitchChain } from "wagmi";
|
|
1210
775
|
var SwitchChainView = /* @__PURE__ */ __name(({ currentChainId, requiredChainId, requiredChainName, onDisconnect, onLog }) => {
|
|
1211
776
|
const { switchChainAsync, isPending } = useSwitchChain();
|
|
1212
777
|
const [error, setError] = useState2(null);
|
|
778
|
+
const isMountedRef = useRef5(true);
|
|
779
|
+
useEffect5(() => {
|
|
780
|
+
isMountedRef.current = true;
|
|
781
|
+
return () => {
|
|
782
|
+
isMountedRef.current = false;
|
|
783
|
+
};
|
|
784
|
+
}, []);
|
|
1213
785
|
const targetLabel = requiredChainName != null ? requiredChainName : `chain ${requiredChainId}`;
|
|
1214
786
|
const handleSwitch = /* @__PURE__ */ __name(() => {
|
|
1215
787
|
setError(null);
|
|
@@ -1223,7 +795,7 @@ var SwitchChainView = /* @__PURE__ */ __name(({ currentChainId, requiredChainId,
|
|
|
1223
795
|
} else {
|
|
1224
796
|
onLog == null ? void 0 : onLog(`[connect-kit] switch chain failed: ${normalized.message}`, normalized);
|
|
1225
797
|
}
|
|
1226
|
-
setError(normalized);
|
|
798
|
+
if (isMountedRef.current) setError(normalized);
|
|
1227
799
|
});
|
|
1228
800
|
}, "handleSwitch");
|
|
1229
801
|
return /* @__PURE__ */ React.createElement("div", {
|
|
@@ -1250,25 +822,41 @@ var SwitchChainView = /* @__PURE__ */ __name(({ currentChainId, requiredChainId,
|
|
|
1250
822
|
|
|
1251
823
|
// src/ConnectModal.tsx
|
|
1252
824
|
var RECENT_KEY = "connect-kit:recent";
|
|
825
|
+
var VALID_CONNECTOR_IDS = /* @__PURE__ */ new Set([
|
|
826
|
+
"CREDIT_CONNECT",
|
|
827
|
+
"CREDIT_WALLET",
|
|
828
|
+
"METAMASK",
|
|
829
|
+
"WALLET_CONNECT"
|
|
830
|
+
]);
|
|
1253
831
|
var readRecentConnector = /* @__PURE__ */ __name(() => {
|
|
1254
832
|
try {
|
|
1255
|
-
|
|
833
|
+
const raw = localStorage.getItem(RECENT_KEY);
|
|
834
|
+
if (raw == null) return null;
|
|
835
|
+
return VALID_CONNECTOR_IDS.has(raw) ? raw : null;
|
|
1256
836
|
} catch {
|
|
1257
837
|
return null;
|
|
1258
838
|
}
|
|
1259
839
|
}, "readRecentConnector");
|
|
1260
|
-
var writeRecentConnector = /* @__PURE__ */ __name((id) => {
|
|
840
|
+
var writeRecentConnector = /* @__PURE__ */ __name((id, onLog) => {
|
|
1261
841
|
try {
|
|
1262
842
|
localStorage.setItem(RECENT_KEY, id);
|
|
1263
|
-
} catch {
|
|
843
|
+
} catch (err) {
|
|
844
|
+
const normalized = err instanceof Error ? err : new Error(String(err));
|
|
845
|
+
onLog == null ? void 0 : onLog(`[connect-kit] writeRecentConnector failed: ${normalized.message}`, normalized);
|
|
1264
846
|
}
|
|
1265
847
|
}, "writeRecentConnector");
|
|
848
|
+
var REJECTED_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
849
|
+
4001,
|
|
850
|
+
"ACTION_REJECTED"
|
|
851
|
+
]);
|
|
1266
852
|
var classifyError = /* @__PURE__ */ __name((error) => {
|
|
1267
853
|
var _a, _b;
|
|
1268
854
|
const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
1269
|
-
if (code
|
|
855
|
+
if (code != null && REJECTED_ERROR_CODES.has(code)) return "rejected";
|
|
1270
856
|
const message = (_b = (_a = error.message) == null ? void 0 : _a.toLowerCase()) != null ? _b : "";
|
|
1271
|
-
if (message.includes("user rejected") || message.includes("user denied"))
|
|
857
|
+
if (message.includes("user rejected") || message.includes("user denied") || message.includes("user cancel") || message.includes("rejected by user") || message.includes("action_rejected") || message.includes("\uC0AC\uC6A9\uC790\uAC00 \uAC70\uBD80") || message.includes("\uC0AC\uC6A9\uC790\uAC00 \uCDE8\uC18C") || message.includes("\u30E6\u30FC\u30B6\u30FC\u304C\u62D2\u5426") || message.includes("\u30E6\u30FC\u30B6\u30FC\u304C\u30AD\u30E3\u30F3\u30BB\u30EB")) {
|
|
858
|
+
return "rejected";
|
|
859
|
+
}
|
|
1272
860
|
if (message.includes("unsupported") || message.includes("not installed")) return "unsupported";
|
|
1273
861
|
return "unknown";
|
|
1274
862
|
}, "classifyError");
|
|
@@ -1414,10 +1002,8 @@ var ConnectModal = /* @__PURE__ */ __name((props) => {
|
|
|
1414
1002
|
});
|
|
1415
1003
|
}, "ConnectModal");
|
|
1416
1004
|
var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, onClose, onLog, wcProjectId, requiredChainId, renderConnectError }) => {
|
|
1417
|
-
var _a;
|
|
1418
1005
|
const [selectedConnector, setSelectedConnector] = useState3(null);
|
|
1419
|
-
const [
|
|
1420
|
-
const pendingQrConnectorRef = useRef3(null);
|
|
1006
|
+
const [qrUri, setQrUri] = useState3(null);
|
|
1421
1007
|
const [recentConnector, setRecentConnector] = useState3(null);
|
|
1422
1008
|
const [hasMetaMaskExtension, setHasMetaMaskExtension] = useState3(false);
|
|
1423
1009
|
const [errorState, setErrorState] = useState3(null);
|
|
@@ -1427,21 +1013,15 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1427
1013
|
const wagmiConfig = useConfig2();
|
|
1428
1014
|
const chainMismatch = requiredChainId != null && account.status === "connected" && account.chainId != null && account.chainId !== requiredChainId;
|
|
1429
1015
|
const requiredChainName = useMemo4(() => {
|
|
1430
|
-
var
|
|
1016
|
+
var _a;
|
|
1431
1017
|
if (requiredChainId == null) return void 0;
|
|
1432
|
-
return (
|
|
1018
|
+
return (_a = wagmiConfig.chains.find((chain) => chain.id === requiredChainId)) == null ? void 0 : _a.name;
|
|
1433
1019
|
}, [
|
|
1434
1020
|
wagmiConfig.chains,
|
|
1435
1021
|
requiredChainId
|
|
1436
1022
|
]);
|
|
1437
1023
|
const handleQrUri = useCallback3((uri) => {
|
|
1438
|
-
|
|
1439
|
-
const id = pendingQrConnectorRef.current;
|
|
1440
|
-
if (id) setQrUriMap((prev) => ({
|
|
1441
|
-
...prev,
|
|
1442
|
-
[id]: uri
|
|
1443
|
-
}));
|
|
1444
|
-
}
|
|
1024
|
+
setQrUri(uri);
|
|
1445
1025
|
}, []);
|
|
1446
1026
|
const handleConnect = useCallback3((result) => {
|
|
1447
1027
|
setErrorState(null);
|
|
@@ -1454,13 +1034,7 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1454
1034
|
const handleError = useCallback3((error, connectorId) => {
|
|
1455
1035
|
const normalizedError = error instanceof Error ? error : new Error(String(error));
|
|
1456
1036
|
onLog == null ? void 0 : onLog(`[connect-kit] connection failed (${connectorId}): ${normalizedError.message}`, normalizedError);
|
|
1457
|
-
|
|
1458
|
-
const next = {
|
|
1459
|
-
...prev
|
|
1460
|
-
};
|
|
1461
|
-
delete next[connectorId];
|
|
1462
|
-
return next;
|
|
1463
|
-
});
|
|
1037
|
+
setQrUri(null);
|
|
1464
1038
|
wc.resetView();
|
|
1465
1039
|
if (renderConnectError) {
|
|
1466
1040
|
setErrorState({
|
|
@@ -1496,15 +1070,14 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1496
1070
|
}, [
|
|
1497
1071
|
wagmiConfig.connectors
|
|
1498
1072
|
]);
|
|
1499
|
-
|
|
1073
|
+
useEffect6(() => {
|
|
1500
1074
|
setRecentConnector(readRecentConnector());
|
|
1501
1075
|
setHasMetaMaskExtension(detectMetaMaskExtension());
|
|
1502
1076
|
}, []);
|
|
1503
|
-
|
|
1077
|
+
useEffect6(() => {
|
|
1504
1078
|
if (!open) {
|
|
1505
1079
|
setSelectedConnector(null);
|
|
1506
|
-
|
|
1507
|
-
pendingQrConnectorRef.current = null;
|
|
1080
|
+
setQrUri(null);
|
|
1508
1081
|
setErrorState(null);
|
|
1509
1082
|
wc.reset();
|
|
1510
1083
|
cancelConnect();
|
|
@@ -1516,11 +1089,11 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1516
1089
|
]);
|
|
1517
1090
|
const handleSelectConnector = useCallback3((id) => {
|
|
1518
1091
|
if (id === selectedConnector && !errorState) return;
|
|
1519
|
-
pendingQrConnectorRef.current = id;
|
|
1520
1092
|
setSelectedConnector(id);
|
|
1093
|
+
setQrUri(null);
|
|
1521
1094
|
setErrorState(null);
|
|
1522
1095
|
wc.resetView();
|
|
1523
|
-
writeRecentConnector(id);
|
|
1096
|
+
writeRecentConnector(id, onLog);
|
|
1524
1097
|
setRecentConnector(id);
|
|
1525
1098
|
if (id === "WALLET_CONNECT" && wcProjectId) {
|
|
1526
1099
|
wc.loadWalletList(wcProjectId);
|
|
@@ -1534,7 +1107,8 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1534
1107
|
cancelConnect,
|
|
1535
1108
|
wcProjectId,
|
|
1536
1109
|
wc.resetView,
|
|
1537
|
-
wc.loadWalletList
|
|
1110
|
+
wc.loadWalletList,
|
|
1111
|
+
onLog
|
|
1538
1112
|
]);
|
|
1539
1113
|
const handleBack = useCallback3(() => {
|
|
1540
1114
|
if (errorState) {
|
|
@@ -1543,8 +1117,8 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1543
1117
|
return;
|
|
1544
1118
|
}
|
|
1545
1119
|
if (selectedConnector === "WALLET_CONNECT" && wc.handleBack()) return;
|
|
1546
|
-
pendingQrConnectorRef.current = null;
|
|
1547
1120
|
setSelectedConnector(null);
|
|
1121
|
+
setQrUri(null);
|
|
1548
1122
|
cancelConnect();
|
|
1549
1123
|
}, [
|
|
1550
1124
|
selectedConnector,
|
|
@@ -1588,7 +1162,7 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1588
1162
|
retry: /* @__PURE__ */ __name(() => {
|
|
1589
1163
|
const id = errorState.connectorId;
|
|
1590
1164
|
setErrorState(null);
|
|
1591
|
-
|
|
1165
|
+
setQrUri(null);
|
|
1592
1166
|
cancelConnect();
|
|
1593
1167
|
triggerConnect(id);
|
|
1594
1168
|
}, "retry"),
|
|
@@ -1654,7 +1228,7 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1654
1228
|
onClose: handleCloseClick
|
|
1655
1229
|
}), /* @__PURE__ */ React.createElement(DetailPane, {
|
|
1656
1230
|
selectedConnector,
|
|
1657
|
-
qrUri
|
|
1231
|
+
qrUri,
|
|
1658
1232
|
hasMetaMaskExtension,
|
|
1659
1233
|
connectorLogoMap,
|
|
1660
1234
|
wc,
|
|
@@ -1665,8 +1239,10 @@ var ConnectModalInner = /* @__PURE__ */ __name(({ open, connectors, onConnect, o
|
|
|
1665
1239
|
}, "ConnectModalInner");
|
|
1666
1240
|
|
|
1667
1241
|
// src/ConnectKitProvider.tsx
|
|
1668
|
-
import { createContext, useCallback as useCallback4, useContext, useEffect as
|
|
1669
|
-
import { useAccount as useAccount2, useDisconnect as useDisconnect2 } from "wagmi";
|
|
1242
|
+
import { createContext, useCallback as useCallback4, useContext, useEffect as useEffect7, useMemo as useMemo5, useRef as useRef6, useState as useState4 } from "react";
|
|
1243
|
+
import { WagmiProvider, useAccount as useAccount2, useDisconnect as useDisconnect2, useSwitchChain as useSwitchChain2 } from "wagmi";
|
|
1244
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
1245
|
+
var internalQueryClient = new QueryClient();
|
|
1670
1246
|
var ConnectKitContext = /* @__PURE__ */ createContext(null);
|
|
1671
1247
|
var resolveConnectorId = /* @__PURE__ */ __name((wagmiConnectorId) => {
|
|
1672
1248
|
if (!wagmiConnectorId) return null;
|
|
@@ -1677,20 +1253,81 @@ var resolveConnectorId = /* @__PURE__ */ __name((wagmiConnectorId) => {
|
|
|
1677
1253
|
if (lower.includes("walletconnect")) return "WALLET_CONNECT";
|
|
1678
1254
|
return null;
|
|
1679
1255
|
}, "resolveConnectorId");
|
|
1680
|
-
var ConnectKitProvider = /* @__PURE__ */ __name((
|
|
1256
|
+
var ConnectKitProvider = /* @__PURE__ */ __name((props) => {
|
|
1257
|
+
var _a;
|
|
1258
|
+
const wagmiConfig = useMemo5(() => props.kitConfig ? initConfig(props.kitConfig) : getConfig(), [
|
|
1259
|
+
props.kitConfig
|
|
1260
|
+
]);
|
|
1261
|
+
const resolvedKitConfig = (_a = props.kitConfig) != null ? _a : getKitConfig();
|
|
1262
|
+
return /* @__PURE__ */ React.createElement(WagmiProvider, {
|
|
1263
|
+
config: wagmiConfig,
|
|
1264
|
+
reconnectOnMount: false
|
|
1265
|
+
}, /* @__PURE__ */ React.createElement(QueryClientProvider, {
|
|
1266
|
+
client: internalQueryClient
|
|
1267
|
+
}, /* @__PURE__ */ React.createElement(ConnectKitProviderInner, {
|
|
1268
|
+
...props,
|
|
1269
|
+
kitConfig: resolvedKitConfig
|
|
1270
|
+
})));
|
|
1271
|
+
}, "ConnectKitProvider");
|
|
1272
|
+
var ConnectKitProviderInner = /* @__PURE__ */ __name(({ children, connectors, kitConfig, requiredChainId, onConnect, onLog, renderConnectError }) => {
|
|
1681
1273
|
var _a;
|
|
1682
1274
|
const [isOpen, setIsOpen] = useState4(false);
|
|
1683
1275
|
const [pendingResult, setPendingResult] = useState4(null);
|
|
1684
1276
|
const account = useAccount2();
|
|
1685
1277
|
const { disconnectAsync } = useDisconnect2();
|
|
1686
|
-
const
|
|
1687
|
-
|
|
1278
|
+
const { switchChainAsync } = useSwitchChain2();
|
|
1279
|
+
const onConnectRef = useRef6(onConnect);
|
|
1280
|
+
useEffect7(() => {
|
|
1688
1281
|
onConnectRef.current = onConnect;
|
|
1689
1282
|
}, [
|
|
1690
1283
|
onConnect
|
|
1691
1284
|
]);
|
|
1692
1285
|
const chainMismatch = requiredChainId != null && account.status === "connected" && account.chainId != null && account.chainId !== requiredChainId;
|
|
1693
|
-
const
|
|
1286
|
+
const [autoSwitchFailedKey, setAutoSwitchFailedKey] = useState4(null);
|
|
1287
|
+
const autoSwitchInFlightRef = useRef6(false);
|
|
1288
|
+
const isMountedRef = useRef6(true);
|
|
1289
|
+
useEffect7(() => {
|
|
1290
|
+
isMountedRef.current = true;
|
|
1291
|
+
return () => {
|
|
1292
|
+
isMountedRef.current = false;
|
|
1293
|
+
};
|
|
1294
|
+
}, []);
|
|
1295
|
+
const mismatchKey = chainMismatch && account.chainId != null && requiredChainId != null ? `${account.chainId}->${requiredChainId}` : null;
|
|
1296
|
+
useEffect7(() => {
|
|
1297
|
+
if (!chainMismatch || requiredChainId == null) return;
|
|
1298
|
+
if (autoSwitchInFlightRef.current) return;
|
|
1299
|
+
if (mismatchKey != null && mismatchKey === autoSwitchFailedKey) return;
|
|
1300
|
+
autoSwitchInFlightRef.current = true;
|
|
1301
|
+
switchChainAsync({
|
|
1302
|
+
chainId: requiredChainId
|
|
1303
|
+
}).catch((err) => {
|
|
1304
|
+
if (!isMountedRef.current) return;
|
|
1305
|
+
const normalized = err instanceof Error ? err : new Error(String(err));
|
|
1306
|
+
onLog == null ? void 0 : onLog(`[connect-kit] silent switch chain failed: ${normalized.message}`, normalized);
|
|
1307
|
+
if (mismatchKey != null) {
|
|
1308
|
+
setAutoSwitchFailedKey(mismatchKey);
|
|
1309
|
+
}
|
|
1310
|
+
}).finally(() => {
|
|
1311
|
+
autoSwitchInFlightRef.current = false;
|
|
1312
|
+
});
|
|
1313
|
+
}, [
|
|
1314
|
+
chainMismatch,
|
|
1315
|
+
mismatchKey,
|
|
1316
|
+
requiredChainId,
|
|
1317
|
+
autoSwitchFailedKey,
|
|
1318
|
+
switchChainAsync,
|
|
1319
|
+
onLog
|
|
1320
|
+
]);
|
|
1321
|
+
useEffect7(() => {
|
|
1322
|
+
if (!chainMismatch && autoSwitchFailedKey != null) {
|
|
1323
|
+
setAutoSwitchFailedKey(null);
|
|
1324
|
+
}
|
|
1325
|
+
}, [
|
|
1326
|
+
chainMismatch,
|
|
1327
|
+
autoSwitchFailedKey
|
|
1328
|
+
]);
|
|
1329
|
+
const autoSwitchFailedForCurrent = mismatchKey != null && mismatchKey === autoSwitchFailedKey;
|
|
1330
|
+
const effectiveOpen = isOpen || chainMismatch && autoSwitchFailedForCurrent;
|
|
1694
1331
|
const open = useCallback4(() => {
|
|
1695
1332
|
setIsOpen(true);
|
|
1696
1333
|
}, []);
|
|
@@ -1705,7 +1342,7 @@ var ConnectKitProvider = /* @__PURE__ */ __name(({ children, connectors, wcProje
|
|
|
1705
1342
|
const handleModalConnect = useCallback4((result) => {
|
|
1706
1343
|
setPendingResult(result);
|
|
1707
1344
|
}, []);
|
|
1708
|
-
|
|
1345
|
+
useEffect7(() => {
|
|
1709
1346
|
var _a2;
|
|
1710
1347
|
if (!pendingResult) return;
|
|
1711
1348
|
if (account.status !== "connected") {
|
|
@@ -1749,14 +1386,14 @@ var ConnectKitProvider = /* @__PURE__ */ __name(({ children, connectors, wcProje
|
|
|
1749
1386
|
}, children, /* @__PURE__ */ React.createElement(ConnectModal, {
|
|
1750
1387
|
open: effectiveOpen,
|
|
1751
1388
|
connectors,
|
|
1752
|
-
wcProjectId,
|
|
1389
|
+
wcProjectId: kitConfig.wcProjectId,
|
|
1753
1390
|
requiredChainId,
|
|
1754
1391
|
renderConnectError,
|
|
1755
1392
|
onConnect: handleModalConnect,
|
|
1756
1393
|
onClose: close,
|
|
1757
1394
|
onLog
|
|
1758
1395
|
}));
|
|
1759
|
-
}, "
|
|
1396
|
+
}, "ConnectKitProviderInner");
|
|
1760
1397
|
var useConnectKit = /* @__PURE__ */ __name(() => {
|
|
1761
1398
|
const ctx = useContext(ConnectKitContext);
|
|
1762
1399
|
if (!ctx) {
|
|
@@ -1765,399 +1402,30 @@ var useConnectKit = /* @__PURE__ */ __name(() => {
|
|
|
1765
1402
|
return ctx;
|
|
1766
1403
|
}, "useConnectKit");
|
|
1767
1404
|
|
|
1768
|
-
// src/
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
}, "emitProviderEvent");
|
|
1789
|
-
const getCurrentSession = /* @__PURE__ */ __name(() => {
|
|
1790
|
-
if (!manager || manager.state.status !== "CONNECTED" || !manager.state.session) return null;
|
|
1791
|
-
return manager.state.session;
|
|
1792
|
-
}, "getCurrentSession");
|
|
1793
|
-
const getEvmAddressInfo = /* @__PURE__ */ __name((session) => session.addressInfoList.filter((info) => info.networkType === "eip155"), "getEvmAddressInfo");
|
|
1794
|
-
const getChecksummedAccounts = /* @__PURE__ */ __name((session) => getEvmAddressInfo(session).map((info) => getAddress(info.address)), "getChecksummedAccounts");
|
|
1795
|
-
const resetState = /* @__PURE__ */ __name(() => {
|
|
1796
|
-
connectPromise = null;
|
|
1797
|
-
selectedChainId = null;
|
|
1798
|
-
}, "resetState");
|
|
1799
|
-
const createManagerIfNeeded = /* @__PURE__ */ __name(() => {
|
|
1800
|
-
if (manager) return manager;
|
|
1801
|
-
manager = new DappSessionManager({
|
|
1802
|
-
projectKey: options.projectKey,
|
|
1803
|
-
serverUrl: options.serverUrl,
|
|
1804
|
-
storage: options.storage,
|
|
1805
|
-
e2ee: options.e2ee,
|
|
1806
|
-
createHub: options.createHub,
|
|
1807
|
-
enableReconnect: true,
|
|
1808
|
-
autoInit: true
|
|
1809
|
-
});
|
|
1810
|
-
manager.on("changeState", (state) => {
|
|
1811
|
-
var _a;
|
|
1812
|
-
if (state.status === "CONNECTING" && state.connectingPayload) {
|
|
1813
|
-
(_a = options.onDisplayUri) == null ? void 0 : _a.call(options, state.connectingPayload);
|
|
1814
|
-
emitWagmiMessage == null ? void 0 : emitWagmiMessage("display_uri", state.connectingPayload);
|
|
1815
|
-
}
|
|
1816
|
-
if (state.status === "DISCONNECTED" && !isLocalDisconnect) {
|
|
1817
|
-
resetState();
|
|
1818
|
-
emitProviderEvent("disconnect");
|
|
1819
|
-
emitWagmiDisconnect == null ? void 0 : emitWagmiDisconnect();
|
|
1820
|
-
}
|
|
1821
|
-
});
|
|
1822
|
-
return manager;
|
|
1823
|
-
}, "createManagerIfNeeded");
|
|
1824
|
-
const ensureManagerInitialized = /* @__PURE__ */ __name(async () => {
|
|
1825
|
-
const m = createManagerIfNeeded();
|
|
1826
|
-
if (m.state.status === "PENDING") {
|
|
1827
|
-
await m.initSession();
|
|
1828
|
-
return m;
|
|
1829
|
-
}
|
|
1830
|
-
if (m.state.status === "INITIALIZING") {
|
|
1831
|
-
await new Promise((resolve) => {
|
|
1832
|
-
const unsub = m.on("changeState", (state) => {
|
|
1833
|
-
if (state.status !== "INITIALIZING") {
|
|
1834
|
-
unsub();
|
|
1835
|
-
resolve();
|
|
1836
|
-
}
|
|
1837
|
-
});
|
|
1838
|
-
});
|
|
1839
|
-
}
|
|
1840
|
-
return m;
|
|
1841
|
-
}, "ensureManagerInitialized");
|
|
1842
|
-
return createConnector((config) => {
|
|
1843
|
-
emitWagmiMessage = /* @__PURE__ */ __name((type, data) => {
|
|
1844
|
-
config.emitter.emit("message", {
|
|
1845
|
-
type,
|
|
1846
|
-
data
|
|
1847
|
-
});
|
|
1848
|
-
}, "emitWagmiMessage");
|
|
1849
|
-
emitWagmiDisconnect = /* @__PURE__ */ __name(() => {
|
|
1850
|
-
config.emitter.emit("disconnect");
|
|
1851
|
-
}, "emitWagmiDisconnect");
|
|
1852
|
-
return {
|
|
1853
|
-
id: CONNECTOR_ID,
|
|
1854
|
-
name: CONNECTOR_NAME,
|
|
1855
|
-
type: CONNECTOR_TYPE,
|
|
1856
|
-
async setup() {
|
|
1857
|
-
await ensureManagerInitialized();
|
|
1858
|
-
},
|
|
1859
|
-
async connect(parameters) {
|
|
1860
|
-
var _a;
|
|
1861
|
-
try {
|
|
1862
|
-
const m = createManagerIfNeeded();
|
|
1863
|
-
if (m.state.status === "INITIALIZING") {
|
|
1864
|
-
await new Promise((resolve) => {
|
|
1865
|
-
const unsub = m.on("changeState", (state) => {
|
|
1866
|
-
if (state.status !== "INITIALIZING") {
|
|
1867
|
-
unsub();
|
|
1868
|
-
resolve();
|
|
1869
|
-
}
|
|
1870
|
-
});
|
|
1871
|
-
});
|
|
1872
|
-
}
|
|
1873
|
-
if (parameters == null ? void 0 : parameters.isReconnecting) {
|
|
1874
|
-
const session2 = getCurrentSession();
|
|
1875
|
-
if (!session2) throw new Error("No active session to reconnect");
|
|
1876
|
-
const accounts2 = getChecksummedAccounts(session2);
|
|
1877
|
-
if (accounts2.length === 0) throw new Error("No EVM address found");
|
|
1878
|
-
const chainId2 = Number.parseInt(getEvmAddressInfo(session2)[0].networkIdentifier, 10);
|
|
1879
|
-
if (!Number.isFinite(chainId2)) throw new Error(`Invalid chainId: ${chainId2}`);
|
|
1880
|
-
selectedChainId = chainId2;
|
|
1881
|
-
if ((parameters == null ? void 0 : parameters.withCapabilities) === true) {
|
|
1882
|
-
return castConnectResult({
|
|
1883
|
-
accounts: accounts2.map((address) => ({
|
|
1884
|
-
address,
|
|
1885
|
-
capabilities: {}
|
|
1886
|
-
})),
|
|
1887
|
-
chainId: chainId2
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
return castConnectResult({
|
|
1891
|
-
accounts: accounts2,
|
|
1892
|
-
chainId: chainId2
|
|
1893
|
-
});
|
|
1894
|
-
}
|
|
1895
|
-
if (m.state.status === "CONNECTING" && m.state.connectingPayload) {
|
|
1896
|
-
(_a = options.onDisplayUri) == null ? void 0 : _a.call(options, m.state.connectingPayload);
|
|
1897
|
-
if (!connectPromise) {
|
|
1898
|
-
connectPromise = new Promise((resolve) => {
|
|
1899
|
-
const unsub = m.on("changeState", (state) => {
|
|
1900
|
-
if (state.status === "CONNECTED") {
|
|
1901
|
-
unsub();
|
|
1902
|
-
resolve(true);
|
|
1903
|
-
} else if (state.status === "DISCONNECTED") {
|
|
1904
|
-
unsub();
|
|
1905
|
-
resolve(false);
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
|
-
});
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
if (m.state.status !== "CONNECTED") {
|
|
1912
|
-
if (!connectPromise) {
|
|
1913
|
-
if (m.state.status !== "DISCONNECTED") {
|
|
1914
|
-
throw new Error(`Cannot connect from ${m.state.status} state`);
|
|
1915
|
-
}
|
|
1916
|
-
connectPromise = m.connectNewSession();
|
|
1917
|
-
}
|
|
1918
|
-
const connected = await connectPromise;
|
|
1919
|
-
connectPromise = null;
|
|
1920
|
-
if (!connected) throw new Error("Credit Connect session failed");
|
|
1921
|
-
}
|
|
1922
|
-
const session = getCurrentSession();
|
|
1923
|
-
if (!session) throw new Error("Credit Connect session failed");
|
|
1924
|
-
const accounts = getChecksummedAccounts(session);
|
|
1925
|
-
if (accounts.length === 0) throw new Error("No EVM address found");
|
|
1926
|
-
const chainId = Number.parseInt(getEvmAddressInfo(session)[0].networkIdentifier, 10);
|
|
1927
|
-
if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
|
|
1928
|
-
selectedChainId = chainId;
|
|
1929
|
-
if ((parameters == null ? void 0 : parameters.withCapabilities) === true) {
|
|
1930
|
-
return castConnectResult({
|
|
1931
|
-
accounts: accounts.map((address) => ({
|
|
1932
|
-
address,
|
|
1933
|
-
capabilities: {}
|
|
1934
|
-
})),
|
|
1935
|
-
chainId
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
return castConnectResult({
|
|
1939
|
-
accounts,
|
|
1940
|
-
chainId
|
|
1941
|
-
});
|
|
1942
|
-
} catch (error) {
|
|
1943
|
-
resetState();
|
|
1944
|
-
throw error;
|
|
1945
|
-
}
|
|
1946
|
-
},
|
|
1947
|
-
async switchChain({ chainId }) {
|
|
1948
|
-
const session = getCurrentSession();
|
|
1949
|
-
if (!session) throw new Error("No active session");
|
|
1950
|
-
const supported = getEvmAddressInfo(session).some((info) => Number.parseInt(info.networkIdentifier, 10) === chainId);
|
|
1951
|
-
if (!supported) {
|
|
1952
|
-
const err = new Error(`Unsupported chain: ${chainId}`);
|
|
1953
|
-
err.code = 4902;
|
|
1954
|
-
throw err;
|
|
1955
|
-
}
|
|
1956
|
-
selectedChainId = chainId;
|
|
1957
|
-
config.emitter.emit("change", {
|
|
1958
|
-
chainId
|
|
1959
|
-
});
|
|
1960
|
-
const chain = config.chains.find((c) => c.id === chainId);
|
|
1961
|
-
if (!chain) throw new Error(`Chain ${chainId} not in config`);
|
|
1962
|
-
return chain;
|
|
1963
|
-
},
|
|
1964
|
-
async isAuthorized() {
|
|
1965
|
-
await ensureManagerInitialized();
|
|
1966
|
-
const session = getCurrentSession();
|
|
1967
|
-
if (!session) return false;
|
|
1968
|
-
return session.addressInfoList.some((info) => info.networkType === "eip155");
|
|
1969
|
-
},
|
|
1970
|
-
async disconnect() {
|
|
1971
|
-
isLocalDisconnect = true;
|
|
1972
|
-
try {
|
|
1973
|
-
if ((manager == null ? void 0 : manager.state.status) === "CONNECTED") {
|
|
1974
|
-
await manager.disconnectSession();
|
|
1975
|
-
}
|
|
1976
|
-
} finally {
|
|
1977
|
-
isLocalDisconnect = false;
|
|
1978
|
-
}
|
|
1979
|
-
resetState();
|
|
1980
|
-
config.emitter.emit("disconnect");
|
|
1981
|
-
},
|
|
1982
|
-
async getAccounts() {
|
|
1983
|
-
await ensureManagerInitialized();
|
|
1984
|
-
const session = getCurrentSession();
|
|
1985
|
-
if (!session) return [];
|
|
1986
|
-
return getChecksummedAccounts(session);
|
|
1987
|
-
},
|
|
1988
|
-
async getChainId() {
|
|
1989
|
-
await ensureManagerInitialized();
|
|
1990
|
-
const session = getCurrentSession();
|
|
1991
|
-
if (!session) throw new Error("No active session");
|
|
1992
|
-
if (selectedChainId !== null) return selectedChainId;
|
|
1993
|
-
const evmAddressInfo = getEvmAddressInfo(session);
|
|
1994
|
-
if (evmAddressInfo.length === 0) throw new Error("No EVM address found");
|
|
1995
|
-
const chainId = Number.parseInt(evmAddressInfo[0].networkIdentifier, 10);
|
|
1996
|
-
if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
|
|
1997
|
-
selectedChainId = chainId;
|
|
1998
|
-
return chainId;
|
|
1999
|
-
},
|
|
2000
|
-
async getProvider() {
|
|
2001
|
-
if (provider) return provider;
|
|
2002
|
-
await ensureManagerInitialized();
|
|
2003
|
-
const createdProvider = {
|
|
2004
|
-
request: /* @__PURE__ */ __name(async (args) => {
|
|
2005
|
-
const { method, params: rawParams } = args;
|
|
2006
|
-
const params = Array.isArray(rawParams) ? [
|
|
2007
|
-
...rawParams
|
|
2008
|
-
] : rawParams === void 0 ? [] : [
|
|
2009
|
-
rawParams
|
|
2010
|
-
];
|
|
2011
|
-
const session = getCurrentSession();
|
|
2012
|
-
const getSelectedAddressInfo = /* @__PURE__ */ __name((address) => {
|
|
2013
|
-
if (!session) throw new Error("No active session");
|
|
2014
|
-
const evmInfo = getEvmAddressInfo(session);
|
|
2015
|
-
if (evmInfo.length === 0) throw new Error("No EVM address found");
|
|
2016
|
-
if (!address) return evmInfo[0];
|
|
2017
|
-
const found = evmInfo.find((info) => info.address.toLowerCase() === address.toLowerCase());
|
|
2018
|
-
if (!found) throw new Error(`Address not in session: ${address}`);
|
|
2019
|
-
return found;
|
|
2020
|
-
}, "getSelectedAddressInfo");
|
|
2021
|
-
if (method === "eth_accounts") {
|
|
2022
|
-
if (!session) return [];
|
|
2023
|
-
return getChecksummedAccounts(session);
|
|
2024
|
-
}
|
|
2025
|
-
if (method === "eth_chainId") {
|
|
2026
|
-
if (!session) throw new Error("No active session");
|
|
2027
|
-
if (selectedChainId !== null) return `0x${selectedChainId.toString(16)}`;
|
|
2028
|
-
const evmInfo = getEvmAddressInfo(session);
|
|
2029
|
-
if (evmInfo.length === 0) throw new Error("No EVM address found");
|
|
2030
|
-
const chainId = Number.parseInt(evmInfo[0].networkIdentifier, 10);
|
|
2031
|
-
if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
|
|
2032
|
-
selectedChainId = chainId;
|
|
2033
|
-
return `0x${chainId.toString(16)}`;
|
|
2034
|
-
}
|
|
2035
|
-
if (method === "wallet_switchEthereumChain") {
|
|
2036
|
-
const [{ chainId: rawChainId }] = params != null ? params : [];
|
|
2037
|
-
if (!rawChainId) throw new Error("wallet_switchEthereumChain missing chainId param");
|
|
2038
|
-
const chainId = Number.parseInt(rawChainId, 16);
|
|
2039
|
-
if (!Number.isFinite(chainId)) throw new Error(`Invalid chainId: ${rawChainId}`);
|
|
2040
|
-
if (!session) throw new Error("No active session");
|
|
2041
|
-
const supported = getEvmAddressInfo(session).some((info) => Number.parseInt(info.networkIdentifier, 10) === chainId);
|
|
2042
|
-
if (!supported) {
|
|
2043
|
-
const err = new Error(`Unsupported chain: ${chainId}`);
|
|
2044
|
-
err.code = 4902;
|
|
2045
|
-
throw err;
|
|
2046
|
-
}
|
|
2047
|
-
selectedChainId = chainId;
|
|
2048
|
-
config.emitter.emit("change", {
|
|
2049
|
-
chainId
|
|
2050
|
-
});
|
|
2051
|
-
return null;
|
|
2052
|
-
}
|
|
2053
|
-
if (method === "personal_sign") {
|
|
2054
|
-
const [messageParam, addressParam] = params != null ? params : [];
|
|
2055
|
-
const message = typeof messageParam === "string" ? messageParam : String(messageParam != null ? messageParam : "");
|
|
2056
|
-
const address = typeof addressParam === "string" ? addressParam : void 0;
|
|
2057
|
-
const addressInfo = getSelectedAddressInfo(address);
|
|
2058
|
-
const response = await (session == null ? void 0 : session.jsonRpc.request("signMessage", {
|
|
2059
|
-
message,
|
|
2060
|
-
addressInfo
|
|
2061
|
-
}));
|
|
2062
|
-
return response == null ? void 0 : response.signature;
|
|
2063
|
-
}
|
|
2064
|
-
if (method === "eth_sign") {
|
|
2065
|
-
const [addressParam, messageParam] = params != null ? params : [];
|
|
2066
|
-
const address = typeof addressParam === "string" ? addressParam : void 0;
|
|
2067
|
-
const message = typeof messageParam === "string" ? messageParam : String(messageParam != null ? messageParam : "");
|
|
2068
|
-
const addressInfo = getSelectedAddressInfo(address);
|
|
2069
|
-
const response = await (session == null ? void 0 : session.jsonRpc.request("signMessage", {
|
|
2070
|
-
message,
|
|
2071
|
-
addressInfo
|
|
2072
|
-
}));
|
|
2073
|
-
return response == null ? void 0 : response.signature;
|
|
2074
|
-
}
|
|
2075
|
-
if (method === "eth_signTypedData" || method === "eth_signTypedData_v4") {
|
|
2076
|
-
const [addressParam, typedDataParam] = params != null ? params : [];
|
|
2077
|
-
const address = typeof addressParam === "string" ? addressParam : void 0;
|
|
2078
|
-
const typedData = typeof typedDataParam === "string" ? typedDataParam : JSON.stringify(typedDataParam != null ? typedDataParam : "");
|
|
2079
|
-
const addressInfo = getSelectedAddressInfo(address);
|
|
2080
|
-
const response = await (session == null ? void 0 : session.jsonRpc.request("signTypedData", {
|
|
2081
|
-
typedData,
|
|
2082
|
-
addressInfo
|
|
2083
|
-
}));
|
|
2084
|
-
return response == null ? void 0 : response.signature;
|
|
2085
|
-
}
|
|
2086
|
-
if (method === "eth_sendTransaction") {
|
|
2087
|
-
const [txParams] = params != null ? params : [];
|
|
2088
|
-
const addressInfo = getSelectedAddressInfo(txParams == null ? void 0 : txParams.from);
|
|
2089
|
-
const response = await (session == null ? void 0 : session.jsonRpc.request("sendTransaction", {
|
|
2090
|
-
addressInfo,
|
|
2091
|
-
to: txParams == null ? void 0 : txParams.to,
|
|
2092
|
-
value: txParams == null ? void 0 : txParams.value,
|
|
2093
|
-
data: txParams == null ? void 0 : txParams.data,
|
|
2094
|
-
gas: txParams == null ? void 0 : txParams.gas,
|
|
2095
|
-
gasPrice: txParams == null ? void 0 : txParams.gasPrice,
|
|
2096
|
-
maxFeePerGas: txParams == null ? void 0 : txParams.maxFeePerGas,
|
|
2097
|
-
maxPriorityFeePerGas: txParams == null ? void 0 : txParams.maxPriorityFeePerGas,
|
|
2098
|
-
nonce: txParams == null ? void 0 : txParams.nonce,
|
|
2099
|
-
chainId: txParams == null ? void 0 : txParams.chainId
|
|
2100
|
-
}));
|
|
2101
|
-
return response == null ? void 0 : response.txHash;
|
|
2102
|
-
}
|
|
2103
|
-
if (method === "credit_connect_send_message") {
|
|
2104
|
-
if (!session) throw new Error("No active session");
|
|
2105
|
-
const [messageParam] = params != null ? params : [];
|
|
2106
|
-
const message = typeof messageParam === "string" ? messageParam : JSON.stringify(messageParam != null ? messageParam : "");
|
|
2107
|
-
await session.msg.sendMessage(message);
|
|
2108
|
-
return true;
|
|
2109
|
-
}
|
|
2110
|
-
if (method === "credit_connect_jsonrpc_ping") {
|
|
2111
|
-
if (!session) throw new Error("No active session");
|
|
2112
|
-
return await session.jsonRpc.request("pingPong", {});
|
|
2113
|
-
}
|
|
2114
|
-
throw new Error(`Unsupported provider method: ${method}`);
|
|
2115
|
-
}, "request"),
|
|
2116
|
-
on: /* @__PURE__ */ __name((event, listener) => {
|
|
2117
|
-
let listeners = providerListeners.get(event);
|
|
2118
|
-
if (!listeners) {
|
|
2119
|
-
listeners = /* @__PURE__ */ new Set();
|
|
2120
|
-
providerListeners.set(event, listeners);
|
|
2121
|
-
}
|
|
2122
|
-
listeners.add(listener);
|
|
2123
|
-
return createdProvider;
|
|
2124
|
-
}, "on"),
|
|
2125
|
-
removeListener: /* @__PURE__ */ __name((event, listener) => {
|
|
2126
|
-
var _a;
|
|
2127
|
-
(_a = providerListeners.get(event)) == null ? void 0 : _a.delete(listener);
|
|
2128
|
-
return createdProvider;
|
|
2129
|
-
}, "removeListener")
|
|
2130
|
-
};
|
|
2131
|
-
provider = createdProvider;
|
|
2132
|
-
return provider;
|
|
2133
|
-
},
|
|
2134
|
-
onAccountsChanged(accounts) {
|
|
2135
|
-
if (!accounts || accounts.length === 0) {
|
|
2136
|
-
config.emitter.emit("disconnect");
|
|
2137
|
-
return;
|
|
2138
|
-
}
|
|
2139
|
-
config.emitter.emit("change", {
|
|
2140
|
-
accounts: accounts.map(getAddress)
|
|
2141
|
-
});
|
|
2142
|
-
},
|
|
2143
|
-
onChainChanged(chainId) {
|
|
2144
|
-
const normalized = typeof chainId === "string" ? Number.parseInt(chainId, 16) : Number(chainId);
|
|
2145
|
-
if (!Number.isFinite(normalized)) return;
|
|
2146
|
-
selectedChainId = normalized;
|
|
2147
|
-
config.emitter.emit("change", {
|
|
2148
|
-
chainId: normalized
|
|
2149
|
-
});
|
|
2150
|
-
},
|
|
2151
|
-
onDisconnect() {
|
|
2152
|
-
resetState();
|
|
2153
|
-
config.emitter.emit("disconnect");
|
|
2154
|
-
}
|
|
2155
|
-
};
|
|
2156
|
-
});
|
|
2157
|
-
}, "creditConnectConnector");
|
|
1405
|
+
// src/index.ts
|
|
1406
|
+
var connectKit = {
|
|
1407
|
+
api: {
|
|
1408
|
+
readContract,
|
|
1409
|
+
writeContract,
|
|
1410
|
+
getBalance,
|
|
1411
|
+
switchChain,
|
|
1412
|
+
getPublicClient,
|
|
1413
|
+
waitForTransactionReceipt,
|
|
1414
|
+
getAccount,
|
|
1415
|
+
signMessage,
|
|
1416
|
+
signTypedData
|
|
1417
|
+
},
|
|
1418
|
+
events: {
|
|
1419
|
+
watchAccount,
|
|
1420
|
+
watchConnections,
|
|
1421
|
+
reconnect,
|
|
1422
|
+
disconnectAll
|
|
1423
|
+
}
|
|
1424
|
+
};
|
|
2158
1425
|
export {
|
|
2159
1426
|
ConnectKitProvider,
|
|
2160
1427
|
ConnectModal,
|
|
2161
|
-
|
|
1428
|
+
connectKit,
|
|
1429
|
+
initConfig,
|
|
2162
1430
|
useConnectKit
|
|
2163
1431
|
};
|