@naculus/connect-appkit-vue 0.2.4 → 0.2.6
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/README.md +38 -4
- package/dist/index.cjs +2748 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +955 -4
- package/dist/index.d.ts +955 -4
- package/dist/index.js +2773 -42
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -48,12 +58,57 @@ __export(index_exports, {
|
|
|
48
58
|
AppkitTabs: () => AppkitTabs,
|
|
49
59
|
AppkitToggleGroup: () => AppkitToggleGroup,
|
|
50
60
|
AppkitTooltip: () => AppkitTooltip,
|
|
61
|
+
useAccount: () => useAccount,
|
|
51
62
|
useAccounts: () => useAccounts,
|
|
63
|
+
useBalance: () => useBalance,
|
|
52
64
|
useCapabilities: () => useCapabilities,
|
|
53
65
|
useChain: () => useChain,
|
|
66
|
+
useCompareCosts: () => useCompareCosts,
|
|
67
|
+
useConnect: () => useConnect,
|
|
68
|
+
useCreateSessionKey: () => useCreateSessionKey,
|
|
69
|
+
useDelegation: () => useDelegation,
|
|
70
|
+
useDelegationPolicy: () => useDelegationPolicy,
|
|
71
|
+
useDisconnect: () => useDisconnect,
|
|
72
|
+
useERC20Approve: () => useERC20Approve,
|
|
73
|
+
useERC20Transfer: () => useERC20Transfer,
|
|
74
|
+
useERC20TransferSimulation: () => useERC20TransferSimulation,
|
|
75
|
+
useEmbeddedWallet: () => useEmbeddedWallet,
|
|
76
|
+
useExecuteCalls: () => useExecuteCalls,
|
|
77
|
+
useExecuteRoute: () => useExecuteRoute,
|
|
78
|
+
useLastTx: () => useLastTx,
|
|
79
|
+
useLookupAddress: () => useLookupAddress,
|
|
80
|
+
useNotification: () => useNotification,
|
|
54
81
|
usePassphraseGate: () => usePassphraseGate,
|
|
82
|
+
useResolveName: () => useResolveName,
|
|
83
|
+
useRevokeSession: () => useRevokeSession,
|
|
84
|
+
useRouteQuote: () => useRouteQuote,
|
|
85
|
+
useSIWxLogin: () => useSIWxLogin,
|
|
86
|
+
useSIWxSession: () => useSIWxSession,
|
|
87
|
+
useSendCalls: () => useSendCalls,
|
|
88
|
+
useSendTransaction: () => useSendTransaction,
|
|
89
|
+
useSendUserOperation: () => useSendUserOperation,
|
|
90
|
+
useSendWithSession: () => useSendWithSession,
|
|
91
|
+
useSession: () => useSession,
|
|
92
|
+
useSessionKeys: () => useSessionKeys,
|
|
93
|
+
useSignInWithEthereum: () => useSignInWithEthereum,
|
|
94
|
+
useSignInWithX: () => useSignInWithX,
|
|
95
|
+
useSignMessage: () => useSignMessage,
|
|
96
|
+
useSimulateTransfer: () => useSimulateTransfer,
|
|
97
|
+
useSiwxAuthSession: () => useSiwxAuthSession,
|
|
98
|
+
useSmartAccount: () => useSmartAccount,
|
|
99
|
+
useSolanaAccount: () => useSolanaAccount,
|
|
55
100
|
useSolanaBalance: () => useSolanaBalance,
|
|
56
|
-
useSolanaRoles: () => useSolanaRoles
|
|
101
|
+
useSolanaRoles: () => useSolanaRoles,
|
|
102
|
+
useSolanaTransaction: () => useSolanaTransaction,
|
|
103
|
+
useSwitchChain: () => useSwitchChain,
|
|
104
|
+
useTokenBalance: () => useTokenBalance,
|
|
105
|
+
useTokenList: () => useTokenList,
|
|
106
|
+
useTokenSearch: () => useTokenSearch,
|
|
107
|
+
useTransactionSimulation: () => useTransactionSimulation,
|
|
108
|
+
useTxHistory: () => useTxHistory,
|
|
109
|
+
useTxMonitor: () => useTxMonitor,
|
|
110
|
+
useUserOpStatus: () => useUserOpStatus,
|
|
111
|
+
useValidateDestination: () => useValidateDestination
|
|
57
112
|
});
|
|
58
113
|
module.exports = __toCommonJS(index_exports);
|
|
59
114
|
|
|
@@ -268,36 +323,2441 @@ function useAccounts(accounts) {
|
|
|
268
323
|
};
|
|
269
324
|
}
|
|
270
325
|
|
|
326
|
+
// src/useNotification.ts
|
|
327
|
+
var import_connect_appkit_core = require("@naculus/connect-appkit-core");
|
|
328
|
+
var import_connect_core2 = require("@naculus/connect-core");
|
|
329
|
+
var import_vue2 = require("vue");
|
|
330
|
+
function useNotification(options = {}) {
|
|
331
|
+
const channel = (0, import_vue2.unref)(options.channel) ?? new import_connect_core2.InAppChannel();
|
|
332
|
+
const storage = (0, import_vue2.unref)(options.storage) ?? (0, import_connect_appkit_core.createNotificationSettingsStorage)();
|
|
333
|
+
const notifications = (0, import_vue2.shallowRef)(channel.getHistory());
|
|
334
|
+
const settings = (0, import_vue2.shallowRef)(
|
|
335
|
+
import_connect_appkit_core.DEFAULT_NOTIFICATION_SETTINGS
|
|
336
|
+
);
|
|
337
|
+
const unreadCount = (0, import_vue2.computed)(
|
|
338
|
+
() => notifications.value.filter((item) => !item.read).length
|
|
339
|
+
);
|
|
340
|
+
let disposed = false;
|
|
341
|
+
void (0, import_connect_appkit_core.loadNotificationSettings)(storage).then((saved) => {
|
|
342
|
+
if (!disposed && saved) settings.value = saved;
|
|
343
|
+
});
|
|
344
|
+
channel.onNotification = (item) => {
|
|
345
|
+
if (!disposed) notifications.value = [...notifications.value, item];
|
|
346
|
+
};
|
|
347
|
+
void channel.restore().then(() => {
|
|
348
|
+
if (!disposed) notifications.value = channel.getHistory();
|
|
349
|
+
});
|
|
350
|
+
(0, import_vue2.onScopeDispose)(() => {
|
|
351
|
+
disposed = true;
|
|
352
|
+
channel.onNotification = void 0;
|
|
353
|
+
});
|
|
354
|
+
const updateSettings = (update) => {
|
|
355
|
+
settings.value = (0, import_connect_appkit_core.updateNotificationSettings)(settings.value, update);
|
|
356
|
+
(0, import_connect_appkit_core.saveNotificationSettings)(storage, settings.value);
|
|
357
|
+
};
|
|
358
|
+
return {
|
|
359
|
+
notifications,
|
|
360
|
+
unreadCount,
|
|
361
|
+
settings,
|
|
362
|
+
addNotification: (item) => (0, import_connect_appkit_core.addInAppNotification)(channel, item),
|
|
363
|
+
clear: () => {
|
|
364
|
+
channel.clear();
|
|
365
|
+
notifications.value = [];
|
|
366
|
+
},
|
|
367
|
+
clearOne: (id) => {
|
|
368
|
+
void (0, import_connect_appkit_core.clearOneInAppNotification)(channel, id).then(() => {
|
|
369
|
+
if (!disposed) notifications.value = channel.getHistory();
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
markAsRead: (id) => {
|
|
373
|
+
channel.markAsRead(id);
|
|
374
|
+
notifications.value = notifications.value.map(
|
|
375
|
+
(item) => item.id === id ? { ...item, read: true } : item
|
|
376
|
+
);
|
|
377
|
+
},
|
|
378
|
+
markAllAsRead: () => {
|
|
379
|
+
channel.markAllAsRead();
|
|
380
|
+
notifications.value = notifications.value.map((item) => ({
|
|
381
|
+
...item,
|
|
382
|
+
read: true
|
|
383
|
+
}));
|
|
384
|
+
},
|
|
385
|
+
updateSettings,
|
|
386
|
+
setChannels: (channels) => updateSettings((0, import_connect_appkit_core.channelsUpdate)(channels)),
|
|
387
|
+
muteChain: (chainId) => updateSettings((0, import_connect_appkit_core.mutedChainSettings)(settings.value, chainId, true)),
|
|
388
|
+
unmuteChain: (chainId) => updateSettings((0, import_connect_appkit_core.mutedChainSettings)(settings.value, chainId, false))
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/useSimulateTransfer.ts
|
|
393
|
+
var import_connect_appkit_core2 = require("@naculus/connect-appkit-core");
|
|
394
|
+
var import_connect_core3 = require("@naculus/connect-core");
|
|
395
|
+
var import_vue3 = require("vue");
|
|
396
|
+
function useSimulateTransfer(options = {}) {
|
|
397
|
+
const result = (0, import_vue3.shallowRef)(null);
|
|
398
|
+
const loading = (0, import_vue3.shallowRef)(false);
|
|
399
|
+
const error = (0, import_vue3.shallowRef)(null);
|
|
400
|
+
let manager;
|
|
401
|
+
let generation = 0;
|
|
402
|
+
let disposed = false;
|
|
403
|
+
const simulate = async (tokenAddress, from, to, amount, callOptions) => {
|
|
404
|
+
const own = ++generation;
|
|
405
|
+
loading.value = true;
|
|
406
|
+
error.value = null;
|
|
407
|
+
try {
|
|
408
|
+
const fallbackRpcUrl = (0, import_vue3.unref)(options.rpcUrl);
|
|
409
|
+
const endpoint = (0, import_connect_appkit_core2.resolveSimulationEndpoint)(
|
|
410
|
+
callOptions?.chainId,
|
|
411
|
+
(0, import_vue3.unref)(options.chainId),
|
|
412
|
+
callOptions?.rpcUrl,
|
|
413
|
+
fallbackRpcUrl
|
|
414
|
+
);
|
|
415
|
+
manager ??= new import_connect_core3.SimulationManager({
|
|
416
|
+
enabled: true,
|
|
417
|
+
rpcUrl: fallbackRpcUrl,
|
|
418
|
+
autoSimulate: false
|
|
419
|
+
});
|
|
420
|
+
const value = await manager.simulateERC20Transfer(
|
|
421
|
+
tokenAddress,
|
|
422
|
+
from,
|
|
423
|
+
to,
|
|
424
|
+
amount,
|
|
425
|
+
endpoint.chainId,
|
|
426
|
+
callOptions?.decimals,
|
|
427
|
+
endpoint.rpcUrl
|
|
428
|
+
);
|
|
429
|
+
if (!disposed && own === generation) result.value = value;
|
|
430
|
+
return value;
|
|
431
|
+
} catch (cause) {
|
|
432
|
+
const normalized = cause instanceof Error ? cause : new Error(String(cause));
|
|
433
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
434
|
+
throw normalized;
|
|
435
|
+
} finally {
|
|
436
|
+
if (!disposed && own === generation) loading.value = false;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
const reset = () => {
|
|
440
|
+
generation++;
|
|
441
|
+
result.value = null;
|
|
442
|
+
error.value = null;
|
|
443
|
+
loading.value = false;
|
|
444
|
+
};
|
|
445
|
+
(0, import_vue3.onScopeDispose)(() => {
|
|
446
|
+
disposed = true;
|
|
447
|
+
generation++;
|
|
448
|
+
});
|
|
449
|
+
return { result, loading, error, simulate, reset };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/useTransactionSimulation.ts
|
|
453
|
+
var import_connect_appkit_core3 = require("@naculus/connect-appkit-core");
|
|
454
|
+
var import_vue4 = require("vue");
|
|
455
|
+
function useTransactionSimulation(tx, options = {}) {
|
|
456
|
+
const result = (0, import_vue4.shallowRef)(void 0);
|
|
457
|
+
const isSimulating = (0, import_vue4.shallowRef)(false);
|
|
458
|
+
const error = (0, import_vue4.shallowRef)(null);
|
|
459
|
+
let timer;
|
|
460
|
+
let generation = 0;
|
|
461
|
+
let disposed = false;
|
|
462
|
+
const simulate = async () => {
|
|
463
|
+
const own = ++generation;
|
|
464
|
+
const transaction = (0, import_vue4.toValue)(tx);
|
|
465
|
+
if (transaction) {
|
|
466
|
+
isSimulating.value = true;
|
|
467
|
+
error.value = null;
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
const value = await (0, import_connect_appkit_core3.simulateTransactionPreview)(transaction, {
|
|
471
|
+
chainId: (0, import_vue4.unref)(options.chainId),
|
|
472
|
+
currentChain: (0, import_vue4.unref)(options.currentChain),
|
|
473
|
+
publicClient: (0, import_vue4.unref)(options.publicClient),
|
|
474
|
+
evmAccount: (0, import_vue4.unref)(options.evmAccount)
|
|
475
|
+
});
|
|
476
|
+
if (!disposed && own === generation) result.value = value;
|
|
477
|
+
return value;
|
|
478
|
+
} catch (cause) {
|
|
479
|
+
const normalized = cause instanceof Error ? cause : new Error("Simulation failed");
|
|
480
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
481
|
+
throw normalized;
|
|
482
|
+
} finally {
|
|
483
|
+
if (transaction && !disposed && own === generation)
|
|
484
|
+
isSimulating.value = false;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
(0, import_vue4.watch)(
|
|
488
|
+
[
|
|
489
|
+
() => (0, import_vue4.toValue)(tx),
|
|
490
|
+
() => (0, import_vue4.unref)(options.chainId),
|
|
491
|
+
() => (0, import_vue4.unref)(options.currentChain),
|
|
492
|
+
() => (0, import_vue4.unref)(options.publicClient),
|
|
493
|
+
() => (0, import_vue4.unref)(options.evmAccount)
|
|
494
|
+
],
|
|
495
|
+
([transaction]) => {
|
|
496
|
+
generation++;
|
|
497
|
+
if (timer) clearTimeout(timer);
|
|
498
|
+
if (!transaction) return;
|
|
499
|
+
timer = setTimeout(() => {
|
|
500
|
+
timer = void 0;
|
|
501
|
+
void simulate().catch(() => {
|
|
502
|
+
});
|
|
503
|
+
}, 300);
|
|
504
|
+
},
|
|
505
|
+
{ immediate: true }
|
|
506
|
+
);
|
|
507
|
+
const reset = () => {
|
|
508
|
+
generation++;
|
|
509
|
+
result.value = void 0;
|
|
510
|
+
error.value = null;
|
|
511
|
+
isSimulating.value = false;
|
|
512
|
+
};
|
|
513
|
+
(0, import_vue4.onScopeDispose)(() => {
|
|
514
|
+
disposed = true;
|
|
515
|
+
generation++;
|
|
516
|
+
if (timer) clearTimeout(timer);
|
|
517
|
+
});
|
|
518
|
+
return { result, isSimulating, error, simulate, reset };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// src/useERC20Transfer.ts
|
|
522
|
+
var import_connect_appkit_core5 = require("@naculus/connect-appkit-core");
|
|
523
|
+
var import_connect_core5 = require("@naculus/connect-core");
|
|
524
|
+
var import_vue5 = require("vue");
|
|
525
|
+
|
|
526
|
+
// src/erc20.ts
|
|
527
|
+
var import_connect_appkit_core4 = require("@naculus/connect-appkit-core");
|
|
528
|
+
var import_connect_core4 = require("@naculus/connect-core");
|
|
529
|
+
function assertErc20Context(token, chainId, account, connected) {
|
|
530
|
+
if (!connected || !account) {
|
|
531
|
+
throw new import_connect_core4.WalletError("wallet_unavailable", "No connected account");
|
|
532
|
+
}
|
|
533
|
+
const mismatch = (0, import_connect_appkit_core4.tokenChainMismatch)(token, chainId);
|
|
534
|
+
if (mismatch) throw mismatch;
|
|
535
|
+
const bare = (0, import_connect_appkit_core4.bareEvmAddress)(account);
|
|
536
|
+
if (!bare) {
|
|
537
|
+
throw new import_connect_core4.WalletError("wallet_unavailable", "No valid EVM account");
|
|
538
|
+
}
|
|
539
|
+
return bare;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/useERC20Transfer.ts
|
|
543
|
+
function useERC20Transfer(options) {
|
|
544
|
+
const initialToken = (0, import_vue5.toValue)(options.token);
|
|
545
|
+
const decimals = (0, import_connect_appkit_core5.createDecimalsCache)(initialToken, initialToken.decimals);
|
|
546
|
+
const isSending = (0, import_vue5.shallowRef)(false);
|
|
547
|
+
const error = (0, import_vue5.shallowRef)(null);
|
|
548
|
+
let generation = 0;
|
|
549
|
+
let disposed = false;
|
|
550
|
+
(0, import_vue5.watch)(
|
|
551
|
+
[
|
|
552
|
+
() => (0, import_vue5.toValue)(options.token).address,
|
|
553
|
+
() => (0, import_vue5.toValue)(options.token).chainId,
|
|
554
|
+
() => (0, import_vue5.toValue)(options.token).decimals,
|
|
555
|
+
() => (0, import_vue5.toValue)(options.account),
|
|
556
|
+
() => (0, import_vue5.toValue)(options.chainId),
|
|
557
|
+
() => (0, import_vue5.toValue)(options.connected),
|
|
558
|
+
() => (0, import_vue5.toValue)(options.publicClient),
|
|
559
|
+
() => (0, import_vue5.unref)(options.sendTransaction)
|
|
560
|
+
],
|
|
561
|
+
() => {
|
|
562
|
+
generation++;
|
|
563
|
+
isSending.value = false;
|
|
564
|
+
error.value = null;
|
|
565
|
+
},
|
|
566
|
+
{ flush: "sync" }
|
|
567
|
+
);
|
|
568
|
+
const sendTransfer = async (to, amount) => {
|
|
569
|
+
const own = ++generation;
|
|
570
|
+
const token = (0, import_vue5.toValue)(options.token);
|
|
571
|
+
const reader = (0, import_vue5.toValue)(options.publicClient);
|
|
572
|
+
const stillCurrent = () => !disposed && own === generation;
|
|
573
|
+
error.value = null;
|
|
574
|
+
isSending.value = true;
|
|
575
|
+
try {
|
|
576
|
+
assertErc20Context(
|
|
577
|
+
token,
|
|
578
|
+
(0, import_vue5.toValue)(options.chainId),
|
|
579
|
+
(0, import_vue5.toValue)(options.account),
|
|
580
|
+
(0, import_vue5.toValue)(options.connected)
|
|
581
|
+
);
|
|
582
|
+
if (!reader) {
|
|
583
|
+
throw new import_connect_core5.WalletError(
|
|
584
|
+
"wallet_unavailable",
|
|
585
|
+
"No public client available"
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
let precision = (0, import_connect_appkit_core5.readDecimals)(decimals, token, token.decimals);
|
|
589
|
+
if (precision === void 0) {
|
|
590
|
+
precision = Number(
|
|
591
|
+
await reader.readContract({
|
|
592
|
+
address: token.address,
|
|
593
|
+
abi: import_connect_core5.ERC20_MIN_ABI,
|
|
594
|
+
functionName: "decimals"
|
|
595
|
+
})
|
|
596
|
+
);
|
|
597
|
+
if (!stillCurrent()) {
|
|
598
|
+
throw new import_connect_core5.WalletError(
|
|
599
|
+
"session_inactive",
|
|
600
|
+
"Wallet or token context changed. Retry the transfer."
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
(0, import_connect_appkit_core5.writeDecimals)(decimals, token, precision);
|
|
604
|
+
}
|
|
605
|
+
const data = (0, import_connect_appkit_core5.encodeErc20Transfer)(to, (0, import_connect_core5.parseUnits)(amount, precision));
|
|
606
|
+
return await (0, import_vue5.unref)(options.sendTransaction)({
|
|
607
|
+
to: token.address,
|
|
608
|
+
data,
|
|
609
|
+
value: "0"
|
|
610
|
+
});
|
|
611
|
+
} catch (cause) {
|
|
612
|
+
const normalized = cause instanceof Error ? cause : new Error("Transfer failed");
|
|
613
|
+
if (stillCurrent()) error.value = normalized;
|
|
614
|
+
throw normalized;
|
|
615
|
+
} finally {
|
|
616
|
+
if (stillCurrent()) isSending.value = false;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
(0, import_vue5.onScopeDispose)(() => {
|
|
620
|
+
disposed = true;
|
|
621
|
+
generation++;
|
|
622
|
+
});
|
|
623
|
+
return { sendTransfer, isSending, error };
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/useERC20Approve.ts
|
|
627
|
+
var import_connect_appkit_core6 = require("@naculus/connect-appkit-core");
|
|
628
|
+
var import_connect_core6 = require("@naculus/connect-core");
|
|
629
|
+
var import_vue6 = require("vue");
|
|
630
|
+
var MAX_UINT256 = (1n << 256n) - 1n;
|
|
631
|
+
function useERC20Approve(options) {
|
|
632
|
+
const initialToken = (0, import_vue6.toValue)(options.token);
|
|
633
|
+
const decimals = (0, import_connect_appkit_core6.createDecimalsCache)(initialToken, initialToken.decimals);
|
|
634
|
+
const allowanceRaw = (0, import_vue6.shallowRef)(null);
|
|
635
|
+
const isApproving = (0, import_vue6.shallowRef)(false);
|
|
636
|
+
const isFetchingAllowance = (0, import_vue6.shallowRef)(false);
|
|
637
|
+
const error = (0, import_vue6.shallowRef)(null);
|
|
638
|
+
let generation = 0;
|
|
639
|
+
let allowanceGeneration = 0;
|
|
640
|
+
let disposed = false;
|
|
641
|
+
(0, import_vue6.watch)(
|
|
642
|
+
[
|
|
643
|
+
() => (0, import_vue6.toValue)(options.token).address,
|
|
644
|
+
() => (0, import_vue6.toValue)(options.token).chainId,
|
|
645
|
+
() => (0, import_vue6.toValue)(options.token).decimals,
|
|
646
|
+
() => (0, import_vue6.toValue)(options.spender),
|
|
647
|
+
() => (0, import_vue6.toValue)(options.account),
|
|
648
|
+
() => (0, import_vue6.toValue)(options.chainId),
|
|
649
|
+
() => (0, import_vue6.toValue)(options.connected),
|
|
650
|
+
() => (0, import_vue6.toValue)(options.publicClient),
|
|
651
|
+
() => (0, import_vue6.unref)(options.sendTransaction)
|
|
652
|
+
],
|
|
653
|
+
() => {
|
|
654
|
+
generation++;
|
|
655
|
+
allowanceGeneration++;
|
|
656
|
+
allowanceRaw.value = null;
|
|
657
|
+
isApproving.value = false;
|
|
658
|
+
isFetchingAllowance.value = false;
|
|
659
|
+
error.value = null;
|
|
660
|
+
},
|
|
661
|
+
{ flush: "sync" }
|
|
662
|
+
);
|
|
663
|
+
const context = () => {
|
|
664
|
+
const token = (0, import_vue6.toValue)(options.token);
|
|
665
|
+
const account = assertErc20Context(
|
|
666
|
+
token,
|
|
667
|
+
(0, import_vue6.toValue)(options.chainId),
|
|
668
|
+
(0, import_vue6.toValue)(options.account),
|
|
669
|
+
(0, import_vue6.toValue)(options.connected)
|
|
670
|
+
);
|
|
671
|
+
const reader = (0, import_vue6.toValue)(options.publicClient);
|
|
672
|
+
if (!reader)
|
|
673
|
+
throw new import_connect_core6.WalletError("wallet_unavailable", "No public client");
|
|
674
|
+
return { token, account, reader, spender: (0, import_vue6.toValue)(options.spender) };
|
|
675
|
+
};
|
|
676
|
+
const readPrecision = async () => {
|
|
677
|
+
const { token, reader } = context();
|
|
678
|
+
let precision = (0, import_connect_appkit_core6.readDecimals)(decimals, token, token.decimals);
|
|
679
|
+
if (precision === void 0) {
|
|
680
|
+
precision = Number(
|
|
681
|
+
await reader.readContract({
|
|
682
|
+
address: token.address,
|
|
683
|
+
abi: import_connect_core6.ERC20_MIN_ABI,
|
|
684
|
+
functionName: "decimals"
|
|
685
|
+
})
|
|
686
|
+
);
|
|
687
|
+
(0, import_connect_appkit_core6.writeDecimals)(decimals, token, precision);
|
|
688
|
+
}
|
|
689
|
+
return precision;
|
|
690
|
+
};
|
|
691
|
+
const refetchAllowance = async () => {
|
|
692
|
+
const own = ++allowanceGeneration;
|
|
693
|
+
allowanceRaw.value = null;
|
|
694
|
+
error.value = null;
|
|
695
|
+
isFetchingAllowance.value = true;
|
|
696
|
+
try {
|
|
697
|
+
const { token, account, reader, spender } = context();
|
|
698
|
+
const raw = BigInt(
|
|
699
|
+
await reader.readContract({
|
|
700
|
+
address: token.address,
|
|
701
|
+
abi: import_connect_core6.ERC20_MIN_ABI,
|
|
702
|
+
functionName: "allowance",
|
|
703
|
+
args: [account, spender]
|
|
704
|
+
})
|
|
705
|
+
);
|
|
706
|
+
if (disposed || own !== allowanceGeneration) return null;
|
|
707
|
+
allowanceRaw.value = raw;
|
|
708
|
+
return raw;
|
|
709
|
+
} catch (cause) {
|
|
710
|
+
if (!disposed && own === allowanceGeneration) {
|
|
711
|
+
error.value = cause instanceof Error ? cause : new Error("Failed to fetch allowance");
|
|
712
|
+
}
|
|
713
|
+
return null;
|
|
714
|
+
} finally {
|
|
715
|
+
if (!disposed && own === allowanceGeneration)
|
|
716
|
+
isFetchingAllowance.value = false;
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
const doApprove = async (rawAmount) => {
|
|
720
|
+
const own = ++generation;
|
|
721
|
+
error.value = null;
|
|
722
|
+
isApproving.value = true;
|
|
723
|
+
try {
|
|
724
|
+
const { token, spender } = context();
|
|
725
|
+
const hash = await (0, import_vue6.unref)(options.sendTransaction)({
|
|
726
|
+
to: token.address,
|
|
727
|
+
data: (0, import_connect_appkit_core6.encodeErc20Approve)(spender, rawAmount),
|
|
728
|
+
value: "0"
|
|
729
|
+
});
|
|
730
|
+
if (!disposed && own === generation) void refetchAllowance();
|
|
731
|
+
return hash;
|
|
732
|
+
} catch (cause) {
|
|
733
|
+
const normalized = cause instanceof Error ? cause : new Error("Approve failed");
|
|
734
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
735
|
+
throw normalized;
|
|
736
|
+
} finally {
|
|
737
|
+
if (!disposed && own === generation) isApproving.value = false;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
const approve = async (amount) => {
|
|
741
|
+
const contextGeneration = generation;
|
|
742
|
+
let rawAmount;
|
|
743
|
+
try {
|
|
744
|
+
const precision = await readPrecision();
|
|
745
|
+
if (contextGeneration !== generation || disposed) {
|
|
746
|
+
throw new import_connect_core6.WalletError(
|
|
747
|
+
"session_inactive",
|
|
748
|
+
"Wallet or token context changed. Retry the approval."
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
rawAmount = (0, import_connect_core6.parseUnits)(amount, precision);
|
|
752
|
+
} catch (cause) {
|
|
753
|
+
const normalized = cause instanceof Error ? cause : new Error("Approve failed");
|
|
754
|
+
if (!disposed && contextGeneration === generation)
|
|
755
|
+
error.value = normalized;
|
|
756
|
+
throw normalized;
|
|
757
|
+
}
|
|
758
|
+
return doApprove(rawAmount);
|
|
759
|
+
};
|
|
760
|
+
const approveMax = () => doApprove(MAX_UINT256);
|
|
761
|
+
const hasAllowance = async (required) => {
|
|
762
|
+
const raw = allowanceRaw.value ?? await refetchAllowance();
|
|
763
|
+
if (raw === null) return false;
|
|
764
|
+
return raw >= (0, import_connect_core6.parseUnits)(required, await readPrecision());
|
|
765
|
+
};
|
|
766
|
+
const allowance = (0, import_vue6.computed)(() => {
|
|
767
|
+
if (allowanceRaw.value === null) return null;
|
|
768
|
+
const token = (0, import_vue6.toValue)(options.token);
|
|
769
|
+
const precision = (0, import_connect_appkit_core6.readDecimals)(decimals, token, token.decimals);
|
|
770
|
+
return precision === void 0 ? null : (0, import_connect_core6.formatUnits)(allowanceRaw.value, precision);
|
|
771
|
+
});
|
|
772
|
+
(0, import_vue6.onScopeDispose)(() => {
|
|
773
|
+
disposed = true;
|
|
774
|
+
generation++;
|
|
775
|
+
allowanceGeneration++;
|
|
776
|
+
});
|
|
777
|
+
return {
|
|
778
|
+
approve,
|
|
779
|
+
approveMax,
|
|
780
|
+
allowanceRaw,
|
|
781
|
+
allowance,
|
|
782
|
+
hasAllowance,
|
|
783
|
+
isApproving,
|
|
784
|
+
isFetchingAllowance,
|
|
785
|
+
error,
|
|
786
|
+
refetchAllowance
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// src/useERC20TransferSimulation.ts
|
|
791
|
+
var import_connect_appkit_core7 = require("@naculus/connect-appkit-core");
|
|
792
|
+
var import_connect_core7 = require("@naculus/connect-core");
|
|
793
|
+
var import_vue7 = require("vue");
|
|
794
|
+
function useERC20TransferSimulation(options) {
|
|
795
|
+
const transaction = (0, import_vue7.computed)(() => {
|
|
796
|
+
const token = (0, import_vue7.toValue)(options.token);
|
|
797
|
+
if (!(0, import_vue7.toValue)(options.connected) || !(0, import_vue7.toValue)(options.evmAccount))
|
|
798
|
+
return void 0;
|
|
799
|
+
try {
|
|
800
|
+
if (token.decimals === void 0) return void 0;
|
|
801
|
+
return {
|
|
802
|
+
to: token.address,
|
|
803
|
+
data: (0, import_connect_appkit_core7.encodeErc20Transfer)(
|
|
804
|
+
(0, import_vue7.toValue)(options.to),
|
|
805
|
+
(0, import_connect_core7.parseUnits)((0, import_vue7.toValue)(options.amount), token.decimals)
|
|
806
|
+
),
|
|
807
|
+
value: "0"
|
|
808
|
+
};
|
|
809
|
+
} catch {
|
|
810
|
+
return void 0;
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
const chainId = (0, import_vue7.computed)(() => {
|
|
814
|
+
const token = (0, import_vue7.toValue)(options.token);
|
|
815
|
+
if (token.chainId !== void 0) return token.chainId;
|
|
816
|
+
const currentChain = (0, import_vue7.toValue)(options.currentChain);
|
|
817
|
+
return currentChain ? (0, import_connect_appkit_core7.chainNumber)(currentChain) ?? void 0 : void 0;
|
|
818
|
+
});
|
|
819
|
+
const simulation = useTransactionSimulation(transaction, {
|
|
820
|
+
chainId,
|
|
821
|
+
currentChain: options.currentChain,
|
|
822
|
+
publicClient: options.publicClient,
|
|
823
|
+
evmAccount: options.evmAccount
|
|
824
|
+
});
|
|
825
|
+
return {
|
|
826
|
+
result: (0, import_vue7.computed)(
|
|
827
|
+
() => transaction.value ? simulation.result.value : void 0
|
|
828
|
+
),
|
|
829
|
+
isSimulating: (0, import_vue7.computed)(
|
|
830
|
+
() => !!transaction.value && simulation.isSimulating.value
|
|
831
|
+
),
|
|
832
|
+
error: (0, import_vue7.computed)(() => transaction.value ? simulation.error.value : null),
|
|
833
|
+
reSimulate: simulation.simulate,
|
|
834
|
+
reset: simulation.reset
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// src/useAccount.ts
|
|
839
|
+
var import_vue8 = require("vue");
|
|
840
|
+
function useAccount(accounts, connected) {
|
|
841
|
+
const parsed = useAccounts(accounts);
|
|
842
|
+
const isConnected = (0, import_vue8.computed)(() => (0, import_vue8.toValue)(connected));
|
|
843
|
+
const accountList = (0, import_vue8.computed)(() => (0, import_vue8.toValue)(accounts) ?? []);
|
|
844
|
+
return {
|
|
845
|
+
accounts: (0, import_vue8.computed)(
|
|
846
|
+
() => isConnected.value && accountList.value.length > 0 ? parsed.accounts.value : null
|
|
847
|
+
),
|
|
848
|
+
evmAccount: (0, import_vue8.computed)(
|
|
849
|
+
() => isConnected.value ? parsed.evmAccount.value : null
|
|
850
|
+
),
|
|
851
|
+
primaryAccount: (0, import_vue8.computed)(() => accountList.value[0] ?? null),
|
|
852
|
+
isConnected,
|
|
853
|
+
count: (0, import_vue8.computed)(() => accountList.value.length)
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// src/useSession.ts
|
|
858
|
+
var import_vue9 = require("vue");
|
|
859
|
+
function readSession(manager) {
|
|
860
|
+
const bundle = manager?.getActiveBundle();
|
|
861
|
+
if (!bundle) {
|
|
862
|
+
return {
|
|
863
|
+
session: null,
|
|
864
|
+
chainSessions: [],
|
|
865
|
+
activeChainId: null,
|
|
866
|
+
connectorId: null
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
session: bundle.walletSession,
|
|
871
|
+
chainSessions: Array.from(bundle.chainSessions.values()),
|
|
872
|
+
activeChainId: bundle.activeChainId,
|
|
873
|
+
connectorId: bundle.walletSession.walletType
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
function useSession(manager) {
|
|
877
|
+
const snapshot = (0, import_vue9.shallowRef)(readSession((0, import_vue9.toValue)(manager)));
|
|
878
|
+
(0, import_vue9.watch)(
|
|
879
|
+
() => (0, import_vue9.toValue)(manager),
|
|
880
|
+
(current, _previous, onCleanup) => {
|
|
881
|
+
const update = () => {
|
|
882
|
+
snapshot.value = readSession(current);
|
|
883
|
+
};
|
|
884
|
+
update();
|
|
885
|
+
if (!current) return;
|
|
886
|
+
current.on("sessionConnected", update);
|
|
887
|
+
current.on("sessionDisconnected", update);
|
|
888
|
+
current.on("chainChanged", update);
|
|
889
|
+
onCleanup(() => {
|
|
890
|
+
current.off("sessionConnected", update);
|
|
891
|
+
current.off("sessionDisconnected", update);
|
|
892
|
+
current.off("chainChanged", update);
|
|
893
|
+
});
|
|
894
|
+
},
|
|
895
|
+
{ immediate: true }
|
|
896
|
+
);
|
|
897
|
+
return {
|
|
898
|
+
session: (0, import_vue9.computed)(() => snapshot.value.session),
|
|
899
|
+
chainSessions: (0, import_vue9.computed)(() => snapshot.value.chainSessions),
|
|
900
|
+
activeChainId: (0, import_vue9.computed)(() => snapshot.value.activeChainId),
|
|
901
|
+
isConnected: (0, import_vue9.computed)(() => snapshot.value.session !== null),
|
|
902
|
+
connectorId: (0, import_vue9.computed)(() => snapshot.value.connectorId)
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// src/useConnect.ts
|
|
907
|
+
var import_connect_core8 = require("@naculus/connect-core");
|
|
908
|
+
var import_vue10 = require("vue");
|
|
909
|
+
function useConnect(action, status) {
|
|
910
|
+
const isLoading = (0, import_vue10.shallowRef)(false);
|
|
911
|
+
const error = (0, import_vue10.shallowRef)(null);
|
|
912
|
+
let disposed = false;
|
|
913
|
+
let inFlight = null;
|
|
914
|
+
const connect = () => {
|
|
915
|
+
if (inFlight) return inFlight;
|
|
916
|
+
const invoke = (0, import_vue10.unref)(action);
|
|
917
|
+
isLoading.value = true;
|
|
918
|
+
error.value = null;
|
|
919
|
+
const pending = Promise.resolve().then(() => invoke()).catch((cause) => {
|
|
920
|
+
if (disposed) return;
|
|
921
|
+
const message = cause instanceof Error ? cause.message : "Connection failed";
|
|
922
|
+
error.value = cause instanceof import_connect_core8.WalletError ? cause : new Error(message);
|
|
923
|
+
}).finally(() => {
|
|
924
|
+
if (inFlight === pending) inFlight = null;
|
|
925
|
+
if (!disposed) isLoading.value = false;
|
|
926
|
+
});
|
|
927
|
+
inFlight = pending;
|
|
928
|
+
return pending;
|
|
929
|
+
};
|
|
930
|
+
(0, import_vue10.onScopeDispose)(() => {
|
|
931
|
+
disposed = true;
|
|
932
|
+
});
|
|
933
|
+
return {
|
|
934
|
+
connect,
|
|
935
|
+
isConnecting: (0, import_vue10.computed)(
|
|
936
|
+
() => isLoading.value || (0, import_vue10.toValue)(status) === "connecting"
|
|
937
|
+
),
|
|
938
|
+
error
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// src/useDisconnect.ts
|
|
943
|
+
var import_vue11 = require("vue");
|
|
944
|
+
function useDisconnect(action, status) {
|
|
945
|
+
const isDisconnecting = (0, import_vue11.shallowRef)(false);
|
|
946
|
+
const error = (0, import_vue11.shallowRef)(null);
|
|
947
|
+
let disposed = false;
|
|
948
|
+
let inFlight = null;
|
|
949
|
+
const disconnect = () => {
|
|
950
|
+
if (inFlight) return inFlight;
|
|
951
|
+
if ((0, import_vue11.toValue)(status) === "disconnected") return Promise.resolve();
|
|
952
|
+
const invoke = (0, import_vue11.unref)(action);
|
|
953
|
+
isDisconnecting.value = true;
|
|
954
|
+
error.value = null;
|
|
955
|
+
const pending = Promise.resolve().then(() => invoke()).catch((cause) => {
|
|
956
|
+
if (!disposed) {
|
|
957
|
+
error.value = cause instanceof Error ? cause : new Error("Disconnect failed");
|
|
958
|
+
}
|
|
959
|
+
}).finally(() => {
|
|
960
|
+
if (inFlight === pending) inFlight = null;
|
|
961
|
+
if (!disposed) isDisconnecting.value = false;
|
|
962
|
+
});
|
|
963
|
+
inFlight = pending;
|
|
964
|
+
return pending;
|
|
965
|
+
};
|
|
966
|
+
const cleanup = () => {
|
|
967
|
+
disposed = true;
|
|
968
|
+
};
|
|
969
|
+
(0, import_vue11.onScopeDispose)(cleanup);
|
|
970
|
+
return { disconnect, isDisconnecting, error, cleanup };
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// src/useSwitchChain.ts
|
|
974
|
+
var import_connect_appkit_core8 = require("@naculus/connect-appkit-core");
|
|
975
|
+
var import_vue12 = require("vue");
|
|
976
|
+
function useSwitchChain(action, chainId) {
|
|
977
|
+
const isSwitching = (0, import_vue12.shallowRef)(false);
|
|
978
|
+
const error = (0, import_vue12.shallowRef)(null);
|
|
979
|
+
let generation = 0;
|
|
980
|
+
let active = 0;
|
|
981
|
+
let disposed = false;
|
|
982
|
+
const switchChain = async (targetChainId) => {
|
|
983
|
+
const invoke = (0, import_vue12.unref)(action);
|
|
984
|
+
const mine = ++generation;
|
|
985
|
+
active++;
|
|
986
|
+
isSwitching.value = true;
|
|
987
|
+
error.value = null;
|
|
988
|
+
try {
|
|
989
|
+
await invoke(targetChainId);
|
|
990
|
+
} catch (cause) {
|
|
991
|
+
const walletError = (0, import_connect_appkit_core8.toChainSwitchError)(cause);
|
|
992
|
+
if (!disposed && mine === generation) error.value = walletError;
|
|
993
|
+
throw walletError;
|
|
994
|
+
} finally {
|
|
995
|
+
active--;
|
|
996
|
+
if (!disposed) isSwitching.value = active > 0;
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
(0, import_vue12.onScopeDispose)(() => {
|
|
1000
|
+
disposed = true;
|
|
1001
|
+
generation++;
|
|
1002
|
+
});
|
|
1003
|
+
return {
|
|
1004
|
+
switchChain,
|
|
1005
|
+
isSwitching,
|
|
1006
|
+
currentChainId: (0, import_vue12.computed)(() => (0, import_vue12.toValue)(chainId) ?? null),
|
|
1007
|
+
error,
|
|
1008
|
+
clearError: () => {
|
|
1009
|
+
error.value = null;
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// src/useSignMessage.ts
|
|
1015
|
+
var import_vue13 = require("vue");
|
|
1016
|
+
function useSignMessage(action) {
|
|
1017
|
+
const isSigning = (0, import_vue13.shallowRef)(false);
|
|
1018
|
+
const error = (0, import_vue13.shallowRef)(null);
|
|
1019
|
+
let active = 0;
|
|
1020
|
+
let generation = 0;
|
|
1021
|
+
let disposed = false;
|
|
1022
|
+
const signMessage = async (message) => {
|
|
1023
|
+
const invoke = (0, import_vue13.unref)(action);
|
|
1024
|
+
const own = ++generation;
|
|
1025
|
+
active++;
|
|
1026
|
+
isSigning.value = true;
|
|
1027
|
+
error.value = null;
|
|
1028
|
+
try {
|
|
1029
|
+
return await invoke(message);
|
|
1030
|
+
} catch (cause) {
|
|
1031
|
+
const normalized = cause instanceof Error ? cause : new Error("Signing failed");
|
|
1032
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1033
|
+
throw normalized;
|
|
1034
|
+
} finally {
|
|
1035
|
+
active--;
|
|
1036
|
+
if (!disposed) isSigning.value = active > 0;
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
const reset = () => {
|
|
1040
|
+
generation++;
|
|
1041
|
+
error.value = null;
|
|
1042
|
+
};
|
|
1043
|
+
(0, import_vue13.onScopeDispose)(() => {
|
|
1044
|
+
disposed = true;
|
|
1045
|
+
generation++;
|
|
1046
|
+
});
|
|
1047
|
+
return { signMessage, isSigning, error, reset };
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// src/useSendTransaction.ts
|
|
1051
|
+
var import_vue14 = require("vue");
|
|
1052
|
+
function useSendTransaction(action) {
|
|
1053
|
+
const status = (0, import_vue14.shallowRef)("idle");
|
|
1054
|
+
const error = (0, import_vue14.shallowRef)(null);
|
|
1055
|
+
let generation = 0;
|
|
1056
|
+
let disposed = false;
|
|
1057
|
+
const sendTransaction = async (transaction) => {
|
|
1058
|
+
const invoke = (0, import_vue14.unref)(action);
|
|
1059
|
+
const own = ++generation;
|
|
1060
|
+
status.value = "awaiting_approval";
|
|
1061
|
+
error.value = null;
|
|
1062
|
+
try {
|
|
1063
|
+
const hash = await invoke(transaction);
|
|
1064
|
+
if (!disposed && own === generation) status.value = "submitted";
|
|
1065
|
+
return hash;
|
|
1066
|
+
} catch (cause) {
|
|
1067
|
+
const normalized = cause instanceof Error ? cause : new Error("Transaction failed");
|
|
1068
|
+
if (!disposed && own === generation) {
|
|
1069
|
+
status.value = "failed";
|
|
1070
|
+
error.value = normalized;
|
|
1071
|
+
}
|
|
1072
|
+
throw normalized;
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
const reset = () => {
|
|
1076
|
+
generation++;
|
|
1077
|
+
status.value = "idle";
|
|
1078
|
+
error.value = null;
|
|
1079
|
+
};
|
|
1080
|
+
(0, import_vue14.onScopeDispose)(() => {
|
|
1081
|
+
disposed = true;
|
|
1082
|
+
generation++;
|
|
1083
|
+
});
|
|
1084
|
+
return {
|
|
1085
|
+
sendTransaction,
|
|
1086
|
+
status,
|
|
1087
|
+
error,
|
|
1088
|
+
reset,
|
|
1089
|
+
isSending: (0, import_vue14.computed)(() => status.value === "awaiting_approval")
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
// src/useSolanaTransaction.ts
|
|
1094
|
+
var import_vue15 = require("vue");
|
|
1095
|
+
function useSolanaTransaction(options) {
|
|
1096
|
+
const isSigning = (0, import_vue15.shallowRef)(false);
|
|
1097
|
+
const isSending = (0, import_vue15.shallowRef)(false);
|
|
1098
|
+
const error = (0, import_vue15.shallowRef)(null);
|
|
1099
|
+
let signing = 0;
|
|
1100
|
+
let sending = 0;
|
|
1101
|
+
let generation = 0;
|
|
1102
|
+
let disposed = false;
|
|
1103
|
+
const signTransaction = async (transaction) => {
|
|
1104
|
+
const invoke = (0, import_vue15.unref)(options.signTransaction);
|
|
1105
|
+
const own = ++generation;
|
|
1106
|
+
signing++;
|
|
1107
|
+
isSigning.value = true;
|
|
1108
|
+
error.value = null;
|
|
1109
|
+
try {
|
|
1110
|
+
return await invoke(transaction);
|
|
1111
|
+
} catch (cause) {
|
|
1112
|
+
const normalized = cause instanceof Error ? cause : new Error("Signing failed");
|
|
1113
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1114
|
+
throw normalized;
|
|
1115
|
+
} finally {
|
|
1116
|
+
signing--;
|
|
1117
|
+
if (!disposed) isSigning.value = signing > 0;
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
const sendTransaction = async (transaction) => {
|
|
1121
|
+
const invoke = (0, import_vue15.unref)(options.sendTransaction);
|
|
1122
|
+
const own = ++generation;
|
|
1123
|
+
sending++;
|
|
1124
|
+
isSending.value = true;
|
|
1125
|
+
error.value = null;
|
|
1126
|
+
try {
|
|
1127
|
+
return await invoke(transaction);
|
|
1128
|
+
} catch (cause) {
|
|
1129
|
+
const normalized = cause instanceof Error ? cause : new Error("Send failed");
|
|
1130
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1131
|
+
throw normalized;
|
|
1132
|
+
} finally {
|
|
1133
|
+
sending--;
|
|
1134
|
+
if (!disposed) isSending.value = sending > 0;
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
const getStatus = (signature) => (0, import_vue15.unref)(options.getStatus)(signature);
|
|
1138
|
+
const reset = () => {
|
|
1139
|
+
generation++;
|
|
1140
|
+
error.value = null;
|
|
1141
|
+
};
|
|
1142
|
+
(0, import_vue15.onScopeDispose)(() => {
|
|
1143
|
+
disposed = true;
|
|
1144
|
+
generation++;
|
|
1145
|
+
});
|
|
1146
|
+
return {
|
|
1147
|
+
signTransaction,
|
|
1148
|
+
sendTransaction,
|
|
1149
|
+
getStatus,
|
|
1150
|
+
isSigning,
|
|
1151
|
+
isSending,
|
|
1152
|
+
error,
|
|
1153
|
+
reset
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// src/useSignInWithX.ts
|
|
1158
|
+
var import_vue16 = require("vue");
|
|
1159
|
+
function useSignInWithX(action) {
|
|
1160
|
+
const isSigningIn = (0, import_vue16.shallowRef)(false);
|
|
1161
|
+
const result = (0, import_vue16.shallowRef)(null);
|
|
1162
|
+
const error = (0, import_vue16.shallowRef)(null);
|
|
1163
|
+
let generation = 0;
|
|
1164
|
+
let active = 0;
|
|
1165
|
+
let disposed = false;
|
|
1166
|
+
const signIn = async (options) => {
|
|
1167
|
+
const invoke = (0, import_vue16.unref)(action);
|
|
1168
|
+
const own = ++generation;
|
|
1169
|
+
active++;
|
|
1170
|
+
isSigningIn.value = true;
|
|
1171
|
+
error.value = null;
|
|
1172
|
+
try {
|
|
1173
|
+
const next = await invoke(options);
|
|
1174
|
+
if (!disposed && own === generation) result.value = next;
|
|
1175
|
+
return next;
|
|
1176
|
+
} catch (cause) {
|
|
1177
|
+
const normalized = cause instanceof Error ? cause : new Error("SIWX sign-in failed");
|
|
1178
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1179
|
+
throw normalized;
|
|
1180
|
+
} finally {
|
|
1181
|
+
active--;
|
|
1182
|
+
if (!disposed) isSigningIn.value = active > 0;
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
const clearError = () => {
|
|
1186
|
+
error.value = null;
|
|
1187
|
+
};
|
|
1188
|
+
const reset = () => {
|
|
1189
|
+
generation++;
|
|
1190
|
+
result.value = null;
|
|
1191
|
+
error.value = null;
|
|
1192
|
+
};
|
|
1193
|
+
(0, import_vue16.onScopeDispose)(() => {
|
|
1194
|
+
disposed = true;
|
|
1195
|
+
generation++;
|
|
1196
|
+
});
|
|
1197
|
+
return { signIn, isSigningIn, result, error, clearError, reset };
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
// src/useSignInWithEthereum.ts
|
|
1201
|
+
function useSignInWithEthereum(action) {
|
|
1202
|
+
return useSignInWithX(action);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// src/useExecuteCalls.ts
|
|
1206
|
+
var import_vue17 = require("vue");
|
|
1207
|
+
function useExecuteCalls(options) {
|
|
1208
|
+
const isExecuting = (0, import_vue17.shallowRef)(false);
|
|
1209
|
+
const error = (0, import_vue17.shallowRef)(null);
|
|
1210
|
+
let generation = 0;
|
|
1211
|
+
let active = 0;
|
|
1212
|
+
let disposed = false;
|
|
1213
|
+
const preview = (callCount, atomicity) => (0, import_vue17.unref)(options.preview)(callCount, atomicity);
|
|
1214
|
+
const execute = async (calls, atomicity) => {
|
|
1215
|
+
const invoke = (0, import_vue17.unref)(options.execute);
|
|
1216
|
+
const own = ++generation;
|
|
1217
|
+
active++;
|
|
1218
|
+
isExecuting.value = true;
|
|
1219
|
+
error.value = null;
|
|
1220
|
+
try {
|
|
1221
|
+
return await invoke(calls, atomicity);
|
|
1222
|
+
} catch (cause) {
|
|
1223
|
+
const normalized = cause instanceof Error ? cause : new Error("Execution failed");
|
|
1224
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1225
|
+
throw normalized;
|
|
1226
|
+
} finally {
|
|
1227
|
+
active--;
|
|
1228
|
+
if (!disposed) isExecuting.value = active > 0;
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
const reset = () => {
|
|
1232
|
+
generation++;
|
|
1233
|
+
error.value = null;
|
|
1234
|
+
(0, import_vue17.unref)(options.reset)();
|
|
1235
|
+
};
|
|
1236
|
+
(0, import_vue17.onScopeDispose)(() => {
|
|
1237
|
+
disposed = true;
|
|
1238
|
+
generation++;
|
|
1239
|
+
});
|
|
1240
|
+
return {
|
|
1241
|
+
preview,
|
|
1242
|
+
execute,
|
|
1243
|
+
isExecuting,
|
|
1244
|
+
error,
|
|
1245
|
+
lastRoute: (0, import_vue17.computed)(() => (0, import_vue17.toValue)(options.lastRoute)),
|
|
1246
|
+
reset
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// src/useDelegationPolicy.ts
|
|
1251
|
+
var import_connect_appkit_core10 = require("@naculus/connect-appkit-core");
|
|
1252
|
+
var import_vue20 = require("vue");
|
|
1253
|
+
|
|
1254
|
+
// src/internal/action-guard.ts
|
|
1255
|
+
var import_vue18 = require("vue");
|
|
1256
|
+
function useActionGuard() {
|
|
1257
|
+
const busy = (0, import_vue18.shallowRef)(false);
|
|
1258
|
+
const error = (0, import_vue18.shallowRef)(null);
|
|
1259
|
+
let active = 0;
|
|
1260
|
+
let generation = 0;
|
|
1261
|
+
let disposed = false;
|
|
1262
|
+
const run = async (action, fallbackMessage) => {
|
|
1263
|
+
const own = ++generation;
|
|
1264
|
+
active++;
|
|
1265
|
+
busy.value = true;
|
|
1266
|
+
error.value = null;
|
|
1267
|
+
try {
|
|
1268
|
+
return await action();
|
|
1269
|
+
} catch (cause) {
|
|
1270
|
+
const normalized = cause instanceof Error ? cause : new Error(fallbackMessage);
|
|
1271
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1272
|
+
throw normalized;
|
|
1273
|
+
} finally {
|
|
1274
|
+
active--;
|
|
1275
|
+
if (!disposed) busy.value = active > 0;
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
const reset = () => {
|
|
1279
|
+
generation++;
|
|
1280
|
+
error.value = null;
|
|
1281
|
+
};
|
|
1282
|
+
(0, import_vue18.onScopeDispose)(() => {
|
|
1283
|
+
disposed = true;
|
|
1284
|
+
generation++;
|
|
1285
|
+
});
|
|
1286
|
+
return { busy, error, run, reset };
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// src/useSessionKeys.ts
|
|
1290
|
+
var import_connect_appkit_core9 = require("@naculus/connect-appkit-core");
|
|
1291
|
+
var import_vue19 = require("vue");
|
|
1292
|
+
function resolveManager(config, options) {
|
|
1293
|
+
return options.manager ?? (0, import_connect_appkit_core9.getSharedSessionKeyManager)(config);
|
|
1294
|
+
}
|
|
1295
|
+
function useSessionKeys(connected, config, options = {}) {
|
|
1296
|
+
const manager = resolveManager(config, options);
|
|
1297
|
+
const sessions = (0, import_vue19.shallowRef)([]);
|
|
1298
|
+
const loading = (0, import_vue19.shallowRef)(false);
|
|
1299
|
+
const error = (0, import_vue19.shallowRef)(null);
|
|
1300
|
+
let generation = 0;
|
|
1301
|
+
let disposed = false;
|
|
1302
|
+
const refresh = async () => {
|
|
1303
|
+
const own = ++generation;
|
|
1304
|
+
if (!(0, import_vue19.toValue)(connected)) {
|
|
1305
|
+
sessions.value = [];
|
|
1306
|
+
return;
|
|
1307
|
+
}
|
|
1308
|
+
loading.value = true;
|
|
1309
|
+
error.value = null;
|
|
1310
|
+
try {
|
|
1311
|
+
const keys = await manager.listSessions();
|
|
1312
|
+
if (!disposed && own === generation) sessions.value = keys;
|
|
1313
|
+
} catch (cause) {
|
|
1314
|
+
if (!disposed && own === generation) {
|
|
1315
|
+
error.value = cause instanceof Error ? cause : new Error("Failed to load session keys");
|
|
1316
|
+
}
|
|
1317
|
+
} finally {
|
|
1318
|
+
if (!disposed && own === generation) loading.value = false;
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
(0, import_vue19.watch)(
|
|
1322
|
+
() => (0, import_vue19.toValue)(connected),
|
|
1323
|
+
() => {
|
|
1324
|
+
void refresh();
|
|
1325
|
+
},
|
|
1326
|
+
{ immediate: true }
|
|
1327
|
+
);
|
|
1328
|
+
(0, import_vue19.onScopeDispose)(() => {
|
|
1329
|
+
disposed = true;
|
|
1330
|
+
generation++;
|
|
1331
|
+
});
|
|
1332
|
+
return {
|
|
1333
|
+
sessions,
|
|
1334
|
+
activeSessions: (0, import_vue19.computed)(
|
|
1335
|
+
() => sessions.value.filter((s) => s.status === "active")
|
|
1336
|
+
),
|
|
1337
|
+
loading,
|
|
1338
|
+
error,
|
|
1339
|
+
refresh,
|
|
1340
|
+
clearError: () => {
|
|
1341
|
+
error.value = null;
|
|
1342
|
+
},
|
|
1343
|
+
storageAvailable: manager.isStorageAvailable()
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
function useCreateSessionKey(config, options = {}) {
|
|
1347
|
+
const manager = resolveManager(config, options);
|
|
1348
|
+
const guard = useActionGuard();
|
|
1349
|
+
const lastCreated = (0, import_vue19.shallowRef)(null);
|
|
1350
|
+
return {
|
|
1351
|
+
createSessionKey: (scope, signerAddress) => guard.run(async () => {
|
|
1352
|
+
const info = await manager.createSessionKey(scope, signerAddress);
|
|
1353
|
+
lastCreated.value = info;
|
|
1354
|
+
return info;
|
|
1355
|
+
}, "Failed to create session key"),
|
|
1356
|
+
lastCreated,
|
|
1357
|
+
isCreating: guard.busy,
|
|
1358
|
+
error: guard.error,
|
|
1359
|
+
clearError: guard.reset
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
function useRevokeSession(config, options = {}) {
|
|
1363
|
+
const manager = resolveManager(config, options);
|
|
1364
|
+
const guard = useActionGuard();
|
|
1365
|
+
return {
|
|
1366
|
+
revokeSession: (sessionId) => guard.run(
|
|
1367
|
+
() => manager.revokeSession(sessionId),
|
|
1368
|
+
"Failed to revoke session key"
|
|
1369
|
+
),
|
|
1370
|
+
isRevoking: guard.busy,
|
|
1371
|
+
error: guard.error,
|
|
1372
|
+
clearError: guard.reset
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
function useSendWithSession(config, options = {}) {
|
|
1376
|
+
const manager = resolveManager(config, options);
|
|
1377
|
+
const guard = useActionGuard();
|
|
1378
|
+
return {
|
|
1379
|
+
signWithSession: (sessionId, messageHash, tx) => guard.run(
|
|
1380
|
+
() => manager.signWithSessionKey(sessionId, messageHash, tx),
|
|
1381
|
+
"Failed to sign with session key"
|
|
1382
|
+
),
|
|
1383
|
+
checkScope: (sessionId, tx) => guard.run(
|
|
1384
|
+
() => manager.checkSessionScope(sessionId, tx),
|
|
1385
|
+
"Failed to check session scope"
|
|
1386
|
+
),
|
|
1387
|
+
isBusy: guard.busy,
|
|
1388
|
+
error: guard.error,
|
|
1389
|
+
clearError: guard.reset
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
// src/useDelegationPolicy.ts
|
|
1394
|
+
function useDelegationPolicy(options) {
|
|
1395
|
+
const manager = options.manager ?? (0, import_connect_appkit_core10.getSharedSessionKeyManager)(options.managerConfig);
|
|
1396
|
+
const sessionKeys = useSessionKeys(options.connected, options.managerConfig, {
|
|
1397
|
+
manager
|
|
1398
|
+
});
|
|
1399
|
+
const guard = useActionGuard();
|
|
1400
|
+
const verifiedIds = (0, import_vue20.shallowRef)(/* @__PURE__ */ new Set());
|
|
1401
|
+
const isVerifying = (0, import_vue20.shallowRef)(false);
|
|
1402
|
+
const verifyError = (0, import_vue20.shallowRef)(null);
|
|
1403
|
+
let verifyGeneration = 0;
|
|
1404
|
+
let disposed = false;
|
|
1405
|
+
const origin = options.origin ?? (typeof window !== "undefined" ? window.location.origin : "unknown");
|
|
1406
|
+
const flow = (0, import_connect_appkit_core10.createDelegationPolicyFlow)({
|
|
1407
|
+
manager,
|
|
1408
|
+
origin,
|
|
1409
|
+
signer: () => (0, import_connect_appkit_core10.bareEvmAddress)((0, import_vue20.toValue)(options.account)),
|
|
1410
|
+
signMessage: (message) => (0, import_vue20.unref)(options.signMessage)(message),
|
|
1411
|
+
verifySignature: (input) => (0, import_vue20.unref)(options.verifySignature)(input),
|
|
1412
|
+
previewExecution: (callCount, atomicity) => (0, import_vue20.unref)(options.previewExecution)(callCount, atomicity),
|
|
1413
|
+
sponsorship: options.sponsorship,
|
|
1414
|
+
adapter: options.adapter,
|
|
1415
|
+
delegation: () => (0, import_vue20.toValue)(options.delegation),
|
|
1416
|
+
encryptionKeyConfigured: Boolean(options.managerConfig?.encryptionKey),
|
|
1417
|
+
storageAvailable: () => sessionKeys.storageAvailable,
|
|
1418
|
+
refresh: sessionKeys.refresh
|
|
1419
|
+
});
|
|
1420
|
+
(0, import_vue20.watch)(
|
|
1421
|
+
() => sessionKeys.sessions.value,
|
|
1422
|
+
(sessions) => {
|
|
1423
|
+
const own = ++verifyGeneration;
|
|
1424
|
+
const candidates = sessions.filter(import_connect_appkit_core10.isVerifiablePolicy);
|
|
1425
|
+
if (candidates.length === 0) {
|
|
1426
|
+
verifiedIds.value = /* @__PURE__ */ new Set();
|
|
1427
|
+
isVerifying.value = false;
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
isVerifying.value = true;
|
|
1431
|
+
void Promise.all(
|
|
1432
|
+
candidates.map(
|
|
1433
|
+
async (policy) => [policy.id, await flow.verifyStoredPolicy(policy)]
|
|
1434
|
+
)
|
|
1435
|
+
).then((results) => {
|
|
1436
|
+
if (disposed || own !== verifyGeneration) return;
|
|
1437
|
+
verifiedIds.value = new Set(
|
|
1438
|
+
results.filter(([, ok]) => ok).map(([id]) => id)
|
|
1439
|
+
);
|
|
1440
|
+
}).catch((cause) => {
|
|
1441
|
+
if (disposed || own !== verifyGeneration) return;
|
|
1442
|
+
verifiedIds.value = /* @__PURE__ */ new Set();
|
|
1443
|
+
verifyError.value = cause instanceof Error ? cause : new Error("Policy verification failed");
|
|
1444
|
+
}).finally(() => {
|
|
1445
|
+
if (!disposed && own === verifyGeneration) isVerifying.value = false;
|
|
1446
|
+
});
|
|
1447
|
+
},
|
|
1448
|
+
{ immediate: true }
|
|
1449
|
+
);
|
|
1450
|
+
(0, import_vue20.onScopeDispose)(() => {
|
|
1451
|
+
disposed = true;
|
|
1452
|
+
verifyGeneration++;
|
|
1453
|
+
});
|
|
1454
|
+
return {
|
|
1455
|
+
policies: sessionKeys.sessions,
|
|
1456
|
+
activePolicies: (0, import_vue20.computed)(
|
|
1457
|
+
() => sessionKeys.activeSessions.value.filter(
|
|
1458
|
+
(p) => verifiedIds.value.has(p.id)
|
|
1459
|
+
)
|
|
1460
|
+
),
|
|
1461
|
+
storageAvailable: sessionKeys.storageAvailable,
|
|
1462
|
+
loading: (0, import_vue20.computed)(() => sessionKeys.loading.value || isVerifying.value),
|
|
1463
|
+
isBusy: guard.busy,
|
|
1464
|
+
error: (0, import_vue20.computed)(
|
|
1465
|
+
() => guard.error.value ?? verifyError.value ?? sessionKeys.error.value
|
|
1466
|
+
),
|
|
1467
|
+
createPolicy: (scope) => guard.run(() => flow.createPolicy(scope), "Policy creation failed"),
|
|
1468
|
+
revokePolicy: (policyId) => guard.run(() => flow.revokePolicy(policyId), "Policy revocation failed"),
|
|
1469
|
+
previewPolicyExecution: flow.previewPolicyExecution,
|
|
1470
|
+
signPolicyDigest: flow.signPolicyDigest,
|
|
1471
|
+
executePolicy: (policyId, tx) => guard.run(
|
|
1472
|
+
() => flow.executePolicy(policyId, tx),
|
|
1473
|
+
"Policy execution failed"
|
|
1474
|
+
),
|
|
1475
|
+
refresh: sessionKeys.refresh,
|
|
1476
|
+
clearError: () => {
|
|
1477
|
+
guard.reset();
|
|
1478
|
+
verifyError.value = null;
|
|
1479
|
+
sessionKeys.clearError();
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
// src/useSmartAccount.ts
|
|
1485
|
+
var import_connect_appkit_core11 = require("@naculus/connect-appkit-core");
|
|
1486
|
+
var import_connect_core9 = require("@naculus/connect-core");
|
|
1487
|
+
var import_vue21 = require("vue");
|
|
1488
|
+
function useSmartAccount(options) {
|
|
1489
|
+
const address = (0, import_vue21.shallowRef)(null);
|
|
1490
|
+
const isDeployed = (0, import_vue21.shallowRef)(false);
|
|
1491
|
+
const accountInfo = (0, import_vue21.shallowRef)(null);
|
|
1492
|
+
const guard = useActionGuard();
|
|
1493
|
+
const managerRef = (0, import_vue21.shallowRef)(null);
|
|
1494
|
+
let generation = 0;
|
|
1495
|
+
let inFlight = false;
|
|
1496
|
+
let disposed = false;
|
|
1497
|
+
const chainId = (0, import_vue21.computed)(
|
|
1498
|
+
() => (0, import_connect_appkit_core11.resolveEvmChainId)(
|
|
1499
|
+
(0, import_vue21.toValue)(options.chainId),
|
|
1500
|
+
(0, import_vue21.toValue)(options.connectedChainId)
|
|
1501
|
+
)
|
|
1502
|
+
);
|
|
1503
|
+
(0, import_vue21.watch)(
|
|
1504
|
+
[
|
|
1505
|
+
() => (0, import_vue21.toValue)(options.manager),
|
|
1506
|
+
() => (0, import_vue21.toValue)(options.rpcUrl),
|
|
1507
|
+
() => (0, import_vue21.toValue)(options.bundlerUrl),
|
|
1508
|
+
() => chainId.value
|
|
1509
|
+
],
|
|
1510
|
+
([supplied, rpcUrl, bundlerUrl, chain]) => {
|
|
1511
|
+
const own = ++generation;
|
|
1512
|
+
managerRef.value = null;
|
|
1513
|
+
if (supplied) {
|
|
1514
|
+
managerRef.value = supplied;
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
if (!rpcUrl || !chain) return;
|
|
1518
|
+
import("@naculus/connect-core").then(({ SmartAccountManager }) => {
|
|
1519
|
+
if (disposed || own !== generation) return;
|
|
1520
|
+
managerRef.value = new SmartAccountManager({
|
|
1521
|
+
rpcUrl,
|
|
1522
|
+
chainId: chain,
|
|
1523
|
+
bundlerClient: { url: bundlerUrl ?? "" }
|
|
1524
|
+
});
|
|
1525
|
+
}).catch((cause) => {
|
|
1526
|
+
if (disposed || own !== generation) return;
|
|
1527
|
+
guard.error.value = cause instanceof Error ? cause : new Error("Failed to load account-abstraction module");
|
|
1528
|
+
});
|
|
1529
|
+
},
|
|
1530
|
+
{ immediate: true }
|
|
1531
|
+
);
|
|
1532
|
+
const config = (0, import_vue21.computed)(() => {
|
|
1533
|
+
const owner = (0, import_connect_appkit_core11.bareEvmAddress)((0, import_vue21.toValue)(options.account));
|
|
1534
|
+
const chain = chainId.value;
|
|
1535
|
+
if (!owner || !chain || !managerRef.value) return null;
|
|
1536
|
+
return (0, import_connect_appkit_core11.buildSmartAccountConfig)(owner, chain, {
|
|
1537
|
+
accountType: options.accountType,
|
|
1538
|
+
entryPoint: options.entryPoint,
|
|
1539
|
+
salt: options.salt
|
|
1540
|
+
});
|
|
1541
|
+
});
|
|
1542
|
+
const apply = (info) => {
|
|
1543
|
+
address.value = info.address;
|
|
1544
|
+
isDeployed.value = info.isDeployed;
|
|
1545
|
+
accountInfo.value = info;
|
|
1546
|
+
};
|
|
1547
|
+
const operate = async (action, fallback) => {
|
|
1548
|
+
const cfg = config.value;
|
|
1549
|
+
const manager = managerRef.value;
|
|
1550
|
+
if (!cfg || !manager) {
|
|
1551
|
+
guard.error.value = new Error("Smart account not configured");
|
|
1552
|
+
return null;
|
|
1553
|
+
}
|
|
1554
|
+
if (inFlight) {
|
|
1555
|
+
guard.error.value = new Error(
|
|
1556
|
+
"Smart account operation already in progress"
|
|
1557
|
+
);
|
|
1558
|
+
return null;
|
|
1559
|
+
}
|
|
1560
|
+
inFlight = true;
|
|
1561
|
+
const own = generation;
|
|
1562
|
+
const current = () => !disposed && own === generation;
|
|
1563
|
+
const commit = (write) => {
|
|
1564
|
+
if (current()) write();
|
|
1565
|
+
};
|
|
1566
|
+
try {
|
|
1567
|
+
return await guard.run(async () => {
|
|
1568
|
+
const result = await action(manager, cfg, commit);
|
|
1569
|
+
return current() ? result : null;
|
|
1570
|
+
}, fallback);
|
|
1571
|
+
} catch {
|
|
1572
|
+
return null;
|
|
1573
|
+
} finally {
|
|
1574
|
+
inFlight = false;
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
const createWallet = () => operate(async (manager, cfg, commit) => {
|
|
1578
|
+
const info = await manager.createAccount(cfg);
|
|
1579
|
+
commit(() => apply(info));
|
|
1580
|
+
return info;
|
|
1581
|
+
}, "Failed to create smart account");
|
|
1582
|
+
const deployWallet = () => operate(async (manager, cfg, commit) => {
|
|
1583
|
+
const send = (0, import_vue21.unref)(options.sendTransaction);
|
|
1584
|
+
if (!send) {
|
|
1585
|
+
throw new import_connect_core9.WalletError(
|
|
1586
|
+
"wallet_unavailable",
|
|
1587
|
+
"deployWallet needs the connected wallet's sendTransaction"
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
const before = await manager.createAccount(cfg);
|
|
1591
|
+
if (before.isDeployed) {
|
|
1592
|
+
commit(() => apply(before));
|
|
1593
|
+
return before.address;
|
|
1594
|
+
}
|
|
1595
|
+
const deployTx = await manager.getDeployCallData(cfg);
|
|
1596
|
+
const hash = await send({
|
|
1597
|
+
to: deployTx.to,
|
|
1598
|
+
data: deployTx.data,
|
|
1599
|
+
value: deployTx.value.toString(),
|
|
1600
|
+
chainId: cfg.chainId
|
|
1601
|
+
});
|
|
1602
|
+
const after = await manager.createAccount(cfg);
|
|
1603
|
+
commit(() => apply(after));
|
|
1604
|
+
return hash;
|
|
1605
|
+
}, "Failed to deploy smart account");
|
|
1606
|
+
const getAddress = () => operate(async (manager, cfg, commit) => {
|
|
1607
|
+
const addr = await manager.getAccountAddress(cfg);
|
|
1608
|
+
commit(() => {
|
|
1609
|
+
address.value = addr;
|
|
1610
|
+
});
|
|
1611
|
+
return addr;
|
|
1612
|
+
}, "Failed to get smart account address");
|
|
1613
|
+
(0, import_vue21.onScopeDispose)(() => {
|
|
1614
|
+
disposed = true;
|
|
1615
|
+
generation++;
|
|
1616
|
+
});
|
|
1617
|
+
return {
|
|
1618
|
+
address,
|
|
1619
|
+
isDeployed,
|
|
1620
|
+
accountInfo,
|
|
1621
|
+
isLoading: guard.busy,
|
|
1622
|
+
error: guard.error,
|
|
1623
|
+
config,
|
|
1624
|
+
createWallet,
|
|
1625
|
+
deployWallet,
|
|
1626
|
+
getAddress
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
// src/useSendUserOperation.ts
|
|
1631
|
+
var import_connect_appkit_core12 = require("@naculus/connect-appkit-core");
|
|
1632
|
+
var import_connect_core10 = require("@naculus/connect-core");
|
|
1633
|
+
var import_vue22 = require("vue");
|
|
1634
|
+
function useSendUserOperation(options) {
|
|
1635
|
+
const userOpHash = (0, import_vue22.shallowRef)(null);
|
|
1636
|
+
const receipt = (0, import_vue22.shallowRef)(null);
|
|
1637
|
+
const isPending = (0, import_vue22.shallowRef)(false);
|
|
1638
|
+
const isEstimating = (0, import_vue22.shallowRef)(false);
|
|
1639
|
+
const error = (0, import_vue22.shallowRef)(null);
|
|
1640
|
+
let requestId = 0;
|
|
1641
|
+
let inFlight = false;
|
|
1642
|
+
let disposed = false;
|
|
1643
|
+
const fail = (cause) => {
|
|
1644
|
+
error.value = cause;
|
|
1645
|
+
return null;
|
|
1646
|
+
};
|
|
1647
|
+
const sendUserOp = async (calls, opts) => {
|
|
1648
|
+
const rpcUrl = (0, import_vue22.toValue)(options.rpcUrl);
|
|
1649
|
+
const bundlerUrl = (0, import_vue22.toValue)(options.bundlerUrl);
|
|
1650
|
+
if (!rpcUrl) return fail(new Error("RPC URL not configured"));
|
|
1651
|
+
if (!bundlerUrl) return fail(new Error("Bundler URL not configured"));
|
|
1652
|
+
if (!calls.length) return fail(new Error("At least one call is required"));
|
|
1653
|
+
if (inFlight) {
|
|
1654
|
+
return fail(new Error("A UserOperation is already in progress"));
|
|
1655
|
+
}
|
|
1656
|
+
const owner = (0, import_connect_appkit_core12.bareEvmAddress)(
|
|
1657
|
+
(0, import_vue22.toValue)(options.owner) ?? (0, import_vue22.toValue)(options.account)
|
|
1658
|
+
);
|
|
1659
|
+
if (!owner) {
|
|
1660
|
+
return fail(
|
|
1661
|
+
new import_connect_core10.WalletError("wallet_unavailable", "No EVM account found")
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
let targetChainId;
|
|
1665
|
+
try {
|
|
1666
|
+
targetChainId = (0, import_connect_appkit_core12.resolveUserOpChain)(
|
|
1667
|
+
(0, import_vue22.toValue)(options.chainId),
|
|
1668
|
+
(0, import_vue22.toValue)(options.connectedChainId)
|
|
1669
|
+
);
|
|
1670
|
+
} catch (chainError) {
|
|
1671
|
+
return fail(chainError);
|
|
1672
|
+
}
|
|
1673
|
+
const signer = (0, import_vue22.unref)(options.signer);
|
|
1674
|
+
const own = ++requestId;
|
|
1675
|
+
inFlight = true;
|
|
1676
|
+
isPending.value = true;
|
|
1677
|
+
isEstimating.value = true;
|
|
1678
|
+
error.value = null;
|
|
1679
|
+
userOpHash.value = null;
|
|
1680
|
+
receipt.value = null;
|
|
1681
|
+
try {
|
|
1682
|
+
const { SmartAccountManager } = await import("@naculus/connect-core");
|
|
1683
|
+
const manager = new SmartAccountManager({
|
|
1684
|
+
rpcUrl,
|
|
1685
|
+
bundlerClient: { url: bundlerUrl },
|
|
1686
|
+
chainId: targetChainId,
|
|
1687
|
+
signer,
|
|
1688
|
+
signerMode: options.signerMode ?? "eip191"
|
|
1689
|
+
});
|
|
1690
|
+
const config = (0, import_connect_appkit_core12.buildSmartAccountConfig)(owner, targetChainId, {
|
|
1691
|
+
accountType: options.accountType,
|
|
1692
|
+
entryPoint: options.entryPoint,
|
|
1693
|
+
salt: options.salt
|
|
1694
|
+
});
|
|
1695
|
+
const response = await manager.sendUserOperation(config, calls, opts);
|
|
1696
|
+
if (disposed || own !== requestId) return null;
|
|
1697
|
+
isEstimating.value = false;
|
|
1698
|
+
userOpHash.value = response.userOpHash;
|
|
1699
|
+
void manager.getUserOperationReceipt(response.userOpHash).then((next) => {
|
|
1700
|
+
if (!disposed && own === requestId) receipt.value = next;
|
|
1701
|
+
}).catch(() => void 0);
|
|
1702
|
+
return response;
|
|
1703
|
+
} catch (cause) {
|
|
1704
|
+
if (disposed || own !== requestId) return null;
|
|
1705
|
+
return fail(
|
|
1706
|
+
cause instanceof Error ? cause : new Error("Failed to send UserOperation")
|
|
1707
|
+
);
|
|
1708
|
+
} finally {
|
|
1709
|
+
inFlight = false;
|
|
1710
|
+
if (!disposed && own === requestId) {
|
|
1711
|
+
isPending.value = false;
|
|
1712
|
+
isEstimating.value = false;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
const reset = () => {
|
|
1717
|
+
requestId++;
|
|
1718
|
+
userOpHash.value = null;
|
|
1719
|
+
receipt.value = null;
|
|
1720
|
+
isPending.value = false;
|
|
1721
|
+
isEstimating.value = false;
|
|
1722
|
+
error.value = null;
|
|
1723
|
+
};
|
|
1724
|
+
(0, import_vue22.onScopeDispose)(() => {
|
|
1725
|
+
disposed = true;
|
|
1726
|
+
requestId++;
|
|
1727
|
+
});
|
|
1728
|
+
return {
|
|
1729
|
+
sendUserOp,
|
|
1730
|
+
userOpHash,
|
|
1731
|
+
receipt,
|
|
1732
|
+
isPending,
|
|
1733
|
+
isEstimating,
|
|
1734
|
+
error,
|
|
1735
|
+
reset
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
// src/useUserOpStatus.ts
|
|
1740
|
+
var import_connect_appkit_core13 = require("@naculus/connect-appkit-core");
|
|
1741
|
+
var import_vue23 = require("vue");
|
|
1742
|
+
function useUserOpStatus(options) {
|
|
1743
|
+
const status = (0, import_vue23.shallowRef)("idle");
|
|
1744
|
+
const receipt = (0, import_vue23.shallowRef)(null);
|
|
1745
|
+
const userOpHash = (0, import_vue23.shallowRef)(null);
|
|
1746
|
+
const error = (0, import_vue23.shallowRef)(null);
|
|
1747
|
+
const isPolling = (0, import_vue23.shallowRef)(false);
|
|
1748
|
+
const elapsedMs = (0, import_vue23.shallowRef)(0);
|
|
1749
|
+
const attempts = (0, import_vue23.shallowRef)(0);
|
|
1750
|
+
const pollInterval = options.pollInterval ?? 2e3;
|
|
1751
|
+
const maxRetries = options.maxRetries ?? 30;
|
|
1752
|
+
let generation = 0;
|
|
1753
|
+
let startedAt = 0;
|
|
1754
|
+
let ticker = null;
|
|
1755
|
+
let timer = null;
|
|
1756
|
+
let controller = null;
|
|
1757
|
+
const clearTimers = () => {
|
|
1758
|
+
if (ticker) clearInterval(ticker);
|
|
1759
|
+
if (timer) clearTimeout(timer);
|
|
1760
|
+
ticker = null;
|
|
1761
|
+
timer = null;
|
|
1762
|
+
};
|
|
1763
|
+
const finish = (next, cause) => {
|
|
1764
|
+
status.value = next;
|
|
1765
|
+
error.value = cause;
|
|
1766
|
+
isPolling.value = false;
|
|
1767
|
+
clearTimers();
|
|
1768
|
+
};
|
|
1769
|
+
const poll = async (hash, own) => {
|
|
1770
|
+
const bundlerUrl = (0, import_vue23.toValue)(options.bundlerUrl);
|
|
1771
|
+
if (!bundlerUrl || own !== generation) return;
|
|
1772
|
+
const attempt = ++attempts.value;
|
|
1773
|
+
const abort = new AbortController();
|
|
1774
|
+
controller = abort;
|
|
1775
|
+
try {
|
|
1776
|
+
const next = await (0, import_connect_appkit_core13.fetchUserOperationReceipt)(
|
|
1777
|
+
bundlerUrl,
|
|
1778
|
+
hash,
|
|
1779
|
+
abort.signal
|
|
1780
|
+
);
|
|
1781
|
+
if (own !== generation) return;
|
|
1782
|
+
if (next) {
|
|
1783
|
+
receipt.value = next;
|
|
1784
|
+
finish(next.success ? "confirmed" : "failed", null);
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
status.value = "pending";
|
|
1788
|
+
if (attempt <= maxRetries) {
|
|
1789
|
+
timer = setTimeout(() => void poll(hash, own), pollInterval);
|
|
1790
|
+
} else {
|
|
1791
|
+
finish(
|
|
1792
|
+
"not_found",
|
|
1793
|
+
new Error("UserOperation not included after maximum retries")
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
} catch (cause) {
|
|
1797
|
+
if (own !== generation || abort.signal.aborted) return;
|
|
1798
|
+
const next = cause instanceof Error ? cause : new Error("Unknown bundler response failure");
|
|
1799
|
+
if (next instanceof import_connect_appkit_core13.InvalidUserOperationReceiptError) {
|
|
1800
|
+
finish("not_found", next);
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
if (attempt <= maxRetries) {
|
|
1804
|
+
timer = setTimeout(() => void poll(hash, own), pollInterval);
|
|
1805
|
+
} else {
|
|
1806
|
+
finish(
|
|
1807
|
+
"not_found",
|
|
1808
|
+
new Error(
|
|
1809
|
+
`UserOperation status unavailable after ${attempt} attempt${attempt === 1 ? "" : "s"}: ${next.message}`
|
|
1810
|
+
)
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
} finally {
|
|
1814
|
+
if (controller === abort) controller = null;
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
const start = (hash) => {
|
|
1818
|
+
const own = ++generation;
|
|
1819
|
+
controller?.abort();
|
|
1820
|
+
controller = null;
|
|
1821
|
+
clearTimers();
|
|
1822
|
+
userOpHash.value = hash;
|
|
1823
|
+
receipt.value = null;
|
|
1824
|
+
error.value = null;
|
|
1825
|
+
attempts.value = 0;
|
|
1826
|
+
elapsedMs.value = 0;
|
|
1827
|
+
if (!(0, import_vue23.toValue)(options.bundlerUrl)) {
|
|
1828
|
+
finish("not_found", new Error("Bundler URL not configured"));
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
status.value = "pending";
|
|
1832
|
+
isPolling.value = true;
|
|
1833
|
+
startedAt = Date.now();
|
|
1834
|
+
ticker = setInterval(() => {
|
|
1835
|
+
elapsedMs.value = Date.now() - startedAt;
|
|
1836
|
+
}, 1e3);
|
|
1837
|
+
void poll(hash, own);
|
|
1838
|
+
};
|
|
1839
|
+
const stop = () => {
|
|
1840
|
+
generation++;
|
|
1841
|
+
controller?.abort();
|
|
1842
|
+
controller = null;
|
|
1843
|
+
clearTimers();
|
|
1844
|
+
isPolling.value = false;
|
|
1845
|
+
};
|
|
1846
|
+
const reset = () => {
|
|
1847
|
+
stop();
|
|
1848
|
+
status.value = "idle";
|
|
1849
|
+
receipt.value = null;
|
|
1850
|
+
userOpHash.value = null;
|
|
1851
|
+
error.value = null;
|
|
1852
|
+
attempts.value = 0;
|
|
1853
|
+
elapsedMs.value = 0;
|
|
1854
|
+
};
|
|
1855
|
+
(0, import_vue23.onScopeDispose)(stop);
|
|
1856
|
+
return {
|
|
1857
|
+
status,
|
|
1858
|
+
receipt,
|
|
1859
|
+
userOpHash,
|
|
1860
|
+
error,
|
|
1861
|
+
isPolling,
|
|
1862
|
+
elapsedMs,
|
|
1863
|
+
attempts,
|
|
1864
|
+
start,
|
|
1865
|
+
stop,
|
|
1866
|
+
reset
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
// src/useSendCalls.ts
|
|
1871
|
+
var import_vue24 = require("vue");
|
|
1872
|
+
function useSendCalls(options) {
|
|
1873
|
+
const status = (0, import_vue24.shallowRef)("idle");
|
|
1874
|
+
const error = (0, import_vue24.shallowRef)(null);
|
|
1875
|
+
const batchHash = (0, import_vue24.shallowRef)(null);
|
|
1876
|
+
const callsStatus = (0, import_vue24.shallowRef)(null);
|
|
1877
|
+
let sendGeneration = 0;
|
|
1878
|
+
let statusGeneration = 0;
|
|
1879
|
+
let disposed = false;
|
|
1880
|
+
const sendCalls = async (calls, input) => {
|
|
1881
|
+
const invoke = (0, import_vue24.unref)(options.sendCalls);
|
|
1882
|
+
const own = ++sendGeneration;
|
|
1883
|
+
status.value = "awaiting_approval";
|
|
1884
|
+
error.value = null;
|
|
1885
|
+
batchHash.value = null;
|
|
1886
|
+
try {
|
|
1887
|
+
const hash = await invoke(calls, input);
|
|
1888
|
+
if (!disposed && own === sendGeneration) {
|
|
1889
|
+
status.value = "submitted";
|
|
1890
|
+
batchHash.value = hash;
|
|
1891
|
+
}
|
|
1892
|
+
return hash;
|
|
1893
|
+
} catch (cause) {
|
|
1894
|
+
const normalized = cause instanceof Error ? cause : new Error("sendCalls failed");
|
|
1895
|
+
if (!disposed && own === sendGeneration) {
|
|
1896
|
+
status.value = "failed";
|
|
1897
|
+
error.value = normalized;
|
|
1898
|
+
}
|
|
1899
|
+
throw normalized;
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
const getCallsStatus = async (hash) => {
|
|
1903
|
+
const invoke = (0, import_vue24.unref)(options.getCallsStatus);
|
|
1904
|
+
const own = ++statusGeneration;
|
|
1905
|
+
const result = await invoke(hash);
|
|
1906
|
+
if (!disposed && own === statusGeneration) callsStatus.value = result;
|
|
1907
|
+
return result;
|
|
1908
|
+
};
|
|
1909
|
+
const showCallsStatus = (hash) => (0, import_vue24.unref)(options.showCallsStatus)(hash);
|
|
1910
|
+
const reset = () => {
|
|
1911
|
+
sendGeneration++;
|
|
1912
|
+
statusGeneration++;
|
|
1913
|
+
status.value = "idle";
|
|
1914
|
+
error.value = null;
|
|
1915
|
+
batchHash.value = null;
|
|
1916
|
+
callsStatus.value = null;
|
|
1917
|
+
};
|
|
1918
|
+
(0, import_vue24.onScopeDispose)(() => {
|
|
1919
|
+
disposed = true;
|
|
1920
|
+
sendGeneration++;
|
|
1921
|
+
statusGeneration++;
|
|
1922
|
+
});
|
|
1923
|
+
return {
|
|
1924
|
+
sendCalls,
|
|
1925
|
+
getCallsStatus,
|
|
1926
|
+
showCallsStatus,
|
|
1927
|
+
status,
|
|
1928
|
+
error,
|
|
1929
|
+
batchHash,
|
|
1930
|
+
callsStatus,
|
|
1931
|
+
execution: (0, import_vue24.computed)(() => (0, import_vue24.toValue)(options.execution) ?? null),
|
|
1932
|
+
isSending: (0, import_vue24.computed)(() => status.value === "awaiting_approval"),
|
|
1933
|
+
reset
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
// src/useEmbeddedWallet.ts
|
|
1938
|
+
var import_vue25 = require("vue");
|
|
1939
|
+
function useEmbeddedWallet(options) {
|
|
1940
|
+
const isBusy = (0, import_vue25.shallowRef)(false);
|
|
1941
|
+
const error = (0, import_vue25.shallowRef)(null);
|
|
1942
|
+
let active = 0;
|
|
1943
|
+
let generation = 0;
|
|
1944
|
+
let disposed = false;
|
|
1945
|
+
const run = async (action) => {
|
|
1946
|
+
const own = ++generation;
|
|
1947
|
+
active++;
|
|
1948
|
+
isBusy.value = true;
|
|
1949
|
+
error.value = null;
|
|
1950
|
+
try {
|
|
1951
|
+
return await action();
|
|
1952
|
+
} catch (cause) {
|
|
1953
|
+
const normalized = cause instanceof Error ? cause : new Error("Embedded wallet action failed");
|
|
1954
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
1955
|
+
throw normalized;
|
|
1956
|
+
} finally {
|
|
1957
|
+
active--;
|
|
1958
|
+
if (!disposed) isBusy.value = active > 0;
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
const wallet = (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.wallet));
|
|
1962
|
+
(0, import_vue25.onScopeDispose)(() => {
|
|
1963
|
+
disposed = true;
|
|
1964
|
+
generation++;
|
|
1965
|
+
});
|
|
1966
|
+
return {
|
|
1967
|
+
wallet,
|
|
1968
|
+
hasWallet: (0, import_vue25.computed)(() => wallet.value !== null),
|
|
1969
|
+
address: (0, import_vue25.computed)(() => wallet.value?.address ?? null),
|
|
1970
|
+
accounts: (0, import_vue25.computed)(() => wallet.value?.accounts ?? []),
|
|
1971
|
+
activeNamespace: (0, import_vue25.computed)(() => wallet.value?.activeNamespace ?? null),
|
|
1972
|
+
backupPending: (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.backupPending)),
|
|
1973
|
+
storageSecurityLevel: (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.storageSecurityLevel)),
|
|
1974
|
+
securityReport: (0, import_vue25.computed)(() => (0, import_vue25.toValue)(options.securityReport)),
|
|
1975
|
+
connectEmbedded: () => run(() => (0, import_vue25.unref)(options.connectEmbedded)()),
|
|
1976
|
+
restoreWallet: () => run(() => (0, import_vue25.unref)(options.restoreWallet)()),
|
|
1977
|
+
generateWallet: () => run(() => (0, import_vue25.unref)(options.generateWallet)()),
|
|
1978
|
+
importFromMnemonic: (value) => run(() => (0, import_vue25.unref)(options.importFromMnemonic)(value)),
|
|
1979
|
+
importFromPrivateKey: (value) => run(() => (0, import_vue25.unref)(options.importFromPrivateKey)(value)),
|
|
1980
|
+
wipe: () => run(() => (0, import_vue25.unref)(options.wipe)()),
|
|
1981
|
+
setActiveNamespace: (value) => (0, import_vue25.unref)(options.setActiveNamespace)(value),
|
|
1982
|
+
backfillAccounts: () => run(() => (0, import_vue25.unref)(options.backfillAccounts)()),
|
|
1983
|
+
getSeedPhrase: () => (0, import_vue25.unref)(options.getSeedPhrase)(),
|
|
1984
|
+
getPrivateKey: () => (0, import_vue25.unref)(options.getPrivateKey)(),
|
|
1985
|
+
confirmBackup: () => (0, import_vue25.unref)(options.confirmBackup)(),
|
|
1986
|
+
isBusy,
|
|
1987
|
+
error,
|
|
1988
|
+
clearError: () => {
|
|
1989
|
+
error.value = null;
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
// src/useSIWxLogin.ts
|
|
1995
|
+
function useSIWxLogin(action) {
|
|
1996
|
+
const state = useSignInWithX(action);
|
|
1997
|
+
return {
|
|
1998
|
+
signIn: state.signIn,
|
|
1999
|
+
isSigningIn: state.isSigningIn,
|
|
2000
|
+
error: state.error,
|
|
2001
|
+
clearError: state.clearError
|
|
2002
|
+
};
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
// src/useSIWxSession.ts
|
|
2006
|
+
var import_vue26 = require("vue");
|
|
2007
|
+
function useSIWxSession(options) {
|
|
2008
|
+
const isSigningIn = (0, import_vue26.shallowRef)(false);
|
|
2009
|
+
const error = (0, import_vue26.shallowRef)(null);
|
|
2010
|
+
let generation = 0;
|
|
2011
|
+
let active = 0;
|
|
2012
|
+
let disposed = false;
|
|
2013
|
+
const run = async (action, message) => {
|
|
2014
|
+
const own = ++generation;
|
|
2015
|
+
active++;
|
|
2016
|
+
isSigningIn.value = true;
|
|
2017
|
+
error.value = null;
|
|
2018
|
+
try {
|
|
2019
|
+
return await action();
|
|
2020
|
+
} catch (cause) {
|
|
2021
|
+
const normalized = cause instanceof Error ? cause : new Error(message);
|
|
2022
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
2023
|
+
throw normalized;
|
|
2024
|
+
} finally {
|
|
2025
|
+
active--;
|
|
2026
|
+
if (!disposed) isSigningIn.value = active > 0;
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
(0, import_vue26.onScopeDispose)(() => {
|
|
2030
|
+
disposed = true;
|
|
2031
|
+
generation++;
|
|
2032
|
+
});
|
|
2033
|
+
return {
|
|
2034
|
+
session: (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.session)),
|
|
2035
|
+
isAuthenticated: (0, import_vue26.computed)(
|
|
2036
|
+
() => (0, import_vue26.toValue)(options.session) !== null && !(0, import_vue26.toValue)(options.isExpired)
|
|
2037
|
+
),
|
|
2038
|
+
isRestoring: (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.isRestoring)),
|
|
2039
|
+
isSigningIn,
|
|
2040
|
+
isExpired: (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.isExpired)),
|
|
2041
|
+
timeUntilExpiry: (0, import_vue26.computed)(() => (0, import_vue26.toValue)(options.timeUntilExpiry)),
|
|
2042
|
+
signIn: (input) => run(() => (0, import_vue26.unref)(options.signIn)(input), "SIWX sign-in failed"),
|
|
2043
|
+
signOut: async () => {
|
|
2044
|
+
await (0, import_vue26.unref)(options.signOut)();
|
|
2045
|
+
error.value = null;
|
|
2046
|
+
},
|
|
2047
|
+
refresh: () => run(() => (0, import_vue26.unref)(options.refresh)(), "Session refresh failed"),
|
|
2048
|
+
error,
|
|
2049
|
+
clearError: () => {
|
|
2050
|
+
error.value = null;
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
// src/useSiwxAuthSession.ts
|
|
2056
|
+
var import_vue27 = require("vue");
|
|
2057
|
+
function useSiwxAuthSession(options) {
|
|
2058
|
+
const isSigningIn = (0, import_vue27.shallowRef)(false);
|
|
2059
|
+
const error = (0, import_vue27.shallowRef)(null);
|
|
2060
|
+
let generation = 0;
|
|
2061
|
+
let disposed = false;
|
|
2062
|
+
const signIn = async (input) => {
|
|
2063
|
+
const own = ++generation;
|
|
2064
|
+
isSigningIn.value = true;
|
|
2065
|
+
error.value = null;
|
|
2066
|
+
try {
|
|
2067
|
+
return await (0, import_vue27.unref)(options.signIn)(input);
|
|
2068
|
+
} catch (cause) {
|
|
2069
|
+
const normalized = cause instanceof Error ? cause : new Error("SIWX sign-in failed");
|
|
2070
|
+
if (!disposed && own === generation) error.value = normalized;
|
|
2071
|
+
throw normalized;
|
|
2072
|
+
} finally {
|
|
2073
|
+
if (!disposed && own === generation) isSigningIn.value = false;
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
const signOut = async () => {
|
|
2077
|
+
generation++;
|
|
2078
|
+
await (0, import_vue27.unref)(options.signOut)();
|
|
2079
|
+
if (!disposed) {
|
|
2080
|
+
isSigningIn.value = false;
|
|
2081
|
+
error.value = null;
|
|
2082
|
+
}
|
|
2083
|
+
};
|
|
2084
|
+
(0, import_vue27.onScopeDispose)(() => {
|
|
2085
|
+
disposed = true;
|
|
2086
|
+
generation++;
|
|
2087
|
+
});
|
|
2088
|
+
const siwxResult = (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.result));
|
|
2089
|
+
return {
|
|
2090
|
+
isSignedIn: (0, import_vue27.computed)(() => siwxResult.value !== null),
|
|
2091
|
+
isRestoring: (0, import_vue27.computed)(() => (0, import_vue27.toValue)(options.isRestoring)),
|
|
2092
|
+
siwxResult,
|
|
2093
|
+
isSigningIn,
|
|
2094
|
+
error,
|
|
2095
|
+
signIn,
|
|
2096
|
+
signOut,
|
|
2097
|
+
clearError: () => {
|
|
2098
|
+
error.value = null;
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
// src/useBalance.ts
|
|
2104
|
+
var import_connect_appkit_core14 = require("@naculus/connect-appkit-core");
|
|
2105
|
+
var import_connect_core11 = require("@naculus/connect-core");
|
|
2106
|
+
var import_vue28 = require("vue");
|
|
2107
|
+
function useBalance(account, client, options = {}) {
|
|
2108
|
+
const balance = (0, import_vue28.shallowRef)(null);
|
|
2109
|
+
const isFetching = (0, import_vue28.shallowRef)(false);
|
|
2110
|
+
const error = (0, import_vue28.shallowRef)(null);
|
|
2111
|
+
let generation = 0;
|
|
2112
|
+
let disposed = false;
|
|
2113
|
+
let timer = null;
|
|
2114
|
+
const refetch = async () => {
|
|
2115
|
+
const reader = (0, import_vue28.toValue)(client);
|
|
2116
|
+
const address = (0, import_connect_appkit_core14.bareEvmAddress)((0, import_vue28.toValue)(account));
|
|
2117
|
+
const own = ++generation;
|
|
2118
|
+
if (!reader || !address) {
|
|
2119
|
+
balance.value = null;
|
|
2120
|
+
error.value = null;
|
|
2121
|
+
isFetching.value = false;
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
isFetching.value = true;
|
|
2125
|
+
error.value = null;
|
|
2126
|
+
try {
|
|
2127
|
+
const next = await reader.getBalance({ address });
|
|
2128
|
+
if (disposed || own !== generation) return;
|
|
2129
|
+
balance.value = next.toString();
|
|
2130
|
+
} catch (cause) {
|
|
2131
|
+
if (disposed || own !== generation) return;
|
|
2132
|
+
balance.value = null;
|
|
2133
|
+
error.value = cause instanceof Error ? cause : new Error("Balance read failed");
|
|
2134
|
+
} finally {
|
|
2135
|
+
if (!disposed && own === generation) isFetching.value = false;
|
|
2136
|
+
}
|
|
2137
|
+
};
|
|
2138
|
+
const stopTimer = () => {
|
|
2139
|
+
if (timer) clearInterval(timer);
|
|
2140
|
+
timer = null;
|
|
2141
|
+
};
|
|
2142
|
+
(0, import_vue28.watch)(
|
|
2143
|
+
[
|
|
2144
|
+
() => (0, import_vue28.toValue)(account),
|
|
2145
|
+
() => (0, import_vue28.toValue)(client),
|
|
2146
|
+
() => (0, import_vue28.toValue)(options.refreshInterval) ?? 0
|
|
2147
|
+
],
|
|
2148
|
+
([, , interval]) => {
|
|
2149
|
+
stopTimer();
|
|
2150
|
+
void refetch();
|
|
2151
|
+
if (interval > 0) timer = setInterval(() => void refetch(), interval);
|
|
2152
|
+
},
|
|
2153
|
+
{ immediate: true }
|
|
2154
|
+
);
|
|
2155
|
+
(0, import_vue28.onScopeDispose)(() => {
|
|
2156
|
+
disposed = true;
|
|
2157
|
+
generation++;
|
|
2158
|
+
stopTimer();
|
|
2159
|
+
});
|
|
2160
|
+
return {
|
|
2161
|
+
balance,
|
|
2162
|
+
formatted: (0, import_vue28.computed)(
|
|
2163
|
+
() => balance.value === null ? null : (0, import_connect_core11.formatUnits)(BigInt(balance.value), (0, import_vue28.toValue)(options.decimals) ?? 18)
|
|
2164
|
+
),
|
|
2165
|
+
symbol: (0, import_vue28.computed)(() => (0, import_vue28.toValue)(options.symbol) ?? null),
|
|
2166
|
+
isFetching,
|
|
2167
|
+
error,
|
|
2168
|
+
refetch
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
// src/useRouteQuote.ts
|
|
2173
|
+
var import_connect_appkit_core15 = require("@naculus/connect-appkit-core");
|
|
2174
|
+
var import_vue29 = require("vue");
|
|
2175
|
+
function useRouteQuote(input, getQuotes, options = {}) {
|
|
2176
|
+
const quotes = (0, import_vue29.shallowRef)([]);
|
|
2177
|
+
const loading = (0, import_vue29.shallowRef)(false);
|
|
2178
|
+
const error = (0, import_vue29.shallowRef)(null);
|
|
2179
|
+
let generation = 0;
|
|
2180
|
+
let disposed = false;
|
|
2181
|
+
let timer = null;
|
|
2182
|
+
const clearTimer = () => {
|
|
2183
|
+
if (timer) clearTimeout(timer);
|
|
2184
|
+
timer = null;
|
|
2185
|
+
};
|
|
2186
|
+
const fetchQuotes = async () => {
|
|
2187
|
+
const current = (0, import_vue29.toValue)(input);
|
|
2188
|
+
const fn = (0, import_vue29.unref)(getQuotes);
|
|
2189
|
+
const own = ++generation;
|
|
2190
|
+
if (!(0, import_connect_appkit_core15.isQuotableInput)(current)) {
|
|
2191
|
+
quotes.value = [];
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
if (!fn) return;
|
|
2195
|
+
loading.value = true;
|
|
2196
|
+
error.value = null;
|
|
2197
|
+
try {
|
|
2198
|
+
const result = await fn(
|
|
2199
|
+
current.fromChain,
|
|
2200
|
+
current.toChain,
|
|
2201
|
+
current.fromToken,
|
|
2202
|
+
current.amount,
|
|
2203
|
+
current.options,
|
|
2204
|
+
current.toToken
|
|
2205
|
+
);
|
|
2206
|
+
if (disposed || own !== generation) return;
|
|
2207
|
+
quotes.value = result;
|
|
2208
|
+
} catch (cause) {
|
|
2209
|
+
if (disposed || own !== generation) return;
|
|
2210
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
2211
|
+
quotes.value = [];
|
|
2212
|
+
} finally {
|
|
2213
|
+
if (!disposed && own === generation) loading.value = false;
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2216
|
+
(0, import_vue29.watch)(
|
|
2217
|
+
[
|
|
2218
|
+
() => (0, import_vue29.toValue)(input).fromChain,
|
|
2219
|
+
() => (0, import_vue29.toValue)(input).toChain,
|
|
2220
|
+
() => (0, import_vue29.toValue)(input).fromToken,
|
|
2221
|
+
() => (0, import_vue29.toValue)(input).toToken,
|
|
2222
|
+
() => (0, import_vue29.toValue)(input).amount,
|
|
2223
|
+
() => (0, import_vue29.unref)(getQuotes)
|
|
2224
|
+
],
|
|
2225
|
+
([fromChain, toChain, fromToken, , amount]) => {
|
|
2226
|
+
clearTimer();
|
|
2227
|
+
if (!fromChain || !toChain || !fromToken || !amount) {
|
|
2228
|
+
quotes.value = [];
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
timer = setTimeout(() => {
|
|
2232
|
+
timer = null;
|
|
2233
|
+
void fetchQuotes();
|
|
2234
|
+
}, options.debounceMs ?? 300);
|
|
2235
|
+
},
|
|
2236
|
+
{ immediate: true }
|
|
2237
|
+
);
|
|
2238
|
+
(0, import_vue29.onScopeDispose)(() => {
|
|
2239
|
+
disposed = true;
|
|
2240
|
+
generation++;
|
|
2241
|
+
clearTimer();
|
|
2242
|
+
});
|
|
2243
|
+
return {
|
|
2244
|
+
quotes,
|
|
2245
|
+
loading,
|
|
2246
|
+
error,
|
|
2247
|
+
refresh: fetchQuotes,
|
|
2248
|
+
clear: () => {
|
|
2249
|
+
clearTimer();
|
|
2250
|
+
generation++;
|
|
2251
|
+
quotes.value = [];
|
|
2252
|
+
error.value = null;
|
|
2253
|
+
loading.value = false;
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
// src/useCompareCosts.ts
|
|
2259
|
+
var import_connect_appkit_core16 = require("@naculus/connect-appkit-core");
|
|
2260
|
+
var import_vue30 = require("vue");
|
|
2261
|
+
function useCompareCosts(input, compareCosts) {
|
|
2262
|
+
const comparisons = (0, import_vue30.shallowRef)([]);
|
|
2263
|
+
const loading = (0, import_vue30.shallowRef)(false);
|
|
2264
|
+
const error = (0, import_vue30.shallowRef)(null);
|
|
2265
|
+
let generation = 0;
|
|
2266
|
+
let disposed = false;
|
|
2267
|
+
const fetchComparisons = async () => {
|
|
2268
|
+
const { operation, chains, options } = (0, import_vue30.toValue)(input);
|
|
2269
|
+
const fn = (0, import_vue30.unref)(compareCosts);
|
|
2270
|
+
const own = ++generation;
|
|
2271
|
+
if (!chains || chains.length === 0) {
|
|
2272
|
+
comparisons.value = [];
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
if (!fn) return;
|
|
2276
|
+
loading.value = true;
|
|
2277
|
+
error.value = null;
|
|
2278
|
+
try {
|
|
2279
|
+
const result = await fn(operation, chains, options);
|
|
2280
|
+
if (disposed || own !== generation) return;
|
|
2281
|
+
comparisons.value = result;
|
|
2282
|
+
} catch (cause) {
|
|
2283
|
+
if (disposed || own !== generation) return;
|
|
2284
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
2285
|
+
comparisons.value = [];
|
|
2286
|
+
} finally {
|
|
2287
|
+
if (!disposed && own === generation) loading.value = false;
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
(0, import_vue30.watch)(
|
|
2291
|
+
[() => (0, import_connect_appkit_core16.compareCostsKey)((0, import_vue30.toValue)(input)), () => (0, import_vue30.unref)(compareCosts)],
|
|
2292
|
+
() => {
|
|
2293
|
+
void fetchComparisons();
|
|
2294
|
+
},
|
|
2295
|
+
{ immediate: true }
|
|
2296
|
+
);
|
|
2297
|
+
(0, import_vue30.onScopeDispose)(() => {
|
|
2298
|
+
disposed = true;
|
|
2299
|
+
generation++;
|
|
2300
|
+
});
|
|
2301
|
+
return { comparisons, loading, error, refresh: fetchComparisons };
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/useExecuteRoute.ts
|
|
2305
|
+
var import_connect_appkit_core17 = require("@naculus/connect-appkit-core");
|
|
2306
|
+
var import_vue31 = require("vue");
|
|
2307
|
+
function useExecuteRoute(executeRoute) {
|
|
2308
|
+
const executing = (0, import_vue31.shallowRef)(false);
|
|
2309
|
+
const result = (0, import_vue31.shallowRef)(null);
|
|
2310
|
+
const error = (0, import_vue31.shallowRef)(null);
|
|
2311
|
+
let inFlight = false;
|
|
2312
|
+
let disposed = false;
|
|
2313
|
+
const execute = async (quote, recipient, options) => {
|
|
2314
|
+
const fn = (0, import_vue31.unref)(executeRoute);
|
|
2315
|
+
if (!fn) {
|
|
2316
|
+
error.value = {
|
|
2317
|
+
code: "no_executor",
|
|
2318
|
+
message: "No executeRoute function provided"
|
|
2319
|
+
};
|
|
2320
|
+
result.value = null;
|
|
2321
|
+
return null;
|
|
2322
|
+
}
|
|
2323
|
+
const recipientError = (0, import_connect_appkit_core17.validateRouteRecipient)(quote, recipient);
|
|
2324
|
+
if (recipientError) {
|
|
2325
|
+
error.value = recipientError;
|
|
2326
|
+
result.value = null;
|
|
2327
|
+
return null;
|
|
2328
|
+
}
|
|
2329
|
+
if (inFlight) {
|
|
2330
|
+
error.value = {
|
|
2331
|
+
code: "execution_in_progress",
|
|
2332
|
+
message: "A route execution is already in progress"
|
|
2333
|
+
};
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2336
|
+
inFlight = true;
|
|
2337
|
+
executing.value = true;
|
|
2338
|
+
error.value = null;
|
|
2339
|
+
result.value = null;
|
|
2340
|
+
try {
|
|
2341
|
+
const execResult = await fn(quote, recipient, options);
|
|
2342
|
+
if (!disposed) result.value = execResult;
|
|
2343
|
+
return execResult;
|
|
2344
|
+
} catch (cause) {
|
|
2345
|
+
if (!disposed) error.value = (0, import_connect_appkit_core17.toExecuteRouteError)(cause);
|
|
2346
|
+
return null;
|
|
2347
|
+
} finally {
|
|
2348
|
+
inFlight = false;
|
|
2349
|
+
if (!disposed) executing.value = false;
|
|
2350
|
+
}
|
|
2351
|
+
};
|
|
2352
|
+
(0, import_vue31.onScopeDispose)(() => {
|
|
2353
|
+
disposed = true;
|
|
2354
|
+
});
|
|
2355
|
+
return {
|
|
2356
|
+
execute,
|
|
2357
|
+
executing,
|
|
2358
|
+
result,
|
|
2359
|
+
error,
|
|
2360
|
+
reset: () => {
|
|
2361
|
+
result.value = null;
|
|
2362
|
+
error.value = null;
|
|
2363
|
+
executing.value = false;
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
// src/useTokenList.ts
|
|
2369
|
+
var import_connect_appkit_core18 = require("@naculus/connect-appkit-core");
|
|
2370
|
+
var import_connect_core12 = require("@naculus/connect-core");
|
|
2371
|
+
var import_vue32 = require("vue");
|
|
2372
|
+
function useTokenList(chainId, options = {}) {
|
|
2373
|
+
const config = {};
|
|
2374
|
+
if (options.sources) config.sources = options.sources;
|
|
2375
|
+
const manager = options.manager ?? new import_connect_core12.TokenListManager(config);
|
|
2376
|
+
const tokens = (0, import_vue32.shallowRef)([]);
|
|
2377
|
+
const isLoading = (0, import_vue32.shallowRef)(options.autoLoad !== false);
|
|
2378
|
+
const isLoaded = (0, import_vue32.shallowRef)(false);
|
|
2379
|
+
const error = (0, import_vue32.shallowRef)(null);
|
|
2380
|
+
let generation = 0;
|
|
2381
|
+
let disposed = false;
|
|
2382
|
+
const select = () => {
|
|
2383
|
+
const id = (0, import_vue32.toValue)(chainId);
|
|
2384
|
+
const numeric = id ? (0, import_connect_appkit_core18.eip155ChainIdToNumber)(id) : void 0;
|
|
2385
|
+
return manager.getTokens(
|
|
2386
|
+
numeric !== void 0 ? { chainId: numeric } : void 0
|
|
2387
|
+
);
|
|
2388
|
+
};
|
|
2389
|
+
const run = async (op) => {
|
|
2390
|
+
const own = ++generation;
|
|
2391
|
+
isLoading.value = true;
|
|
2392
|
+
error.value = null;
|
|
2393
|
+
try {
|
|
2394
|
+
await op();
|
|
2395
|
+
if (disposed || own !== generation) return;
|
|
2396
|
+
tokens.value = select();
|
|
2397
|
+
isLoaded.value = true;
|
|
2398
|
+
} catch (cause) {
|
|
2399
|
+
if (disposed || own !== generation) return;
|
|
2400
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
2401
|
+
} finally {
|
|
2402
|
+
if (!disposed && own === generation) isLoading.value = false;
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
(0, import_vue32.watch)(
|
|
2406
|
+
() => (0, import_vue32.toValue)(chainId),
|
|
2407
|
+
() => {
|
|
2408
|
+
if (options.autoLoad !== false) void run(() => manager.load());
|
|
2409
|
+
},
|
|
2410
|
+
{ immediate: true }
|
|
2411
|
+
);
|
|
2412
|
+
(0, import_vue32.onScopeDispose)(() => {
|
|
2413
|
+
disposed = true;
|
|
2414
|
+
generation++;
|
|
2415
|
+
});
|
|
2416
|
+
return {
|
|
2417
|
+
tokens,
|
|
2418
|
+
isLoading,
|
|
2419
|
+
isLoaded,
|
|
2420
|
+
error,
|
|
2421
|
+
refetch: () => run(() => manager.refresh())
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
// src/useTokenSearch.ts
|
|
2426
|
+
var import_connect_appkit_core19 = require("@naculus/connect-appkit-core");
|
|
2427
|
+
var import_connect_core13 = require("@naculus/connect-core");
|
|
2428
|
+
var import_vue33 = require("vue");
|
|
2429
|
+
var DEBOUNCE_MS = 300;
|
|
2430
|
+
var EMPTY = { exact: [], fuzzy: [], hasMore: false };
|
|
2431
|
+
var sharedManager = null;
|
|
2432
|
+
function getSharedManager() {
|
|
2433
|
+
if (!sharedManager) {
|
|
2434
|
+
sharedManager = new import_connect_core13.TokenListManager();
|
|
2435
|
+
sharedManager.load().catch(() => {
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
return sharedManager;
|
|
2439
|
+
}
|
|
2440
|
+
function useTokenSearch(query, chainId, options = {}) {
|
|
2441
|
+
const results = (0, import_vue33.shallowRef)(EMPTY);
|
|
2442
|
+
const isSearching = (0, import_vue33.shallowRef)(false);
|
|
2443
|
+
let timer = null;
|
|
2444
|
+
const clear = () => {
|
|
2445
|
+
if (timer) clearTimeout(timer);
|
|
2446
|
+
timer = null;
|
|
2447
|
+
};
|
|
2448
|
+
(0, import_vue33.watch)(
|
|
2449
|
+
[() => ((0, import_vue33.toValue)(query) ?? "").trim(), () => (0, import_vue33.toValue)(chainId)],
|
|
2450
|
+
([q, id]) => {
|
|
2451
|
+
clear();
|
|
2452
|
+
if (!q) {
|
|
2453
|
+
results.value = EMPTY;
|
|
2454
|
+
isSearching.value = false;
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2457
|
+
isSearching.value = true;
|
|
2458
|
+
timer = setTimeout(() => {
|
|
2459
|
+
timer = null;
|
|
2460
|
+
const manager = options.manager ?? getSharedManager();
|
|
2461
|
+
const numeric = id ? (0, import_connect_appkit_core19.eip155ChainIdToNumber)(id) : void 0;
|
|
2462
|
+
results.value = manager.search(q, {
|
|
2463
|
+
chainId: numeric,
|
|
2464
|
+
limit: options.limit ?? 20
|
|
2465
|
+
});
|
|
2466
|
+
isSearching.value = false;
|
|
2467
|
+
}, options.debounceMs ?? DEBOUNCE_MS);
|
|
2468
|
+
},
|
|
2469
|
+
{ immediate: true }
|
|
2470
|
+
);
|
|
2471
|
+
(0, import_vue33.onScopeDispose)(clear);
|
|
2472
|
+
return { results, isSearching };
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
// src/useValidateDestination.ts
|
|
2476
|
+
var import_connect_appkit_core20 = require("@naculus/connect-appkit-core");
|
|
2477
|
+
var import_vue34 = require("vue");
|
|
2478
|
+
function useValidateDestination(address) {
|
|
2479
|
+
return {
|
|
2480
|
+
validation: (0, import_vue34.computed)(() => (0, import_connect_appkit_core20.validateDestination)((0, import_vue34.toValue)(address) ?? ""))
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
// src/useTokenBalance.ts
|
|
2485
|
+
var import_connect_appkit_core21 = require("@naculus/connect-appkit-core");
|
|
2486
|
+
var import_connect_core14 = require("@naculus/connect-core");
|
|
2487
|
+
var import_vue35 = require("vue");
|
|
2488
|
+
function tokensKey(tokens) {
|
|
2489
|
+
return tokens.map((t) => `${t.address.toLowerCase()}|${t.decimals}|${t.symbol}`).join(",");
|
|
2490
|
+
}
|
|
2491
|
+
function useTokenBalance(account, client, tokens, options = {}) {
|
|
2492
|
+
const tokenBalances = (0, import_vue35.shallowRef)([]);
|
|
2493
|
+
const isFetching = (0, import_vue35.shallowRef)(false);
|
|
2494
|
+
const error = (0, import_vue35.shallowRef)(null);
|
|
2495
|
+
let generation = 0;
|
|
2496
|
+
let disposed = false;
|
|
2497
|
+
let timer = null;
|
|
2498
|
+
const refetch = async () => {
|
|
2499
|
+
const reader = (0, import_vue35.toValue)(client);
|
|
2500
|
+
const address = (0, import_connect_appkit_core21.bareEvmAddress)((0, import_vue35.toValue)(account));
|
|
2501
|
+
const list = (0, import_vue35.toValue)(tokens) ?? [];
|
|
2502
|
+
const own = ++generation;
|
|
2503
|
+
if (!reader || !address || list.length === 0) {
|
|
2504
|
+
tokenBalances.value = [];
|
|
2505
|
+
error.value = null;
|
|
2506
|
+
isFetching.value = false;
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
isFetching.value = true;
|
|
2510
|
+
error.value = null;
|
|
2511
|
+
try {
|
|
2512
|
+
const results = await Promise.all(
|
|
2513
|
+
list.map(async (token) => {
|
|
2514
|
+
try {
|
|
2515
|
+
const raw = await reader.readContract({
|
|
2516
|
+
address: token.address,
|
|
2517
|
+
abi: import_connect_core14.ERC20_MIN_ABI,
|
|
2518
|
+
functionName: "balanceOf",
|
|
2519
|
+
args: [address]
|
|
2520
|
+
});
|
|
2521
|
+
const value = BigInt(raw);
|
|
2522
|
+
return {
|
|
2523
|
+
...token,
|
|
2524
|
+
balance: value.toString(),
|
|
2525
|
+
formatted: (0, import_connect_core14.formatUnits)(value, token.decimals)
|
|
2526
|
+
};
|
|
2527
|
+
} catch {
|
|
2528
|
+
return { ...token, balance: null, formatted: null };
|
|
2529
|
+
}
|
|
2530
|
+
})
|
|
2531
|
+
);
|
|
2532
|
+
if (disposed || own !== generation) return;
|
|
2533
|
+
tokenBalances.value = results;
|
|
2534
|
+
} catch (cause) {
|
|
2535
|
+
if (disposed || own !== generation) return;
|
|
2536
|
+
tokenBalances.value = [];
|
|
2537
|
+
error.value = cause instanceof Error ? cause : new Error("Failed to fetch token balances");
|
|
2538
|
+
} finally {
|
|
2539
|
+
if (!disposed && own === generation) isFetching.value = false;
|
|
2540
|
+
}
|
|
2541
|
+
};
|
|
2542
|
+
const stopTimer = () => {
|
|
2543
|
+
if (timer) clearInterval(timer);
|
|
2544
|
+
timer = null;
|
|
2545
|
+
};
|
|
2546
|
+
(0, import_vue35.watch)(
|
|
2547
|
+
[
|
|
2548
|
+
() => (0, import_vue35.toValue)(account),
|
|
2549
|
+
() => (0, import_vue35.toValue)(client),
|
|
2550
|
+
() => tokensKey((0, import_vue35.toValue)(tokens) ?? []),
|
|
2551
|
+
() => (0, import_vue35.toValue)(options.refreshInterval) ?? 0
|
|
2552
|
+
],
|
|
2553
|
+
([, , , interval]) => {
|
|
2554
|
+
stopTimer();
|
|
2555
|
+
void refetch();
|
|
2556
|
+
if (interval > 0) timer = setInterval(() => void refetch(), interval);
|
|
2557
|
+
},
|
|
2558
|
+
{ immediate: true }
|
|
2559
|
+
);
|
|
2560
|
+
(0, import_vue35.onScopeDispose)(() => {
|
|
2561
|
+
disposed = true;
|
|
2562
|
+
generation++;
|
|
2563
|
+
stopTimer();
|
|
2564
|
+
});
|
|
2565
|
+
return {
|
|
2566
|
+
tokenBalances,
|
|
2567
|
+
isFetching,
|
|
2568
|
+
error,
|
|
2569
|
+
refetch,
|
|
2570
|
+
getTokenBalance: (tokenAddress) => tokenBalances.value.find(
|
|
2571
|
+
(t) => t.address.toLowerCase() === tokenAddress.toLowerCase()
|
|
2572
|
+
)
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
// src/useDelegation.ts
|
|
2577
|
+
var import_connect_appkit_core22 = require("@naculus/connect-appkit-core");
|
|
2578
|
+
var import_connect_core15 = require("@naculus/connect-core");
|
|
2579
|
+
var import_vue36 = require("vue");
|
|
2580
|
+
function useDelegation(account, client, chainId) {
|
|
2581
|
+
const status = (0, import_vue36.shallowRef)(import_connect_core15.UNKNOWN_DELEGATION);
|
|
2582
|
+
const isFetching = (0, import_vue36.shallowRef)(false);
|
|
2583
|
+
const error = (0, import_vue36.shallowRef)(null);
|
|
2584
|
+
let generation = 0;
|
|
2585
|
+
let disposed = false;
|
|
2586
|
+
const refetch = async () => {
|
|
2587
|
+
const mine = ++generation;
|
|
2588
|
+
const reader = (0, import_vue36.toValue)(client);
|
|
2589
|
+
const address = (0, import_connect_appkit_core22.bareEvmAddress)((0, import_vue36.toValue)(account));
|
|
2590
|
+
status.value = import_connect_core15.UNKNOWN_DELEGATION;
|
|
2591
|
+
error.value = null;
|
|
2592
|
+
if (!reader || !address) {
|
|
2593
|
+
isFetching.value = false;
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
isFetching.value = true;
|
|
2597
|
+
try {
|
|
2598
|
+
const code = await reader.getCode({ address });
|
|
2599
|
+
if (!disposed && mine === generation) {
|
|
2600
|
+
status.value = (0, import_connect_core15.readDelegation)(code ?? "0x");
|
|
2601
|
+
}
|
|
2602
|
+
} catch (cause) {
|
|
2603
|
+
if (!disposed && mine === generation) {
|
|
2604
|
+
status.value = import_connect_core15.UNKNOWN_DELEGATION;
|
|
2605
|
+
error.value = cause instanceof Error ? cause : new Error("Code read failed");
|
|
2606
|
+
}
|
|
2607
|
+
} finally {
|
|
2608
|
+
if (!disposed && mine === generation) isFetching.value = false;
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
(0, import_vue36.watch)(
|
|
2612
|
+
[() => (0, import_vue36.toValue)(account), () => (0, import_vue36.toValue)(client), () => (0, import_vue36.toValue)(chainId)],
|
|
2613
|
+
() => {
|
|
2614
|
+
void refetch();
|
|
2615
|
+
},
|
|
2616
|
+
{ immediate: true, flush: "sync" }
|
|
2617
|
+
);
|
|
2618
|
+
(0, import_vue36.onScopeDispose)(() => {
|
|
2619
|
+
disposed = true;
|
|
2620
|
+
generation++;
|
|
2621
|
+
});
|
|
2622
|
+
return {
|
|
2623
|
+
delegated: (0, import_vue36.computed)(() => status.value.delegated),
|
|
2624
|
+
delegate: (0, import_vue36.computed)(() => status.value.delegate),
|
|
2625
|
+
isFetching,
|
|
2626
|
+
error,
|
|
2627
|
+
refetch
|
|
2628
|
+
};
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
// src/name-lookup.ts
|
|
2632
|
+
var import_connect_appkit_core23 = require("@naculus/connect-appkit-core");
|
|
2633
|
+
var import_vue37 = require("vue");
|
|
2634
|
+
function useNameLookup(options) {
|
|
2635
|
+
const data = (0, import_vue37.shallowRef)(null);
|
|
2636
|
+
const loading = (0, import_vue37.shallowRef)(false);
|
|
2637
|
+
const error = (0, import_vue37.shallowRef)(null);
|
|
2638
|
+
let generation = 0;
|
|
2639
|
+
let disposed = false;
|
|
2640
|
+
const run = () => {
|
|
2641
|
+
const input = (0, import_vue37.toValue)(options.input).trim();
|
|
2642
|
+
const skip = (0, import_vue37.toValue)(options.skip) ?? false;
|
|
2643
|
+
const scope = (0, import_vue37.toValue)(options.scope);
|
|
2644
|
+
const config = (0, import_vue37.toValue)(options.resolverConfig);
|
|
2645
|
+
const mine = ++generation;
|
|
2646
|
+
if (!input || skip) {
|
|
2647
|
+
data.value = null;
|
|
2648
|
+
loading.value = false;
|
|
2649
|
+
error.value = null;
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
data.value = null;
|
|
2653
|
+
loading.value = true;
|
|
2654
|
+
error.value = null;
|
|
2655
|
+
Promise.resolve().then(() => options.query((0, import_connect_appkit_core23.getResolver)(config), input, scope)).then((result) => {
|
|
2656
|
+
if (disposed || mine !== generation) return;
|
|
2657
|
+
data.value = result;
|
|
2658
|
+
loading.value = false;
|
|
2659
|
+
}).catch((cause) => {
|
|
2660
|
+
if (disposed || mine !== generation) return;
|
|
2661
|
+
data.value = null;
|
|
2662
|
+
error.value = cause instanceof Error ? cause : new Error(String(cause));
|
|
2663
|
+
loading.value = false;
|
|
2664
|
+
});
|
|
2665
|
+
};
|
|
2666
|
+
(0, import_vue37.watch)(
|
|
2667
|
+
() => [
|
|
2668
|
+
(0, import_vue37.toValue)(options.input),
|
|
2669
|
+
(0, import_vue37.toValue)(options.skip),
|
|
2670
|
+
(0, import_vue37.toValue)(options.scope),
|
|
2671
|
+
(0, import_vue37.toValue)(options.resolverConfig)
|
|
2672
|
+
],
|
|
2673
|
+
run,
|
|
2674
|
+
{ immediate: true, flush: "sync", deep: true }
|
|
2675
|
+
);
|
|
2676
|
+
(0, import_vue37.onScopeDispose)(() => {
|
|
2677
|
+
disposed = true;
|
|
2678
|
+
generation++;
|
|
2679
|
+
});
|
|
2680
|
+
return {
|
|
2681
|
+
data,
|
|
2682
|
+
isLoading: (0, import_vue37.computed)(() => loading.value),
|
|
2683
|
+
error,
|
|
2684
|
+
refetch: run
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
// src/useResolveName.ts
|
|
2689
|
+
function useResolveName(name, options) {
|
|
2690
|
+
return useNameLookup({
|
|
2691
|
+
input: name,
|
|
2692
|
+
skip: options?.skip,
|
|
2693
|
+
resolverConfig: options?.resolverConfig,
|
|
2694
|
+
query: (resolver, input) => resolver.resolveName(input)
|
|
2695
|
+
});
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
// src/useLookupAddress.ts
|
|
2699
|
+
function useLookupAddress(address, options) {
|
|
2700
|
+
return useNameLookup({
|
|
2701
|
+
input: address,
|
|
2702
|
+
scope: options?.chainId,
|
|
2703
|
+
skip: options?.skip,
|
|
2704
|
+
resolverConfig: options?.resolverConfig,
|
|
2705
|
+
query: (resolver, input, scope) => resolver.lookupAddress(input, scope)
|
|
2706
|
+
});
|
|
2707
|
+
}
|
|
2708
|
+
|
|
2709
|
+
// src/useSolanaAccount.ts
|
|
2710
|
+
var import_vue38 = require("vue");
|
|
2711
|
+
function useSolanaAccount(accounts, connected) {
|
|
2712
|
+
const isConnected = (0, import_vue38.computed)(() => (0, import_vue38.toValue)(connected));
|
|
2713
|
+
const caip10 = (0, import_vue38.computed)(
|
|
2714
|
+
() => isConnected.value ? ((0, import_vue38.toValue)(accounts) ?? []).find(
|
|
2715
|
+
(account) => account.startsWith("solana:")
|
|
2716
|
+
) ?? null : null
|
|
2717
|
+
);
|
|
2718
|
+
const parts = (0, import_vue38.computed)(() => caip10.value?.split(":") ?? []);
|
|
2719
|
+
return {
|
|
2720
|
+
address: (0, import_vue38.computed)(
|
|
2721
|
+
() => parts.value.length >= 3 ? parts.value.at(-1) ?? null : null
|
|
2722
|
+
),
|
|
2723
|
+
caip10,
|
|
2724
|
+
chainId: (0, import_vue38.computed)(
|
|
2725
|
+
() => parts.value.length >= 3 ? parts.value.slice(0, -1).join(":") : null
|
|
2726
|
+
),
|
|
2727
|
+
isConnected
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
|
|
271
2731
|
// src/useChain.ts
|
|
272
|
-
var
|
|
273
|
-
var
|
|
2732
|
+
var import_connect_appkit_core24 = require("@naculus/connect-appkit-core");
|
|
2733
|
+
var import_vue39 = require("vue");
|
|
274
2734
|
function useChain(chains, chainId) {
|
|
275
|
-
const list = (0,
|
|
276
|
-
const id = (0,
|
|
277
|
-
const currentChain = (0,
|
|
2735
|
+
const list = (0, import_vue39.computed)(() => (0, import_vue39.toValue)(chains) ?? []);
|
|
2736
|
+
const id = (0, import_vue39.computed)(() => (0, import_vue39.toValue)(chainId) ?? null);
|
|
2737
|
+
const currentChain = (0, import_vue39.computed)(() => (0, import_connect_appkit_core24.resolveChain)(list.value, id.value));
|
|
278
2738
|
return {
|
|
279
2739
|
currentChain,
|
|
280
|
-
chainInfo: (0,
|
|
281
|
-
availableChains: (0,
|
|
282
|
-
currentChainNumber: (0,
|
|
283
|
-
() => currentChain.value ? (0,
|
|
2740
|
+
chainInfo: (0, import_vue39.computed)(() => (0, import_connect_appkit_core24.describeChain)(list.value, id.value)),
|
|
2741
|
+
availableChains: (0, import_vue39.computed)(() => (0, import_connect_appkit_core24.chainsForNamespace)(list.value, id.value)),
|
|
2742
|
+
currentChainNumber: (0, import_vue39.computed)(
|
|
2743
|
+
() => currentChain.value ? (0, import_connect_appkit_core24.chainNumber)(currentChain.value) : null
|
|
284
2744
|
),
|
|
285
|
-
namespace: (0,
|
|
286
|
-
() => currentChain.value ? (0,
|
|
2745
|
+
namespace: (0, import_vue39.computed)(
|
|
2746
|
+
() => currentChain.value ? (0, import_connect_appkit_core24.chainNamespace)(currentChain.value) : null
|
|
287
2747
|
)
|
|
288
2748
|
};
|
|
289
2749
|
}
|
|
290
2750
|
|
|
291
2751
|
// src/usePassphraseGate.ts
|
|
292
|
-
var
|
|
2752
|
+
var import_vue40 = require("vue");
|
|
293
2753
|
function usePassphraseGate(gate) {
|
|
294
|
-
const request = (0,
|
|
2754
|
+
const request = (0, import_vue40.shallowRef)(gate.getSnapshot());
|
|
295
2755
|
const unsubscribe = gate.subscribe(() => {
|
|
296
2756
|
request.value = gate.getSnapshot();
|
|
297
2757
|
});
|
|
298
|
-
(0,
|
|
2758
|
+
(0, import_vue40.onScopeDispose)(unsubscribe);
|
|
299
2759
|
return {
|
|
300
|
-
request: (0,
|
|
2760
|
+
request: (0, import_vue40.readonly)(request),
|
|
301
2761
|
submit: (passphrase) => gate.submit(passphrase),
|
|
302
2762
|
cancel: (reason) => gate.cancel(reason),
|
|
303
2763
|
forget: (reason) => gate.forget(reason)
|
|
@@ -305,17 +2765,17 @@ function usePassphraseGate(gate) {
|
|
|
305
2765
|
}
|
|
306
2766
|
|
|
307
2767
|
// src/useSolanaBalance.ts
|
|
308
|
-
var
|
|
309
|
-
var
|
|
2768
|
+
var import_connect_core16 = require("@naculus/connect-core");
|
|
2769
|
+
var import_vue41 = require("vue");
|
|
310
2770
|
function useSolanaBalance(address, rpcUrl) {
|
|
311
|
-
const balance = (0,
|
|
312
|
-
const isFetching = (0,
|
|
313
|
-
const error = (0,
|
|
2771
|
+
const balance = (0, import_vue41.shallowRef)(null);
|
|
2772
|
+
const isFetching = (0, import_vue41.ref)(false);
|
|
2773
|
+
const error = (0, import_vue41.shallowRef)(null);
|
|
314
2774
|
let generation = 0;
|
|
315
2775
|
let disposed = false;
|
|
316
2776
|
const refetch = async () => {
|
|
317
|
-
const addr = (0,
|
|
318
|
-
const url = (0,
|
|
2777
|
+
const addr = (0, import_vue41.toValue)(address);
|
|
2778
|
+
const url = (0, import_vue41.toValue)(rpcUrl);
|
|
319
2779
|
if (!addr || !url) {
|
|
320
2780
|
balance.value = null;
|
|
321
2781
|
return;
|
|
@@ -324,7 +2784,7 @@ function useSolanaBalance(address, rpcUrl) {
|
|
|
324
2784
|
isFetching.value = true;
|
|
325
2785
|
error.value = null;
|
|
326
2786
|
try {
|
|
327
|
-
const next = await (0,
|
|
2787
|
+
const next = await (0, import_connect_core16.getSolanaBalance)(url, addr);
|
|
328
2788
|
if (disposed || own !== generation) return;
|
|
329
2789
|
balance.value = next;
|
|
330
2790
|
} catch (err) {
|
|
@@ -335,31 +2795,221 @@ function useSolanaBalance(address, rpcUrl) {
|
|
|
335
2795
|
if (!disposed && own === generation) isFetching.value = false;
|
|
336
2796
|
}
|
|
337
2797
|
};
|
|
338
|
-
(0,
|
|
339
|
-
(0,
|
|
340
|
-
(0,
|
|
2798
|
+
(0, import_vue41.watchEffect)(() => {
|
|
2799
|
+
(0, import_vue41.toValue)(address);
|
|
2800
|
+
(0, import_vue41.toValue)(rpcUrl);
|
|
341
2801
|
void refetch();
|
|
342
2802
|
});
|
|
343
|
-
(0,
|
|
2803
|
+
(0, import_vue41.onScopeDispose)(() => {
|
|
344
2804
|
disposed = true;
|
|
345
2805
|
});
|
|
346
2806
|
return { balance, isFetching, error, refetch };
|
|
347
2807
|
}
|
|
348
2808
|
|
|
2809
|
+
// src/useLastTx.ts
|
|
2810
|
+
var import_vue42 = require("vue");
|
|
2811
|
+
function useLastTx(monitor) {
|
|
2812
|
+
const lastTx = (0, import_vue42.shallowRef)(null);
|
|
2813
|
+
const lastConfirmedTx = (0, import_vue42.shallowRef)(null);
|
|
2814
|
+
const lastFailedTx = (0, import_vue42.shallowRef)(null);
|
|
2815
|
+
(0, import_vue42.watch)(
|
|
2816
|
+
() => (0, import_vue42.toValue)(monitor),
|
|
2817
|
+
(activeMonitor, _previous, onCleanup) => {
|
|
2818
|
+
if (!activeMonitor) return;
|
|
2819
|
+
const recordLatest = (entry) => {
|
|
2820
|
+
if (!lastTx.value || entry.createdAt >= lastTx.value.createdAt) {
|
|
2821
|
+
lastTx.value = entry;
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
const onConfirmed = (entry) => {
|
|
2825
|
+
lastConfirmedTx.value = entry;
|
|
2826
|
+
recordLatest(entry);
|
|
2827
|
+
};
|
|
2828
|
+
const onFailed = (entry) => {
|
|
2829
|
+
lastFailedTx.value = entry;
|
|
2830
|
+
recordLatest(entry);
|
|
2831
|
+
};
|
|
2832
|
+
activeMonitor.on("confirmed", onConfirmed);
|
|
2833
|
+
activeMonitor.on("failed", onFailed);
|
|
2834
|
+
onCleanup(() => {
|
|
2835
|
+
activeMonitor.off("confirmed", onConfirmed);
|
|
2836
|
+
activeMonitor.off("failed", onFailed);
|
|
2837
|
+
});
|
|
2838
|
+
},
|
|
2839
|
+
{ immediate: true }
|
|
2840
|
+
);
|
|
2841
|
+
return {
|
|
2842
|
+
lastTx,
|
|
2843
|
+
lastConfirmedTx,
|
|
2844
|
+
lastFailedTx,
|
|
2845
|
+
clear: () => {
|
|
2846
|
+
lastTx.value = null;
|
|
2847
|
+
lastConfirmedTx.value = null;
|
|
2848
|
+
lastFailedTx.value = null;
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
// src/useTxHistory.ts
|
|
2854
|
+
var import_vue43 = require("vue");
|
|
2855
|
+
function useTxHistory(address, chainId, monitor) {
|
|
2856
|
+
const entries = (0, import_vue43.shallowRef)([]);
|
|
2857
|
+
const isLoading = (0, import_vue43.shallowRef)(false);
|
|
2858
|
+
const error = (0, import_vue43.shallowRef)(null);
|
|
2859
|
+
let generation = 0;
|
|
2860
|
+
const refresh = async () => {
|
|
2861
|
+
const mine = ++generation;
|
|
2862
|
+
const activeMonitor = (0, import_vue43.toValue)(monitor);
|
|
2863
|
+
if (!activeMonitor) {
|
|
2864
|
+
entries.value = [];
|
|
2865
|
+
isLoading.value = false;
|
|
2866
|
+
error.value = null;
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
isLoading.value = true;
|
|
2870
|
+
error.value = null;
|
|
2871
|
+
try {
|
|
2872
|
+
const result = await activeMonitor.getTxHistory(
|
|
2873
|
+
(0, import_vue43.toValue)(address) ?? void 0,
|
|
2874
|
+
(0, import_vue43.toValue)(chainId) ?? void 0
|
|
2875
|
+
);
|
|
2876
|
+
if (mine === generation) entries.value = result;
|
|
2877
|
+
} catch (err) {
|
|
2878
|
+
if (mine !== generation) return;
|
|
2879
|
+
error.value = err instanceof Error ? err : new Error("Failed to load transaction history");
|
|
2880
|
+
} finally {
|
|
2881
|
+
if (mine === generation) isLoading.value = false;
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
(0, import_vue43.watch)(
|
|
2885
|
+
[() => (0, import_vue43.toValue)(monitor), () => (0, import_vue43.toValue)(address), () => (0, import_vue43.toValue)(chainId)],
|
|
2886
|
+
([activeMonitor], _previous, onCleanup) => {
|
|
2887
|
+
if (!activeMonitor) {
|
|
2888
|
+
void refresh();
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
const onStatusChange = () => {
|
|
2892
|
+
void refresh();
|
|
2893
|
+
};
|
|
2894
|
+
activeMonitor.on("statusChange", onStatusChange);
|
|
2895
|
+
onCleanup(() => activeMonitor.off("statusChange", onStatusChange));
|
|
2896
|
+
void refresh();
|
|
2897
|
+
},
|
|
2898
|
+
{ immediate: true }
|
|
2899
|
+
);
|
|
2900
|
+
return {
|
|
2901
|
+
entries,
|
|
2902
|
+
isLoading,
|
|
2903
|
+
error,
|
|
2904
|
+
refresh,
|
|
2905
|
+
summary: (0, import_vue43.computed)(() => ({
|
|
2906
|
+
pending: entries.value.filter((item) => item.status === "pending").length,
|
|
2907
|
+
confirmed: entries.value.filter((item) => item.status === "confirmed").length,
|
|
2908
|
+
failed: entries.value.filter((item) => item.status === "failed").length
|
|
2909
|
+
}))
|
|
2910
|
+
};
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2913
|
+
// src/useTxMonitor.ts
|
|
2914
|
+
var import_vue44 = require("vue");
|
|
2915
|
+
function useTxMonitor(hash, chainId, monitor) {
|
|
2916
|
+
const entry = (0, import_vue44.shallowRef)(null);
|
|
2917
|
+
const isLoading = (0, import_vue44.shallowRef)(false);
|
|
2918
|
+
const isWatching = (0, import_vue44.shallowRef)(false);
|
|
2919
|
+
const error = (0, import_vue44.shallowRef)(null);
|
|
2920
|
+
let generation = 0;
|
|
2921
|
+
const refresh = async () => {
|
|
2922
|
+
const activeMonitor = (0, import_vue44.toValue)(monitor);
|
|
2923
|
+
const activeHash = (0, import_vue44.toValue)(hash);
|
|
2924
|
+
const activeChainId = (0, import_vue44.toValue)(chainId);
|
|
2925
|
+
if (!activeMonitor || !activeHash) return;
|
|
2926
|
+
isLoading.value = true;
|
|
2927
|
+
error.value = null;
|
|
2928
|
+
try {
|
|
2929
|
+
await activeMonitor.refreshTx(activeHash, activeChainId ?? void 0);
|
|
2930
|
+
const current = activeMonitor.getTxStatus(
|
|
2931
|
+
activeHash,
|
|
2932
|
+
activeChainId ?? void 0
|
|
2933
|
+
);
|
|
2934
|
+
if (current) entry.value = current;
|
|
2935
|
+
} catch (err) {
|
|
2936
|
+
error.value = err instanceof Error ? err : new Error("Failed to refresh transaction");
|
|
2937
|
+
} finally {
|
|
2938
|
+
isLoading.value = false;
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
const stopWatching = () => {
|
|
2942
|
+
const activeMonitor = (0, import_vue44.toValue)(monitor);
|
|
2943
|
+
const activeHash = (0, import_vue44.toValue)(hash);
|
|
2944
|
+
const activeChainId = (0, import_vue44.toValue)(chainId);
|
|
2945
|
+
if (!activeMonitor || !activeHash) return;
|
|
2946
|
+
activeMonitor.stopWatching(activeHash, activeChainId ?? void 0);
|
|
2947
|
+
isWatching.value = false;
|
|
2948
|
+
};
|
|
2949
|
+
(0, import_vue44.watch)(
|
|
2950
|
+
[() => (0, import_vue44.toValue)(monitor), () => (0, import_vue44.toValue)(hash), () => (0, import_vue44.toValue)(chainId)],
|
|
2951
|
+
([activeMonitor, activeHash, activeChainId], _previous, onCleanup) => {
|
|
2952
|
+
const mine = ++generation;
|
|
2953
|
+
if (!activeMonitor || !activeHash || !activeChainId) {
|
|
2954
|
+
entry.value = null;
|
|
2955
|
+
isLoading.value = false;
|
|
2956
|
+
isWatching.value = false;
|
|
2957
|
+
error.value = null;
|
|
2958
|
+
return;
|
|
2959
|
+
}
|
|
2960
|
+
let cancelled = false;
|
|
2961
|
+
const onStatusChange = (updated) => {
|
|
2962
|
+
if (!cancelled && updated.hash === activeHash && updated.chainId === activeChainId) {
|
|
2963
|
+
entry.value = { ...updated };
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
activeMonitor.on("statusChange", onStatusChange);
|
|
2967
|
+
onCleanup(() => {
|
|
2968
|
+
cancelled = true;
|
|
2969
|
+
activeMonitor.off("statusChange", onStatusChange);
|
|
2970
|
+
});
|
|
2971
|
+
isWatching.value = true;
|
|
2972
|
+
isLoading.value = true;
|
|
2973
|
+
error.value = null;
|
|
2974
|
+
const current = activeMonitor.getTxStatus(activeHash, activeChainId);
|
|
2975
|
+
if (current) entry.value = current;
|
|
2976
|
+
activeMonitor.watchTx(activeHash, activeChainId, {}).then((initial) => {
|
|
2977
|
+
if (cancelled || mine !== generation) return;
|
|
2978
|
+
entry.value = initial;
|
|
2979
|
+
isLoading.value = false;
|
|
2980
|
+
}).catch((err) => {
|
|
2981
|
+
if (cancelled || mine !== generation) return;
|
|
2982
|
+
error.value = err instanceof Error ? err : new Error("Failed to watch transaction");
|
|
2983
|
+
isLoading.value = false;
|
|
2984
|
+
});
|
|
2985
|
+
},
|
|
2986
|
+
{ immediate: true }
|
|
2987
|
+
);
|
|
2988
|
+
return {
|
|
2989
|
+
entry,
|
|
2990
|
+
status: (0, import_vue44.computed)(() => entry.value?.status ?? "idle"),
|
|
2991
|
+
isLoading,
|
|
2992
|
+
isWatching,
|
|
2993
|
+
error,
|
|
2994
|
+
refresh,
|
|
2995
|
+
stopWatching
|
|
2996
|
+
};
|
|
2997
|
+
}
|
|
2998
|
+
|
|
349
2999
|
// src/useCapabilities.ts
|
|
350
|
-
var
|
|
351
|
-
var
|
|
3000
|
+
var import_connect_appkit_core25 = require("@naculus/connect-appkit-core");
|
|
3001
|
+
var import_vue45 = require("vue");
|
|
352
3002
|
function useCapabilities(client, session, chainId) {
|
|
353
|
-
const capabilities = (0,
|
|
3003
|
+
const capabilities = (0, import_vue45.shallowRef)(
|
|
354
3004
|
null
|
|
355
3005
|
);
|
|
356
|
-
const isFetching = (0,
|
|
357
|
-
const error = (0,
|
|
3006
|
+
const isFetching = (0, import_vue45.shallowRef)(false);
|
|
3007
|
+
const error = (0, import_vue45.shallowRef)(null);
|
|
358
3008
|
let generation = 0;
|
|
359
3009
|
const refetch = async () => {
|
|
360
3010
|
const mine = ++generation;
|
|
361
|
-
const activeClient = (0,
|
|
362
|
-
const activeSession = (0,
|
|
3011
|
+
const activeClient = (0, import_vue45.toValue)(client);
|
|
3012
|
+
const activeSession = (0, import_vue45.toValue)(session);
|
|
363
3013
|
if (!activeClient?.getCapabilities || !activeSession) {
|
|
364
3014
|
capabilities.value = null;
|
|
365
3015
|
isFetching.value = false;
|
|
@@ -371,7 +3021,7 @@ function useCapabilities(client, session, chainId) {
|
|
|
371
3021
|
try {
|
|
372
3022
|
const raw = await activeClient.getCapabilities(activeSession);
|
|
373
3023
|
if (mine !== generation) return;
|
|
374
|
-
capabilities.value = (0,
|
|
3024
|
+
capabilities.value = (0, import_connect_appkit_core25.normalizeCapabilities)(raw);
|
|
375
3025
|
} catch (err) {
|
|
376
3026
|
if (mine !== generation) return;
|
|
377
3027
|
capabilities.value = null;
|
|
@@ -380,18 +3030,18 @@ function useCapabilities(client, session, chainId) {
|
|
|
380
3030
|
if (mine === generation) isFetching.value = false;
|
|
381
3031
|
}
|
|
382
3032
|
};
|
|
383
|
-
(0,
|
|
384
|
-
void (0,
|
|
385
|
-
void (0,
|
|
3033
|
+
(0, import_vue45.watchEffect)(() => {
|
|
3034
|
+
void (0, import_vue45.toValue)(client);
|
|
3035
|
+
void (0, import_vue45.toValue)(session);
|
|
386
3036
|
void refetch();
|
|
387
3037
|
});
|
|
388
3038
|
return {
|
|
389
3039
|
capabilities,
|
|
390
|
-
current: (0,
|
|
391
|
-
() => (0,
|
|
3040
|
+
current: (0, import_vue45.computed)(
|
|
3041
|
+
() => (0, import_connect_appkit_core25.selectChainCapabilities)(capabilities.value, (0, import_vue45.toValue)(chainId))
|
|
392
3042
|
),
|
|
393
|
-
atomic: (0,
|
|
394
|
-
() => (0,
|
|
3043
|
+
atomic: (0, import_vue45.computed)(
|
|
3044
|
+
() => (0, import_connect_appkit_core25.atomicSupportFor)(capabilities.value, (0, import_vue45.toValue)(chainId))
|
|
395
3045
|
),
|
|
396
3046
|
isFetching,
|
|
397
3047
|
error,
|
|
@@ -400,18 +3050,18 @@ function useCapabilities(client, session, chainId) {
|
|
|
400
3050
|
}
|
|
401
3051
|
|
|
402
3052
|
// src/useSolanaRoles.ts
|
|
403
|
-
var
|
|
404
|
-
var
|
|
3053
|
+
var import_connect_appkit_core26 = require("@naculus/connect-appkit-core");
|
|
3054
|
+
var import_vue46 = require("vue");
|
|
405
3055
|
function useSolanaRoles(connector, session) {
|
|
406
|
-
const state = (0,
|
|
407
|
-
() => (0,
|
|
3056
|
+
const state = (0, import_vue46.computed)(
|
|
3057
|
+
() => (0, import_connect_appkit_core26.readSolanaRoles)((0, import_vue46.toValue)(connector), (0, import_vue46.toValue)(session))
|
|
408
3058
|
);
|
|
409
3059
|
return {
|
|
410
|
-
roles: (0,
|
|
411
|
-
absence: (0,
|
|
412
|
-
identity: (0,
|
|
413
|
-
signer: (0,
|
|
414
|
-
payer: (0,
|
|
3060
|
+
roles: (0, import_vue46.computed)(() => state.value.roles),
|
|
3061
|
+
absence: (0, import_vue46.computed)(() => state.value.absence),
|
|
3062
|
+
identity: (0, import_vue46.computed)(() => state.value.roles?.identity ?? null),
|
|
3063
|
+
signer: (0, import_vue46.computed)(() => state.value.roles?.signer ?? null),
|
|
3064
|
+
payer: (0, import_vue46.computed)(() => state.value.roles?.payer ?? null)
|
|
415
3065
|
};
|
|
416
3066
|
}
|
|
417
3067
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -444,11 +3094,56 @@ function useSolanaRoles(connector, session) {
|
|
|
444
3094
|
AppkitTabs,
|
|
445
3095
|
AppkitToggleGroup,
|
|
446
3096
|
AppkitTooltip,
|
|
3097
|
+
useAccount,
|
|
447
3098
|
useAccounts,
|
|
3099
|
+
useBalance,
|
|
448
3100
|
useCapabilities,
|
|
449
3101
|
useChain,
|
|
3102
|
+
useCompareCosts,
|
|
3103
|
+
useConnect,
|
|
3104
|
+
useCreateSessionKey,
|
|
3105
|
+
useDelegation,
|
|
3106
|
+
useDelegationPolicy,
|
|
3107
|
+
useDisconnect,
|
|
3108
|
+
useERC20Approve,
|
|
3109
|
+
useERC20Transfer,
|
|
3110
|
+
useERC20TransferSimulation,
|
|
3111
|
+
useEmbeddedWallet,
|
|
3112
|
+
useExecuteCalls,
|
|
3113
|
+
useExecuteRoute,
|
|
3114
|
+
useLastTx,
|
|
3115
|
+
useLookupAddress,
|
|
3116
|
+
useNotification,
|
|
450
3117
|
usePassphraseGate,
|
|
3118
|
+
useResolveName,
|
|
3119
|
+
useRevokeSession,
|
|
3120
|
+
useRouteQuote,
|
|
3121
|
+
useSIWxLogin,
|
|
3122
|
+
useSIWxSession,
|
|
3123
|
+
useSendCalls,
|
|
3124
|
+
useSendTransaction,
|
|
3125
|
+
useSendUserOperation,
|
|
3126
|
+
useSendWithSession,
|
|
3127
|
+
useSession,
|
|
3128
|
+
useSessionKeys,
|
|
3129
|
+
useSignInWithEthereum,
|
|
3130
|
+
useSignInWithX,
|
|
3131
|
+
useSignMessage,
|
|
3132
|
+
useSimulateTransfer,
|
|
3133
|
+
useSiwxAuthSession,
|
|
3134
|
+
useSmartAccount,
|
|
3135
|
+
useSolanaAccount,
|
|
451
3136
|
useSolanaBalance,
|
|
452
|
-
useSolanaRoles
|
|
3137
|
+
useSolanaRoles,
|
|
3138
|
+
useSolanaTransaction,
|
|
3139
|
+
useSwitchChain,
|
|
3140
|
+
useTokenBalance,
|
|
3141
|
+
useTokenList,
|
|
3142
|
+
useTokenSearch,
|
|
3143
|
+
useTransactionSimulation,
|
|
3144
|
+
useTxHistory,
|
|
3145
|
+
useTxMonitor,
|
|
3146
|
+
useUserOpStatus,
|
|
3147
|
+
useValidateDestination
|
|
453
3148
|
});
|
|
454
3149
|
//# sourceMappingURL=index.cjs.map
|