@zkp2p/sdk 0.9.0 → 0.10.0-rc.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/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, dw as SendTransactionFn, dx as SendBatchFn, du as DelegationDepositTarget, dv as BatchResult } from './vaultUtils-CxUP_m-J.mjs';
2
+ export { ds as DelegationRoute, dt as DelegationState, dy as VAULT_ZERO_ADDRESS, dl as ZERO_RATE_MANAGER_ID, dz as asErrorMessage, dA as assertDelegationMethodSupport, dr as classifyDelegationState, dq as getDelegationRoute, dm as isZeroRateManagerId, dn as normalizeRateManagerId, dp as normalizeRegistry } from './vaultUtils-CxUP_m-J.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, dw as SendTransactionFn, dx as SendBatchFn, du as DelegationDepositTarget, dv as BatchResult } from './vaultUtils-CxUP_m-J.js';
2
+ export { ds as DelegationRoute, dt as DelegationState, dy as VAULT_ZERO_ADDRESS, dl as ZERO_RATE_MANAGER_ID, dz as asErrorMessage, dA as assertDelegationMethodSupport, dr as classifyDelegationState, dq as getDelegationRoute, dm as isZeroRateManagerId, dn as normalizeRateManagerId, dp as normalizeRegistry } from './vaultUtils-CxUP_m-J.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,129 @@ 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 requestSeqRef = useRef(0);
126
+ const getTakerStake = useCallback(
121
127
  async (params) => {
122
128
  if (!client) {
123
129
  const err = new Error("Zkp2pClient is not initialized");
124
130
  setError(err);
125
- onError?.(err);
131
+ onErrorRef.current?.(err);
126
132
  return null;
127
133
  }
128
134
  const request = params ?? (owner && chainId ? { owner, chainId } : null);
129
135
  if (!request) {
130
136
  const err = new Error("Owner address and chainId are required");
131
137
  setError(err);
132
- onError?.(err);
138
+ onErrorRef.current?.(err);
133
139
  return null;
134
140
  }
141
+ const requestId = ++requestSeqRef.current;
135
142
  setIsLoading(true);
136
143
  setError(null);
137
- setTakerTier(null);
144
+ setTakerStake(null);
138
145
  try {
139
- const response = await client.getTakerTier(request);
140
- setTakerTier(response.responseObject);
141
- onSuccess?.(response.responseObject);
146
+ const response = await client.getTakerStake(request);
147
+ if (requestId !== requestSeqRef.current) return null;
148
+ if (!response.success || !response.responseObject) {
149
+ throw new Error(response.message || "Taker stake request failed");
150
+ }
151
+ setTakerStake(response.responseObject);
152
+ onSuccessRef.current?.(response.responseObject);
142
153
  return response;
143
154
  } catch (err) {
155
+ if (requestId !== requestSeqRef.current) return null;
144
156
  const e = err instanceof Error ? err : new Error(String(err));
145
157
  setError(e);
146
- onError?.(e);
158
+ onErrorRef.current?.(e);
147
159
  return null;
148
160
  } finally {
149
- setIsLoading(false);
161
+ if (requestId === requestSeqRef.current) setIsLoading(false);
150
162
  }
151
163
  },
152
- [client, owner, chainId, onSuccess, onError]
164
+ [client, owner, chainId]
153
165
  );
154
166
  useEffect(() => {
155
167
  if (!autoFetch || !owner || !chainId) return;
156
- void getTakerTier({ owner, chainId });
157
- }, [autoFetch, owner, chainId, getTakerTier]);
168
+ void getTakerStake({ owner, chainId });
169
+ }, [autoFetch, owner, chainId, getTakerStake]);
158
170
  return useMemo(
159
- () => ({ getTakerTier, takerTier, isLoading, error }),
160
- [getTakerTier, takerTier, isLoading, error]
171
+ () => ({ getTakerStake, takerStake, isLoading, error }),
172
+ [getTakerStake, takerStake, isLoading, error]
161
173
  );
162
174
  }
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
- };
175
+ function useGetTakerCapacity({
176
+ client,
177
+ owner,
178
+ chainId,
179
+ autoFetch = true,
180
+ onSuccess,
181
+ onError
182
+ }) {
183
+ const [isLoading, setIsLoading] = useState(false);
184
+ const [error, setError] = useState(null);
185
+ const [takerCapacity, setTakerCapacity] = useState(null);
186
+ const onSuccessRef = useRef(onSuccess);
187
+ const onErrorRef = useRef(onError);
188
+ useEffect(() => {
189
+ onSuccessRef.current = onSuccess;
190
+ onErrorRef.current = onError;
191
+ });
192
+ const requestSeqRef = useRef(0);
193
+ const getTakerCapacity = useCallback(
194
+ async (params) => {
195
+ if (!client) {
196
+ const err = new Error("Zkp2pClient is not initialized");
197
+ setError(err);
198
+ onErrorRef.current?.(err);
199
+ return null;
200
+ }
201
+ const request = params ?? (owner && chainId ? { owner, chainId } : null);
202
+ if (!request) {
203
+ const err = new Error("Owner address and chainId are required");
204
+ setError(err);
205
+ onErrorRef.current?.(err);
206
+ return null;
207
+ }
208
+ const requestId = ++requestSeqRef.current;
209
+ setIsLoading(true);
210
+ setError(null);
211
+ setTakerCapacity(null);
212
+ try {
213
+ const response = await client.getTakerCapacity(request);
214
+ if (requestId !== requestSeqRef.current) return null;
215
+ if (!response.success || !response.responseObject) {
216
+ throw new Error(response.message || "Taker capacity request failed");
217
+ }
218
+ setTakerCapacity(response.responseObject);
219
+ onSuccessRef.current?.(response.responseObject);
220
+ return response;
221
+ } catch (err) {
222
+ if (requestId !== requestSeqRef.current) return null;
223
+ const e = err instanceof Error ? err : new Error(String(err));
224
+ setError(e);
225
+ onErrorRef.current?.(e);
226
+ return null;
227
+ } finally {
228
+ if (requestId === requestSeqRef.current) setIsLoading(false);
229
+ }
230
+ },
231
+ [client, owner, chainId]
232
+ );
233
+ useEffect(() => {
234
+ if (!autoFetch || !owner || !chainId) return;
235
+ void getTakerCapacity({ owner, chainId });
236
+ }, [autoFetch, owner, chainId, getTakerCapacity]);
237
+ return useMemo(
238
+ () => ({ getTakerCapacity, takerCapacity, isLoading, error }),
239
+ [getTakerCapacity, takerCapacity, isLoading, error]
240
+ );
210
241
  }
211
242
  function useFulfillIntent({ client, onSuccess, onError }) {
212
243
  const [isLoading, setIsLoading] = useState(false);
@@ -1467,6 +1498,6 @@ function usePruneExpiredIntents({ client, onSuccess, onError }) {
1467
1498
  return useMemo(() => ({ pruneExpiredIntents, isLoading, error, txHash }), [pruneExpiredIntents, isLoading, error, txHash]);
1468
1499
  }
1469
1500
 
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 };
1501
+ 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
1502
  //# sourceMappingURL=react.mjs.map
1472
1503
  //# sourceMappingURL=react.mjs.map