@zkp2p/sdk 0.9.0 → 0.10.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a1 as SignalIntentMethodParams, bG as PreparedTransaction, bJ as TakerTier, E as GetTakerTierRequest, F as GetTakerTierResponse, a2 as FulfillIntentMethodParams, c$ as SendTransactionFn, d0 as SendBatchFn, cZ as DelegationDepositTarget, c_ as BatchResult } from './vaultUtils-aJdIIILM.mjs';
2
- export { cX as DelegationRoute, cY as DelegationState, d1 as VAULT_ZERO_ADDRESS, cR as ZERO_RATE_MANAGER_ID, d2 as asErrorMessage, d3 as assertDelegationMethodSupport, cW as classifyDelegationState, cV as getDelegationRoute, cS as isZeroRateManagerId, cT as normalizeRateManagerId, cU as normalizeRegistry } from './vaultUtils-aJdIIILM.mjs';
1
+ import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a2 as SignalIntentMethodParams, bM as PreparedTransaction, bX as TakerStake, E as GetTakerStakeRequest, F as GetTakerStakeResponse, c8 as TakerCapacity, H as GetTakerCapacityRequest, J as GetTakerCapacityResponse, a3 as FulfillIntentMethodParams, dp as SendTransactionFn, dq as SendBatchFn, dm as DelegationDepositTarget, dn as BatchResult } from './vaultUtils-DtkWNsxi.mjs';
2
+ export { dk as DelegationRoute, dl as DelegationState, dr as VAULT_ZERO_ADDRESS, de as ZERO_RATE_MANAGER_ID, ds as asErrorMessage, dt as assertDelegationMethodSupport, dj as classifyDelegationState, di as getDelegationRoute, df as isZeroRateManagerId, dg as normalizeRateManagerId, dh as normalizeRegistry } from './vaultUtils-DtkWNsxi.mjs';
3
3
  import { Hash, Address, Hex } from 'viem';
4
4
  import '@zkp2p/indexer-schema';
5
5
  import 'abitype';
@@ -60,26 +60,45 @@ declare function useSignalIntent({ client, onSuccess, onError }: UseSignalIntent
60
60
  prepared: PreparedTransaction | null;
61
61
  };
62
62
 
