@agg-build/hooks 1.0.0 → 1.0.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.
@@ -0,0 +1,293 @@
1
+ import * as _agg_build_sdk from '@agg-build/sdk';
2
+ import { WsWithdrawalLifecycleStatus, WsWithdrawalLifecycleLeg, WithdrawManagedResponse, WithdrawManagedParams } from '@agg-build/sdk';
3
+ import * as _tanstack_react_query from '@tanstack/react-query';
4
+ export { U as UseDepositAddressesOptions, u as useDepositAddresses } from './use-deposit-addresses-B9ICS-3U.js';
5
+
6
+ type WithdrawSelectOption = {
7
+ value: string;
8
+ label: string;
9
+ };
10
+ type WithdrawSummary = {
11
+ /**
12
+ * The amount the user submitted for withdrawal — NOT a confirmed payout
13
+ * figure. The API today returns `pricingStatus: "unquoted"` with no fee
14
+ * or net-output guarantee, so labeling this "received" was misleading.
15
+ * The label string is "Amount" until the multi-stable quote layer ships.
16
+ */
17
+ amountReceived: string;
18
+ network: string;
19
+ toWallet: string;
20
+ fees: string;
21
+ };
22
+ interface UseWithdrawFlowResult {
23
+ open: boolean;
24
+ onOpenChange: (open: boolean) => void;
25
+ withdrawFlow: {
26
+ balance: number;
27
+ balanceDisplay: string;
28
+ amount: string;
29
+ destinationWallet: string;
30
+ tokenOptions: WithdrawSelectOption[];
31
+ networkOptions: WithdrawSelectOption[];
32
+ selectedToken: string;
33
+ selectedNetwork: string;
34
+ purchaseSummary: WithdrawSummary;
35
+ /**
36
+ * The id returned by `POST /execution/withdraw-managed` once the user
37
+ * has submitted the flow — used by the success step to subscribe to
38
+ * `withdrawal_lifecycle` WS events. `null` until submission succeeds
39
+ * and reset to `null` when the modal closes.
40
+ */
41
+ withdrawalId: string | null;
42
+ };
43
+ onWithdrawDestinationChange: (address: string) => void;
44
+ onWithdrawAmountChange: (amount: string) => void;
45
+ onWithdrawTokenChange: (token: string) => void;
46
+ onWithdrawNetworkChange: (network: string) => void;
47
+ onMaxClick: () => void;
48
+ onSelectWithdrawProvider: (providerId: string) => Promise<void>;
49
+ onDoneWithdraw: () => void;
50
+ }
51
+ interface UseWithdrawFlowOptions {
52
+ open: boolean;
53
+ onOpenChange: (open: boolean) => void;
54
+ }
55
+ declare function useWithdrawFlow(options: UseWithdrawFlowOptions): UseWithdrawFlowResult;
56
+
57
+ /**
58
+ * Latest lifecycle snapshot for a single withdrawal, materialized from the
59
+ * most recent `WsWithdrawalLifecycleEvent` whose `withdrawalId` matches.
60
+ *
61
+ * The wire format is intentionally additive (legs may arrive partial), so
62
+ * `legs` reflects the latest snapshot the server emitted — earlier per-leg
63
+ * deltas are not re-merged on the client. Consumers should treat `legs` as
64
+ * "last known truth" rather than a derived rollup.
65
+ */
66
+ interface WithdrawalLifecycleState {
67
+ /** True until the first lifecycle event for this withdrawal arrives. */
68
+ pending: boolean;
69
+ /** Top-level status, or `null` until the first event arrives. */
70
+ status: WsWithdrawalLifecycleStatus | null;
71
+ /** Whether `status` is a terminal state (`completed` / `partial` / `failed`). */
72
+ terminal: boolean;
73
+ /** Last leg delta (the leg whose flip triggered the most recent event). */
74
+ lastLeg: WsWithdrawalLifecycleLeg | null;
75
+ /** All legs at the moment of the most recent event (server snapshot). */
76
+ legs: WsWithdrawalLifecycleLeg[];
77
+ /** Failure reason for terminal `failed` / `partial`. */
78
+ errorMessage: string | null;
79
+ /** Server timestamp (ms) of the most recent event. */
80
+ timestamp: number | null;
81
+ }
82
+ interface UseWithdrawalLifecycleResult {
83
+ /** Latest lifecycle snapshot for the watched `withdrawalId`. */
84
+ state: WithdrawalLifecycleState;
85
+ /** Reset to the initial pre-event state — call when the modal is closed or a new flow starts. */
86
+ reset: () => void;
87
+ }
88
+ /**
89
+ * Subscribes to `withdrawal_lifecycle` WS events for a single `withdrawalId`
90
+ * and exposes the latest snapshot. Returns a stable `pending` initial state
91
+ * until the first matching event arrives.
92
+ *
93
+ * Pass `null` for `withdrawalId` to disable the subscription (e.g. before
94
+ * the user has submitted a withdrawal). Switching the `withdrawalId` resets
95
+ * the state so a stale snapshot from a prior withdrawal can never bleed
96
+ * across.
97
+ *
98
+ * **Backfill behavior**: on mount with a non-null `withdrawalId`, and again
99
+ * whenever the WS connection re-opens, the hook calls
100
+ * `GET /execution/withdrawals/:id` to recover any lifecycle events that fired
101
+ * before the listener was attached or while the socket was disconnected. WS
102
+ * events always win over REST snapshots (REST stamps as `timestamp: 0`), so a
103
+ * race between the two never regresses to a stale state.
104
+ */
105
+ declare function useWithdrawalLifecycle(withdrawalId: string | null): UseWithdrawalLifecycleResult;
106
+
107
+ interface UseWithdrawManagedOptions {
108
+ onSuccess?: (data: WithdrawManagedResponse) => void;
109
+ onError?: (error: Error) => void;
110
+ }
111
+ /**
112
+ * Mutation hook for withdrawing funds from managed wallets.
113
+ * On success, invalidates balances queries.
114
+ */
115
+ declare function useWithdrawManaged(options?: UseWithdrawManagedOptions): _tanstack_react_query.UseMutationResult<WithdrawManagedResponse, Error, WithdrawManagedParams, unknown>;
116
+
117
+ interface UseManagedBalancesOptions {
118
+ enabled?: boolean;
119
+ }
120
+ /**
121
+ * Query hook for fetching unified managed wallet balances across all chains.
122
+ */
123
+ declare function useManagedBalances(options?: UseManagedBalancesOptions): {
124
+ balances: _agg_build_sdk.UnifiedBalanceResponse | undefined;
125
+ data: _agg_build_sdk.UnifiedBalanceResponse;
126
+ error: Error;
127
+ isError: true;
128
+ isPending: false;
129
+ isLoading: false;
130
+ isLoadingError: false;
131
+ isRefetchError: true;
132
+ isSuccess: false;
133
+ isPlaceholderData: false;
134
+ status: "error";
135
+ dataUpdatedAt: number;
136
+ errorUpdatedAt: number;
137
+ failureCount: number;
138
+ failureReason: Error | null;
139
+ errorUpdateCount: number;
140
+ isFetched: boolean;
141
+ isFetchedAfterMount: boolean;
142
+ isFetching: boolean;
143
+ isInitialLoading: boolean;
144
+ isPaused: boolean;
145
+ isRefetching: boolean;
146
+ isStale: boolean;
147
+ isEnabled: boolean;
148
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_agg_build_sdk.UnifiedBalanceResponse, Error>>;
149
+ fetchStatus: _tanstack_react_query.FetchStatus;
150
+ promise: Promise<_agg_build_sdk.UnifiedBalanceResponse>;
151
+ } | {
152
+ balances: _agg_build_sdk.UnifiedBalanceResponse | undefined;
153
+ data: _agg_build_sdk.UnifiedBalanceResponse;
154
+ error: null;
155
+ isError: false;
156
+ isPending: false;
157
+ isLoading: false;
158
+ isLoadingError: false;
159
+ isRefetchError: false;
160
+ isSuccess: true;
161
+ isPlaceholderData: false;
162
+ status: "success";
163
+ dataUpdatedAt: number;
164
+ errorUpdatedAt: number;
165
+ failureCount: number;
166
+ failureReason: Error | null;
167
+ errorUpdateCount: number;
168
+ isFetched: boolean;
169
+ isFetchedAfterMount: boolean;
170
+ isFetching: boolean;
171
+ isInitialLoading: boolean;
172
+ isPaused: boolean;
173
+ isRefetching: boolean;
174
+ isStale: boolean;
175
+ isEnabled: boolean;
176
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_agg_build_sdk.UnifiedBalanceResponse, Error>>;
177
+ fetchStatus: _tanstack_react_query.FetchStatus;
178
+ promise: Promise<_agg_build_sdk.UnifiedBalanceResponse>;
179
+ } | {
180
+ balances: _agg_build_sdk.UnifiedBalanceResponse | undefined;
181
+ data: undefined;
182
+ error: Error;
183
+ isError: true;
184
+ isPending: false;
185
+ isLoading: false;
186
+ isLoadingError: true;
187
+ isRefetchError: false;
188
+ isSuccess: false;
189
+ isPlaceholderData: false;
190
+ status: "error";
191
+ dataUpdatedAt: number;
192
+ errorUpdatedAt: number;
193
+ failureCount: number;
194
+ failureReason: Error | null;
195
+ errorUpdateCount: number;
196
+ isFetched: boolean;
197
+ isFetchedAfterMount: boolean;
198
+ isFetching: boolean;
199
+ isInitialLoading: boolean;
200
+ isPaused: boolean;
201
+ isRefetching: boolean;
202
+ isStale: boolean;
203
+ isEnabled: boolean;
204
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_agg_build_sdk.UnifiedBalanceResponse, Error>>;
205
+ fetchStatus: _tanstack_react_query.FetchStatus;
206
+ promise: Promise<_agg_build_sdk.UnifiedBalanceResponse>;
207
+ } | {
208
+ balances: _agg_build_sdk.UnifiedBalanceResponse | undefined;
209
+ data: undefined;
210
+ error: null;
211
+ isError: false;
212
+ isPending: true;
213
+ isLoading: true;
214
+ isLoadingError: false;
215
+ isRefetchError: false;
216
+ isSuccess: false;
217
+ isPlaceholderData: false;
218
+ status: "pending";
219
+ dataUpdatedAt: number;
220
+ errorUpdatedAt: number;
221
+ failureCount: number;
222
+ failureReason: Error | null;
223
+ errorUpdateCount: number;
224
+ isFetched: boolean;
225
+ isFetchedAfterMount: boolean;
226
+ isFetching: boolean;
227
+ isInitialLoading: boolean;
228
+ isPaused: boolean;
229
+ isRefetching: boolean;
230
+ isStale: boolean;
231
+ isEnabled: boolean;
232
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_agg_build_sdk.UnifiedBalanceResponse, Error>>;
233
+ fetchStatus: _tanstack_react_query.FetchStatus;
234
+ promise: Promise<_agg_build_sdk.UnifiedBalanceResponse>;
235
+ } | {
236
+ balances: _agg_build_sdk.UnifiedBalanceResponse | undefined;
237
+ data: undefined;
238
+ error: null;
239
+ isError: false;
240
+ isPending: true;
241
+ isLoadingError: false;
242
+ isRefetchError: false;
243
+ isSuccess: false;
244
+ isPlaceholderData: false;
245
+ status: "pending";
246
+ dataUpdatedAt: number;
247
+ errorUpdatedAt: number;
248
+ failureCount: number;
249
+ failureReason: Error | null;
250
+ errorUpdateCount: number;
251
+ isFetched: boolean;
252
+ isFetchedAfterMount: boolean;
253
+ isFetching: boolean;
254
+ isLoading: boolean;
255
+ isInitialLoading: boolean;
256
+ isPaused: boolean;
257
+ isRefetching: boolean;
258
+ isStale: boolean;
259
+ isEnabled: boolean;
260
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_agg_build_sdk.UnifiedBalanceResponse, Error>>;
261
+ fetchStatus: _tanstack_react_query.FetchStatus;
262
+ promise: Promise<_agg_build_sdk.UnifiedBalanceResponse>;
263
+ } | {
264
+ balances: _agg_build_sdk.UnifiedBalanceResponse | undefined;
265
+ data: _agg_build_sdk.UnifiedBalanceResponse;
266
+ isError: false;
267
+ error: null;
268
+ isPending: false;
269
+ isLoading: false;
270
+ isLoadingError: false;
271
+ isRefetchError: false;
272
+ isSuccess: true;
273
+ isPlaceholderData: true;
274
+ status: "success";
275
+ dataUpdatedAt: number;
276
+ errorUpdatedAt: number;
277
+ failureCount: number;
278
+ failureReason: Error | null;
279
+ errorUpdateCount: number;
280
+ isFetched: boolean;
281
+ isFetchedAfterMount: boolean;
282
+ isFetching: boolean;
283
+ isInitialLoading: boolean;
284
+ isPaused: boolean;
285
+ isRefetching: boolean;
286
+ isStale: boolean;
287
+ isEnabled: boolean;
288
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<_agg_build_sdk.UnifiedBalanceResponse, Error>>;
289
+ fetchStatus: _tanstack_react_query.FetchStatus;
290
+ promise: Promise<_agg_build_sdk.UnifiedBalanceResponse>;
291
+ };
292
+
293
+ export { type UseManagedBalancesOptions, type UseWithdrawFlowOptions, type UseWithdrawFlowResult, type UseWithdrawManagedOptions, type UseWithdrawalLifecycleResult, type WithdrawalLifecycleState, useManagedBalances, useWithdrawFlow, useWithdrawManaged, useWithdrawalLifecycle };