@miden-sdk/react 0.15.0-alpha.4 → 0.15.0-alpha.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/CLAUDE.md +3 -0
- package/README.md +146 -7
- package/dist/index.d.ts +222 -10
- package/dist/index.mjs +370 -130
- package/dist/{index.d.mts → lazy.d.ts} +222 -10
- package/dist/lazy.mjs +3865 -0
- package/dist/mt/lazy.d.ts +1711 -0
- package/dist/mt/lazy.mjs +3865 -0
- package/dist/mt.d.ts +1711 -0
- package/dist/{index.js → mt.mjs} +716 -513
- package/lazy/package.json +5 -0
- package/mt/lazy/package.json +5 -0
- package/mt/package.json +5 -0
- package/package.json +22 -14
package/dist/index.mjs
CHANGED
|
@@ -443,15 +443,6 @@ function useSigner() {
|
|
|
443
443
|
}
|
|
444
444
|
|
|
445
445
|
// src/utils/signerAccount.ts
|
|
446
|
-
var WASM_ACCOUNT_TYPE = {
|
|
447
|
-
FungibleFaucet: 0,
|
|
448
|
-
NonFungibleFaucet: 1,
|
|
449
|
-
RegularAccountImmutableCode: 2,
|
|
450
|
-
RegularAccountUpdatableCode: 3
|
|
451
|
-
};
|
|
452
|
-
function getAccountType(accountType) {
|
|
453
|
-
return WASM_ACCOUNT_TYPE[accountType] ?? WASM_ACCOUNT_TYPE.RegularAccountImmutableCode;
|
|
454
|
-
}
|
|
455
446
|
function isPrivateStorageMode(storageMode) {
|
|
456
447
|
return storageMode.toString() === "private";
|
|
457
448
|
}
|
|
@@ -463,8 +454,10 @@ async function initializeSignerAccount(client, config) {
|
|
|
463
454
|
try {
|
|
464
455
|
await client.importAccountById(accountId2);
|
|
465
456
|
} catch (e) {
|
|
466
|
-
const
|
|
467
|
-
|
|
457
|
+
const code = e?.code;
|
|
458
|
+
const isFreshAccount = code === "ACCOUNT_NOT_FOUND_ON_CHAIN";
|
|
459
|
+
const isAlreadyTracked = code === "ACCOUNT_ALREADY_TRACKED";
|
|
460
|
+
if (!isAlreadyTracked && !isFreshAccount) {
|
|
468
461
|
throw e;
|
|
469
462
|
}
|
|
470
463
|
}
|
|
@@ -473,13 +466,12 @@ async function initializeSignerAccount(client, config) {
|
|
|
473
466
|
}
|
|
474
467
|
const commitmentWord = Word2.deserialize(config.publicKeyCommitment);
|
|
475
468
|
const seed = config.accountSeed ?? crypto.getRandomValues(new Uint8Array(32));
|
|
476
|
-
const accountType = getAccountType(config.accountType);
|
|
477
469
|
let builder = new AccountBuilder(seed).withAuthComponent(
|
|
478
470
|
AccountComponent.createAuthComponentFromCommitment(
|
|
479
471
|
commitmentWord,
|
|
480
472
|
AuthScheme2.AuthEcdsaK256Keccak
|
|
481
473
|
)
|
|
482
|
-
).
|
|
474
|
+
).storageMode(config.storageMode).withBasicWalletComponent();
|
|
483
475
|
if (config.customComponents?.length) {
|
|
484
476
|
for (const component of config.customComponents) {
|
|
485
477
|
if (component == null || typeof component.getProcedures !== "function") {
|
|
@@ -550,15 +542,20 @@ function MidenProvider({
|
|
|
550
542
|
}),
|
|
551
543
|
[config]
|
|
552
544
|
);
|
|
553
|
-
const defaultProver =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
545
|
+
const [defaultProver, setDefaultProver] = useState(null);
|
|
546
|
+
useEffect(() => {
|
|
547
|
+
if (!isReady) {
|
|
548
|
+
setDefaultProver(null);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
setDefaultProver(resolveTransactionProver(resolvedConfig));
|
|
552
|
+
}, [
|
|
553
|
+
isReady,
|
|
554
|
+
resolvedConfig.prover,
|
|
555
|
+
resolvedConfig.proverTimeoutMs,
|
|
556
|
+
resolvedConfig.proverUrls?.devnet,
|
|
557
|
+
resolvedConfig.proverUrls?.testnet
|
|
558
|
+
]);
|
|
562
559
|
const runExclusive = useCallback(
|
|
563
560
|
async (fn) => clientLockRef.current.runExclusive(fn),
|
|
564
561
|
[]
|
|
@@ -644,7 +641,9 @@ function MidenProvider({
|
|
|
644
641
|
storeName,
|
|
645
642
|
signerContext.getKeyCb,
|
|
646
643
|
signerContext.insertKeyCb,
|
|
647
|
-
wrappedSignCb
|
|
644
|
+
wrappedSignCb,
|
|
645
|
+
void 0,
|
|
646
|
+
resolvedConfig.useWorker
|
|
648
647
|
);
|
|
649
648
|
if (cancelled) return;
|
|
650
649
|
const accountId = await initializeSignerAccount(
|
|
@@ -660,7 +659,10 @@ function MidenProvider({
|
|
|
660
659
|
webClient = await WebClient.createClient(
|
|
661
660
|
resolvedConfig.rpcUrl,
|
|
662
661
|
resolvedConfig.noteTransportUrl,
|
|
663
|
-
seed
|
|
662
|
+
seed,
|
|
663
|
+
void 0,
|
|
664
|
+
void 0,
|
|
665
|
+
resolvedConfig.useWorker
|
|
664
666
|
);
|
|
665
667
|
if (cancelled) return;
|
|
666
668
|
}
|
|
@@ -1204,6 +1206,27 @@ var parseAssetAmount = (input, decimals) => {
|
|
|
1204
1206
|
};
|
|
1205
1207
|
|
|
1206
1208
|
// src/utils/notes.ts
|
|
1209
|
+
var resolveNoteInput = async (input, client) => {
|
|
1210
|
+
if (typeof input === "string") {
|
|
1211
|
+
const record2 = await client.getInputNote(input);
|
|
1212
|
+
if (!record2) {
|
|
1213
|
+
throw new Error(`Note not found: ${input}`);
|
|
1214
|
+
}
|
|
1215
|
+
return record2.toNote();
|
|
1216
|
+
}
|
|
1217
|
+
if (typeof input.toNote === "function") {
|
|
1218
|
+
return input.toNote();
|
|
1219
|
+
}
|
|
1220
|
+
if (typeof input.id === "function") {
|
|
1221
|
+
return input;
|
|
1222
|
+
}
|
|
1223
|
+
const hex = input.toString();
|
|
1224
|
+
const record = await client.getInputNote(hex);
|
|
1225
|
+
if (!record) {
|
|
1226
|
+
throw new Error(`Note not found: ${hex}`);
|
|
1227
|
+
}
|
|
1228
|
+
return record.toNote();
|
|
1229
|
+
};
|
|
1207
1230
|
var getInputNoteRecord = (note) => {
|
|
1208
1231
|
const maybeConsumable = note;
|
|
1209
1232
|
if (typeof maybeConsumable.inputNoteRecord === "function") {
|
|
@@ -1214,7 +1237,9 @@ var getInputNoteRecord = (note) => {
|
|
|
1214
1237
|
var getNoteSummary = (note, getAssetMetadata) => {
|
|
1215
1238
|
try {
|
|
1216
1239
|
const record = getInputNoteRecord(note);
|
|
1217
|
-
const
|
|
1240
|
+
const rawId = record.id();
|
|
1241
|
+
if (!rawId) return null;
|
|
1242
|
+
const id = rawId.toString();
|
|
1218
1243
|
const assets = [];
|
|
1219
1244
|
try {
|
|
1220
1245
|
const details = record.details();
|
|
@@ -1473,38 +1498,23 @@ import { NoteFilter as NoteFilter2 } from "@miden-sdk/miden-sdk";
|
|
|
1473
1498
|
// src/utils/noteAttachment.ts
|
|
1474
1499
|
import {
|
|
1475
1500
|
NoteAttachment,
|
|
1476
|
-
NoteAttachmentKind,
|
|
1477
1501
|
NoteAttachmentScheme,
|
|
1478
1502
|
Word
|
|
1479
1503
|
} from "@miden-sdk/miden-sdk";
|
|
1480
1504
|
function readNoteAttachment(note) {
|
|
1481
1505
|
try {
|
|
1482
|
-
const
|
|
1483
|
-
if (!
|
|
1484
|
-
const
|
|
1485
|
-
if (
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
(v) => BigInt(v)
|
|
1495
|
-
);
|
|
1496
|
-
return { values, kind: "word" };
|
|
1497
|
-
}
|
|
1498
|
-
if (kind === NoteAttachmentKind.Array) {
|
|
1499
|
-
const arr = attachment.asArray?.();
|
|
1500
|
-
if (!arr) return null;
|
|
1501
|
-
const u64s = arr.toU64s();
|
|
1502
|
-
const values = Array.from(u64s).map(
|
|
1503
|
-
(v) => BigInt(v)
|
|
1504
|
-
);
|
|
1505
|
-
return { values, kind: "array" };
|
|
1506
|
-
}
|
|
1507
|
-
return null;
|
|
1506
|
+
const attachments = note.attachments?.();
|
|
1507
|
+
if (!attachments || attachments.length === 0) return null;
|
|
1508
|
+
const words = attachments[0].toWords();
|
|
1509
|
+
if (words.length === 0) return null;
|
|
1510
|
+
const values = [];
|
|
1511
|
+
for (const word of words) {
|
|
1512
|
+
for (const value of word.toU64s()) {
|
|
1513
|
+
values.push(BigInt(value));
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
if (values.every((value) => value === 0n)) return null;
|
|
1517
|
+
return { values, kind: words.length === 1 ? "word" : "array" };
|
|
1508
1518
|
} catch {
|
|
1509
1519
|
return null;
|
|
1510
1520
|
}
|
|
@@ -1515,7 +1525,7 @@ function createNoteAttachment(values) {
|
|
|
1515
1525
|
bigints.push(BigInt(values[i]));
|
|
1516
1526
|
}
|
|
1517
1527
|
if (bigints.length === 0) {
|
|
1518
|
-
return
|
|
1528
|
+
return emptyAttachment();
|
|
1519
1529
|
}
|
|
1520
1530
|
const scheme = NoteAttachmentScheme.none();
|
|
1521
1531
|
if (bigints.length <= 4) {
|
|
@@ -1523,7 +1533,7 @@ function createNoteAttachment(values) {
|
|
|
1523
1533
|
bigints.push(0n);
|
|
1524
1534
|
}
|
|
1525
1535
|
const word = new Word(BigUint64Array.from(bigints));
|
|
1526
|
-
return NoteAttachment.
|
|
1536
|
+
return NoteAttachment.fromWord(scheme, word);
|
|
1527
1537
|
}
|
|
1528
1538
|
while (bigints.length % 4 !== 0) {
|
|
1529
1539
|
bigints.push(0n);
|
|
@@ -1532,13 +1542,12 @@ function createNoteAttachment(values) {
|
|
|
1532
1542
|
for (let i = 0; i < bigints.length; i += 4) {
|
|
1533
1543
|
words.push(new Word(BigUint64Array.from(bigints.slice(i, i + 4))));
|
|
1534
1544
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
return newArray.call(NoteAttachment, scheme, words);
|
|
1545
|
+
return NoteAttachment.fromWords(scheme, words);
|
|
1546
|
+
}
|
|
1547
|
+
function emptyAttachment() {
|
|
1548
|
+
const scheme = NoteAttachmentScheme.none();
|
|
1549
|
+
const word = new Word(BigUint64Array.from([0n, 0n, 0n, 0n]));
|
|
1550
|
+
return NoteAttachment.fromWord(scheme, word);
|
|
1542
1551
|
}
|
|
1543
1552
|
|
|
1544
1553
|
// src/hooks/useNoteStream.ts
|
|
@@ -1647,7 +1656,9 @@ function useNoteStream(options = {}) {
|
|
|
1647
1656
|
}
|
|
1648
1657
|
function buildStreamedNote(record, noteFirstSeen) {
|
|
1649
1658
|
try {
|
|
1650
|
-
const
|
|
1659
|
+
const rawId = record.id();
|
|
1660
|
+
if (!rawId) return null;
|
|
1661
|
+
const id = rawId.toString();
|
|
1651
1662
|
const metadata = record.metadata?.();
|
|
1652
1663
|
const senderHex = metadata?.sender?.()?.toString?.();
|
|
1653
1664
|
const sender = senderHex ? toBech32AccountId(senderHex) : "";
|
|
@@ -1862,8 +1873,6 @@ function getStorageMode(mode) {
|
|
|
1862
1873
|
return AccountStorageMode.private();
|
|
1863
1874
|
case "public":
|
|
1864
1875
|
return AccountStorageMode.public();
|
|
1865
|
-
case "network":
|
|
1866
|
-
return AccountStorageMode.network();
|
|
1867
1876
|
default:
|
|
1868
1877
|
return AccountStorageMode.private();
|
|
1869
1878
|
}
|
|
@@ -1897,6 +1906,7 @@ function useCreateFaucet() {
|
|
|
1897
1906
|
storageMode,
|
|
1898
1907
|
false,
|
|
1899
1908
|
// nonFungible - currently only fungible faucets supported
|
|
1909
|
+
options.tokenName ?? options.tokenSymbol,
|
|
1900
1910
|
options.tokenSymbol,
|
|
1901
1911
|
decimals,
|
|
1902
1912
|
BigInt(options.maxSupply),
|
|
@@ -1937,8 +1947,6 @@ function getStorageMode2(mode) {
|
|
|
1937
1947
|
return AccountStorageMode2.private();
|
|
1938
1948
|
case "public":
|
|
1939
1949
|
return AccountStorageMode2.public();
|
|
1940
|
-
case "network":
|
|
1941
|
-
return AccountStorageMode2.network();
|
|
1942
1950
|
default:
|
|
1943
1951
|
return AccountStorageMode2.private();
|
|
1944
1952
|
}
|
|
@@ -2155,7 +2163,6 @@ import {
|
|
|
2155
2163
|
FungibleAsset,
|
|
2156
2164
|
Note,
|
|
2157
2165
|
NoteAssets,
|
|
2158
|
-
NoteAttachment as NoteAttachment2,
|
|
2159
2166
|
NoteType as NoteType2,
|
|
2160
2167
|
NoteArray,
|
|
2161
2168
|
TransactionRequestBuilder
|
|
@@ -2234,7 +2241,7 @@ function useSend() {
|
|
|
2234
2241
|
toId,
|
|
2235
2242
|
assets,
|
|
2236
2243
|
noteType,
|
|
2237
|
-
|
|
2244
|
+
emptyAttachment()
|
|
2238
2245
|
);
|
|
2239
2246
|
const ownOutputs = new NoteArray();
|
|
2240
2247
|
ownOutputs.push(p2idNote);
|
|
@@ -2245,7 +2252,7 @@ function useSend() {
|
|
|
2245
2252
|
txRequest,
|
|
2246
2253
|
prover
|
|
2247
2254
|
) : await client.submitNewTransaction(execFromId, txRequest);
|
|
2248
|
-
return { txId: txId.
|
|
2255
|
+
return { txId: txId.toHex(), note: p2idNote };
|
|
2249
2256
|
});
|
|
2250
2257
|
setStage("complete");
|
|
2251
2258
|
setResult(returnResult);
|
|
@@ -2297,7 +2304,6 @@ function useSend() {
|
|
|
2297
2304
|
() => client.submitProvenTransaction(provenTransaction, txResult)
|
|
2298
2305
|
);
|
|
2299
2306
|
const txIdHex = txResult.id().toHex();
|
|
2300
|
-
const txIdString = txResult.id().toString();
|
|
2301
2307
|
let fullNote = null;
|
|
2302
2308
|
if (noteType === NoteType2.Private) {
|
|
2303
2309
|
fullNote = extractFullNote(txResult);
|
|
@@ -2321,7 +2327,7 @@ function useSend() {
|
|
|
2321
2327
|
);
|
|
2322
2328
|
}
|
|
2323
2329
|
const sendResult = {
|
|
2324
|
-
txId:
|
|
2330
|
+
txId: txIdHex,
|
|
2325
2331
|
note: null
|
|
2326
2332
|
};
|
|
2327
2333
|
setStage("complete");
|
|
@@ -2372,7 +2378,6 @@ import {
|
|
|
2372
2378
|
FungibleAsset as FungibleAsset2,
|
|
2373
2379
|
Note as Note2,
|
|
2374
2380
|
NoteAssets as NoteAssets2,
|
|
2375
|
-
NoteAttachment as NoteAttachment3,
|
|
2376
2381
|
NoteType as NoteType3,
|
|
2377
2382
|
NoteArray as NoteArray2,
|
|
2378
2383
|
TransactionRequestBuilder as TransactionRequestBuilder2
|
|
@@ -2417,7 +2422,7 @@ function useMultiSend() {
|
|
|
2417
2422
|
new FungibleAsset2(iterAssetId, BigInt(amount))
|
|
2418
2423
|
]);
|
|
2419
2424
|
const resolvedNoteType = recipientNoteType ? getNoteType(recipientNoteType) : noteType;
|
|
2420
|
-
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) :
|
|
2425
|
+
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) : emptyAttachment();
|
|
2421
2426
|
const note = Note2.createP2IDNote(
|
|
2422
2427
|
iterSenderId,
|
|
2423
2428
|
receiverId,
|
|
@@ -2433,7 +2438,11 @@ function useMultiSend() {
|
|
|
2433
2438
|
};
|
|
2434
2439
|
}
|
|
2435
2440
|
);
|
|
2436
|
-
const
|
|
2441
|
+
const ownOutputs = new NoteArray2();
|
|
2442
|
+
for (const o of outputs) {
|
|
2443
|
+
ownOutputs.push(o.note);
|
|
2444
|
+
}
|
|
2445
|
+
const txRequest = new TransactionRequestBuilder2().withOwnOutputNotes(ownOutputs).build();
|
|
2437
2446
|
const txSenderId = parseAccountId(options.from);
|
|
2438
2447
|
const txResult = await client.executeTransaction(txSenderId, txRequest);
|
|
2439
2448
|
setStage("proving");
|
|
@@ -2450,7 +2459,6 @@ function useMultiSend() {
|
|
|
2450
2459
|
txResult
|
|
2451
2460
|
);
|
|
2452
2461
|
const txIdHex = txResult.id().toHex();
|
|
2453
|
-
const txIdString = txResult.id().toString();
|
|
2454
2462
|
await client.applyTransaction(txResult, submissionHeight);
|
|
2455
2463
|
const hasPrivate = outputs.some((o) => o.noteType === NoteType3.Private);
|
|
2456
2464
|
if (hasPrivate) {
|
|
@@ -2468,7 +2476,7 @@ function useMultiSend() {
|
|
|
2468
2476
|
}
|
|
2469
2477
|
}
|
|
2470
2478
|
}
|
|
2471
|
-
const txSummary = { transactionId:
|
|
2479
|
+
const txSummary = { transactionId: txIdHex };
|
|
2472
2480
|
setStage("complete");
|
|
2473
2481
|
setResult(txSummary);
|
|
2474
2482
|
await sync();
|
|
@@ -2617,7 +2625,7 @@ function useMint() {
|
|
|
2617
2625
|
txRequest,
|
|
2618
2626
|
prover
|
|
2619
2627
|
) : await client.submitNewTransaction(faucetIdObj, txRequest);
|
|
2620
|
-
return { transactionId: txId.
|
|
2628
|
+
return { transactionId: txId.toHex() };
|
|
2621
2629
|
});
|
|
2622
2630
|
setStage("complete");
|
|
2623
2631
|
setResult(txResult);
|
|
@@ -2693,16 +2701,25 @@ function useConsume() {
|
|
|
2693
2701
|
}
|
|
2694
2702
|
}
|
|
2695
2703
|
if (lookupIds.length > 0) {
|
|
2704
|
+
const lookupIdStrings = lookupIds.map((id) => id.toString());
|
|
2696
2705
|
const filter = new NoteFilter3(NoteFilterTypes2.List, lookupIds);
|
|
2697
2706
|
const noteRecords = await client.getInputNotes(filter);
|
|
2698
|
-
if (noteRecords.length !==
|
|
2707
|
+
if (noteRecords.length !== lookupIdStrings.length) {
|
|
2699
2708
|
throw new Error("Some notes could not be found for provided IDs");
|
|
2700
2709
|
}
|
|
2701
2710
|
const recordById = new Map(
|
|
2702
|
-
noteRecords.map((r) =>
|
|
2711
|
+
noteRecords.map((r) => {
|
|
2712
|
+
const id = r.id();
|
|
2713
|
+
if (!id) {
|
|
2714
|
+
throw new Error(
|
|
2715
|
+
"getInputNotes returned a record without a note id"
|
|
2716
|
+
);
|
|
2717
|
+
}
|
|
2718
|
+
return [id.toString(), r];
|
|
2719
|
+
})
|
|
2703
2720
|
);
|
|
2704
2721
|
for (let j = 0; j < lookupIndices.length; j++) {
|
|
2705
|
-
const record = recordById.get(
|
|
2722
|
+
const record = recordById.get(lookupIdStrings[j]);
|
|
2706
2723
|
if (!record) {
|
|
2707
2724
|
throw new Error(
|
|
2708
2725
|
"Some notes could not be found for provided IDs"
|
|
@@ -2718,7 +2735,7 @@ function useConsume() {
|
|
|
2718
2735
|
txRequest,
|
|
2719
2736
|
prover
|
|
2720
2737
|
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2721
|
-
return { transactionId: txId.
|
|
2738
|
+
return { transactionId: txId.toHex() };
|
|
2722
2739
|
});
|
|
2723
2740
|
setStage("complete");
|
|
2724
2741
|
setResult(txResult);
|
|
@@ -2792,7 +2809,7 @@ function useSwap() {
|
|
|
2792
2809
|
txRequest,
|
|
2793
2810
|
prover
|
|
2794
2811
|
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2795
|
-
return { transactionId: txId.
|
|
2812
|
+
return { transactionId: txId.toHex() };
|
|
2796
2813
|
});
|
|
2797
2814
|
setStage("complete");
|
|
2798
2815
|
setResult(txResult);
|
|
@@ -2825,8 +2842,228 @@ function useSwap() {
|
|
|
2825
2842
|
};
|
|
2826
2843
|
}
|
|
2827
2844
|
|
|
2845
|
+
// src/hooks/usePswapCreate.ts
|
|
2846
|
+
import { useCallback as useCallback19, useState as useState15 } from "react";
|
|
2847
|
+
function usePswapCreate() {
|
|
2848
|
+
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2849
|
+
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2850
|
+
const [result, setResult] = useState15(null);
|
|
2851
|
+
const [isLoading, setIsLoading] = useState15(false);
|
|
2852
|
+
const [stage, setStage] = useState15("idle");
|
|
2853
|
+
const [error, setError] = useState15(null);
|
|
2854
|
+
const pswapCreate = useCallback19(
|
|
2855
|
+
async (options) => {
|
|
2856
|
+
if (!client || !isReady) {
|
|
2857
|
+
throw new Error("Miden client is not ready");
|
|
2858
|
+
}
|
|
2859
|
+
const offeredAmount = BigInt(options.offeredAmount);
|
|
2860
|
+
const requestedAmount = BigInt(options.requestedAmount);
|
|
2861
|
+
if (offeredAmount <= 0n) {
|
|
2862
|
+
throw new Error("offeredAmount must be greater than 0");
|
|
2863
|
+
}
|
|
2864
|
+
if (requestedAmount <= 0n) {
|
|
2865
|
+
throw new Error("requestedAmount must be greater than 0");
|
|
2866
|
+
}
|
|
2867
|
+
setIsLoading(true);
|
|
2868
|
+
setStage("executing");
|
|
2869
|
+
setError(null);
|
|
2870
|
+
try {
|
|
2871
|
+
const noteType = getNoteType(options.noteType ?? DEFAULTS.NOTE_TYPE);
|
|
2872
|
+
const paybackNoteType = getNoteType(
|
|
2873
|
+
options.paybackNoteType ?? DEFAULTS.NOTE_TYPE
|
|
2874
|
+
);
|
|
2875
|
+
const accountIdObj = parseAccountId(options.accountId);
|
|
2876
|
+
const offeredFaucetIdObj = parseAccountId(options.offeredFaucetId);
|
|
2877
|
+
const requestedFaucetIdObj = parseAccountId(options.requestedFaucetId);
|
|
2878
|
+
setStage("proving");
|
|
2879
|
+
const txResult = await runExclusiveSafe(async () => {
|
|
2880
|
+
const txRequest = await client.newPswapCreateTransactionRequest(
|
|
2881
|
+
accountIdObj,
|
|
2882
|
+
offeredFaucetIdObj,
|
|
2883
|
+
offeredAmount,
|
|
2884
|
+
requestedFaucetIdObj,
|
|
2885
|
+
requestedAmount,
|
|
2886
|
+
noteType,
|
|
2887
|
+
paybackNoteType
|
|
2888
|
+
);
|
|
2889
|
+
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2890
|
+
accountIdObj,
|
|
2891
|
+
txRequest,
|
|
2892
|
+
prover
|
|
2893
|
+
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2894
|
+
return { transactionId: txId.toHex() };
|
|
2895
|
+
});
|
|
2896
|
+
setStage("complete");
|
|
2897
|
+
setResult(txResult);
|
|
2898
|
+
await sync();
|
|
2899
|
+
return txResult;
|
|
2900
|
+
} catch (err) {
|
|
2901
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
2902
|
+
setError(error2);
|
|
2903
|
+
setStage("idle");
|
|
2904
|
+
throw error2;
|
|
2905
|
+
} finally {
|
|
2906
|
+
setIsLoading(false);
|
|
2907
|
+
}
|
|
2908
|
+
},
|
|
2909
|
+
[client, isReady, prover, runExclusive, sync]
|
|
2910
|
+
);
|
|
2911
|
+
const reset = useCallback19(() => {
|
|
2912
|
+
setResult(null);
|
|
2913
|
+
setIsLoading(false);
|
|
2914
|
+
setStage("idle");
|
|
2915
|
+
setError(null);
|
|
2916
|
+
}, []);
|
|
2917
|
+
return {
|
|
2918
|
+
pswapCreate,
|
|
2919
|
+
result,
|
|
2920
|
+
isLoading,
|
|
2921
|
+
stage,
|
|
2922
|
+
error,
|
|
2923
|
+
reset
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// src/hooks/usePswapConsume.ts
|
|
2928
|
+
import { useCallback as useCallback20, useState as useState16 } from "react";
|
|
2929
|
+
function usePswapConsume() {
|
|
2930
|
+
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2931
|
+
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2932
|
+
const [result, setResult] = useState16(null);
|
|
2933
|
+
const [isLoading, setIsLoading] = useState16(false);
|
|
2934
|
+
const [stage, setStage] = useState16("idle");
|
|
2935
|
+
const [error, setError] = useState16(null);
|
|
2936
|
+
const pswapConsume = useCallback20(
|
|
2937
|
+
async (options) => {
|
|
2938
|
+
if (!client || !isReady) {
|
|
2939
|
+
throw new Error("Miden client is not ready");
|
|
2940
|
+
}
|
|
2941
|
+
const fillAmount = BigInt(options.fillAmount);
|
|
2942
|
+
const noteFillAmount = BigInt(options.noteFillAmount ?? 0);
|
|
2943
|
+
if (fillAmount <= 0n) {
|
|
2944
|
+
throw new Error("fillAmount must be greater than 0");
|
|
2945
|
+
}
|
|
2946
|
+
if (noteFillAmount < 0n) {
|
|
2947
|
+
throw new Error("noteFillAmount must not be negative");
|
|
2948
|
+
}
|
|
2949
|
+
setIsLoading(true);
|
|
2950
|
+
setStage("executing");
|
|
2951
|
+
setError(null);
|
|
2952
|
+
try {
|
|
2953
|
+
const accountIdObj = parseAccountId(options.accountId);
|
|
2954
|
+
setStage("proving");
|
|
2955
|
+
const txResult = await runExclusiveSafe(async () => {
|
|
2956
|
+
const note = await resolveNoteInput(options.note, client);
|
|
2957
|
+
const txRequest = await client.newPswapConsumeTransactionRequest(
|
|
2958
|
+
note,
|
|
2959
|
+
accountIdObj,
|
|
2960
|
+
fillAmount,
|
|
2961
|
+
noteFillAmount
|
|
2962
|
+
);
|
|
2963
|
+
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2964
|
+
accountIdObj,
|
|
2965
|
+
txRequest,
|
|
2966
|
+
prover
|
|
2967
|
+
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2968
|
+
return { transactionId: txId.toHex() };
|
|
2969
|
+
});
|
|
2970
|
+
setStage("complete");
|
|
2971
|
+
setResult(txResult);
|
|
2972
|
+
await sync();
|
|
2973
|
+
return txResult;
|
|
2974
|
+
} catch (err) {
|
|
2975
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
2976
|
+
setError(error2);
|
|
2977
|
+
setStage("idle");
|
|
2978
|
+
throw error2;
|
|
2979
|
+
} finally {
|
|
2980
|
+
setIsLoading(false);
|
|
2981
|
+
}
|
|
2982
|
+
},
|
|
2983
|
+
[client, isReady, prover, runExclusive, sync]
|
|
2984
|
+
);
|
|
2985
|
+
const reset = useCallback20(() => {
|
|
2986
|
+
setResult(null);
|
|
2987
|
+
setIsLoading(false);
|
|
2988
|
+
setStage("idle");
|
|
2989
|
+
setError(null);
|
|
2990
|
+
}, []);
|
|
2991
|
+
return {
|
|
2992
|
+
pswapConsume,
|
|
2993
|
+
result,
|
|
2994
|
+
isLoading,
|
|
2995
|
+
stage,
|
|
2996
|
+
error,
|
|
2997
|
+
reset
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
// src/hooks/usePswapCancel.ts
|
|
3002
|
+
import { useCallback as useCallback21, useState as useState17 } from "react";
|
|
3003
|
+
function usePswapCancel() {
|
|
3004
|
+
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3005
|
+
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3006
|
+
const [result, setResult] = useState17(null);
|
|
3007
|
+
const [isLoading, setIsLoading] = useState17(false);
|
|
3008
|
+
const [stage, setStage] = useState17("idle");
|
|
3009
|
+
const [error, setError] = useState17(null);
|
|
3010
|
+
const pswapCancel = useCallback21(
|
|
3011
|
+
async (options) => {
|
|
3012
|
+
if (!client || !isReady) {
|
|
3013
|
+
throw new Error("Miden client is not ready");
|
|
3014
|
+
}
|
|
3015
|
+
setIsLoading(true);
|
|
3016
|
+
setStage("executing");
|
|
3017
|
+
setError(null);
|
|
3018
|
+
try {
|
|
3019
|
+
const accountIdObj = parseAccountId(options.accountId);
|
|
3020
|
+
setStage("proving");
|
|
3021
|
+
const txResult = await runExclusiveSafe(async () => {
|
|
3022
|
+
const note = await resolveNoteInput(options.note, client);
|
|
3023
|
+
const txRequest = await client.newPswapCancelTransactionRequest(
|
|
3024
|
+
note,
|
|
3025
|
+
accountIdObj
|
|
3026
|
+
);
|
|
3027
|
+
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
3028
|
+
accountIdObj,
|
|
3029
|
+
txRequest,
|
|
3030
|
+
prover
|
|
3031
|
+
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
3032
|
+
return { transactionId: txId.toHex() };
|
|
3033
|
+
});
|
|
3034
|
+
setStage("complete");
|
|
3035
|
+
setResult(txResult);
|
|
3036
|
+
await sync();
|
|
3037
|
+
return txResult;
|
|
3038
|
+
} catch (err) {
|
|
3039
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
3040
|
+
setError(error2);
|
|
3041
|
+
setStage("idle");
|
|
3042
|
+
throw error2;
|
|
3043
|
+
} finally {
|
|
3044
|
+
setIsLoading(false);
|
|
3045
|
+
}
|
|
3046
|
+
},
|
|
3047
|
+
[client, isReady, prover, runExclusive, sync]
|
|
3048
|
+
);
|
|
3049
|
+
const reset = useCallback21(() => {
|
|
3050
|
+
setResult(null);
|
|
3051
|
+
setIsLoading(false);
|
|
3052
|
+
setStage("idle");
|
|
3053
|
+
setError(null);
|
|
3054
|
+
}, []);
|
|
3055
|
+
return {
|
|
3056
|
+
pswapCancel,
|
|
3057
|
+
result,
|
|
3058
|
+
isLoading,
|
|
3059
|
+
stage,
|
|
3060
|
+
error,
|
|
3061
|
+
reset
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
|
|
2828
3065
|
// src/hooks/useTransaction.ts
|
|
2829
|
-
import { useCallback as
|
|
3066
|
+
import { useCallback as useCallback22, useRef as useRef6, useState as useState18 } from "react";
|
|
2830
3067
|
|
|
2831
3068
|
// src/utils/transactions.ts
|
|
2832
3069
|
import { NoteType as NoteType4, TransactionFilter as TransactionFilter4 } from "@miden-sdk/miden-sdk";
|
|
@@ -2873,11 +3110,11 @@ function useTransaction() {
|
|
|
2873
3110
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
2874
3111
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2875
3112
|
const isBusyRef = useRef6(false);
|
|
2876
|
-
const [result, setResult] =
|
|
2877
|
-
const [isLoading, setIsLoading] =
|
|
2878
|
-
const [stage, setStage] =
|
|
2879
|
-
const [error, setError] =
|
|
2880
|
-
const execute =
|
|
3113
|
+
const [result, setResult] = useState18(null);
|
|
3114
|
+
const [isLoading, setIsLoading] = useState18(false);
|
|
3115
|
+
const [stage, setStage] = useState18("idle");
|
|
3116
|
+
const [error, setError] = useState18(null);
|
|
3117
|
+
const execute = useCallback22(
|
|
2881
3118
|
async (options) => {
|
|
2882
3119
|
if (!client || !isReady) {
|
|
2883
3120
|
throw new Error("Miden client is not ready");
|
|
@@ -2927,7 +3164,7 @@ function useTransaction() {
|
|
|
2927
3164
|
);
|
|
2928
3165
|
}
|
|
2929
3166
|
}
|
|
2930
|
-
const txSummary = { transactionId: txId.
|
|
3167
|
+
const txSummary = { transactionId: txId.toHex() };
|
|
2931
3168
|
setStage("complete");
|
|
2932
3169
|
setResult(txSummary);
|
|
2933
3170
|
await sync();
|
|
@@ -2944,7 +3181,7 @@ function useTransaction() {
|
|
|
2944
3181
|
},
|
|
2945
3182
|
[client, isReady, runExclusive, sync]
|
|
2946
3183
|
);
|
|
2947
|
-
const reset =
|
|
3184
|
+
const reset = useCallback22(() => {
|
|
2948
3185
|
setResult(null);
|
|
2949
3186
|
setIsLoading(false);
|
|
2950
3187
|
setStage("idle");
|
|
@@ -2967,7 +3204,7 @@ async function resolveRequest(request, client) {
|
|
|
2967
3204
|
}
|
|
2968
3205
|
|
|
2969
3206
|
// src/hooks/useExecuteProgram.ts
|
|
2970
|
-
import { useCallback as
|
|
3207
|
+
import { useCallback as useCallback23, useRef as useRef7, useState as useState19 } from "react";
|
|
2971
3208
|
import {
|
|
2972
3209
|
AdviceInputs,
|
|
2973
3210
|
ForeignAccount,
|
|
@@ -2981,10 +3218,10 @@ function useExecuteProgram() {
|
|
|
2981
3218
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
2982
3219
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2983
3220
|
const isBusyRef = useRef7(false);
|
|
2984
|
-
const [result, setResult] =
|
|
2985
|
-
const [isLoading, setIsLoading] =
|
|
2986
|
-
const [error, setError] =
|
|
2987
|
-
const execute =
|
|
3221
|
+
const [result, setResult] = useState19(null);
|
|
3222
|
+
const [isLoading, setIsLoading] = useState19(false);
|
|
3223
|
+
const [error, setError] = useState19(null);
|
|
3224
|
+
const execute = useCallback23(
|
|
2988
3225
|
async (options) => {
|
|
2989
3226
|
if (!client || !isReady) {
|
|
2990
3227
|
throw new Error("Miden client is not ready");
|
|
@@ -3043,7 +3280,7 @@ function useExecuteProgram() {
|
|
|
3043
3280
|
},
|
|
3044
3281
|
[client, isReady, runExclusive, sync]
|
|
3045
3282
|
);
|
|
3046
|
-
const reset =
|
|
3283
|
+
const reset = useCallback23(() => {
|
|
3047
3284
|
setResult(null);
|
|
3048
3285
|
setIsLoading(false);
|
|
3049
3286
|
setError(null);
|
|
@@ -3058,7 +3295,7 @@ function useExecuteProgram() {
|
|
|
3058
3295
|
}
|
|
3059
3296
|
|
|
3060
3297
|
// src/hooks/useCompile.ts
|
|
3061
|
-
import { useCallback as
|
|
3298
|
+
import { useCallback as useCallback24, useMemo as useMemo8 } from "react";
|
|
3062
3299
|
import { CompilerResource, getWasmOrThrow } from "@miden-sdk/miden-sdk";
|
|
3063
3300
|
function useCompile() {
|
|
3064
3301
|
const { client, isReady } = useMiden();
|
|
@@ -3066,21 +3303,21 @@ function useCompile() {
|
|
|
3066
3303
|
() => client && isReady ? new CompilerResource(client, getWasmOrThrow) : null,
|
|
3067
3304
|
[client, isReady]
|
|
3068
3305
|
);
|
|
3069
|
-
const requireResource =
|
|
3306
|
+
const requireResource = useCallback24(() => {
|
|
3070
3307
|
if (!resource) {
|
|
3071
3308
|
throw new Error("Miden client is not ready");
|
|
3072
3309
|
}
|
|
3073
3310
|
return resource;
|
|
3074
3311
|
}, [resource]);
|
|
3075
|
-
const component =
|
|
3312
|
+
const component = useCallback24(
|
|
3076
3313
|
async (options) => requireResource().component(options),
|
|
3077
3314
|
[requireResource]
|
|
3078
3315
|
);
|
|
3079
|
-
const txScript =
|
|
3316
|
+
const txScript = useCallback24(
|
|
3080
3317
|
async (options) => requireResource().txScript(options),
|
|
3081
3318
|
[requireResource]
|
|
3082
3319
|
);
|
|
3083
|
-
const noteScript =
|
|
3320
|
+
const noteScript = useCallback24(
|
|
3084
3321
|
async (options) => requireResource().noteScript(options),
|
|
3085
3322
|
[requireResource]
|
|
3086
3323
|
);
|
|
@@ -3088,14 +3325,14 @@ function useCompile() {
|
|
|
3088
3325
|
}
|
|
3089
3326
|
|
|
3090
3327
|
// src/hooks/useSessionAccount.ts
|
|
3091
|
-
import { useCallback as
|
|
3328
|
+
import { useCallback as useCallback25, useEffect as useEffect9, useRef as useRef8, useState as useState20 } from "react";
|
|
3092
3329
|
import { AccountStorageMode as AccountStorageMode3 } from "@miden-sdk/miden-sdk";
|
|
3093
3330
|
function useSessionAccount(options) {
|
|
3094
3331
|
const { client, isReady, sync } = useMiden();
|
|
3095
3332
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
3096
|
-
const [sessionAccountId, setSessionAccountId] =
|
|
3097
|
-
const [step, setStep] =
|
|
3098
|
-
const [error, setError] =
|
|
3333
|
+
const [sessionAccountId, setSessionAccountId] = useState20(null);
|
|
3334
|
+
const [step, setStep] = useState20("idle");
|
|
3335
|
+
const [error, setError] = useState20(null);
|
|
3099
3336
|
const cancelledRef = useRef8(false);
|
|
3100
3337
|
const isBusyRef = useRef8(false);
|
|
3101
3338
|
const storagePrefix = options.storagePrefix ?? "miden-session";
|
|
@@ -3123,7 +3360,7 @@ function useSessionAccount(options) {
|
|
|
3123
3360
|
localStorage.removeItem(`${storagePrefix}:ready`);
|
|
3124
3361
|
}
|
|
3125
3362
|
}, [storagePrefix]);
|
|
3126
|
-
const initialize =
|
|
3363
|
+
const initialize = useCallback25(async () => {
|
|
3127
3364
|
if (!client || !isReady) {
|
|
3128
3365
|
throw new Error("Miden client is not ready");
|
|
3129
3366
|
}
|
|
@@ -3192,7 +3429,7 @@ function useSessionAccount(options) {
|
|
|
3192
3429
|
maxWaitMs,
|
|
3193
3430
|
setAccounts
|
|
3194
3431
|
]);
|
|
3195
|
-
const reset =
|
|
3432
|
+
const reset = useCallback25(() => {
|
|
3196
3433
|
cancelledRef.current = true;
|
|
3197
3434
|
isBusyRef.current = false;
|
|
3198
3435
|
setSessionAccountId(null);
|
|
@@ -3241,13 +3478,13 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
|
|
|
3241
3478
|
}
|
|
3242
3479
|
|
|
3243
3480
|
// src/hooks/useExportStore.ts
|
|
3244
|
-
import { useCallback as
|
|
3481
|
+
import { useCallback as useCallback26, useState as useState21 } from "react";
|
|
3245
3482
|
import { exportStore as sdkExportStore } from "@miden-sdk/miden-sdk";
|
|
3246
3483
|
function useExportStore() {
|
|
3247
3484
|
const { client, isReady, runExclusive } = useMiden();
|
|
3248
|
-
const [isExporting, setIsExporting] =
|
|
3249
|
-
const [error, setError] =
|
|
3250
|
-
const exportStore =
|
|
3485
|
+
const [isExporting, setIsExporting] = useState21(false);
|
|
3486
|
+
const [error, setError] = useState21(null);
|
|
3487
|
+
const exportStore = useCallback26(async () => {
|
|
3251
3488
|
if (!client || !isReady) {
|
|
3252
3489
|
throw new Error("Miden client is not ready");
|
|
3253
3490
|
}
|
|
@@ -3265,7 +3502,7 @@ function useExportStore() {
|
|
|
3265
3502
|
setIsExporting(false);
|
|
3266
3503
|
}
|
|
3267
3504
|
}, [client, isReady, runExclusive]);
|
|
3268
|
-
const reset =
|
|
3505
|
+
const reset = useCallback26(() => {
|
|
3269
3506
|
setIsExporting(false);
|
|
3270
3507
|
setError(null);
|
|
3271
3508
|
}, []);
|
|
@@ -3278,13 +3515,13 @@ function useExportStore() {
|
|
|
3278
3515
|
}
|
|
3279
3516
|
|
|
3280
3517
|
// src/hooks/useImportStore.ts
|
|
3281
|
-
import { useCallback as
|
|
3518
|
+
import { useCallback as useCallback27, useState as useState22 } from "react";
|
|
3282
3519
|
import { importStore as sdkImportStore } from "@miden-sdk/miden-sdk";
|
|
3283
3520
|
function useImportStore() {
|
|
3284
3521
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3285
|
-
const [isImporting, setIsImporting] =
|
|
3286
|
-
const [error, setError] =
|
|
3287
|
-
const importStore =
|
|
3522
|
+
const [isImporting, setIsImporting] = useState22(false);
|
|
3523
|
+
const [error, setError] = useState22(null);
|
|
3524
|
+
const importStore = useCallback27(
|
|
3288
3525
|
async (storeDump, storeName, options) => {
|
|
3289
3526
|
if (!client || !isReady) {
|
|
3290
3527
|
throw new Error("Miden client is not ready");
|
|
@@ -3306,7 +3543,7 @@ function useImportStore() {
|
|
|
3306
3543
|
},
|
|
3307
3544
|
[client, isReady, runExclusive, sync]
|
|
3308
3545
|
);
|
|
3309
|
-
const reset =
|
|
3546
|
+
const reset = useCallback27(() => {
|
|
3310
3547
|
setIsImporting(false);
|
|
3311
3548
|
setError(null);
|
|
3312
3549
|
}, []);
|
|
@@ -3319,13 +3556,13 @@ function useImportStore() {
|
|
|
3319
3556
|
}
|
|
3320
3557
|
|
|
3321
3558
|
// src/hooks/useImportNote.ts
|
|
3322
|
-
import { useCallback as
|
|
3559
|
+
import { useCallback as useCallback28, useState as useState23 } from "react";
|
|
3323
3560
|
import { NoteFile } from "@miden-sdk/miden-sdk";
|
|
3324
3561
|
function useImportNote() {
|
|
3325
3562
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3326
|
-
const [isImporting, setIsImporting] =
|
|
3327
|
-
const [error, setError] =
|
|
3328
|
-
const importNote =
|
|
3563
|
+
const [isImporting, setIsImporting] = useState23(false);
|
|
3564
|
+
const [error, setError] = useState23(null);
|
|
3565
|
+
const importNote = useCallback28(
|
|
3329
3566
|
async (noteBytes) => {
|
|
3330
3567
|
if (!client || !isReady) {
|
|
3331
3568
|
throw new Error("Miden client is not ready");
|
|
@@ -3349,7 +3586,7 @@ function useImportNote() {
|
|
|
3349
3586
|
},
|
|
3350
3587
|
[client, isReady, runExclusive, sync]
|
|
3351
3588
|
);
|
|
3352
|
-
const reset =
|
|
3589
|
+
const reset = useCallback28(() => {
|
|
3353
3590
|
setIsImporting(false);
|
|
3354
3591
|
setError(null);
|
|
3355
3592
|
}, []);
|
|
@@ -3362,13 +3599,13 @@ function useImportNote() {
|
|
|
3362
3599
|
}
|
|
3363
3600
|
|
|
3364
3601
|
// src/hooks/useExportNote.ts
|
|
3365
|
-
import { useCallback as
|
|
3602
|
+
import { useCallback as useCallback29, useState as useState24 } from "react";
|
|
3366
3603
|
import { NoteExportFormat } from "@miden-sdk/miden-sdk";
|
|
3367
3604
|
function useExportNote() {
|
|
3368
3605
|
const { client, isReady, runExclusive } = useMiden();
|
|
3369
|
-
const [isExporting, setIsExporting] =
|
|
3370
|
-
const [error, setError] =
|
|
3371
|
-
const exportNote =
|
|
3606
|
+
const [isExporting, setIsExporting] = useState24(false);
|
|
3607
|
+
const [error, setError] = useState24(null);
|
|
3608
|
+
const exportNote = useCallback29(
|
|
3372
3609
|
async (noteId) => {
|
|
3373
3610
|
if (!client || !isReady) {
|
|
3374
3611
|
throw new Error("Miden client is not ready");
|
|
@@ -3390,7 +3627,7 @@ function useExportNote() {
|
|
|
3390
3627
|
},
|
|
3391
3628
|
[client, isReady, runExclusive]
|
|
3392
3629
|
);
|
|
3393
|
-
const reset =
|
|
3630
|
+
const reset = useCallback29(() => {
|
|
3394
3631
|
setIsExporting(false);
|
|
3395
3632
|
setError(null);
|
|
3396
3633
|
}, []);
|
|
@@ -3403,12 +3640,12 @@ function useExportNote() {
|
|
|
3403
3640
|
}
|
|
3404
3641
|
|
|
3405
3642
|
// src/hooks/useSyncControl.ts
|
|
3406
|
-
import { useCallback as
|
|
3643
|
+
import { useCallback as useCallback30 } from "react";
|
|
3407
3644
|
function useSyncControl() {
|
|
3408
3645
|
const isPaused = useMidenStore((state) => state.syncPaused);
|
|
3409
3646
|
const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
|
|
3410
|
-
const pauseSync =
|
|
3411
|
-
const resumeSync =
|
|
3647
|
+
const pauseSync = useCallback30(() => setSyncPaused(true), [setSyncPaused]);
|
|
3648
|
+
const resumeSync = useCallback30(() => setSyncPaused(false), [setSyncPaused]);
|
|
3412
3649
|
return {
|
|
3413
3650
|
pauseSync,
|
|
3414
3651
|
resumeSync,
|
|
@@ -3610,6 +3847,9 @@ export {
|
|
|
3610
3847
|
useMultiSigner,
|
|
3611
3848
|
useNoteStream,
|
|
3612
3849
|
useNotes,
|
|
3850
|
+
usePswapCancel,
|
|
3851
|
+
usePswapConsume,
|
|
3852
|
+
usePswapCreate,
|
|
3613
3853
|
useSend,
|
|
3614
3854
|
useSessionAccount,
|
|
3615
3855
|
useSigner,
|