63
- interface UseGetTakerTierOptions {
63
+ interface UseGetTakerStakeOptions {
64
64
  client: Zkp2pClient | null;
65
65
  owner?: string | null;
66
66
  chainId?: number | null;
67
67
  autoFetch?: boolean;
68
- onSuccess?: (tier: TakerTier) => void;
68
+ onSuccess?: (stake: TakerStake) => void;
69
69
  onError?: (error: Error) => void;
70
70
  }
71
- declare function useGetTakerTier({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerTierOptions): {
72
- getTakerTier: (params?: GetTakerTierRequest) => Promise<GetTakerTierResponse | null>;
73
- takerTier: TakerTier | null;
71
+ /**
72
+ * Fetches the stake portfolio backing a taker: balances, reservation
73
+ * aggregates, delegation, and exit state.
74
+ */
75
+ declare function useGetTakerStake({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerStakeOptions): {
76
+ getTakerStake: (params?: GetTakerStakeRequest) => Promise<GetTakerStakeResponse | null>;
77
+ takerStake: TakerStake | null;
74
78
  isLoading: boolean;
75
79
  error: Error | null;
76
80
  };
77
- declare function getNextTierCap(currentTier: string | undefined): string | null;
78
- declare function getTierDisplayInfo(tier: TakerTier | undefined): {
79
- tierLabel: string;
80
- capDisplay: string;
81
- isNewUser: boolean;
82
- showScore: boolean;
81
+
82
+ interface UseGetTakerCapacityOptions {
83
+ client: Zkp2pClient | null;
84
+ owner?: string | null;
85
+ chainId?: number | null;
86
+ autoFetch?: boolean;
87
+ onSuccess?: (capacity: TakerCapacity) => void;
88
+ onError?: (error: Error) => void;
89
+ }
90
+ /**
91
+ * Fetches per-platform bonded taking capacity, free takes, and operational
92
+ * gates for a taker's shared stake portfolio. Platform capacities are
93
+ * alternative views of one shared balance — never sum them. Capacity can
94
+ * change whenever any authorized relayer uses the shared stake, so refetch
95
+ * immediately before signaling an intent; the contract stays authoritative.
96
+ */
97
+ declare function useGetTakerCapacity({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerCapacityOptions): {
98
+ getTakerCapacity: (params?: GetTakerCapacityRequest) => Promise<GetTakerCapacityResponse | null>;
99
+ takerCapacity: TakerCapacity | null;
100
+ isLoading: boolean;
101
+ error: Error | null;
83
102
  };
84
103
 
85
104
  interface UseFulfillIntentOptions {
@@ -431,4 +450,4 @@ declare function usePruneExpiredIntents({ client, onSuccess, onError }: UsePrune
431
450
  txHash: `0x${string}` | null;
432
451
  };
433
452
 
434
- export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseFulfillIntentOptions, type UseGetTakerTierOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, getNextTierCap, getTierDisplayInfo, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerTier, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
453
+ export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseFulfillIntentOptions, type UseGetTakerCapacityOptions, type UseGetTakerStakeOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerCapacity, useGetTakerStake, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a1 as SignalIntentMethodParams, bG as PreparedTransaction, bJ as TakerTier, E as GetTakerTierRequest, F as GetTakerTierResponse, a2 as FulfillIntentMethodParams, c$ as SendTransactionFn, d0 as SendBatchFn, cZ as DelegationDepositTarget, c_ as BatchResult } from './vaultUtils-aJdIIILM.js';
2
- export { cX as DelegationRoute, cY as DelegationState, d1 as VAULT_ZERO_ADDRESS, cR as ZERO_RATE_MANAGER_ID, d2 as asErrorMessage, d3 as assertDelegationMethodSupport, cW as classifyDelegationState, cV as getDelegationRoute, cS as isZeroRateManagerId, cT as normalizeRateManagerId, cU as normalizeRegistry } from './vaultUtils-aJdIIILM.js';
1
+ import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a2 as SignalIntentMethodParams, bM as PreparedTransaction, bX as TakerStake, E as GetTakerStakeRequest, F as GetTakerStakeResponse, c8 as TakerCapacity, H as GetTakerCapacityRequest, J as GetTakerCapacityResponse, a3 as FulfillIntentMethodParams, dp as SendTransactionFn, dq as SendBatchFn, dm as DelegationDepositTarget, dn as BatchResult } from './vaultUtils-DtkWNsxi.js';
2
+ export { dk as DelegationRoute, dl as DelegationState, dr as VAULT_ZERO_ADDRESS, de as ZERO_RATE_MANAGER_ID, ds as asErrorMessage, dt as assertDelegationMethodSupport, dj as classifyDelegationState, di as getDelegationRoute, df as isZeroRateManagerId, dg as normalizeRateManagerId, dh as normalizeRegistry } from './vaultUtils-DtkWNsxi.js';
3
3
  import { Hash, Address, Hex } from 'viem';
4
4
  import '@zkp2p/indexer-schema';
5
5
  import 'abitype';
@@ -60,26 +60,45 @@ declare function useSignalIntent({ client, onSuccess, onError }: UseSignalIntent
60
60
  prepared: PreparedTransaction | null;
61
61
  };
62
62
 
63
- interface UseGetTakerTierOptions {
63
+ interface UseGetTakerStakeOptions {
64
64
  client: Zkp2pClient | null;
65
65
  owner?: string | null;
66
66
  chainId?: number | null;
67
67
  autoFetch?: boolean;
68
- onSuccess?: (tier: TakerTier) => void;
68
+ onSuccess?: (stake: TakerStake) => void;
69
69
  onError?: (error: Error) => void;
70
70
  }
71
- declare function useGetTakerTier({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerTierOptions): {
72
- getTakerTier: (params?: GetTakerTierRequest) => Promise<GetTakerTierResponse | null>;
73
- takerTier: TakerTier | null;
71
+ /**
72
+ * Fetches the stake portfolio backing a taker: balances, reservation
73
+ * aggregates, delegation, and exit state.
74
+ */
75
+ declare function useGetTakerStake({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerStakeOptions): {
76
+ getTakerStake: (params?: GetTakerStakeRequest) => Promise<GetTakerStakeResponse | null>;
77
+ takerStake: TakerStake | null;
74
78
  isLoading: boolean;
75
79
  error: Error | null;
76
80
  };
77
- declare function getNextTierCap(currentTier: string | undefined): string | null;
78
- declare function getTierDisplayInfo(tier: TakerTier | undefined): {
79
- tierLabel: string;
80
- capDisplay: string;
81
- isNewUser: boolean;
82
- showScore: boolean;
81
+
82
+ interface UseGetTakerCapacityOptions {
83
+ client: Zkp2pClient | null;
84
+ owner?: string | null;
85
+ chainId?: number | null;
86
+ autoFetch?: boolean;
87
+ onSuccess?: (capacity: TakerCapacity) => void;
88
+ onError?: (error: Error) => void;
89
+ }
90
+ /**
91
+ * Fetches per-platform bonded taking capacity, free takes, and operational
92
+ * gates for a taker's shared stake portfolio. Platform capacities are
93
+ * alternative views of one shared balance — never sum them. Capacity can
94
+ * change whenever any authorized relayer uses the shared stake, so refetch
95
+ * immediately before signaling an intent; the contract stays authoritative.
96
+ */
97
+ declare function useGetTakerCapacity({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerCapacityOptions): {
98
+ getTakerCapacity: (params?: GetTakerCapacityRequest) => Promise<GetTakerCapacityResponse | null>;
99
+ takerCapacity: TakerCapacity | null;
100
+ isLoading: boolean;
101
+ error: Error | null;
83
102
  };
84
103
 
85
104
  interface UseFulfillIntentOptions {
@@ -431,4 +450,4 @@ declare function usePruneExpiredIntents({ client, onSuccess, onError }: UsePrune
431
450
  txHash: `0x${string}` | null;
432
451
  };
433
452
 
434
- export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseFulfillIntentOptions, type UseGetTakerTierOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, getNextTierCap, getTierDisplayInfo, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerTier, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
453
+ export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseFulfillIntentOptions, type UseGetTakerCapacityOptions, type UseGetTakerStakeOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerCapacity, useGetTakerStake, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
package/dist/react.mjs CHANGED
@@ -1,8 +1,7 @@
1
- import { getNextTakerTier, TAKER_TIER_CAPS, asErrorMessage, ZERO_ADDRESS, getDelegationRoute, assertDelegationMethodSupport, prepareClearDelegationTx, normalizeRateManagerId, normalizeRegistry, isZeroRateManagerId, assertAtomicDelegationSwitchSupport, prepareSetDelegationTx } from './chunk-EIOXBVXP.mjs';
2
- export { ZERO_ADDRESS as VAULT_ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-EIOXBVXP.mjs';
1
+ import { asErrorMessage, ZERO_ADDRESS, getDelegationRoute, assertDelegationMethodSupport, prepareClearDelegationTx, normalizeRateManagerId, normalizeRegistry, isZeroRateManagerId, assertAtomicDelegationSwitchSupport, prepareSetDelegationTx } from './chunk-LPJE2MN7.mjs';
2
+ export { ZERO_ADDRESS as VAULT_ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-LPJE2MN7.mjs';
3
3
  import './chunk-J5LGTIGS.mjs';
4
- import { useState, useCallback, useMemo, useEffect } from 'react';
5
- import { formatUnits } from 'viem';
4
+ import { useState, useCallback, useMemo, useRef, useEffect } from 'react';
6
5
 
7
6
  function useCreateDeposit({ client, onSuccess, onError }) {
8
7
  const [isLoading, setIsLoading] = useState(false);
@@ -106,7 +105,7 @@ function useSignalIntent({ client, onSuccess, onError }) {
106
105
  [signalIntent, prepareSignalIntent, isLoading, error, txHash, prepared]
107
106
  );
108
107
  }
109
- function useGetTakerTier({
108
+ function useGetTakerStake({
110
109
  client,
111
110
  owner,
112
111
  chainId,
@@ -116,97 +115,115 @@ function useGetTakerTier({
116
115
  }) {
117
116
  const [isLoading, setIsLoading] = useState(false);
118
117
  const [error, setError] = useState(null);
119
- const [takerTier, setTakerTier] = useState(null);
120
- const getTakerTier = useCallback(
118
+ const [takerStake, setTakerStake] = useState(null);
119
+ const onSuccessRef = useRef(onSuccess);
120
+ const onErrorRef = useRef(onError);
121
+ useEffect(() => {
122
+ onSuccessRef.current = onSuccess;
123
+ onErrorRef.current = onError;
124
+ });
125
+ const getTakerStake = useCallback(
121
126
  async (params) => {
122
127
  if (!client) {
123
128
  const err = new Error("Zkp2pClient is not initialized");
124
129
  setError(err);
125
- onError?.(err);
130
+ onErrorRef.current?.(err);
126
131
  return null;
127
132
  }
128
133
  const request = params ?? (owner && chainId ? { owner, chainId } : null);
129
134
  if (!request) {
130
135
  const err = new Error("Owner address and chainId are required");
131
136
  setError(err);
132
- onError?.(err);
137
+ onErrorRef.current?.(err);
133
138
  return null;
134
139
  }
135
140
  setIsLoading(true);
136
141
  setError(null);
137
- setTakerTier(null);
142
+ setTakerStake(null);
138
143
  try {
139
- const response = await client.getTakerTier(request);
140
- setTakerTier(response.responseObject);
141
- onSuccess?.(response.responseObject);
144
+ const response = await client.getTakerStake(request);
145
+ setTakerStake(response.responseObject);
146
+ onSuccessRef.current?.(response.responseObject);
142
147
  return response;
143
148
  } catch (err) {
144
149
  const e = err instanceof Error ? err : new Error(String(err));
145
150
  setError(e);
146
- onError?.(e);
151
+ onErrorRef.current?.(e);
147
152
  return null;
148
153
  } finally {
149
154
  setIsLoading(false);
150
155
  }
151
156
  },
152
- [client, owner, chainId, onSuccess, onError]
157
+ [client, owner, chainId]
153
158
  );
154
159
  useEffect(() => {
155
160
  if (!autoFetch || !owner || !chainId) return;
156
- void getTakerTier({ owner, chainId });
157
- }, [autoFetch, owner, chainId, getTakerTier]);
161
+ void getTakerStake({ owner, chainId });
162
+ }, [autoFetch, owner, chainId, getTakerStake]);
158
163
  return useMemo(
159
- () => ({ getTakerTier, takerTier, isLoading, error }),
160
- [getTakerTier, takerTier, isLoading, error]
164
+ () => ({ getTakerStake, takerStake, isLoading, error }),
165
+ [getTakerStake, takerStake, isLoading, error]
161
166
  );
162
167
  }
163
- function getNextTierCap(currentTier) {
164
- const nextTier = getNextTakerTier(currentTier);
165
- if (!nextTier) return null;
166
- const nextCap = TAKER_TIER_CAPS[nextTier];
167
- return nextCap != null ? `$${nextCap.toLocaleString()}` : null;
168
- }
169
- function formatCapFromBaseUnits(baseUnits) {
170
- if (!baseUnits || baseUnits === "") return "$0";
171
- const value = Number(formatUnits(BigInt(baseUnits), 6));
172
- return `$${value.toLocaleString()}`;
173
- }
174
- function getCapForDisplay(tier) {
175
- const platformLimits = tier.platformLimits ?? [];
176
- if (platformLimits.length === 0) {
177
- return tier.perIntentCapBaseUnits ?? tier.maxOrderSize;
178
- }
179
- const bestCap = platformLimits.filter((limit) => !limit.isLocked && limit.effectiveCap && limit.effectiveCap !== "0").reduce((current, limit) => {
180
- if (!current) return limit.effectiveCap;
181
- return BigInt(limit.effectiveCap) > BigInt(current) ? limit.effectiveCap : current;
182
- }, void 0);
183
- return bestCap ?? "0";
184
- }
185
- function getTierDisplayInfo(tier) {
186
- if (!tier) {
187
- return {
188
- tierLabel: "Loading...",
189
- capDisplay: "...",
190
- isNewUser: false,
191
- showScore: false
192
- };
193
- }
194
- const isNewUser = tier.source === "fallback";
195
- const isZeroFulfills = tier.stats?.lifetimeFulfilledCount === 0;
196
- const tierLabels = {
197
- PEASANT: "Peer Peasant",
198
- PEER: "Peer",
199
- PLUS: "Peer Plus",
200
- PRO: "Peer Pro",
201
- PLATINUM: "Peer Platinum"
202
- };
203
- const capDisplay = formatCapFromBaseUnits(getCapForDisplay(tier));
204
- return {
205
- tierLabel: tierLabels[tier.tier] || tier.tier,
206
- capDisplay,
207
- isNewUser: isNewUser || isZeroFulfills,
208
- showScore: !isNewUser && !!tier.stats && tier.stats.lockScoreDiluted !== "0"
209
- };
168
+ function useGetTakerCapacity({
169
+ client,
170
+ owner,
171
+ chainId,
172
+ autoFetch = true,
173
+ onSuccess,
174
+ onError
175
+ }) {
176
+ const [isLoading, setIsLoading] = useState(false);
177
+ const [error, setError] = useState(null);
178
+ const [takerCapacity, setTakerCapacity] = useState(null);
179
+ const onSuccessRef = useRef(onSuccess);
180
+ const onErrorRef = useRef(onError);
181
+ useEffect(() => {
182
+ onSuccessRef.current = onSuccess;
183
+ onErrorRef.current = onError;
184
+ });
185
+ const getTakerCapacity = useCallback(
186
+ async (params) => {
187
+ if (!client) {
188
+ const err = new Error("Zkp2pClient is not initialized");
189
+ setError(err);
190
+ onErrorRef.current?.(err);
191
+ return null;
192
+ }
193
+ const request = params ?? (owner && chainId ? { owner, chainId } : null);
194
+ if (!request) {
195
+ const err = new Error("Owner address and chainId are required");
196
+ setError(err);
197
+ onErrorRef.current?.(err);
198
+ return null;
199
+ }
200
+ setIsLoading(true);
201
+ setError(null);
202
+ setTakerCapacity(null);
203
+ try {
204
+ const response = await client.getTakerCapacity(request);
205
+ setTakerCapacity(response.responseObject);
206
+ onSuccessRef.current?.(response.responseObject);
207
+ return response;
208
+ } catch (err) {
209
+ const e = err instanceof Error ? err : new Error(String(err));
210
+ setError(e);
211
+ onErrorRef.current?.(e);
212
+ return null;
213
+ } finally {
214
+ setIsLoading(false);
215
+ }
216
+ },
217
+ [client, owner, chainId]
218
+ );
219
+ useEffect(() => {
220
+ if (!autoFetch || !owner || !chainId) return;
221
+ void getTakerCapacity({ owner, chainId });
222
+ }, [autoFetch, owner, chainId, getTakerCapacity]);
223
+ return useMemo(
224
+ () => ({ getTakerCapacity, takerCapacity, isLoading, error }),
225
+ [getTakerCapacity, takerCapacity, isLoading, error]
226
+ );
210
227
  }
211
228
  function useFulfillIntent({ client, onSuccess, onError }) {
212
229
  const [isLoading, setIsLoading] = useState(false);
@@ -1467,6 +1484,6 @@ function usePruneExpiredIntents({ client, onSuccess, onError }) {
1467
1484
  return useMemo(() => ({ pruneExpiredIntents, isLoading, error, txHash }), [pruneExpiredIntents, isLoading, error, txHash]);
1468
1485
  }
1469
1486
 
1470
- export { getNextTierCap, getTierDisplayInfo, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerTier, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
1487
+ export { useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerCapacity, useGetTakerStake, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
1471
1488
  //# sourceMappingURL=react.mjs.map
1472
1489
  //# sourceMappingURL=react.mjs.map