@miden-sdk/react 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +78 -2
- package/dist/index.d.ts +78 -2
- package/dist/index.js +251 -136
- package/dist/index.mjs +176 -72
- package/package.json +1 -1
package/dist/index.js
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
|
|
@@ -22,6 +32,7 @@ var index_exports = {};
|
|
|
22
32
|
__export(index_exports, {
|
|
23
33
|
DEFAULTS: () => DEFAULTS,
|
|
24
34
|
MidenProvider: () => MidenProvider,
|
|
35
|
+
SignerContext: () => SignerContext,
|
|
25
36
|
formatAssetAmount: () => formatAssetAmount,
|
|
26
37
|
formatNoteSummary: () => formatNoteSummary,
|
|
27
38
|
getNoteSummary: () => getNoteSummary,
|
|
@@ -41,6 +52,7 @@ __export(index_exports, {
|
|
|
41
52
|
useMultiSend: () => useMultiSend,
|
|
42
53
|
useNotes: () => useNotes,
|
|
43
54
|
useSend: () => useSend,
|
|
55
|
+
useSigner: () => useSigner,
|
|
44
56
|
useSwap: () => useSwap,
|
|
45
57
|
useSyncState: () => useSyncState,
|
|
46
58
|
useTransaction: () => useTransaction,
|
|
@@ -83,7 +95,7 @@ var useMidenStore = (0, import_zustand.create)()((set) => ({
|
|
|
83
95
|
...initialState,
|
|
84
96
|
setClient: (client) => set({
|
|
85
97
|
client,
|
|
86
|
-
isReady:
|
|
98
|
+
isReady: client !== null,
|
|
87
99
|
isInitializing: false,
|
|
88
100
|
initError: null
|
|
89
101
|
}),
|
|
@@ -245,7 +257,7 @@ var toBech32AccountId = (accountId) => {
|
|
|
245
257
|
};
|
|
246
258
|
|
|
247
259
|
// src/context/MidenProvider.tsx
|
|
248
|
-
var
|
|
260
|
+
var import_react2 = require("react");
|
|
249
261
|
var import_miden_sdk5 = require("@miden-sdk/miden-sdk");
|
|
250
262
|
|
|
251
263
|
// src/types/index.ts
|
|
@@ -351,9 +363,72 @@ function normalizeTimeout(timeoutMs) {
|
|
|
351
363
|
return typeof timeoutMs === "bigint" ? timeoutMs : BigInt(timeoutMs);
|
|
352
364
|
}
|
|
353
365
|
|
|
366
|
+
// src/context/SignerContext.ts
|
|
367
|
+
var import_react = require("react");
|
|
368
|
+
var SignerContext = (0, import_react.createContext)(null);
|
|
369
|
+
function useSigner() {
|
|
370
|
+
return (0, import_react.useContext)(SignerContext);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// src/utils/signerAccount.ts
|
|
374
|
+
async function getAccountType(accountType) {
|
|
375
|
+
const { AccountType } = await import("@miden-sdk/miden-sdk");
|
|
376
|
+
switch (accountType) {
|
|
377
|
+
case "RegularAccountImmutableCode":
|
|
378
|
+
return AccountType.RegularAccountImmutableCode;
|
|
379
|
+
case "RegularAccountUpdatableCode":
|
|
380
|
+
return AccountType.RegularAccountUpdatableCode;
|
|
381
|
+
case "FungibleFaucet":
|
|
382
|
+
return AccountType.FungibleFaucet;
|
|
383
|
+
case "NonFungibleFaucet":
|
|
384
|
+
return AccountType.NonFungibleFaucet;
|
|
385
|
+
default:
|
|
386
|
+
return AccountType.RegularAccountImmutableCode;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function isPrivateStorageMode(storageMode) {
|
|
390
|
+
return storageMode.toString() === "private";
|
|
391
|
+
}
|
|
392
|
+
async function initializeSignerAccount(client, config) {
|
|
393
|
+
const { AccountBuilder, AccountComponent, Word } = await import("@miden-sdk/miden-sdk");
|
|
394
|
+
await client.syncState();
|
|
395
|
+
const commitmentWord = Word.deserialize(config.publicKeyCommitment);
|
|
396
|
+
const seed = config.accountSeed ?? crypto.getRandomValues(new Uint8Array(32));
|
|
397
|
+
const accountType = await getAccountType(config.accountType);
|
|
398
|
+
const builder = new AccountBuilder(seed);
|
|
399
|
+
const buildResult = builder.withAuthComponent(
|
|
400
|
+
AccountComponent.createAuthComponentFromCommitment(
|
|
401
|
+
commitmentWord,
|
|
402
|
+
1
|
|
403
|
+
// ECDSA auth scheme (K256/Keccak)
|
|
404
|
+
)
|
|
405
|
+
).accountType(accountType).storageMode(config.storageMode).withBasicWalletComponent().build();
|
|
406
|
+
const account = buildResult.account;
|
|
407
|
+
const accountId = account.id();
|
|
408
|
+
if (!isPrivateStorageMode(config.storageMode)) {
|
|
409
|
+
try {
|
|
410
|
+
await client.importAccountById(accountId);
|
|
411
|
+
await client.syncState();
|
|
412
|
+
return accountId.toString();
|
|
413
|
+
} catch {
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
const existing = await client.getAccount(accountId);
|
|
418
|
+
if (existing) {
|
|
419
|
+
await client.syncState();
|
|
420
|
+
return accountId.toString();
|
|
421
|
+
}
|
|
422
|
+
} catch {
|
|
423
|
+
}
|
|
424
|
+
await client.newAccount(account, false);
|
|
425
|
+
await client.syncState();
|
|
426
|
+
return accountId.toString();
|
|
427
|
+
}
|
|
428
|
+
|
|
354
429
|
// src/context/MidenProvider.tsx
|
|
355
430
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
356
|
-
var MidenContext = (0,
|
|
431
|
+
var MidenContext = (0, import_react2.createContext)(null);
|
|
357
432
|
function MidenProvider({
|
|
358
433
|
children,
|
|
359
434
|
config = {},
|
|
@@ -371,17 +446,19 @@ function MidenProvider({
|
|
|
371
446
|
setConfig,
|
|
372
447
|
setSyncState
|
|
373
448
|
} = useMidenStore();
|
|
374
|
-
const syncIntervalRef = (0,
|
|
375
|
-
const isInitializedRef = (0,
|
|
376
|
-
const clientLockRef = (0,
|
|
377
|
-
const
|
|
449
|
+
const syncIntervalRef = (0, import_react2.useRef)(null);
|
|
450
|
+
const isInitializedRef = (0, import_react2.useRef)(false);
|
|
451
|
+
const clientLockRef = (0, import_react2.useRef)(new AsyncLock());
|
|
452
|
+
const signerContext = useSigner();
|
|
453
|
+
const [signerAccountId, setSignerAccountId] = (0, import_react2.useState)(null);
|
|
454
|
+
const resolvedConfig = (0, import_react2.useMemo)(
|
|
378
455
|
() => ({
|
|
379
456
|
...config,
|
|
380
457
|
rpcUrl: resolveRpcUrl(config.rpcUrl)
|
|
381
458
|
}),
|
|
382
459
|
[config]
|
|
383
460
|
);
|
|
384
|
-
const defaultProver = (0,
|
|
461
|
+
const defaultProver = (0, import_react2.useMemo)(
|
|
385
462
|
() => resolveTransactionProver(resolvedConfig),
|
|
386
463
|
[
|
|
387
464
|
resolvedConfig.prover,
|
|
@@ -390,11 +467,11 @@ function MidenProvider({
|
|
|
390
467
|
resolvedConfig.proverUrls?.testnet
|
|
391
468
|
]
|
|
392
469
|
);
|
|
393
|
-
const runExclusive = (0,
|
|
470
|
+
const runExclusive = (0, import_react2.useCallback)(
|
|
394
471
|
async (fn) => clientLockRef.current.runExclusive(fn),
|
|
395
472
|
[]
|
|
396
473
|
);
|
|
397
|
-
const sync = (0,
|
|
474
|
+
const sync = (0, import_react2.useCallback)(async () => {
|
|
398
475
|
if (!client || !isReady) return;
|
|
399
476
|
const store = useMidenStore.getState();
|
|
400
477
|
if (store.sync.isSyncing) return;
|
|
@@ -419,19 +496,50 @@ function MidenProvider({
|
|
|
419
496
|
}
|
|
420
497
|
});
|
|
421
498
|
}, [client, isReady, runExclusive, setSyncState]);
|
|
422
|
-
(0,
|
|
423
|
-
if (isInitializedRef.current) return;
|
|
424
|
-
|
|
499
|
+
(0, import_react2.useEffect)(() => {
|
|
500
|
+
if (!signerContext && isInitializedRef.current) return;
|
|
501
|
+
if (signerContext && !signerContext.isConnected) {
|
|
502
|
+
if (client) {
|
|
503
|
+
useMidenStore.getState().reset();
|
|
504
|
+
setClient(null);
|
|
505
|
+
setSignerAccountId(null);
|
|
506
|
+
}
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
if (!signerContext) {
|
|
510
|
+
isInitializedRef.current = true;
|
|
511
|
+
}
|
|
425
512
|
const initClient = async () => {
|
|
426
513
|
setInitializing(true);
|
|
427
514
|
setConfig(resolvedConfig);
|
|
428
515
|
try {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
516
|
+
let webClient;
|
|
517
|
+
if (signerContext && signerContext.isConnected) {
|
|
518
|
+
const storeName = `MidenClientDB_${signerContext.storeName}`;
|
|
519
|
+
webClient = await import_miden_sdk5.WebClient.createClientWithExternalKeystore(
|
|
520
|
+
resolvedConfig.rpcUrl,
|
|
521
|
+
resolvedConfig.noteTransportUrl,
|
|
522
|
+
resolvedConfig.seed,
|
|
523
|
+
storeName,
|
|
524
|
+
void 0,
|
|
525
|
+
// getKeyCb - not needed for public accounts
|
|
526
|
+
void 0,
|
|
527
|
+
// insertKeyCb - not needed for public accounts
|
|
528
|
+
signerContext.signCb
|
|
529
|
+
);
|
|
530
|
+
const accountId = await initializeSignerAccount(
|
|
531
|
+
webClient,
|
|
532
|
+
signerContext.accountConfig
|
|
533
|
+
);
|
|
534
|
+
setSignerAccountId(accountId);
|
|
535
|
+
} else {
|
|
536
|
+
const seed = resolvedConfig.seed;
|
|
537
|
+
webClient = await import_miden_sdk5.WebClient.createClient(
|
|
538
|
+
resolvedConfig.rpcUrl,
|
|
539
|
+
resolvedConfig.noteTransportUrl,
|
|
540
|
+
seed
|
|
541
|
+
);
|
|
542
|
+
}
|
|
435
543
|
setClient(webClient);
|
|
436
544
|
try {
|
|
437
545
|
const summary = await runExclusive(() => webClient.syncState());
|
|
@@ -439,6 +547,8 @@ function MidenProvider({
|
|
|
439
547
|
syncHeight: summary.blockNum(),
|
|
440
548
|
lastSyncTime: Date.now()
|
|
441
549
|
});
|
|
550
|
+
const accounts = await webClient.getAccounts();
|
|
551
|
+
useMidenStore.getState().setAccounts(accounts);
|
|
442
552
|
} catch {
|
|
443
553
|
}
|
|
444
554
|
} catch (error) {
|
|
@@ -453,9 +563,11 @@ function MidenProvider({
|
|
|
453
563
|
setConfig,
|
|
454
564
|
setInitError,
|
|
455
565
|
setInitializing,
|
|
456
|
-
setSyncState
|
|
566
|
+
setSyncState,
|
|
567
|
+
signerContext,
|
|
568
|
+
client
|
|
457
569
|
]);
|
|
458
|
-
(0,
|
|
570
|
+
(0, import_react2.useEffect)(() => {
|
|
459
571
|
if (!isReady || !client) return;
|
|
460
572
|
const interval = config.autoSyncInterval ?? DEFAULTS.AUTO_SYNC_INTERVAL;
|
|
461
573
|
if (interval <= 0) return;
|
|
@@ -485,12 +597,13 @@ function MidenProvider({
|
|
|
485
597
|
error: initError,
|
|
486
598
|
sync,
|
|
487
599
|
runExclusive,
|
|
488
|
-
prover: defaultProver
|
|
600
|
+
prover: defaultProver,
|
|
601
|
+
signerAccountId
|
|
489
602
|
};
|
|
490
603
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MidenContext.Provider, { value: contextValue, children });
|
|
491
604
|
}
|
|
492
605
|
function useMiden() {
|
|
493
|
-
const context = (0,
|
|
606
|
+
const context = (0, import_react2.useContext)(MidenContext);
|
|
494
607
|
if (!context) {
|
|
495
608
|
throw new Error("useMiden must be used within a MidenProvider");
|
|
496
609
|
}
|
|
@@ -507,7 +620,7 @@ function useMidenClient() {
|
|
|
507
620
|
}
|
|
508
621
|
|
|
509
622
|
// src/hooks/useAccounts.ts
|
|
510
|
-
var
|
|
623
|
+
var import_react3 = require("react");
|
|
511
624
|
|
|
512
625
|
// src/utils/runExclusive.ts
|
|
513
626
|
var runExclusiveDirect = async (fn) => fn();
|
|
@@ -520,7 +633,7 @@ function useAccounts() {
|
|
|
520
633
|
const isLoadingAccounts = useMidenStore((state) => state.isLoadingAccounts);
|
|
521
634
|
const setLoadingAccounts = useMidenStore((state) => state.setLoadingAccounts);
|
|
522
635
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
523
|
-
const refetch = (0,
|
|
636
|
+
const refetch = (0, import_react3.useCallback)(async () => {
|
|
524
637
|
if (!client || !isReady) return;
|
|
525
638
|
setLoadingAccounts(true);
|
|
526
639
|
try {
|
|
@@ -534,7 +647,7 @@ function useAccounts() {
|
|
|
534
647
|
setLoadingAccounts(false);
|
|
535
648
|
}
|
|
536
649
|
}, [client, isReady, runExclusive, setAccounts, setLoadingAccounts]);
|
|
537
|
-
(0,
|
|
650
|
+
(0, import_react3.useEffect)(() => {
|
|
538
651
|
if (isReady && accounts.length === 0) {
|
|
539
652
|
refetch();
|
|
540
653
|
}
|
|
@@ -570,10 +683,10 @@ function isFaucetId(accountId) {
|
|
|
570
683
|
}
|
|
571
684
|
|
|
572
685
|
// src/hooks/useAccount.ts
|
|
573
|
-
var
|
|
686
|
+
var import_react5 = require("react");
|
|
574
687
|
|
|
575
688
|
// src/hooks/useAssetMetadata.ts
|
|
576
|
-
var
|
|
689
|
+
var import_react4 = require("react");
|
|
577
690
|
var import_miden_sdk6 = require("@miden-sdk/miden-sdk");
|
|
578
691
|
var inflight = /* @__PURE__ */ new Map();
|
|
579
692
|
var rpcClients = /* @__PURE__ */ new Map();
|
|
@@ -616,12 +729,12 @@ function useAssetMetadata(assetIds = []) {
|
|
|
616
729
|
const assetMetadata = useAssetMetadataStore();
|
|
617
730
|
const setAssetMetadata = useMidenStore((state) => state.setAssetMetadata);
|
|
618
731
|
const rpcUrl = useMidenStore((state) => state.config.rpcUrl);
|
|
619
|
-
const rpcClient = (0,
|
|
620
|
-
const uniqueAssetIds = (0,
|
|
732
|
+
const rpcClient = (0, import_react4.useMemo)(() => getRpcClient(rpcUrl), [rpcUrl]);
|
|
733
|
+
const uniqueAssetIds = (0, import_react4.useMemo)(
|
|
621
734
|
() => Array.from(new Set(assetIds.filter(Boolean))),
|
|
622
735
|
[assetIds]
|
|
623
736
|
);
|
|
624
|
-
(0,
|
|
737
|
+
(0, import_react4.useEffect)(() => {
|
|
625
738
|
if (!client || !isReady || uniqueAssetIds.length === 0) return;
|
|
626
739
|
uniqueAssetIds.forEach((assetId) => {
|
|
627
740
|
const existing = assetMetadata.get(assetId);
|
|
@@ -658,9 +771,9 @@ function useAccount(accountId) {
|
|
|
658
771
|
const accountDetails = useMidenStore((state) => state.accountDetails);
|
|
659
772
|
const setAccountDetails = useMidenStore((state) => state.setAccountDetails);
|
|
660
773
|
const { lastSyncTime } = useSyncStateStore();
|
|
661
|
-
const [isLoading, setIsLoading] = (0,
|
|
662
|
-
const [error, setError] = (0,
|
|
663
|
-
const accountIdStr = (0,
|
|
774
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
|
|
775
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
776
|
+
const accountIdStr = (0, import_react5.useMemo)(() => {
|
|
664
777
|
if (!accountId) return void 0;
|
|
665
778
|
if (typeof accountId === "string") return accountId;
|
|
666
779
|
if (typeof accountId.toString === "function") {
|
|
@@ -669,7 +782,7 @@ function useAccount(accountId) {
|
|
|
669
782
|
return String(accountId);
|
|
670
783
|
}, [accountId]);
|
|
671
784
|
const account = accountIdStr ? accountDetails.get(accountIdStr) ?? null : null;
|
|
672
|
-
const refetch = (0,
|
|
785
|
+
const refetch = (0, import_react5.useCallback)(async () => {
|
|
673
786
|
if (!client || !isReady || !accountIdStr) return;
|
|
674
787
|
setIsLoading(true);
|
|
675
788
|
setError(null);
|
|
@@ -688,16 +801,16 @@ function useAccount(accountId) {
|
|
|
688
801
|
setIsLoading(false);
|
|
689
802
|
}
|
|
690
803
|
}, [client, isReady, runExclusive, accountIdStr, setAccountDetails]);
|
|
691
|
-
(0,
|
|
804
|
+
(0, import_react5.useEffect)(() => {
|
|
692
805
|
if (isReady && accountIdStr && !account) {
|
|
693
806
|
refetch();
|
|
694
807
|
}
|
|
695
808
|
}, [isReady, accountIdStr, account, refetch]);
|
|
696
|
-
(0,
|
|
809
|
+
(0, import_react5.useEffect)(() => {
|
|
697
810
|
if (!isReady || !accountIdStr || !lastSyncTime) return;
|
|
698
811
|
refetch();
|
|
699
812
|
}, [isReady, accountIdStr, lastSyncTime, refetch]);
|
|
700
|
-
const rawAssets = (0,
|
|
813
|
+
const rawAssets = (0, import_react5.useMemo)(() => {
|
|
701
814
|
if (!account) return [];
|
|
702
815
|
try {
|
|
703
816
|
const vault = account.vault();
|
|
@@ -714,12 +827,12 @@ function useAccount(accountId) {
|
|
|
714
827
|
return [];
|
|
715
828
|
}
|
|
716
829
|
}, [account]);
|
|
717
|
-
const assetIds = (0,
|
|
830
|
+
const assetIds = (0, import_react5.useMemo)(
|
|
718
831
|
() => rawAssets.map((asset) => asset.assetId),
|
|
719
832
|
[rawAssets]
|
|
720
833
|
);
|
|
721
834
|
const { assetMetadata } = useAssetMetadata(assetIds);
|
|
722
|
-
const assets = (0,
|
|
835
|
+
const assets = (0, import_react5.useMemo)(
|
|
723
836
|
() => rawAssets.map((asset) => {
|
|
724
837
|
const metadata = assetMetadata.get(asset.assetId);
|
|
725
838
|
return {
|
|
@@ -730,7 +843,7 @@ function useAccount(accountId) {
|
|
|
730
843
|
}),
|
|
731
844
|
[rawAssets, assetMetadata]
|
|
732
845
|
);
|
|
733
|
-
const getBalance = (0,
|
|
846
|
+
const getBalance = (0, import_react5.useCallback)(
|
|
734
847
|
(assetId) => {
|
|
735
848
|
const asset = assets.find((a) => a.assetId === assetId);
|
|
736
849
|
return asset?.amount ?? 0n;
|
|
@@ -748,7 +861,7 @@ function useAccount(accountId) {
|
|
|
748
861
|
}
|
|
749
862
|
|
|
750
863
|
// src/hooks/useNotes.ts
|
|
751
|
-
var
|
|
864
|
+
var import_react6 = require("react");
|
|
752
865
|
var import_miden_sdk7 = require("@miden-sdk/miden-sdk");
|
|
753
866
|
|
|
754
867
|
// src/utils/amounts.ts
|
|
@@ -844,8 +957,8 @@ function useNotes(options) {
|
|
|
844
957
|
const setNotes = useMidenStore((state) => state.setNotes);
|
|
845
958
|
const setConsumableNotes = useMidenStore((state) => state.setConsumableNotes);
|
|
846
959
|
const { lastSyncTime } = useSyncStateStore();
|
|
847
|
-
const [error, setError] = (0,
|
|
848
|
-
const refetch = (0,
|
|
960
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
961
|
+
const refetch = (0, import_react6.useCallback)(async () => {
|
|
849
962
|
if (!client || !isReady) return;
|
|
850
963
|
setLoadingNotes(true);
|
|
851
964
|
setError(null);
|
|
@@ -885,16 +998,16 @@ function useNotes(options) {
|
|
|
885
998
|
setNotes,
|
|
886
999
|
setConsumableNotes
|
|
887
1000
|
]);
|
|
888
|
-
(0,
|
|
1001
|
+
(0, import_react6.useEffect)(() => {
|
|
889
1002
|
if (isReady && notes.length === 0) {
|
|
890
1003
|
refetch();
|
|
891
1004
|
}
|
|
892
1005
|
}, [isReady, notes.length, refetch]);
|
|
893
|
-
(0,
|
|
1006
|
+
(0, import_react6.useEffect)(() => {
|
|
894
1007
|
if (!isReady || !lastSyncTime) return;
|
|
895
1008
|
refetch();
|
|
896
1009
|
}, [isReady, lastSyncTime, refetch]);
|
|
897
|
-
const noteAssetIds = (0,
|
|
1010
|
+
const noteAssetIds = (0, import_react6.useMemo)(() => {
|
|
898
1011
|
const ids = /* @__PURE__ */ new Set();
|
|
899
1012
|
const collect = (note) => {
|
|
900
1013
|
const summary = getNoteSummary(note);
|
|
@@ -906,15 +1019,15 @@ function useNotes(options) {
|
|
|
906
1019
|
return Array.from(ids);
|
|
907
1020
|
}, [notes, consumableNotes]);
|
|
908
1021
|
const { assetMetadata } = useAssetMetadata(noteAssetIds);
|
|
909
|
-
const getMetadata = (0,
|
|
1022
|
+
const getMetadata = (0, import_react6.useCallback)(
|
|
910
1023
|
(assetId) => assetMetadata.get(assetId),
|
|
911
1024
|
[assetMetadata]
|
|
912
1025
|
);
|
|
913
|
-
const noteSummaries = (0,
|
|
1026
|
+
const noteSummaries = (0, import_react6.useMemo)(
|
|
914
1027
|
() => notes.map((note) => getNoteSummary(note, getMetadata)).filter(Boolean),
|
|
915
1028
|
[notes, getMetadata]
|
|
916
1029
|
);
|
|
917
|
-
const consumableNoteSummaries = (0,
|
|
1030
|
+
const consumableNoteSummaries = (0, import_react6.useMemo)(
|
|
918
1031
|
() => consumableNotes.map((note) => getNoteSummary(note, getMetadata)).filter(Boolean),
|
|
919
1032
|
[consumableNotes, getMetadata]
|
|
920
1033
|
);
|
|
@@ -945,21 +1058,21 @@ function getNoteFilterType(status) {
|
|
|
945
1058
|
}
|
|
946
1059
|
|
|
947
1060
|
// src/hooks/useTransactionHistory.ts
|
|
948
|
-
var
|
|
1061
|
+
var import_react7 = require("react");
|
|
949
1062
|
var import_miden_sdk8 = require("@miden-sdk/miden-sdk");
|
|
950
1063
|
function useTransactionHistory(options = {}) {
|
|
951
1064
|
const { client, isReady, runExclusive } = useMiden();
|
|
952
1065
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
953
1066
|
const { lastSyncTime } = useSyncStateStore();
|
|
954
|
-
const [records, setRecords] = (0,
|
|
955
|
-
const [isLoading, setIsLoading] = (0,
|
|
956
|
-
const [error, setError] = (0,
|
|
957
|
-
const rawIds = (0,
|
|
1067
|
+
const [records, setRecords] = (0, import_react7.useState)([]);
|
|
1068
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
|
|
1069
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
1070
|
+
const rawIds = (0, import_react7.useMemo)(() => {
|
|
958
1071
|
if (options.id) return [options.id];
|
|
959
1072
|
if (options.ids && options.ids.length > 0) return options.ids;
|
|
960
1073
|
return null;
|
|
961
1074
|
}, [options.id, options.ids]);
|
|
962
|
-
const idsHex = (0,
|
|
1075
|
+
const idsHex = (0, import_react7.useMemo)(() => {
|
|
963
1076
|
if (!rawIds) return null;
|
|
964
1077
|
return rawIds.map(
|
|
965
1078
|
(id) => normalizeHex(typeof id === "string" ? id : id.toHex())
|
|
@@ -967,7 +1080,7 @@ function useTransactionHistory(options = {}) {
|
|
|
967
1080
|
}, [rawIds]);
|
|
968
1081
|
const filter = options.filter;
|
|
969
1082
|
const refreshOnSync = options.refreshOnSync !== false;
|
|
970
|
-
const refetch = (0,
|
|
1083
|
+
const refetch = (0, import_react7.useCallback)(async () => {
|
|
971
1084
|
if (!client || !isReady) return;
|
|
972
1085
|
setIsLoading(true);
|
|
973
1086
|
setError(null);
|
|
@@ -990,19 +1103,19 @@ function useTransactionHistory(options = {}) {
|
|
|
990
1103
|
setIsLoading(false);
|
|
991
1104
|
}
|
|
992
1105
|
}, [client, isReady, runExclusiveSafe, filter, rawIds, idsHex]);
|
|
993
|
-
(0,
|
|
1106
|
+
(0, import_react7.useEffect)(() => {
|
|
994
1107
|
if (!isReady) return;
|
|
995
1108
|
refetch();
|
|
996
1109
|
}, [isReady, refetch]);
|
|
997
|
-
(0,
|
|
1110
|
+
(0, import_react7.useEffect)(() => {
|
|
998
1111
|
if (!isReady || !refreshOnSync || !lastSyncTime) return;
|
|
999
1112
|
refetch();
|
|
1000
1113
|
}, [isReady, lastSyncTime, refreshOnSync, refetch]);
|
|
1001
|
-
const record = (0,
|
|
1114
|
+
const record = (0, import_react7.useMemo)(() => {
|
|
1002
1115
|
if (!idsHex || idsHex.length !== 1) return null;
|
|
1003
1116
|
return records.find((item) => normalizeHex(item.id().toHex()) === idsHex[0]) ?? null;
|
|
1004
1117
|
}, [records, idsHex]);
|
|
1005
|
-
const status = (0,
|
|
1118
|
+
const status = (0, import_react7.useMemo)(() => {
|
|
1006
1119
|
if (!record) return null;
|
|
1007
1120
|
const current = record.transactionStatus();
|
|
1008
1121
|
if (current.isCommitted()) return "committed";
|
|
@@ -1042,11 +1155,11 @@ function normalizeHex(value) {
|
|
|
1042
1155
|
}
|
|
1043
1156
|
|
|
1044
1157
|
// src/hooks/useSyncState.ts
|
|
1045
|
-
var
|
|
1158
|
+
var import_react8 = require("react");
|
|
1046
1159
|
function useSyncState() {
|
|
1047
1160
|
const { sync: triggerSync } = useMiden();
|
|
1048
1161
|
const syncState = useSyncStateStore();
|
|
1049
|
-
const sync = (0,
|
|
1162
|
+
const sync = (0, import_react8.useCallback)(async () => {
|
|
1050
1163
|
await triggerSync();
|
|
1051
1164
|
}, [triggerSync]);
|
|
1052
1165
|
return {
|
|
@@ -1056,16 +1169,16 @@ function useSyncState() {
|
|
|
1056
1169
|
}
|
|
1057
1170
|
|
|
1058
1171
|
// src/hooks/useCreateWallet.ts
|
|
1059
|
-
var
|
|
1172
|
+
var import_react9 = require("react");
|
|
1060
1173
|
var import_miden_sdk9 = require("@miden-sdk/miden-sdk");
|
|
1061
1174
|
function useCreateWallet() {
|
|
1062
1175
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
1063
1176
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1064
1177
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1065
|
-
const [wallet, setWallet] = (0,
|
|
1066
|
-
const [isCreating, setIsCreating] = (0,
|
|
1067
|
-
const [error, setError] = (0,
|
|
1068
|
-
const createWallet = (0,
|
|
1178
|
+
const [wallet, setWallet] = (0, import_react9.useState)(null);
|
|
1179
|
+
const [isCreating, setIsCreating] = (0, import_react9.useState)(false);
|
|
1180
|
+
const [error, setError] = (0, import_react9.useState)(null);
|
|
1181
|
+
const createWallet = (0, import_react9.useCallback)(
|
|
1069
1182
|
async (options = {}) => {
|
|
1070
1183
|
if (!client || !isReady) {
|
|
1071
1184
|
throw new Error("Miden client is not ready");
|
|
@@ -1103,7 +1216,7 @@ function useCreateWallet() {
|
|
|
1103
1216
|
},
|
|
1104
1217
|
[client, isReady, runExclusive, setAccounts]
|
|
1105
1218
|
);
|
|
1106
|
-
const reset = (0,
|
|
1219
|
+
const reset = (0, import_react9.useCallback)(() => {
|
|
1107
1220
|
setWallet(null);
|
|
1108
1221
|
setIsCreating(false);
|
|
1109
1222
|
setError(null);
|
|
@@ -1130,16 +1243,16 @@ function getStorageMode(mode) {
|
|
|
1130
1243
|
}
|
|
1131
1244
|
|
|
1132
1245
|
// src/hooks/useCreateFaucet.ts
|
|
1133
|
-
var
|
|
1246
|
+
var import_react10 = require("react");
|
|
1134
1247
|
var import_miden_sdk10 = require("@miden-sdk/miden-sdk");
|
|
1135
1248
|
function useCreateFaucet() {
|
|
1136
1249
|
const { client, isReady, runExclusive } = useMiden();
|
|
1137
1250
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1138
1251
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1139
|
-
const [faucet, setFaucet] = (0,
|
|
1140
|
-
const [isCreating, setIsCreating] = (0,
|
|
1141
|
-
const [error, setError] = (0,
|
|
1142
|
-
const createFaucet = (0,
|
|
1252
|
+
const [faucet, setFaucet] = (0, import_react10.useState)(null);
|
|
1253
|
+
const [isCreating, setIsCreating] = (0, import_react10.useState)(false);
|
|
1254
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
1255
|
+
const createFaucet = (0, import_react10.useCallback)(
|
|
1143
1256
|
async (options) => {
|
|
1144
1257
|
if (!client || !isReady) {
|
|
1145
1258
|
throw new Error("Miden client is not ready");
|
|
@@ -1178,7 +1291,7 @@ function useCreateFaucet() {
|
|
|
1178
1291
|
},
|
|
1179
1292
|
[client, isReady, runExclusive, setAccounts]
|
|
1180
1293
|
);
|
|
1181
|
-
const reset = (0,
|
|
1294
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
1182
1295
|
setFaucet(null);
|
|
1183
1296
|
setIsCreating(false);
|
|
1184
1297
|
setError(null);
|
|
@@ -1205,16 +1318,16 @@ function getStorageMode2(mode) {
|
|
|
1205
1318
|
}
|
|
1206
1319
|
|
|
1207
1320
|
// src/hooks/useImportAccount.ts
|
|
1208
|
-
var
|
|
1321
|
+
var import_react11 = require("react");
|
|
1209
1322
|
var import_miden_sdk11 = require("@miden-sdk/miden-sdk");
|
|
1210
1323
|
function useImportAccount() {
|
|
1211
1324
|
const { client, isReady, runExclusive } = useMiden();
|
|
1212
1325
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1213
1326
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1214
|
-
const [account, setAccount] = (0,
|
|
1215
|
-
const [isImporting, setIsImporting] = (0,
|
|
1216
|
-
const [error, setError] = (0,
|
|
1217
|
-
const importAccount = (0,
|
|
1327
|
+
const [account, setAccount] = (0, import_react11.useState)(null);
|
|
1328
|
+
const [isImporting, setIsImporting] = (0, import_react11.useState)(false);
|
|
1329
|
+
const [error, setError] = (0, import_react11.useState)(null);
|
|
1330
|
+
const importAccount = (0, import_react11.useCallback)(
|
|
1218
1331
|
async (options) => {
|
|
1219
1332
|
if (!client || !isReady) {
|
|
1220
1333
|
throw new Error("Miden client is not ready");
|
|
@@ -1309,7 +1422,7 @@ function useImportAccount() {
|
|
|
1309
1422
|
},
|
|
1310
1423
|
[client, isReady, runExclusive, setAccounts]
|
|
1311
1424
|
);
|
|
1312
|
-
const reset = (0,
|
|
1425
|
+
const reset = (0, import_react11.useCallback)(() => {
|
|
1313
1426
|
setAccount(null);
|
|
1314
1427
|
setIsImporting(false);
|
|
1315
1428
|
setError(null);
|
|
@@ -1359,16 +1472,16 @@ function bytesEqual(left, right) {
|
|
|
1359
1472
|
}
|
|
1360
1473
|
|
|
1361
1474
|
// src/hooks/useSend.ts
|
|
1362
|
-
var
|
|
1475
|
+
var import_react12 = require("react");
|
|
1363
1476
|
var import_miden_sdk12 = require("@miden-sdk/miden-sdk");
|
|
1364
1477
|
function useSend() {
|
|
1365
1478
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
1366
1479
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1367
|
-
const [result, setResult] = (0,
|
|
1368
|
-
const [isLoading, setIsLoading] = (0,
|
|
1369
|
-
const [stage, setStage] = (0,
|
|
1370
|
-
const [error, setError] = (0,
|
|
1371
|
-
const send = (0,
|
|
1480
|
+
const [result, setResult] = (0, import_react12.useState)(null);
|
|
1481
|
+
const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
|
|
1482
|
+
const [stage, setStage] = (0, import_react12.useState)("idle");
|
|
1483
|
+
const [error, setError] = (0, import_react12.useState)(null);
|
|
1484
|
+
const send = (0, import_react12.useCallback)(
|
|
1372
1485
|
async (options) => {
|
|
1373
1486
|
if (!client || !isReady) {
|
|
1374
1487
|
throw new Error("Miden client is not ready");
|
|
@@ -1436,7 +1549,7 @@ function useSend() {
|
|
|
1436
1549
|
},
|
|
1437
1550
|
[client, isReady, prover, runExclusive, sync]
|
|
1438
1551
|
);
|
|
1439
|
-
const reset = (0,
|
|
1552
|
+
const reset = (0, import_react12.useCallback)(() => {
|
|
1440
1553
|
setResult(null);
|
|
1441
1554
|
setIsLoading(false);
|
|
1442
1555
|
setStage("idle");
|
|
@@ -1496,16 +1609,16 @@ function extractFullNote(txResult) {
|
|
|
1496
1609
|
}
|
|
1497
1610
|
|
|
1498
1611
|
// src/hooks/useMultiSend.ts
|
|
1499
|
-
var
|
|
1612
|
+
var import_react13 = require("react");
|
|
1500
1613
|
var import_miden_sdk13 = require("@miden-sdk/miden-sdk");
|
|
1501
1614
|
function useMultiSend() {
|
|
1502
1615
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
1503
1616
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1504
|
-
const [result, setResult] = (0,
|
|
1505
|
-
const [isLoading, setIsLoading] = (0,
|
|
1506
|
-
const [stage, setStage] = (0,
|
|
1507
|
-
const [error, setError] = (0,
|
|
1508
|
-
const sendMany = (0,
|
|
1617
|
+
const [result, setResult] = (0, import_react13.useState)(null);
|
|
1618
|
+
const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
|
|
1619
|
+
const [stage, setStage] = (0, import_react13.useState)("idle");
|
|
1620
|
+
const [error, setError] = (0, import_react13.useState)(null);
|
|
1621
|
+
const sendMany = (0, import_react13.useCallback)(
|
|
1509
1622
|
async (options) => {
|
|
1510
1623
|
if (!client || !isReady) {
|
|
1511
1624
|
throw new Error("Miden client is not ready");
|
|
@@ -1583,7 +1696,7 @@ function useMultiSend() {
|
|
|
1583
1696
|
},
|
|
1584
1697
|
[client, isReady, prover, runExclusive, sync]
|
|
1585
1698
|
);
|
|
1586
|
-
const reset = (0,
|
|
1699
|
+
const reset = (0, import_react13.useCallback)(() => {
|
|
1587
1700
|
setResult(null);
|
|
1588
1701
|
setIsLoading(false);
|
|
1589
1702
|
setStage("idle");
|
|
@@ -1633,16 +1746,16 @@ async function waitForTransactionCommit2(client, runExclusiveSafe, txId, maxWait
|
|
|
1633
1746
|
}
|
|
1634
1747
|
|
|
1635
1748
|
// src/hooks/useInternalTransfer.ts
|
|
1636
|
-
var
|
|
1749
|
+
var import_react14 = require("react");
|
|
1637
1750
|
var import_miden_sdk14 = require("@miden-sdk/miden-sdk");
|
|
1638
1751
|
function useInternalTransfer() {
|
|
1639
1752
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
1640
1753
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1641
|
-
const [result, setResult] = (0,
|
|
1642
|
-
const [isLoading, setIsLoading] = (0,
|
|
1643
|
-
const [stage, setStage] = (0,
|
|
1644
|
-
const [error, setError] = (0,
|
|
1645
|
-
const transferOnce = (0,
|
|
1754
|
+
const [result, setResult] = (0, import_react14.useState)(null);
|
|
1755
|
+
const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
|
|
1756
|
+
const [stage, setStage] = (0, import_react14.useState)("idle");
|
|
1757
|
+
const [error, setError] = (0, import_react14.useState)(null);
|
|
1758
|
+
const transferOnce = (0, import_react14.useCallback)(
|
|
1646
1759
|
async (options) => {
|
|
1647
1760
|
if (!client || !isReady) {
|
|
1648
1761
|
throw new Error("Miden client is not ready");
|
|
@@ -1686,7 +1799,7 @@ function useInternalTransfer() {
|
|
|
1686
1799
|
},
|
|
1687
1800
|
[client, isReady, prover, runExclusiveSafe]
|
|
1688
1801
|
);
|
|
1689
|
-
const transfer = (0,
|
|
1802
|
+
const transfer = (0, import_react14.useCallback)(
|
|
1690
1803
|
async (options) => {
|
|
1691
1804
|
if (!client || !isReady) {
|
|
1692
1805
|
throw new Error("Miden client is not ready");
|
|
@@ -1712,7 +1825,7 @@ function useInternalTransfer() {
|
|
|
1712
1825
|
},
|
|
1713
1826
|
[client, isReady, sync, transferOnce]
|
|
1714
1827
|
);
|
|
1715
|
-
const transferChain = (0,
|
|
1828
|
+
const transferChain = (0, import_react14.useCallback)(
|
|
1716
1829
|
async (options) => {
|
|
1717
1830
|
if (!client || !isReady) {
|
|
1718
1831
|
throw new Error("Miden client is not ready");
|
|
@@ -1753,7 +1866,7 @@ function useInternalTransfer() {
|
|
|
1753
1866
|
},
|
|
1754
1867
|
[client, isReady, sync, transferOnce]
|
|
1755
1868
|
);
|
|
1756
|
-
const reset = (0,
|
|
1869
|
+
const reset = (0, import_react14.useCallback)(() => {
|
|
1757
1870
|
setResult(null);
|
|
1758
1871
|
setIsLoading(false);
|
|
1759
1872
|
setStage("idle");
|
|
@@ -1783,12 +1896,12 @@ function getNoteType3(type) {
|
|
|
1783
1896
|
}
|
|
1784
1897
|
|
|
1785
1898
|
// src/hooks/useWaitForCommit.ts
|
|
1786
|
-
var
|
|
1899
|
+
var import_react15 = require("react");
|
|
1787
1900
|
var import_miden_sdk15 = require("@miden-sdk/miden-sdk");
|
|
1788
1901
|
function useWaitForCommit() {
|
|
1789
1902
|
const { client, isReady, runExclusive } = useMiden();
|
|
1790
1903
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1791
|
-
const waitForCommit = (0,
|
|
1904
|
+
const waitForCommit = (0, import_react15.useCallback)(
|
|
1792
1905
|
async (txId, options) => {
|
|
1793
1906
|
if (!client || !isReady) {
|
|
1794
1907
|
throw new Error("Miden client is not ready");
|
|
@@ -1836,11 +1949,11 @@ function normalizeHex2(value) {
|
|
|
1836
1949
|
}
|
|
1837
1950
|
|
|
1838
1951
|
// src/hooks/useWaitForNotes.ts
|
|
1839
|
-
var
|
|
1952
|
+
var import_react16 = require("react");
|
|
1840
1953
|
function useWaitForNotes() {
|
|
1841
1954
|
const { client, isReady, runExclusive } = useMiden();
|
|
1842
1955
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1843
|
-
const waitForConsumableNotes = (0,
|
|
1956
|
+
const waitForConsumableNotes = (0, import_react16.useCallback)(
|
|
1844
1957
|
async (options) => {
|
|
1845
1958
|
if (!client || !isReady) {
|
|
1846
1959
|
throw new Error("Miden client is not ready");
|
|
@@ -1869,16 +1982,16 @@ function useWaitForNotes() {
|
|
|
1869
1982
|
}
|
|
1870
1983
|
|
|
1871
1984
|
// src/hooks/useMint.ts
|
|
1872
|
-
var
|
|
1985
|
+
var import_react17 = require("react");
|
|
1873
1986
|
var import_miden_sdk16 = require("@miden-sdk/miden-sdk");
|
|
1874
1987
|
function useMint() {
|
|
1875
1988
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
1876
1989
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1877
|
-
const [result, setResult] = (0,
|
|
1878
|
-
const [isLoading, setIsLoading] = (0,
|
|
1879
|
-
const [stage, setStage] = (0,
|
|
1880
|
-
const [error, setError] = (0,
|
|
1881
|
-
const mint = (0,
|
|
1990
|
+
const [result, setResult] = (0, import_react17.useState)(null);
|
|
1991
|
+
const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
|
|
1992
|
+
const [stage, setStage] = (0, import_react17.useState)("idle");
|
|
1993
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
1994
|
+
const mint = (0, import_react17.useCallback)(
|
|
1882
1995
|
async (options) => {
|
|
1883
1996
|
if (!client || !isReady) {
|
|
1884
1997
|
throw new Error("Miden client is not ready");
|
|
@@ -1920,7 +2033,7 @@ function useMint() {
|
|
|
1920
2033
|
},
|
|
1921
2034
|
[client, isReady, prover, runExclusive, sync]
|
|
1922
2035
|
);
|
|
1923
|
-
const reset = (0,
|
|
2036
|
+
const reset = (0, import_react17.useCallback)(() => {
|
|
1924
2037
|
setResult(null);
|
|
1925
2038
|
setIsLoading(false);
|
|
1926
2039
|
setStage("idle");
|
|
@@ -1949,16 +2062,16 @@ function getNoteType4(type) {
|
|
|
1949
2062
|
}
|
|
1950
2063
|
|
|
1951
2064
|
// src/hooks/useConsume.ts
|
|
1952
|
-
var
|
|
2065
|
+
var import_react18 = require("react");
|
|
1953
2066
|
var import_miden_sdk17 = require("@miden-sdk/miden-sdk");
|
|
1954
2067
|
function useConsume() {
|
|
1955
2068
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
1956
2069
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1957
|
-
const [result, setResult] = (0,
|
|
1958
|
-
const [isLoading, setIsLoading] = (0,
|
|
1959
|
-
const [stage, setStage] = (0,
|
|
1960
|
-
const [error, setError] = (0,
|
|
1961
|
-
const consume = (0,
|
|
2070
|
+
const [result, setResult] = (0, import_react18.useState)(null);
|
|
2071
|
+
const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
|
|
2072
|
+
const [stage, setStage] = (0, import_react18.useState)("idle");
|
|
2073
|
+
const [error, setError] = (0, import_react18.useState)(null);
|
|
2074
|
+
const consume = (0, import_react18.useCallback)(
|
|
1962
2075
|
async (options) => {
|
|
1963
2076
|
if (!client || !isReady) {
|
|
1964
2077
|
throw new Error("Miden client is not ready");
|
|
@@ -2008,7 +2121,7 @@ function useConsume() {
|
|
|
2008
2121
|
},
|
|
2009
2122
|
[client, isReady, prover, runExclusive, sync]
|
|
2010
2123
|
);
|
|
2011
|
-
const reset = (0,
|
|
2124
|
+
const reset = (0, import_react18.useCallback)(() => {
|
|
2012
2125
|
setResult(null);
|
|
2013
2126
|
setIsLoading(false);
|
|
2014
2127
|
setStage("idle");
|
|
@@ -2025,16 +2138,16 @@ function useConsume() {
|
|
|
2025
2138
|
}
|
|
2026
2139
|
|
|
2027
2140
|
// src/hooks/useSwap.ts
|
|
2028
|
-
var
|
|
2141
|
+
var import_react19 = require("react");
|
|
2029
2142
|
var import_miden_sdk18 = require("@miden-sdk/miden-sdk");
|
|
2030
2143
|
function useSwap() {
|
|
2031
2144
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2032
2145
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2033
|
-
const [result, setResult] = (0,
|
|
2034
|
-
const [isLoading, setIsLoading] = (0,
|
|
2035
|
-
const [stage, setStage] = (0,
|
|
2036
|
-
const [error, setError] = (0,
|
|
2037
|
-
const swap = (0,
|
|
2146
|
+
const [result, setResult] = (0, import_react19.useState)(null);
|
|
2147
|
+
const [isLoading, setIsLoading] = (0, import_react19.useState)(false);
|
|
2148
|
+
const [stage, setStage] = (0, import_react19.useState)("idle");
|
|
2149
|
+
const [error, setError] = (0, import_react19.useState)(null);
|
|
2150
|
+
const swap = (0, import_react19.useCallback)(
|
|
2038
2151
|
async (options) => {
|
|
2039
2152
|
if (!client || !isReady) {
|
|
2040
2153
|
throw new Error("Miden client is not ready");
|
|
@@ -2083,7 +2196,7 @@ function useSwap() {
|
|
|
2083
2196
|
},
|
|
2084
2197
|
[client, isReady, prover, runExclusive, sync]
|
|
2085
2198
|
);
|
|
2086
|
-
const reset = (0,
|
|
2199
|
+
const reset = (0, import_react19.useCallback)(() => {
|
|
2087
2200
|
setResult(null);
|
|
2088
2201
|
setIsLoading(false);
|
|
2089
2202
|
setStage("idle");
|
|
@@ -2112,15 +2225,15 @@ function getNoteType5(type) {
|
|
|
2112
2225
|
}
|
|
2113
2226
|
|
|
2114
2227
|
// src/hooks/useTransaction.ts
|
|
2115
|
-
var
|
|
2228
|
+
var import_react20 = require("react");
|
|
2116
2229
|
function useTransaction() {
|
|
2117
2230
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2118
2231
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2119
|
-
const [result, setResult] = (0,
|
|
2120
|
-
const [isLoading, setIsLoading] = (0,
|
|
2121
|
-
const [stage, setStage] = (0,
|
|
2122
|
-
const [error, setError] = (0,
|
|
2123
|
-
const execute = (0,
|
|
2232
|
+
const [result, setResult] = (0, import_react20.useState)(null);
|
|
2233
|
+
const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
|
|
2234
|
+
const [stage, setStage] = (0, import_react20.useState)("idle");
|
|
2235
|
+
const [error, setError] = (0, import_react20.useState)(null);
|
|
2236
|
+
const execute = (0, import_react20.useCallback)(
|
|
2124
2237
|
async (options) => {
|
|
2125
2238
|
if (!client || !isReady) {
|
|
2126
2239
|
throw new Error("Miden client is not ready");
|
|
@@ -2155,7 +2268,7 @@ function useTransaction() {
|
|
|
2155
2268
|
},
|
|
2156
2269
|
[client, isReady, prover, runExclusive, sync]
|
|
2157
2270
|
);
|
|
2158
|
-
const reset = (0,
|
|
2271
|
+
const reset = (0, import_react20.useCallback)(() => {
|
|
2159
2272
|
setResult(null);
|
|
2160
2273
|
setIsLoading(false);
|
|
2161
2274
|
setStage("idle");
|
|
@@ -2186,6 +2299,7 @@ installAccountBech32();
|
|
|
2186
2299
|
0 && (module.exports = {
|
|
2187
2300
|
DEFAULTS,
|
|
2188
2301
|
MidenProvider,
|
|
2302
|
+
SignerContext,
|
|
2189
2303
|
formatAssetAmount,
|
|
2190
2304
|
formatNoteSummary,
|
|
2191
2305
|
getNoteSummary,
|
|
@@ -2205,6 +2319,7 @@ installAccountBech32();
|
|
|
2205
2319
|
useMultiSend,
|
|
2206
2320
|
useNotes,
|
|
2207
2321
|
useSend,
|
|
2322
|
+
useSigner,
|
|
2208
2323
|
useSwap,
|
|
2209
2324
|
useSyncState,
|
|
2210
2325
|
useTransaction,
|