@miden-sdk/react 0.15.1 → 0.15.2

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 CHANGED
@@ -394,6 +394,9 @@ Query hooks return `{ ...data, isLoading, error, refetch }`. Mutation hooks retu
394
394
  | `useTransactionHistory(...)` | `transactions` | Local transaction log |
395
395
  | `useSessionAccount()` | `account` | The signer's connected account |
396
396
  | `useWaitForNotes(...)` | resolves when matching notes appear | Pull-style note waiting |
397
+ | `usePswapLineages()` | `lineages` | All tracked PSWAP order lineages |
398
+ | `usePswapLineagesFor(creator)` | `lineages` | Tracked PSWAP lineages for one creator |
399
+ | `usePswapLineage(orderId)` | `lineage` | One tracked PSWAP lineage by stable order id |
397
400
 
398
401
  ### Mutation (write)
399
402
  | Hook | Action | Returns on success |
@@ -412,6 +415,7 @@ Query hooks return `{ ...data, isLoading, error, refetch }`. Mutation hooks retu
412
415
  | `usePswapCreate()` | `pswapCreate({ accountId, offeredFaucetId, offeredAmount, requestedFaucetId, requestedAmount, ... })` | `TransactionResult` (creates partial-swap note) |
413
416
  | `usePswapConsume()` | `pswapConsume({ accountId, note, fillAmount, noteFillAmount? })` — `note` accepts hex string \| `NoteId` \| `InputNoteRecord` \| `Note` | `TransactionResult` (fills PSWAP fully or partially) |
414
417
  | `usePswapCancel()` | `pswapCancel({ accountId, note })` — creator only, reclaims unfilled offered asset | `TransactionResult` |
418
+ | `usePswapCancelByOrder()` | `pswapCancelByOrder({ orderId })` — creator only, resolves the current tip + creator from the tracked lineage | `TransactionResult` |
415
419
  | `useTransaction()` | `transact({ ... })` | `TransactionResult` (custom tx) |
416
420
  | `useExecuteProgram()` | `execute(...)` | program output |
417
421
  | `useCompile()` | `compile({ source })` | `{ component, txScript, noteScript }` |
package/README.md CHANGED
@@ -1105,6 +1105,64 @@ function CancelPswapButton({ accountId, note }: Props) {
1105
1105
  }
