@miden-sdk/react 0.15.6 → 0.16.0-alpha.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/CLAUDE.md +0 -38
- package/README.md +0 -60
- package/dist/index.d.ts +3 -239
- package/dist/index.mjs +136 -529
- package/dist/lazy.d.ts +3 -239
- package/dist/lazy.mjs +136 -529
- package/dist/mt/lazy.d.ts +3 -239
- package/dist/mt/lazy.mjs +136 -529
- package/dist/mt.d.ts +3 -239
- package/dist/mt.mjs +136 -529
- package/package.json +3 -3
package/dist/mt.mjs
CHANGED
|
@@ -1775,142 +1775,8 @@ function useSyncState() {
|
|
|
1775
1775
|
};
|
|
1776
1776
|
}
|
|
1777
1777
|
|
|
1778
|
-
// src/hooks/usePswapLineages.ts
|
|
1779
|
-
import { useCallback as useCallback9, useEffect as useEffect9, useRef as useRef4, useState as useState7 } from "react";
|
|
1780
|
-
function usePswapLineages() {
|
|
1781
|
-
const { client, isReady } = useMiden();
|
|
1782
|
-
const { lastSyncTime } = useSyncStateStore();
|
|
1783
|
-
const [lineages, setLineages] = useState7([]);
|
|
1784
|
-
const [isLoading, setIsLoading] = useState7(false);
|
|
1785
|
-
const [error, setError] = useState7(null);
|
|
1786
|
-
const fetchGenRef = useRef4(0);
|
|
1787
|
-
const refetch = useCallback9(async () => {
|
|
1788
|
-
if (!client || !isReady) return;
|
|
1789
|
-
const gen = ++fetchGenRef.current;
|
|
1790
|
-
setIsLoading(true);
|
|
1791
|
-
setError(null);
|
|
1792
|
-
try {
|
|
1793
|
-
const fetched = await client.getPswapLineages();
|
|
1794
|
-
if (gen === fetchGenRef.current) setLineages(fetched);
|
|
1795
|
-
} catch (err) {
|
|
1796
|
-
if (gen === fetchGenRef.current)
|
|
1797
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1798
|
-
} finally {
|
|
1799
|
-
if (gen === fetchGenRef.current) setIsLoading(false);
|
|
1800
|
-
}
|
|
1801
|
-
}, [client, isReady]);
|
|
1802
|
-
useEffect9(() => {
|
|
1803
|
-
if (!isReady) return;
|
|
1804
|
-
refetch();
|
|
1805
|
-
return () => {
|
|
1806
|
-
fetchGenRef.current++;
|
|
1807
|
-
};
|
|
1808
|
-
}, [isReady, refetch]);
|
|
1809
|
-
useEffect9(() => {
|
|
1810
|
-
if (!isReady || !lastSyncTime) return;
|
|
1811
|
-
refetch();
|
|
1812
|
-
return () => {
|
|
1813
|
-
fetchGenRef.current++;
|
|
1814
|
-
};
|
|
1815
|
-
}, [isReady, lastSyncTime, refetch]);
|
|
1816
|
-
return { lineages, isLoading, error, refetch };
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
// src/hooks/usePswapLineagesFor.ts
|
|
1820
|
-
import { useCallback as useCallback10, useEffect as useEffect10, useMemo as useMemo8, useRef as useRef5, useState as useState8 } from "react";
|
|
1821
|
-
import { AccountId as AccountId3 } from "@miden-sdk/miden-sdk/mt";
|
|
1822
|
-
function usePswapLineagesFor(account) {
|
|
1823
|
-
const { client, isReady } = useMiden();
|
|
1824
|
-
const { lastSyncTime } = useSyncStateStore();
|
|
1825
|
-
const [lineages, setLineages] = useState8([]);
|
|
1826
|
-
const [isLoading, setIsLoading] = useState8(false);
|
|
1827
|
-
const [error, setError] = useState8(null);
|
|
1828
|
-
const fetchGenRef = useRef5(0);
|
|
1829
|
-
const accountKey = useMemo8(() => {
|
|
1830
|
-
if (account == null) return null;
|
|
1831
|
-
try {
|
|
1832
|
-
return parseAccountId(account).toString();
|
|
1833
|
-
} catch {
|
|
1834
|
-
return null;
|
|
1835
|
-
}
|
|
1836
|
-
}, [account]);
|
|
1837
|
-
const refetch = useCallback10(async () => {
|
|
1838
|
-
if (!client || !isReady || accountKey == null) return;
|
|
1839
|
-
const gen = ++fetchGenRef.current;
|
|
1840
|
-
setIsLoading(true);
|
|
1841
|
-
setError(null);
|
|
1842
|
-
try {
|
|
1843
|
-
const accountIdObj = AccountId3.fromHex(accountKey);
|
|
1844
|
-
const fetched = await client.getPswapLineagesFor(accountIdObj);
|
|
1845
|
-
if (gen === fetchGenRef.current) setLineages(fetched);
|
|
1846
|
-
} catch (err) {
|
|
1847
|
-
if (gen === fetchGenRef.current)
|
|
1848
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1849
|
-
} finally {
|
|
1850
|
-
if (gen === fetchGenRef.current) setIsLoading(false);
|
|
1851
|
-
}
|
|
1852
|
-
}, [client, isReady, accountKey]);
|
|
1853
|
-
useEffect10(() => {
|
|
1854
|
-
if (!isReady) return;
|
|
1855
|
-
refetch();
|
|
1856
|
-
return () => {
|
|
1857
|
-
fetchGenRef.current++;
|
|
1858
|
-
};
|
|
1859
|
-
}, [isReady, refetch]);
|
|
1860
|
-
useEffect10(() => {
|
|
1861
|
-
if (!isReady || !lastSyncTime) return;
|
|
1862
|
-
refetch();
|
|
1863
|
-
return () => {
|
|
1864
|
-
fetchGenRef.current++;
|
|
1865
|
-
};
|
|
1866
|
-
}, [isReady, lastSyncTime, refetch]);
|
|
1867
|
-
return { lineages, isLoading, error, refetch };
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
|
-
// src/hooks/usePswapLineage.ts
|
|
1871
|
-
import { useCallback as useCallback11, useEffect as useEffect11, useRef as useRef6, useState as useState9 } from "react";
|
|
1872
|
-
function usePswapLineage(orderId) {
|
|
1873
|
-
const { client, isReady } = useMiden();
|
|
1874
|
-
const { lastSyncTime } = useSyncStateStore();
|
|
1875
|
-
const [lineage, setLineage] = useState9(null);
|
|
1876
|
-
const [isLoading, setIsLoading] = useState9(false);
|
|
1877
|
-
const [error, setError] = useState9(null);
|
|
1878
|
-
const orderIdStr = orderId == null ? null : String(orderId);
|
|
1879
|
-
const fetchGenRef = useRef6(0);
|
|
1880
|
-
const refetch = useCallback11(async () => {
|
|
1881
|
-
if (!client || !isReady || orderIdStr == null) return;
|
|
1882
|
-
const gen = ++fetchGenRef.current;
|
|
1883
|
-
setIsLoading(true);
|
|
1884
|
-
setError(null);
|
|
1885
|
-
try {
|
|
1886
|
-
const fetched = await client.getPswapLineage(orderIdStr);
|
|
1887
|
-
if (gen === fetchGenRef.current) setLineage(fetched ?? null);
|
|
1888
|
-
} catch (err) {
|
|
1889
|
-
if (gen === fetchGenRef.current)
|
|
1890
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1891
|
-
} finally {
|
|
1892
|
-
if (gen === fetchGenRef.current) setIsLoading(false);
|
|
1893
|
-
}
|
|
1894
|
-
}, [client, isReady, orderIdStr]);
|
|
1895
|
-
useEffect11(() => {
|
|
1896
|
-
if (!isReady) return;
|
|
1897
|
-
refetch();
|
|
1898
|
-
return () => {
|
|
1899
|
-
fetchGenRef.current++;
|
|
1900
|
-
};
|
|
1901
|
-
}, [isReady, refetch]);
|
|
1902
|
-
useEffect11(() => {
|
|
1903
|
-
if (!isReady || !lastSyncTime) return;
|
|
1904
|
-
refetch();
|
|
1905
|
-
return () => {
|
|
1906
|
-
fetchGenRef.current++;
|
|
1907
|
-
};
|
|
1908
|
-
}, [isReady, lastSyncTime, refetch]);
|
|
1909
|
-
return { lineage, isLoading, error, refetch };
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
1778
|
// src/hooks/useCreateWallet.ts
|
|
1913
|
-
import { useCallback as
|
|
1779
|
+
import { useCallback as useCallback9, useState as useState7 } from "react";
|
|
1914
1780
|
import { AccountStorageMode } from "@miden-sdk/miden-sdk/mt";
|
|
1915
1781
|
|
|
1916
1782
|
// src/utils/runExclusive.ts
|
|
@@ -1921,10 +1787,10 @@ function useCreateWallet() {
|
|
|
1921
1787
|
const { client, isReady, runExclusive } = useMiden();
|
|
1922
1788
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1923
1789
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1924
|
-
const [wallet, setWallet] =
|
|
1925
|
-
const [isCreating, setIsCreating] =
|
|
1926
|
-
const [error, setError] =
|
|
1927
|
-
const createWallet =
|
|
1790
|
+
const [wallet, setWallet] = useState7(null);
|
|
1791
|
+
const [isCreating, setIsCreating] = useState7(false);
|
|
1792
|
+
const [error, setError] = useState7(null);
|
|
1793
|
+
const createWallet = useCallback9(
|
|
1928
1794
|
async (options = {}) => {
|
|
1929
1795
|
if (!client || !isReady) {
|
|
1930
1796
|
throw new Error("Miden client is not ready");
|
|
@@ -1959,7 +1825,7 @@ function useCreateWallet() {
|
|
|
1959
1825
|
},
|
|
1960
1826
|
[client, isReady, runExclusive, setAccounts]
|
|
1961
1827
|
);
|
|
1962
|
-
const reset =
|
|
1828
|
+
const reset = useCallback9(() => {
|
|
1963
1829
|
setWallet(null);
|
|
1964
1830
|
setIsCreating(false);
|
|
1965
1831
|
setError(null);
|
|
@@ -1984,16 +1850,16 @@ function getStorageMode(mode) {
|
|
|
1984
1850
|
}
|
|
1985
1851
|
|
|
1986
1852
|
// src/hooks/useCreateFaucet.ts
|
|
1987
|
-
import { useCallback as
|
|
1853
|
+
import { useCallback as useCallback10, useState as useState8 } from "react";
|
|
1988
1854
|
import { AccountStorageMode as AccountStorageMode2 } from "@miden-sdk/miden-sdk/mt";
|
|
1989
1855
|
function useCreateFaucet() {
|
|
1990
1856
|
const { client, isReady, runExclusive } = useMiden();
|
|
1991
1857
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1992
1858
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1993
|
-
const [faucet, setFaucet] =
|
|
1994
|
-
const [isCreating, setIsCreating] =
|
|
1995
|
-
const [error, setError] =
|
|
1996
|
-
const createFaucet =
|
|
1859
|
+
const [faucet, setFaucet] = useState8(null);
|
|
1860
|
+
const [isCreating, setIsCreating] = useState8(false);
|
|
1861
|
+
const [error, setError] = useState8(null);
|
|
1862
|
+
const createFaucet = useCallback10(
|
|
1997
1863
|
async (options) => {
|
|
1998
1864
|
if (!client || !isReady) {
|
|
1999
1865
|
throw new Error("Miden client is not ready");
|
|
@@ -2033,7 +1899,7 @@ function useCreateFaucet() {
|
|
|
2033
1899
|
},
|
|
2034
1900
|
[client, isReady, runExclusive, setAccounts]
|
|
2035
1901
|
);
|
|
2036
|
-
const reset =
|
|
1902
|
+
const reset = useCallback10(() => {
|
|
2037
1903
|
setFaucet(null);
|
|
2038
1904
|
setIsCreating(false);
|
|
2039
1905
|
setError(null);
|
|
@@ -2058,7 +1924,7 @@ function getStorageMode2(mode) {
|
|
|
2058
1924
|
}
|
|
2059
1925
|
|
|
2060
1926
|
// src/hooks/useImportAccount.ts
|
|
2061
|
-
import { useCallback as
|
|
1927
|
+
import { useCallback as useCallback11, useState as useState9 } from "react";
|
|
2062
1928
|
import { AccountFile } from "@miden-sdk/miden-sdk/mt";
|
|
2063
1929
|
|
|
2064
1930
|
// src/utils/errors.ts
|
|
@@ -2117,10 +1983,10 @@ function wrapWasmError(e) {
|
|
|
2117
1983
|
function useImportAccount() {
|
|
2118
1984
|
const { client, isReady, signerConnected } = useMiden();
|
|
2119
1985
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
2120
|
-
const [account, setAccount] =
|
|
2121
|
-
const [isImporting, setIsImporting] =
|
|
2122
|
-
const [error, setError] =
|
|
2123
|
-
const importAccount =
|
|
1986
|
+
const [account, setAccount] = useState9(null);
|
|
1987
|
+
const [isImporting, setIsImporting] = useState9(false);
|
|
1988
|
+
const [error, setError] = useState9(null);
|
|
1989
|
+
const importAccount = useCallback11(
|
|
2124
1990
|
async (options) => {
|
|
2125
1991
|
if (!client || !isReady) {
|
|
2126
1992
|
throw new Error("Miden client is not ready");
|
|
@@ -2214,7 +2080,7 @@ function useImportAccount() {
|
|
|
2214
2080
|
},
|
|
2215
2081
|
[client, isReady, setAccounts, signerConnected]
|
|
2216
2082
|
);
|
|
2217
|
-
const reset =
|
|
2083
|
+
const reset = useCallback11(() => {
|
|
2218
2084
|
setAccount(null);
|
|
2219
2085
|
setIsImporting(false);
|
|
2220
2086
|
setError(null);
|
|
@@ -2261,7 +2127,7 @@ function bytesEqual(left, right) {
|
|
|
2261
2127
|
}
|
|
2262
2128
|
|
|
2263
2129
|
// src/hooks/useSend.ts
|
|
2264
|
-
import { useCallback as
|
|
2130
|
+
import { useCallback as useCallback12, useRef as useRef4, useState as useState10 } from "react";
|
|
2265
2131
|
import {
|
|
2266
2132
|
FungibleAsset,
|
|
2267
2133
|
Note,
|
|
@@ -2273,12 +2139,12 @@ import {
|
|
|
2273
2139
|
function useSend() {
|
|
2274
2140
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2275
2141
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2276
|
-
const isBusyRef =
|
|
2277
|
-
const [result, setResult] =
|
|
2278
|
-
const [isLoading, setIsLoading] =
|
|
2279
|
-
const [stage, setStage] =
|
|
2280
|
-
const [error, setError] =
|
|
2281
|
-
const send =
|
|
2142
|
+
const isBusyRef = useRef4(false);
|
|
2143
|
+
const [result, setResult] = useState10(null);
|
|
2144
|
+
const [isLoading, setIsLoading] = useState10(false);
|
|
2145
|
+
const [stage, setStage] = useState10("idle");
|
|
2146
|
+
const [error, setError] = useState10(null);
|
|
2147
|
+
const send = useCallback12(
|
|
2282
2148
|
async (options) => {
|
|
2283
2149
|
if (!client || !isReady) {
|
|
2284
2150
|
throw new Error("Miden client is not ready");
|
|
@@ -2449,7 +2315,7 @@ function useSend() {
|
|
|
2449
2315
|
},
|
|
2450
2316
|
[client, isReady, prover, runExclusive, sync]
|
|
2451
2317
|
);
|
|
2452
|
-
const reset =
|
|
2318
|
+
const reset = useCallback12(() => {
|
|
2453
2319
|
setResult(null);
|
|
2454
2320
|
setIsLoading(false);
|
|
2455
2321
|
setStage("idle");
|
|
@@ -2476,7 +2342,7 @@ function extractFullNote(txResult) {
|
|
|
2476
2342
|
}
|
|
2477
2343
|
|
|
2478
2344
|
// src/hooks/useMultiSend.ts
|
|
2479
|
-
import { useCallback as
|
|
2345
|
+
import { useCallback as useCallback13, useRef as useRef5, useState as useState11 } from "react";
|
|
2480
2346
|
import {
|
|
2481
2347
|
FungibleAsset as FungibleAsset2,
|
|
2482
2348
|
Note as Note2,
|
|
@@ -2487,12 +2353,12 @@ import {
|
|
|
2487
2353
|
} from "@miden-sdk/miden-sdk/mt";
|
|
2488
2354
|
function useMultiSend() {
|
|
2489
2355
|
const { client, isReady, sync, prover, signerConnected } = useMiden();
|
|
2490
|
-
const isBusyRef =
|
|
2491
|
-
const [result, setResult] =
|
|
2492
|
-
const [isLoading, setIsLoading] =
|
|
2493
|
-
const [stage, setStage] =
|
|
2494
|
-
const [error, setError] =
|
|
2495
|
-
const sendMany =
|
|
2356
|
+
const isBusyRef = useRef5(false);
|
|
2357
|
+
const [result, setResult] = useState11(null);
|
|
2358
|
+
const [isLoading, setIsLoading] = useState11(false);
|
|
2359
|
+
const [stage, setStage] = useState11("idle");
|
|
2360
|
+
const [error, setError] = useState11(null);
|
|
2361
|
+
const sendMany = useCallback13(
|
|
2496
2362
|
async (options) => {
|
|
2497
2363
|
if (!client || !isReady) {
|
|
2498
2364
|
throw new Error("Miden client is not ready");
|
|
@@ -2596,7 +2462,7 @@ function useMultiSend() {
|
|
|
2596
2462
|
},
|
|
2597
2463
|
[client, isReady, prover, signerConnected, sync]
|
|
2598
2464
|
);
|
|
2599
|
-
const reset =
|
|
2465
|
+
const reset = useCallback13(() => {
|
|
2600
2466
|
setResult(null);
|
|
2601
2467
|
setIsLoading(false);
|
|
2602
2468
|
setStage("idle");
|
|
@@ -2613,11 +2479,11 @@ function useMultiSend() {
|
|
|
2613
2479
|
}
|
|
2614
2480
|
|
|
2615
2481
|
// src/hooks/useWaitForCommit.ts
|
|
2616
|
-
import { useCallback as
|
|
2482
|
+
import { useCallback as useCallback14 } from "react";
|
|
2617
2483
|
import { TransactionFilter as TransactionFilter3 } from "@miden-sdk/miden-sdk/mt";
|
|
2618
2484
|
function useWaitForCommit() {
|
|
2619
2485
|
const { client, isReady } = useMiden();
|
|
2620
|
-
const waitForCommit =
|
|
2486
|
+
const waitForCommit = useCallback14(
|
|
2621
2487
|
async (txId, options) => {
|
|
2622
2488
|
if (!client || !isReady) {
|
|
2623
2489
|
throw new Error("Miden client is not ready");
|
|
@@ -2660,11 +2526,11 @@ function normalizeHex3(value) {
|
|
|
2660
2526
|
}
|
|
2661
2527
|
|
|
2662
2528
|
// src/hooks/useWaitForNotes.ts
|
|
2663
|
-
import { useCallback as
|
|
2529
|
+
import { useCallback as useCallback15 } from "react";
|
|
2664
2530
|
function useWaitForNotes() {
|
|
2665
2531
|
const { client, isReady, runExclusive } = useMiden();
|
|
2666
2532
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2667
|
-
const waitForConsumableNotes =
|
|
2533
|
+
const waitForConsumableNotes = useCallback15(
|
|
2668
2534
|
async (options) => {
|
|
2669
2535
|
if (!client || !isReady) {
|
|
2670
2536
|
throw new Error("Miden client is not ready");
|
|
@@ -2695,15 +2561,15 @@ function useWaitForNotes() {
|
|
|
2695
2561
|
}
|
|
2696
2562
|
|
|
2697
2563
|
// src/hooks/useMint.ts
|
|
2698
|
-
import { useCallback as
|
|
2564
|
+
import { useCallback as useCallback16, useState as useState12 } from "react";
|
|
2699
2565
|
function useMint() {
|
|
2700
2566
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2701
2567
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2702
|
-
const [result, setResult] =
|
|
2703
|
-
const [isLoading, setIsLoading] =
|
|
2704
|
-
const [stage, setStage] =
|
|
2705
|
-
const [error, setError] =
|
|
2706
|
-
const mint =
|
|
2568
|
+
const [result, setResult] = useState12(null);
|
|
2569
|
+
const [isLoading, setIsLoading] = useState12(false);
|
|
2570
|
+
const [stage, setStage] = useState12("idle");
|
|
2571
|
+
const [error, setError] = useState12(null);
|
|
2572
|
+
const mint = useCallback16(
|
|
2707
2573
|
async (options) => {
|
|
2708
2574
|
if (!client || !isReady) {
|
|
2709
2575
|
throw new Error("Miden client is not ready");
|
|
@@ -2745,7 +2611,7 @@ function useMint() {
|
|
|
2745
2611
|
},
|
|
2746
2612
|
[client, isReady, prover, runExclusive, sync]
|
|
2747
2613
|
);
|
|
2748
|
-
const reset =
|
|
2614
|
+
const reset = useCallback16(() => {
|
|
2749
2615
|
setResult(null);
|
|
2750
2616
|
setIsLoading(false);
|
|
2751
2617
|
setStage("idle");
|
|
@@ -2761,92 +2627,17 @@ function useMint() {
|
|
|
2761
2627
|
};
|
|
2762
2628
|
}
|
|
2763
2629
|
|
|
2764
|
-
// src/hooks/useBridge.ts
|
|
2765
|
-
import { useCallback as useCallback20, useState as useState16 } from "react";
|
|
2766
|
-
import { EthAddress } from "@miden-sdk/miden-sdk/mt";
|
|
2767
|
-
function useBridge() {
|
|
2768
|
-
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2769
|
-
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2770
|
-
const [result, setResult] = useState16(null);
|
|
2771
|
-
const [isLoading, setIsLoading] = useState16(false);
|
|
2772
|
-
const [stage, setStage] = useState16("idle");
|
|
2773
|
-
const [error, setError] = useState16(null);
|
|
2774
|
-
const bridge = useCallback20(
|
|
2775
|
-
async (options) => {
|
|
2776
|
-
if (!client || !isReady) {
|
|
2777
|
-
throw new Error("Miden client is not ready");
|
|
2778
|
-
}
|
|
2779
|
-
setIsLoading(true);
|
|
2780
|
-
setStage("executing");
|
|
2781
|
-
setError(null);
|
|
2782
|
-
try {
|
|
2783
|
-
const senderId = parseAccountId(options.from);
|
|
2784
|
-
const bridgeId = parseAccountId(options.bridgeAccount);
|
|
2785
|
-
const assetId = parseAccountId(options.assetId);
|
|
2786
|
-
const destinationAddress = EthAddress.fromHex(
|
|
2787
|
-
options.destinationAddress
|
|
2788
|
-
);
|
|
2789
|
-
setStage("proving");
|
|
2790
|
-
const txResult = await runExclusiveSafe(async () => {
|
|
2791
|
-
const txRequest = await client.newB2AggTransactionRequest(
|
|
2792
|
-
senderId,
|
|
2793
|
-
bridgeId,
|
|
2794
|
-
assetId,
|
|
2795
|
-
BigInt(options.amount),
|
|
2796
|
-
options.destinationNetwork,
|
|
2797
|
-
destinationAddress
|
|
2798
|
-
);
|
|
2799
|
-
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2800
|
-
senderId,
|
|
2801
|
-
txRequest,
|
|
2802
|
-
prover
|
|
2803
|
-
) : await client.submitNewTransaction(senderId, txRequest);
|
|
2804
|
-
return { transactionId: txId.toHex() };
|
|
2805
|
-
});
|
|
2806
|
-
setStage("complete");
|
|
2807
|
-
setResult(txResult);
|
|
2808
|
-
if (!options.skipSync) {
|
|
2809
|
-
await sync();
|
|
2810
|
-
}
|
|
2811
|
-
return txResult;
|
|
2812
|
-
} catch (err) {
|
|
2813
|
-
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
2814
|
-
setError(error2);
|
|
2815
|
-
setStage("idle");
|
|
2816
|
-
throw error2;
|
|
2817
|
-
} finally {
|
|
2818
|
-
setIsLoading(false);
|
|
2819
|
-
}
|
|
2820
|
-
},
|
|
2821
|
-
[client, isReady, prover, runExclusive, sync]
|
|
2822
|
-
);
|
|
2823
|
-
const reset = useCallback20(() => {
|
|
2824
|
-
setResult(null);
|
|
2825
|
-
setIsLoading(false);
|
|
2826
|
-
setStage("idle");
|
|
2827
|
-
setError(null);
|
|
2828
|
-
}, []);
|
|
2829
|
-
return {
|
|
2830
|
-
bridge,
|
|
2831
|
-
result,
|
|
2832
|
-
isLoading,
|
|
2833
|
-
stage,
|
|
2834
|
-
error,
|
|
2835
|
-
reset
|
|
2836
|
-
};
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
2630
|
// src/hooks/useConsume.ts
|
|
2840
|
-
import { useCallback as
|
|
2631
|
+
import { useCallback as useCallback17, useState as useState13 } from "react";
|
|
2841
2632
|
import { NoteFilter as NoteFilter3, NoteFilterTypes as NoteFilterTypes2, NoteId } from "@miden-sdk/miden-sdk/mt";
|
|
2842
2633
|
function useConsume() {
|
|
2843
2634
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2844
2635
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2845
|
-
const [result, setResult] =
|
|
2846
|
-
const [isLoading, setIsLoading] =
|
|
2847
|
-
const [stage, setStage] =
|
|
2848
|
-
const [error, setError] =
|
|
2849
|
-
const consume =
|
|
2636
|
+
const [result, setResult] = useState13(null);
|
|
2637
|
+
const [isLoading, setIsLoading] = useState13(false);
|
|
2638
|
+
const [stage, setStage] = useState13("idle");
|
|
2639
|
+
const [error, setError] = useState13(null);
|
|
2640
|
+
const consume = useCallback17(
|
|
2850
2641
|
async (options) => {
|
|
2851
2642
|
if (!client || !isReady) {
|
|
2852
2643
|
throw new Error("Miden client is not ready");
|
|
@@ -2930,7 +2721,7 @@ function useConsume() {
|
|
|
2930
2721
|
},
|
|
2931
2722
|
[client, isReady, prover, runExclusive, sync]
|
|
2932
2723
|
);
|
|
2933
|
-
const reset =
|
|
2724
|
+
const reset = useCallback17(() => {
|
|
2934
2725
|
setResult(null);
|
|
2935
2726
|
setIsLoading(false);
|
|
2936
2727
|
setStage("idle");
|
|
@@ -2947,15 +2738,15 @@ function useConsume() {
|
|
|
2947
2738
|
}
|
|
2948
2739
|
|
|
2949
2740
|
// src/hooks/useSwap.ts
|
|
2950
|
-
import { useCallback as
|
|
2741
|
+
import { useCallback as useCallback18, useState as useState14 } from "react";
|
|
2951
2742
|
function useSwap() {
|
|
2952
2743
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2953
2744
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2954
|
-
const [result, setResult] =
|
|
2955
|
-
const [isLoading, setIsLoading] =
|
|
2956
|
-
const [stage, setStage] =
|
|
2957
|
-
const [error, setError] =
|
|
2958
|
-
const swap =
|
|
2745
|
+
const [result, setResult] = useState14(null);
|
|
2746
|
+
const [isLoading, setIsLoading] = useState14(false);
|
|
2747
|
+
const [stage, setStage] = useState14("idle");
|
|
2748
|
+
const [error, setError] = useState14(null);
|
|
2749
|
+
const swap = useCallback18(
|
|
2959
2750
|
async (options) => {
|
|
2960
2751
|
if (!client || !isReady) {
|
|
2961
2752
|
throw new Error("Miden client is not ready");
|
|
@@ -3004,7 +2795,7 @@ function useSwap() {
|
|
|
3004
2795
|
},
|
|
3005
2796
|
[client, isReady, prover, runExclusive, sync]
|
|
3006
2797
|
);
|
|
3007
|
-
const reset =
|
|
2798
|
+
const reset = useCallback18(() => {
|
|
3008
2799
|
setResult(null);
|
|
3009
2800
|
setIsLoading(false);
|
|
3010
2801
|
setStage("idle");
|
|
@@ -3021,15 +2812,15 @@ function useSwap() {
|
|
|
3021
2812
|
}
|
|
3022
2813
|
|
|
3023
2814
|
// src/hooks/usePswapCreate.ts
|
|
3024
|
-
import { useCallback as
|
|
2815
|
+
import { useCallback as useCallback19, useState as useState15 } from "react";
|
|
3025
2816
|
function usePswapCreate() {
|
|
3026
2817
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3027
2818
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3028
|
-
const [result, setResult] =
|
|
3029
|
-
const [isLoading, setIsLoading] =
|
|
3030
|
-
const [stage, setStage] =
|
|
3031
|
-
const [error, setError] =
|
|
3032
|
-
const pswapCreate =
|
|
2819
|
+
const [result, setResult] = useState15(null);
|
|
2820
|
+
const [isLoading, setIsLoading] = useState15(false);
|
|
2821
|
+
const [stage, setStage] = useState15("idle");
|
|
2822
|
+
const [error, setError] = useState15(null);
|
|
2823
|
+
const pswapCreate = useCallback19(
|
|
3033
2824
|
async (options) => {
|
|
3034
2825
|
if (!client || !isReady) {
|
|
3035
2826
|
throw new Error("Miden client is not ready");
|
|
@@ -3086,7 +2877,7 @@ function usePswapCreate() {
|
|
|
3086
2877
|
},
|
|
3087
2878
|
[client, isReady, prover, runExclusive, sync]
|
|
3088
2879
|
);
|
|
3089
|
-
const reset =
|
|
2880
|
+
const reset = useCallback19(() => {
|
|
3090
2881
|
setResult(null);
|
|
3091
2882
|
setIsLoading(false);
|
|
3092
2883
|
setStage("idle");
|
|
@@ -3103,15 +2894,15 @@ function usePswapCreate() {
|
|
|
3103
2894
|
}
|
|
3104
2895
|
|
|
3105
2896
|
// src/hooks/usePswapConsume.ts
|
|
3106
|
-
import { useCallback as
|
|
2897
|
+
import { useCallback as useCallback20, useState as useState16 } from "react";
|
|
3107
2898
|
function usePswapConsume() {
|
|
3108
2899
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3109
2900
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3110
|
-
const [result, setResult] =
|
|
3111
|
-
const [isLoading, setIsLoading] =
|
|
3112
|
-
const [stage, setStage] =
|
|
3113
|
-
const [error, setError] =
|
|
3114
|
-
const pswapConsume =
|
|
2901
|
+
const [result, setResult] = useState16(null);
|
|
2902
|
+
const [isLoading, setIsLoading] = useState16(false);
|
|
2903
|
+
const [stage, setStage] = useState16("idle");
|
|
2904
|
+
const [error, setError] = useState16(null);
|
|
2905
|
+
const pswapConsume = useCallback20(
|
|
3115
2906
|
async (options) => {
|
|
3116
2907
|
if (!client || !isReady) {
|
|
3117
2908
|
throw new Error("Miden client is not ready");
|
|
@@ -3160,7 +2951,7 @@ function usePswapConsume() {
|
|
|
3160
2951
|
},
|
|
3161
2952
|
[client, isReady, prover, runExclusive, sync]
|
|
3162
2953
|
);
|
|
3163
|
-
const reset =
|
|
2954
|
+
const reset = useCallback20(() => {
|
|
3164
2955
|
setResult(null);
|
|
3165
2956
|
setIsLoading(false);
|
|
3166
2957
|
setStage("idle");
|
|
@@ -3177,15 +2968,15 @@ function usePswapConsume() {
|
|
|
3177
2968
|
}
|
|
3178
2969
|
|
|
3179
2970
|
// src/hooks/usePswapCancel.ts
|
|
3180
|
-
import { useCallback as
|
|
2971
|
+
import { useCallback as useCallback21, useState as useState17 } from "react";
|
|
3181
2972
|
function usePswapCancel() {
|
|
3182
2973
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3183
2974
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3184
|
-
const [result, setResult] =
|
|
3185
|
-
const [isLoading, setIsLoading] =
|
|
3186
|
-
const [stage, setStage] =
|
|
3187
|
-
const [error, setError] =
|
|
3188
|
-
const pswapCancel =
|
|
2975
|
+
const [result, setResult] = useState17(null);
|
|
2976
|
+
const [isLoading, setIsLoading] = useState17(false);
|
|
2977
|
+
const [stage, setStage] = useState17("idle");
|
|
2978
|
+
const [error, setError] = useState17(null);
|
|
2979
|
+
const pswapCancel = useCallback21(
|
|
3189
2980
|
async (options) => {
|
|
3190
2981
|
if (!client || !isReady) {
|
|
3191
2982
|
throw new Error("Miden client is not ready");
|
|
@@ -3224,7 +3015,7 @@ function usePswapCancel() {
|
|
|
3224
3015
|
},
|
|
3225
3016
|
[client, isReady, prover, runExclusive, sync]
|
|
3226
3017
|
);
|
|
3227
|
-
const reset =
|
|
3018
|
+
const reset = useCallback21(() => {
|
|
3228
3019
|
setResult(null);
|
|
3229
3020
|
setIsLoading(false);
|
|
3230
3021
|
setStage("idle");
|
|
@@ -3240,189 +3031,11 @@ function usePswapCancel() {
|
|
|
3240
3031
|
};
|
|
3241
3032
|
}
|
|
3242
3033
|
|
|
3243
|
-
// src/hooks/usePswapCancelByOrder.ts
|
|
3244
|
-
import { useCallback as useCallback26, useState as useState22 } from "react";
|
|
3245
|
-
function usePswapCancelByOrder() {
|
|
3246
|
-
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3247
|
-
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3248
|
-
const [result, setResult] = useState22(null);
|
|
3249
|
-
const [isLoading, setIsLoading] = useState22(false);
|
|
3250
|
-
const [stage, setStage] = useState22("idle");
|
|
3251
|
-
const [error, setError] = useState22(null);
|
|
3252
|
-
const pswapCancelByOrder = useCallback26(
|
|
3253
|
-
async (options) => {
|
|
3254
|
-
if (!client || !isReady) {
|
|
3255
|
-
throw new Error("Miden client is not ready");
|
|
3256
|
-
}
|
|
3257
|
-
setIsLoading(true);
|
|
3258
|
-
setStage("executing");
|
|
3259
|
-
setError(null);
|
|
3260
|
-
try {
|
|
3261
|
-
const orderId = String(options.orderId);
|
|
3262
|
-
setStage("proving");
|
|
3263
|
-
const txResult = await runExclusiveSafe(async () => {
|
|
3264
|
-
const lineage = await client.getPswapLineage(orderId);
|
|
3265
|
-
if (!lineage) {
|
|
3266
|
-
throw new Error(`No PSWAP lineage tracked for order ${orderId}`);
|
|
3267
|
-
}
|
|
3268
|
-
const accountIdObj = lineage.creatorAccountId();
|
|
3269
|
-
const txRequest = await client.buildPswapCancelByOrder(orderId);
|
|
3270
|
-
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
3271
|
-
accountIdObj,
|
|
3272
|
-
txRequest,
|
|
3273
|
-
prover
|
|
3274
|
-
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
3275
|
-
return { transactionId: txId.toHex() };
|
|
3276
|
-
});
|
|
3277
|
-
setResult(txResult);
|
|
3278
|
-
await sync();
|
|
3279
|
-
setStage("complete");
|
|
3280
|
-
return txResult;
|
|
3281
|
-
} catch (err) {
|
|
3282
|
-
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
3283
|
-
setError(error2);
|
|
3284
|
-
setStage("idle");
|
|
3285
|
-
throw error2;
|
|
3286
|
-
} finally {
|
|
3287
|
-
setIsLoading(false);
|
|
3288
|
-
}
|
|
3289
|
-
},
|
|
3290
|
-
[client, isReady, prover, runExclusive, sync]
|
|
3291
|
-
);
|
|
3292
|
-
const reset = useCallback26(() => {
|
|
3293
|
-
setResult(null);
|
|
3294
|
-
setIsLoading(false);
|
|
3295
|
-
setStage("idle");
|
|
3296
|
-
setError(null);
|
|
3297
|
-
}, []);
|
|
3298
|
-
return {
|
|
3299
|
-
pswapCancelByOrder,
|
|
3300
|
-
result,
|
|
3301
|
-
isLoading,
|
|
3302
|
-
stage,
|
|
3303
|
-
error,
|
|
3304
|
-
reset
|
|
3305
|
-
};
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
// src/hooks/useCreateNetworkNote.ts
|
|
3309
|
-
import { useCallback as useCallback27, useState as useState23 } from "react";
|
|
3310
|
-
import {
|
|
3311
|
-
Felt,
|
|
3312
|
-
FeltArray,
|
|
3313
|
-
FungibleAsset as FungibleAsset3,
|
|
3314
|
-
Note as Note3,
|
|
3315
|
-
NoteArray as NoteArray3,
|
|
3316
|
-
NoteAssets as NoteAssets3,
|
|
3317
|
-
NoteMetadata,
|
|
3318
|
-
NoteStorage,
|
|
3319
|
-
NoteRecipient,
|
|
3320
|
-
NoteTag,
|
|
3321
|
-
NoteType as NoteType4,
|
|
3322
|
-
NetworkAccountTarget,
|
|
3323
|
-
TransactionRequestBuilder as TransactionRequestBuilder3
|
|
3324
|
-
} from "@miden-sdk/miden-sdk/mt";
|
|
3325
|
-
function useCreateNetworkNote() {
|
|
3326
|
-
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3327
|
-
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3328
|
-
const [result, setResult] = useState23(null);
|
|
3329
|
-
const [isLoading, setIsLoading] = useState23(false);
|
|
3330
|
-
const [stage, setStage] = useState23("idle");
|
|
3331
|
-
const [error, setError] = useState23(null);
|
|
3332
|
-
const createNetworkNote = useCallback27(
|
|
3333
|
-
async (options) => {
|
|
3334
|
-
if (!client || !isReady) {
|
|
3335
|
-
throw new Error("Miden client is not ready");
|
|
3336
|
-
}
|
|
3337
|
-
if (options.recipient && options.script) {
|
|
3338
|
-
throw new Error(
|
|
3339
|
-
"createNetworkNote requires exactly one of `recipient` or `script`, not both."
|
|
3340
|
-
);
|
|
3341
|
-
}
|
|
3342
|
-
if (!options.recipient && !options.script) {
|
|
3343
|
-
throw new Error(
|
|
3344
|
-
"createNetworkNote requires either `recipient` or `script`."
|
|
3345
|
-
);
|
|
3346
|
-
}
|
|
3347
|
-
setIsLoading(true);
|
|
3348
|
-
setStage("executing");
|
|
3349
|
-
setError(null);
|
|
3350
|
-
try {
|
|
3351
|
-
const built = await runExclusiveSafe(async () => {
|
|
3352
|
-
const senderId = parseAccountId(options.accountId);
|
|
3353
|
-
const targetId = parseAccountId(options.target);
|
|
3354
|
-
const target = new NetworkAccountTarget(
|
|
3355
|
-
targetId,
|
|
3356
|
-
options.executionHint
|
|
3357
|
-
);
|
|
3358
|
-
const noteAssets = options.assetId != null ? new NoteAssets3([
|
|
3359
|
-
new FungibleAsset3(
|
|
3360
|
-
parseAccountId(options.assetId),
|
|
3361
|
-
BigInt(options.amount ?? 0)
|
|
3362
|
-
)
|
|
3363
|
-
]) : new NoteAssets3();
|
|
3364
|
-
const metadata = new NoteMetadata(
|
|
3365
|
-
senderId,
|
|
3366
|
-
NoteType4.Public,
|
|
3367
|
-
NoteTag.withAccountTarget(target.targetId())
|
|
3368
|
-
);
|
|
3369
|
-
const recipient = options.recipient ?? NoteRecipient.fromScript(
|
|
3370
|
-
options.script,
|
|
3371
|
-
new NoteStorage(
|
|
3372
|
-
new FeltArray(
|
|
3373
|
-
(options.inputs ?? []).map((value) => new Felt(value))
|
|
3374
|
-
)
|
|
3375
|
-
)
|
|
3376
|
-
);
|
|
3377
|
-
const attachments = [target.toAttachment()];
|
|
3378
|
-
if (options.attachment) {
|
|
3379
|
-
attachments.push(createNoteAttachment(options.attachment));
|
|
3380
|
-
}
|
|
3381
|
-
const note = Note3.withAttachments(
|
|
3382
|
-
noteAssets,
|
|
3383
|
-
metadata,
|
|
3384
|
-
recipient,
|
|
3385
|
-
attachments
|
|
3386
|
-
);
|
|
3387
|
-
const ownOutputs = new NoteArray3();
|
|
3388
|
-
ownOutputs.push(note);
|
|
3389
|
-
const txRequest = new TransactionRequestBuilder3().withOwnOutputNotes(ownOutputs).build();
|
|
3390
|
-
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
3391
|
-
senderId,
|
|
3392
|
-
txRequest,
|
|
3393
|
-
prover
|
|
3394
|
-
) : await client.submitNewTransaction(senderId, txRequest);
|
|
3395
|
-
return { txId: txId.toHex(), note };
|
|
3396
|
-
});
|
|
3397
|
-
setStage("complete");
|
|
3398
|
-
setResult(built);
|
|
3399
|
-
await sync();
|
|
3400
|
-
return built;
|
|
3401
|
-
} catch (err) {
|
|
3402
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
3403
|
-
setError(e);
|
|
3404
|
-
setStage("idle");
|
|
3405
|
-
throw e;
|
|
3406
|
-
} finally {
|
|
3407
|
-
setIsLoading(false);
|
|
3408
|
-
}
|
|
3409
|
-
},
|
|
3410
|
-
[client, isReady, prover, runExclusive, sync]
|
|
3411
|
-
);
|
|
3412
|
-
const reset = useCallback27(() => {
|
|
3413
|
-
setResult(null);
|
|
3414
|
-
setIsLoading(false);
|
|
3415
|
-
setStage("idle");
|
|
3416
|
-
setError(null);
|
|
3417
|
-
}, []);
|
|
3418
|
-
return { createNetworkNote, result, isLoading, stage, error, reset };
|
|
3419
|
-
}
|
|
3420
|
-
|
|
3421
3034
|
// src/hooks/useTransaction.ts
|
|
3422
|
-
import { useCallback as
|
|
3035
|
+
import { useCallback as useCallback22, useRef as useRef6, useState as useState18 } from "react";
|
|
3423
3036
|
|
|
3424
3037
|
// src/utils/transactions.ts
|
|
3425
|
-
import { NoteType as
|
|
3038
|
+
import { NoteType as NoteType4, TransactionFilter as TransactionFilter4 } from "@miden-sdk/miden-sdk/mt";
|
|
3426
3039
|
async function waitForTransactionCommit2(client, runExclusiveSafe, txId, maxWaitMs = 1e4, delayMs = 1e3) {
|
|
3427
3040
|
let waited = 0;
|
|
3428
3041
|
while (waited < maxWaitMs) {
|
|
@@ -3450,7 +3063,7 @@ function extractFullNotes(txResult) {
|
|
|
3450
3063
|
const notes = executedTx?.outputNotes?.().notes?.() ?? [];
|
|
3451
3064
|
const result = [];
|
|
3452
3065
|
for (const note of notes) {
|
|
3453
|
-
if (note.noteType?.() ===
|
|
3066
|
+
if (note.noteType?.() === NoteType4.Private) {
|
|
3454
3067
|
const full = note.intoFull?.();
|
|
3455
3068
|
if (full) result.push(full);
|
|
3456
3069
|
}
|
|
@@ -3465,12 +3078,12 @@ function extractFullNotes(txResult) {
|
|
|
3465
3078
|
function useTransaction() {
|
|
3466
3079
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
3467
3080
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3468
|
-
const isBusyRef =
|
|
3469
|
-
const [result, setResult] =
|
|
3470
|
-
const [isLoading, setIsLoading] =
|
|
3471
|
-
const [stage, setStage] =
|
|
3472
|
-
const [error, setError] =
|
|
3473
|
-
const execute =
|
|
3081
|
+
const isBusyRef = useRef6(false);
|
|
3082
|
+
const [result, setResult] = useState18(null);
|
|
3083
|
+
const [isLoading, setIsLoading] = useState18(false);
|
|
3084
|
+
const [stage, setStage] = useState18("idle");
|
|
3085
|
+
const [error, setError] = useState18(null);
|
|
3086
|
+
const execute = useCallback22(
|
|
3474
3087
|
async (options) => {
|
|
3475
3088
|
if (!client || !isReady) {
|
|
3476
3089
|
throw new Error("Miden client is not ready");
|
|
@@ -3537,7 +3150,7 @@ function useTransaction() {
|
|
|
3537
3150
|
},
|
|
3538
3151
|
[client, isReady, runExclusive, sync]
|
|
3539
3152
|
);
|
|
3540
|
-
const reset =
|
|
3153
|
+
const reset = useCallback22(() => {
|
|
3541
3154
|
setResult(null);
|
|
3542
3155
|
setIsLoading(false);
|
|
3543
3156
|
setStage("idle");
|
|
@@ -3560,7 +3173,7 @@ async function resolveRequest(request, client) {
|
|
|
3560
3173
|
}
|
|
3561
3174
|
|
|
3562
3175
|
// src/hooks/useExecuteProgram.ts
|
|
3563
|
-
import { useCallback as
|
|
3176
|
+
import { useCallback as useCallback23, useRef as useRef7, useState as useState19 } from "react";
|
|
3564
3177
|
import {
|
|
3565
3178
|
AdviceInputs,
|
|
3566
3179
|
ForeignAccount,
|
|
@@ -3573,11 +3186,11 @@ function isForeignAccountWrapper(fa) {
|
|
|
3573
3186
|
function useExecuteProgram() {
|
|
3574
3187
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
3575
3188
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3576
|
-
const isBusyRef =
|
|
3577
|
-
const [result, setResult] =
|
|
3578
|
-
const [isLoading, setIsLoading] =
|
|
3579
|
-
const [error, setError] =
|
|
3580
|
-
const execute =
|
|
3189
|
+
const isBusyRef = useRef7(false);
|
|
3190
|
+
const [result, setResult] = useState19(null);
|
|
3191
|
+
const [isLoading, setIsLoading] = useState19(false);
|
|
3192
|
+
const [error, setError] = useState19(null);
|
|
3193
|
+
const execute = useCallback23(
|
|
3581
3194
|
async (options) => {
|
|
3582
3195
|
if (!client || !isReady) {
|
|
3583
3196
|
throw new Error("Miden client is not ready");
|
|
@@ -3636,7 +3249,7 @@ function useExecuteProgram() {
|
|
|
3636
3249
|
},
|
|
3637
3250
|
[client, isReady, runExclusive, sync]
|
|
3638
3251
|
);
|
|
3639
|
-
const reset =
|
|
3252
|
+
const reset = useCallback23(() => {
|
|
3640
3253
|
setResult(null);
|
|
3641
3254
|
setIsLoading(false);
|
|
3642
3255
|
setError(null);
|
|
@@ -3651,29 +3264,29 @@ function useExecuteProgram() {
|
|
|
3651
3264
|
}
|
|
3652
3265
|
|
|
3653
3266
|
// src/hooks/useCompile.ts
|
|
3654
|
-
import { useCallback as
|
|
3267
|
+
import { useCallback as useCallback24, useMemo as useMemo8 } from "react";
|
|
3655
3268
|
import { CompilerResource, getWasmOrThrow } from "@miden-sdk/miden-sdk/mt";
|
|
3656
3269
|
function useCompile() {
|
|
3657
3270
|
const { client, isReady } = useMiden();
|
|
3658
|
-
const resource =
|
|
3271
|
+
const resource = useMemo8(
|
|
3659
3272
|
() => client && isReady ? new CompilerResource(client, getWasmOrThrow) : null,
|
|
3660
3273
|
[client, isReady]
|
|
3661
3274
|
);
|
|
3662
|
-
const requireResource =
|
|
3275
|
+
const requireResource = useCallback24(() => {
|
|
3663
3276
|
if (!resource) {
|
|
3664
3277
|
throw new Error("Miden client is not ready");
|
|
3665
3278
|
}
|
|
3666
3279
|
return resource;
|
|
3667
3280
|
}, [resource]);
|
|
3668
|
-
const component =
|
|
3281
|
+
const component = useCallback24(
|
|
3669
3282
|
async (options) => requireResource().component(options),
|
|
3670
3283
|
[requireResource]
|
|
3671
3284
|
);
|
|
3672
|
-
const txScript =
|
|
3285
|
+
const txScript = useCallback24(
|
|
3673
3286
|
async (options) => requireResource().txScript(options),
|
|
3674
3287
|
[requireResource]
|
|
3675
3288
|
);
|
|
3676
|
-
const noteScript =
|
|
3289
|
+
const noteScript = useCallback24(
|
|
3677
3290
|
async (options) => requireResource().noteScript(options),
|
|
3678
3291
|
[requireResource]
|
|
3679
3292
|
);
|
|
@@ -3681,24 +3294,24 @@ function useCompile() {
|
|
|
3681
3294
|
}
|
|
3682
3295
|
|
|
3683
3296
|
// src/hooks/useSessionAccount.ts
|
|
3684
|
-
import { useCallback as
|
|
3297
|
+
import { useCallback as useCallback25, useEffect as useEffect9, useRef as useRef8, useState as useState20 } from "react";
|
|
3685
3298
|
import { AccountStorageMode as AccountStorageMode3 } from "@miden-sdk/miden-sdk/mt";
|
|
3686
3299
|
function useSessionAccount(options) {
|
|
3687
3300
|
const { client, isReady, sync } = useMiden();
|
|
3688
3301
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
3689
|
-
const [sessionAccountId, setSessionAccountId] =
|
|
3690
|
-
const [step, setStep] =
|
|
3691
|
-
const [error, setError] =
|
|
3692
|
-
const cancelledRef =
|
|
3693
|
-
const isBusyRef =
|
|
3302
|
+
const [sessionAccountId, setSessionAccountId] = useState20(null);
|
|
3303
|
+
const [step, setStep] = useState20("idle");
|
|
3304
|
+
const [error, setError] = useState20(null);
|
|
3305
|
+
const cancelledRef = useRef8(false);
|
|
3306
|
+
const isBusyRef = useRef8(false);
|
|
3694
3307
|
const storagePrefix = options.storagePrefix ?? "miden-session";
|
|
3695
3308
|
const pollIntervalMs = options.pollIntervalMs ?? 3e3;
|
|
3696
3309
|
const maxWaitMs = options.maxWaitMs ?? 6e4;
|
|
3697
3310
|
const storageMode = options.walletOptions?.storageMode ?? "public";
|
|
3698
3311
|
const authScheme = options.walletOptions?.authScheme ?? DEFAULTS.AUTH_SCHEME;
|
|
3699
|
-
const fundRef =
|
|
3312
|
+
const fundRef = useRef8(options.fund);
|
|
3700
3313
|
fundRef.current = options.fund;
|
|
3701
|
-
|
|
3314
|
+
useEffect9(() => {
|
|
3702
3315
|
try {
|
|
3703
3316
|
const stored = localStorage.getItem(`${storagePrefix}:accountId`);
|
|
3704
3317
|
const storedReady = localStorage.getItem(`${storagePrefix}:ready`);
|
|
@@ -3715,7 +3328,7 @@ function useSessionAccount(options) {
|
|
|
3715
3328
|
localStorage.removeItem(`${storagePrefix}:ready`);
|
|
3716
3329
|
}
|
|
3717
3330
|
}, [storagePrefix]);
|
|
3718
|
-
const initialize =
|
|
3331
|
+
const initialize = useCallback25(async () => {
|
|
3719
3332
|
if (!client || !isReady) {
|
|
3720
3333
|
throw new Error("Miden client is not ready");
|
|
3721
3334
|
}
|
|
@@ -3779,7 +3392,7 @@ function useSessionAccount(options) {
|
|
|
3779
3392
|
maxWaitMs,
|
|
3780
3393
|
setAccounts
|
|
3781
3394
|
]);
|
|
3782
|
-
const reset =
|
|
3395
|
+
const reset = useCallback25(() => {
|
|
3783
3396
|
cancelledRef.current = true;
|
|
3784
3397
|
isBusyRef.current = false;
|
|
3785
3398
|
setSessionAccountId(null);
|
|
@@ -3828,13 +3441,13 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
|
|
|
3828
3441
|
}
|
|
3829
3442
|
|
|
3830
3443
|
// src/hooks/useExportStore.ts
|
|
3831
|
-
import { useCallback as
|
|
3444
|
+
import { useCallback as useCallback26, useState as useState21 } from "react";
|
|
3832
3445
|
import { exportStore as sdkExportStore } from "@miden-sdk/miden-sdk/mt";
|
|
3833
3446
|
function useExportStore() {
|
|
3834
3447
|
const { client, isReady, runExclusive } = useMiden();
|
|
3835
|
-
const [isExporting, setIsExporting] =
|
|
3836
|
-
const [error, setError] =
|
|
3837
|
-
const exportStore =
|
|
3448
|
+
const [isExporting, setIsExporting] = useState21(false);
|
|
3449
|
+
const [error, setError] = useState21(null);
|
|
3450
|
+
const exportStore = useCallback26(async () => {
|
|
3838
3451
|
if (!client || !isReady) {
|
|
3839
3452
|
throw new Error("Miden client is not ready");
|
|
3840
3453
|
}
|
|
@@ -3852,7 +3465,7 @@ function useExportStore() {
|
|
|
3852
3465
|
setIsExporting(false);
|
|
3853
3466
|
}
|
|
3854
3467
|
}, [client, isReady, runExclusive]);
|
|
3855
|
-
const reset =
|
|
3468
|
+
const reset = useCallback26(() => {
|
|
3856
3469
|
setIsExporting(false);
|
|
3857
3470
|
setError(null);
|
|
3858
3471
|
}, []);
|
|
@@ -3865,13 +3478,13 @@ function useExportStore() {
|
|
|
3865
3478
|
}
|
|
3866
3479
|
|
|
3867
3480
|
// src/hooks/useImportStore.ts
|
|
3868
|
-
import { useCallback as
|
|
3481
|
+
import { useCallback as useCallback27, useState as useState22 } from "react";
|
|
3869
3482
|
import { importStore as sdkImportStore } from "@miden-sdk/miden-sdk/mt";
|
|
3870
3483
|
function useImportStore() {
|
|
3871
3484
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3872
|
-
const [isImporting, setIsImporting] =
|
|
3873
|
-
const [error, setError] =
|
|
3874
|
-
const importStore =
|
|
3485
|
+
const [isImporting, setIsImporting] = useState22(false);
|
|
3486
|
+
const [error, setError] = useState22(null);
|
|
3487
|
+
const importStore = useCallback27(
|
|
3875
3488
|
async (storeDump, storeName, options) => {
|
|
3876
3489
|
if (!client || !isReady) {
|
|
3877
3490
|
throw new Error("Miden client is not ready");
|
|
@@ -3893,7 +3506,7 @@ function useImportStore() {
|
|
|
3893
3506
|
},
|
|
3894
3507
|
[client, isReady, runExclusive, sync]
|
|
3895
3508
|
);
|
|
3896
|
-
const reset =
|
|
3509
|
+
const reset = useCallback27(() => {
|
|
3897
3510
|
setIsImporting(false);
|
|
3898
3511
|
setError(null);
|
|
3899
3512
|
}, []);
|
|
@@ -3906,13 +3519,13 @@ function useImportStore() {
|
|
|
3906
3519
|
}
|
|
3907
3520
|
|
|
3908
3521
|
// src/hooks/useImportNote.ts
|
|
3909
|
-
import { useCallback as
|
|
3522
|
+
import { useCallback as useCallback28, useState as useState23 } from "react";
|
|
3910
3523
|
import { NoteFile } from "@miden-sdk/miden-sdk/mt";
|
|
3911
3524
|
function useImportNote() {
|
|
3912
3525
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3913
|
-
const [isImporting, setIsImporting] =
|
|
3914
|
-
const [error, setError] =
|
|
3915
|
-
const importNote =
|
|
3526
|
+
const [isImporting, setIsImporting] = useState23(false);
|
|
3527
|
+
const [error, setError] = useState23(null);
|
|
3528
|
+
const importNote = useCallback28(
|
|
3916
3529
|
async (noteBytes) => {
|
|
3917
3530
|
if (!client || !isReady) {
|
|
3918
3531
|
throw new Error("Miden client is not ready");
|
|
@@ -3936,7 +3549,7 @@ function useImportNote() {
|
|
|
3936
3549
|
},
|
|
3937
3550
|
[client, isReady, runExclusive, sync]
|
|
3938
3551
|
);
|
|
3939
|
-
const reset =
|
|
3552
|
+
const reset = useCallback28(() => {
|
|
3940
3553
|
setIsImporting(false);
|
|
3941
3554
|
setError(null);
|
|
3942
3555
|
}, []);
|
|
@@ -3949,13 +3562,13 @@ function useImportNote() {
|
|
|
3949
3562
|
}
|
|
3950
3563
|
|
|
3951
3564
|
// src/hooks/useExportNote.ts
|
|
3952
|
-
import { useCallback as
|
|
3565
|
+
import { useCallback as useCallback29, useState as useState24 } from "react";
|
|
3953
3566
|
import { NoteExportFormat } from "@miden-sdk/miden-sdk/mt";
|
|
3954
3567
|
function useExportNote() {
|
|
3955
3568
|
const { client, isReady, runExclusive } = useMiden();
|
|
3956
|
-
const [isExporting, setIsExporting] =
|
|
3957
|
-
const [error, setError] =
|
|
3958
|
-
const exportNote =
|
|
3569
|
+
const [isExporting, setIsExporting] = useState24(false);
|
|
3570
|
+
const [error, setError] = useState24(null);
|
|
3571
|
+
const exportNote = useCallback29(
|
|
3959
3572
|
async (noteId) => {
|
|
3960
3573
|
if (!client || !isReady) {
|
|
3961
3574
|
throw new Error("Miden client is not ready");
|
|
@@ -3977,7 +3590,7 @@ function useExportNote() {
|
|
|
3977
3590
|
},
|
|
3978
3591
|
[client, isReady, runExclusive]
|
|
3979
3592
|
);
|
|
3980
|
-
const reset =
|
|
3593
|
+
const reset = useCallback29(() => {
|
|
3981
3594
|
setIsExporting(false);
|
|
3982
3595
|
setError(null);
|
|
3983
3596
|
}, []);
|
|
@@ -3990,12 +3603,12 @@ function useExportNote() {
|
|
|
3990
3603
|
}
|
|
3991
3604
|
|
|
3992
3605
|
// src/hooks/useSyncControl.ts
|
|
3993
|
-
import { useCallback as
|
|
3606
|
+
import { useCallback as useCallback30 } from "react";
|
|
3994
3607
|
function useSyncControl() {
|
|
3995
3608
|
const isPaused = useMidenStore((state) => state.syncPaused);
|
|
3996
3609
|
const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
|
|
3997
|
-
const pauseSync =
|
|
3998
|
-
const resumeSync =
|
|
3610
|
+
const pauseSync = useCallback30(() => setSyncPaused(true), [setSyncPaused]);
|
|
3611
|
+
const resumeSync = useCallback30(() => setSyncPaused(false), [setSyncPaused]);
|
|
3999
3612
|
return {
|
|
4000
3613
|
pauseSync,
|
|
4001
3614
|
resumeSync,
|
|
@@ -4180,11 +3793,9 @@ export {
|
|
|
4180
3793
|
useAccount,
|
|
4181
3794
|
useAccounts,
|
|
4182
3795
|
useAssetMetadata,
|
|
4183
|
-
useBridge,
|
|
4184
3796
|
useCompile,
|
|
4185
3797
|
useConsume,
|
|
4186
3798
|
useCreateFaucet,
|
|
4187
|
-
useCreateNetworkNote,
|
|
4188
3799
|
useCreateWallet,
|
|
4189
3800
|
useExecuteProgram,
|
|
4190
3801
|
useExportNote,
|
|
@@ -4200,12 +3811,8 @@ export {
|
|
|
4200
3811
|
useNoteStream,
|
|
4201
3812
|
useNotes,
|
|
4202
3813
|
usePswapCancel,
|
|
4203
|
-
usePswapCancelByOrder,
|
|
4204
3814
|
usePswapConsume,
|
|
4205
3815
|
usePswapCreate,
|
|
4206
|
-
usePswapLineage,
|
|
4207
|
-
usePswapLineages,
|
|
4208
|
-
usePswapLineagesFor,
|
|
4209
3816
|
useSend,
|
|
4210
3817
|
useSessionAccount,
|
|
4211
3818
|
useSigner,
|