Skip to content

Commit ac9e5cb

Browse files
ghermetclaude
andauthored
refactor(react-sdk): use batchDecryptBalancesAsMutationOptions factory (#204)
* refactor(react-sdk): use batchDecryptBalancesAsMutationOptions factory useBatchDecryptBalancesAs was the only delegation hook inlining its mutation key and function instead of using the corresponding SDK options factory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: regenerate react-sdk API report Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix(sdk): prevent concurrent contract extensions from dropping addresses When two allow() calls with different contracts ran concurrently, the second could start from stale credentials after the first's extend promise resolved and was nulled. Cache the last extend result so subsequent calls use it as the base, preserving all added addresses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: remove #lastExtendResult from credentials manager Reverts the concurrent extension caching (cee34b8) to keep this branch's diff minimal. Formatting-only changes from the linter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0ba9c55 commit ac9e5cb

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

packages/react-sdk/etc/react-sdk.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ export function useAllow(options?: UseMutationOptions<void, Error, Address[]>):
859859
export function useApproveUnderlying(config: UseZamaConfig, options?: UseMutationOptions<TransactionResult, Error, ApproveUnderlyingParams, Address>): _$_tanstack_react_query0.UseMutationResult<TransactionResult, Error, ApproveUnderlyingParams, `0x${string}`>;
860860

861861
// @public
862-
export function useBatchDecryptBalancesAs(tokens: ReadonlyToken[], options?: UseMutationOptions<Map<Address, bigint>, Error, BatchDecryptAsOptions>): _$_tanstack_react_query0.UseMutationResult<Map<`0x${string}`, bigint>, Error, BatchDecryptAsOptions, unknown>;
862+
export function useBatchDecryptBalancesAs(tokens: ReadonlyToken[], options?: UseMutationOptions<Map<Address, bigint>, Error, BatchDecryptBalancesAsParams>): _$_tanstack_react_query0.UseMutationResult<Map<`0x${string}`, bigint>, Error, _$_zama_fhe_sdk0.BatchDecryptAsOptions, unknown>;
863863

864864
// @public
865865
export function useBatchTransferFee(feeManagerAddress: Address, options?: Omit<UseQueryOptions<bigint>, "queryKey" | "queryFn">): _$_tanstack_react_query0.UseQueryResult<bigint, Error>;

packages/react-sdk/src/delegation/use-batch-decrypt-balances-as.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
"use client";
22

33
import { useMutation, type UseMutationOptions } from "@tanstack/react-query";
4-
import { ReadonlyToken, type Address, type BatchDecryptAsOptions } from "@zama-fhe/sdk";
4+
import type { Address, ReadonlyToken } from "@zama-fhe/sdk";
5+
import {
6+
batchDecryptBalancesAsMutationOptions,
7+
type BatchDecryptBalancesAsParams,
8+
} from "@zama-fhe/sdk/query";
59

610
/**
711
* Batch decrypt confidential balances as a delegate across multiple tokens.
@@ -20,11 +24,10 @@ import { ReadonlyToken, type Address, type BatchDecryptAsOptions } from "@zama-f
2024
*/
2125
export function useBatchDecryptBalancesAs(
2226
tokens: ReadonlyToken[],
23-
options?: UseMutationOptions<Map<Address, bigint>, Error, BatchDecryptAsOptions>,
27+
options?: UseMutationOptions<Map<Address, bigint>, Error, BatchDecryptBalancesAsParams>,
2428
) {
25-
return useMutation<Map<Address, bigint>, Error, BatchDecryptAsOptions>({
26-
mutationKey: ["zama.batchDecryptBalancesAs", ...tokens.map((t) => t.address)] as const,
27-
mutationFn: async (params) => ReadonlyToken.batchDecryptBalancesAs(tokens, params),
29+
return useMutation<Map<Address, bigint>, Error, BatchDecryptBalancesAsParams>({
30+
...batchDecryptBalancesAsMutationOptions(tokens),
2831
...options,
2932
});
3033
}

0 commit comments

Comments
 (0)