1106
1106
  ```
1107
1107
 
1108
+ #### `usePswapLineages()` / `usePswapLineagesFor()` / `usePswapLineage()`
1109
+
1110
+ Read the partial-swap orders this client is tracking. As a PSWAP note is filled
1111
+ round by round, the client follows the chain — original note → remainder →
1112
+ remainder — and records each step as a **lineage** keyed by a stable `orderId`.
1113
+ These query hooks expose that tracked state and refresh after every successful
1114
+ sync. They return `{ lineages | lineage, isLoading, error, refetch }`.
1115
+
1116
+ ```tsx
1117
+ import {
1118
+ usePswapLineages,
1119
+ usePswapLineagesFor,
1120
+ usePswapLineage,
1121
+ } from '@miden-sdk/react';
1122
+
1123
+ // Every lineage tracked by this client
1124
+ const { lineages } = usePswapLineages();
1125
+
1126
+ // Only the lineages created by one account
1127
+ const { lineages: mine } = usePswapLineagesFor('0xmywallet...');
1128
+
1129
+ // A single order by its stable id
1130
+ const { lineage } = usePswapLineage(orderId);
1131
+
1132
+ function OrderRow({ orderId }: { orderId: string }) {
1133
+ const { lineage, isLoading } = usePswapLineage(orderId);
1134
+ if (isLoading) return <span>Loading…</span>;
1135
+ if (!lineage) return <span>Not tracked</span>;
1136
+ return (
1137
+ <span>
1138
+ {lineage.orderId()} — {lineage.remainingOffered().toString()} left,
1139
+ state {lineage.state()}
1140
+ </span>
1141
+ );
1142
+ }
1143
+ ```
1144
+
1145
+ #### `usePswapCancelByOrder()`
1146
+
1147
+ Cancel a tracked PSWAP by its stable `orderId` and reclaim the unfilled offered
1148
+ asset on the lineage's current tip. Unlike `usePswapCancel`, you don't need to
1149
+ hold the tip note — the creator account and tip are resolved from the locally
1150
+ tracked lineage, so only the order id is required.
1151
+
1152
+ ```tsx
1153
+ import { usePswapCancelByOrder } from '@miden-sdk/react';
1154
+
1155
+ function CancelOrderButton({ orderId }: { orderId: string }) {
1156
+ const { pswapCancelByOrder, isLoading, stage } = usePswapCancelByOrder();
1157
+
1158
+ return (
1159
+ <button onClick={() => pswapCancelByOrder({ orderId })} disabled={isLoading}>
1160
+ {isLoading ? stage : 'Cancel order'}
1161
+ </button>
1162
+ );
1163
+ }
1164
+ ```
1165
+
1108
1166
  #### `useTransaction()`
1109
1167
 
1110
1168
  Execute a custom `TransactionRequest` or build one with the client. This is the
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode } from 'react';
4
- import { AccountId, Account, AccountHeader, AccountStorageMode, AccountComponent, NoteId, InputNoteRecord, Note, StorageMode, AuthScheme, TransactionScript, AdviceInputs, AccountStorageRequirements, TransactionRequest, WasmWebClient, AccountFile, NoteVisibility, ConsumableNoteRecord, NoteInput, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
5
- export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk';
4
+ import { AccountId, Account, AccountHeader, AccountStorageMode, AccountComponent, NoteId, InputNoteRecord, Note, StorageMode, AuthScheme, TransactionScript, AdviceInputs, AccountStorageRequirements, TransactionRequest, WasmWebClient, AccountFile, NoteVisibility, ConsumableNoteRecord, NoteInput, PswapLineageRecord, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
5
+ export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, PswapLineageRecord, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk';
6
6
 
7
7
  declare module "@miden-sdk/miden-sdk" {
8
8
  interface Account {
@@ -462,6 +462,29 @@ interface PswapCancelOptions {
462
462
  */
463
463
  note: NoteInput;
464
464
  }
465
+ interface PswapCancelByOrderOptions {
466
+ /**
467
+ * Stable order id of the lineage to cancel (decimal string or bigint).
468
+ * `number` is not accepted: a PSWAP order id is `u64`-shaped and routinely
469
+ * exceeds `Number.MAX_SAFE_INTEGER`, which a JS `number` cannot represent
470
+ * without silent precision loss.
471
+ */
472
+ orderId: string | bigint;
473
+ }
474
+ interface PswapLineagesResult {
475
+ /** Tracked PSWAP lineages. */
476
+ lineages: PswapLineageRecord[];
477
+ isLoading: boolean;
478
+ error: Error | null;
479
+ refetch: () => Promise<void>;
480
+ }
481
+ interface PswapLineageResult {
482
+ /** The tracked lineage, or `null` if not tracked. */
483
+ lineage: PswapLineageRecord | null;
484
+ isLoading: boolean;
485
+ error: Error | null;
486
+ refetch: () => Promise<void>;
487
+ }
465
488
  interface ExecuteTransactionOptions {
466
489
  /** Account ID the transaction applies to */
467
490
  accountId: AccountRef;
@@ -814,6 +837,74 @@ declare function useAssetMetadata(assetIds?: string[]): {
814
837
  assetMetadata: Map<string, AssetMetadata>;
815
838
  };
816
839
 
840
+ /**
841
+ * Hook to list every partial-swap (PSWAP) lineage tracked by this client.
842
+ *
843
+ * A lineage records how a PSWAP note has been filled round by round, from the
844
+ * original note through each remainder to the current tip. The list refreshes
845
+ * after each successful sync.
846
+ *
847
+ * @example
848
+ * ```tsx
849
+ * function LineageList() {
850
+ * const { lineages, isLoading } = usePswapLineages();
851
+ * if (isLoading) return <div>Loading...</div>;
852
+ * return (
853
+ * <ul>
854
+ * {lineages.map((l) => (
855
+ * <li key={l.orderId()}>
856
+ * {l.orderId()} — {l.remainingOffered().toString()} remaining
857
+ * </li>
858
+ * ))}
859
+ * </ul>
860
+ * );
861
+ * }
862
+ * ```
863
+ */
864
+ declare function usePswapLineages(): PswapLineagesResult;
865
+ type UsePswapLineagesResult = PswapLineagesResult;
866
+
867
+ /**
868
+ * Hook to list the partial-swap (PSWAP) lineages created by a specific local
869
+ * account. Refreshes after each successful sync.
870
+ *
871
+ * @param account - Creator account (hex, bech32, `Account`, or `AccountId`).
872
+ *
873
+ * @example
874
+ * ```tsx
875
+ * function MyLineages({ accountId }: { accountId: string }) {
876
+ * const { lineages, isLoading } = usePswapLineagesFor(accountId);
877
+ * if (isLoading) return <div>Loading...</div>;
878
+ * return <div>{lineages.length} open orders</div>;
879
+ * }
880
+ * ```
881
+ */
882
+ declare function usePswapLineagesFor(account: AccountRef | null | undefined): PswapLineagesResult;
883
+ type UsePswapLineagesForResult = PswapLineagesResult;
884
+
885
+ /**
886
+ * Hook to fetch a single partial-swap (PSWAP) lineage by its stable order id.
887
+ * Returns `null` if this client is not tracking the order. Refreshes after each
888
+ * successful sync.
889
+ *
890
+ * @param orderId - Stable order id (decimal string or bigint). `number` is
891
+ * not accepted: a PSWAP order id is `u64`-shaped and routinely exceeds
892
+ * `Number.MAX_SAFE_INTEGER`, which a JS `number` cannot represent without
893
+ * silent precision loss.
894
+ *
895
+ * @example
896
+ * ```tsx
897
+ * function OrderStatus({ orderId }: { orderId: string }) {
898
+ * const { lineage, isLoading } = usePswapLineage(orderId);
899
+ * if (isLoading) return <div>Loading...</div>;
900
+ * if (!lineage) return <div>Not tracked</div>;
901
+ * return <div>State: {lineage.state()}</div>;
902
+ * }
903
+ * ```
904
+ */
905
+ declare function usePswapLineage(orderId: string | bigint | null | undefined): PswapLineageResult;
906
+ type UsePswapLineageResult = PswapLineageResult;
907
+
817
908
  interface UseCreateWalletResult {
818
909
  /** Create a new wallet with optional configuration */
819
910
  createWallet: (options?: CreateWalletOptions) => Promise<Account>;
@@ -1296,6 +1387,40 @@ interface UsePswapCancelResult {
1296
1387
  */
1297
1388
  declare function usePswapCancel(): UsePswapCancelResult;
1298
1389
 
1390
+ interface UsePswapCancelByOrderResult {
1391
+ /** Cancel a PSWAP lineage by its stable order id, reclaiming the unfilled offered asset. */
1392
+ pswapCancelByOrder: (options: PswapCancelByOrderOptions) => Promise<TransactionResult>;
1393
+ /** The transaction result */
1394
+ result: TransactionResult | null;
1395
+ /** Whether the transaction is in progress */
1396
+ isLoading: boolean;
1397
+ /** Current stage of the transaction */
1398
+ stage: TransactionStage;
1399
+ /** Error if transaction failed */
1400
+ error: Error | null;
1401
+ /** Reset the hook state */
1402
+ reset: () => void;
1403
+ }
1404
+ /**
1405
+ * Hook to cancel a PSWAP lineage by its stable order id and reclaim the
1406
+ * unfilled offered asset on the lineage's current tip. Unlike
1407
+ * {@link usePswapCancel}, the creator account and tip note are resolved from
1408
+ * the locally tracked lineage, so only the order id is required.
1409
+ *
1410
+ * @example
1411
+ * ```tsx
1412
+ * function CancelOrderButton({ orderId }: { orderId: string }) {
1413
+ * const { pswapCancelByOrder, isLoading, stage } = usePswapCancelByOrder();
1414
+ * return (
1415
+ * <button onClick={() => pswapCancelByOrder({ orderId })} disabled={isLoading}>
1416
+ * {isLoading ? stage : "Cancel order"}
1417
+ * </button>
1418
+ * );
1419
+ * }
1420
+ * ```
1421
+ */
1422
+ declare function usePswapCancelByOrder(): UsePswapCancelByOrderResult;
1423
+
1299
1424
  interface UseTransactionResult {
1300
1425
  /** Execute a transaction request end-to-end */
1301
1426
  execute: (options: ExecuteTransactionOptions) => Promise<TransactionResult>;
@@ -1715,4 +1840,4 @@ declare function createMidenStorage(prefix: string): {
1715
1840
  clear(): void;
1716
1841
  };
1717
1842
 
1718
- export { type AccountRef, type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type ConsumeOptions, type CreateFaucetOptions, type CreateWalletOptions, DEFAULTS, type ExecuteProgramOptions, type ExecuteProgramResult, type ExecuteTransactionOptions, type ImportAccountOptions, type ImportStoreOptions, type MidenConfig, MidenError, type MidenErrorCode, MidenProvider, type MidenState, type MigrateStorageOptions, type MintOptions, type MultiSendOptions, type MultiSendRecipient, type MultiSignerContextValue, MultiSignerProvider, type MutationResult, type NoteAsset, type NoteAttachmentData, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverTarget, type ProverUrls, type PswapCancelOptions, type PswapConsumeOptions, type PswapCreateOptions, type QueryResult, type RpcUrlConfig, type SendOptions, type SendResult, type SessionAccountStep, type SignCallback, type SignerAccountConfig, type SignerAccountType, SignerContext, type SignerContextValue, SignerSlot, type StreamedNote, type SwapOptions, type SyncState, type TransactionHistoryOptions, type TransactionHistoryResult, type TransactionResult, type TransactionStage, type TransactionStatus, type UseCompileResult, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateWalletResult, type UseExecuteProgramResult, type UseExportNoteResult, type UseExportStoreResult, type UseImportAccountResult, type UseImportNoteResult, type UseImportStoreResult, type UseMintResult, type UseMultiSendResult, type UseNoteStreamOptions, type UseNoteStreamReturn, type UsePswapCancelResult, type UsePswapConsumeResult, type UsePswapCreateResult, type UseSendResult, type UseSessionAccountOptions, type UseSessionAccountReturn, type UseSwapResult, type UseSyncControlResult, type UseSyncStateResult, type UseTransactionHistoryResult, type UseTransactionResult, type UseWaitForCommitResult, type UseWaitForNotesResult, type WaitForCommitOptions, type WaitForNotesOptions, type WalletAdapterLike, accountIdsEqual, bigIntToBytes, bytesToBigInt, clearMidenStorage, concatBytes, createMidenStorage, createNoteAttachment, ensureAccountBech32, formatAssetAmount, formatNoteSummary, getNoteSummary, installAccountBech32, migrateStorage, normalizeAccountId, parseAssetAmount, readNoteAttachment, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useCompile, useConsume, useCreateFaucet, useCreateWallet, useExecuteProgram, useExportNote, useExportStore, useImportAccount, useImportNote, useImportStore, useMiden, useMidenClient, useMint, useMultiSend, useMultiSigner, useNoteStream, useNotes, usePswapCancel, usePswapConsume, usePswapCreate, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };
1843
+ export { type AccountRef, type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type ConsumeOptions, type CreateFaucetOptions, type CreateWalletOptions, DEFAULTS, type ExecuteProgramOptions, type ExecuteProgramResult, type ExecuteTransactionOptions, type ImportAccountOptions, type ImportStoreOptions, type MidenConfig, MidenError, type MidenErrorCode, MidenProvider, type MidenState, type MigrateStorageOptions, type MintOptions, type MultiSendOptions, type MultiSendRecipient, type MultiSignerContextValue, MultiSignerProvider, type MutationResult, type NoteAsset, type NoteAttachmentData, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverTarget, type ProverUrls, type PswapCancelByOrderOptions, type PswapCancelOptions, type PswapConsumeOptions, type PswapCreateOptions, type PswapLineageResult, type PswapLineagesResult, type QueryResult, type RpcUrlConfig, type SendOptions, type SendResult, type SessionAccountStep, type SignCallback, type SignerAccountConfig, type SignerAccountType, SignerContext, type SignerContextValue, SignerSlot, type StreamedNote, type SwapOptions, type SyncState, type TransactionHistoryOptions, type TransactionHistoryResult, type TransactionResult, type TransactionStage, type TransactionStatus, type UseCompileResult, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateWalletResult, type UseExecuteProgramResult, type UseExportNoteResult, type UseExportStoreResult, type UseImportAccountResult, type UseImportNoteResult, type UseImportStoreResult, type UseMintResult, type UseMultiSendResult, type UseNoteStreamOptions, type UseNoteStreamReturn, type UsePswapCancelByOrderResult, type UsePswapCancelResult, type UsePswapConsumeResult, type UsePswapCreateResult, type UsePswapLineageResult, type UsePswapLineagesForResult, type UsePswapLineagesResult, type UseSendResult, type UseSessionAccountOptions, type UseSessionAccountReturn, type UseSwapResult, type UseSyncControlResult, type UseSyncStateResult, type UseTransactionHistoryResult, type UseTransactionResult, type UseWaitForCommitResult, type UseWaitForNotesResult, type WaitForCommitOptions, type WaitForNotesOptions, type WalletAdapterLike, accountIdsEqual, bigIntToBytes, bytesToBigInt, clearMidenStorage, concatBytes, createMidenStorage, createNoteAttachment, ensureAccountBech32, formatAssetAmount, formatNoteSummary, getNoteSummary, installAccountBech32, migrateStorage, normalizeAccountId, parseAssetAmount, readNoteAttachment, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useCompile, useConsume, useCreateFaucet, useCreateWallet, useExecuteProgram, useExportNote, useExportStore, useImportAccount, useImportNote, useImportStore, useMiden, useMidenClient, useMint, useMultiSend, useMultiSigner, useNoteStream, useNotes, usePswapCancel, usePswapCancelByOrder, usePswapConsume, usePswapCreate, usePswapLineage, usePswapLineages, usePswapLineagesFor, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };