@agg-build/hooks 1.0.2 → 1.2.11
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/README.md +1 -1
- package/dist/{chunk-V6VNA7MX.mjs → chunk-553OI6M2.mjs} +565 -89
- package/dist/{chunk-NOYHQUW2.mjs → chunk-CWEJLBYY.mjs} +66 -11
- package/dist/{chunk-EB64HHYM.mjs → chunk-JWPZNCGY.mjs} +1 -1
- package/dist/deposit.d.mts +8 -2
- package/dist/deposit.d.ts +8 -2
- package/dist/deposit.js +215 -76
- package/dist/deposit.mjs +119 -66
- package/dist/index.d.mts +712 -42
- package/dist/index.d.ts +712 -42
- package/dist/index.js +1405 -357
- package/dist/index.mjs +681 -163
- package/dist/{use-sync-balances-B1_8tBKw.d.ts → use-sync-balances-CeD8qZWP.d.mts} +5 -2
- package/dist/{use-sync-balances-B1_8tBKw.d.mts → use-sync-balances-CeD8qZWP.d.ts} +5 -2
- package/dist/withdraw.d.mts +27 -3
- package/dist/withdraw.d.ts +27 -3
- package/dist/withdraw.js +178 -26
- package/dist/withdraw.mjs +4 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__async,
|
|
3
|
-
|
|
3
|
+
invalidateUserMoneyState,
|
|
4
4
|
useAggBalanceState,
|
|
5
5
|
useAggClient,
|
|
6
6
|
useAggWebSocket,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
useOnWithdrawalLifecycle,
|
|
11
11
|
useSyncBalances,
|
|
12
12
|
useWithdrawManaged
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-553OI6M2.mjs";
|
|
14
14
|
|
|
15
15
|
// src/withdraw/use-withdraw-flow.ts
|
|
16
16
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
@@ -28,7 +28,9 @@ var WITHDRAWAL_SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([
|
|
|
28
28
|
// Base
|
|
29
29
|
56,
|
|
30
30
|
// BNB
|
|
31
|
-
SOLANA_CHAIN_ID
|
|
31
|
+
SOLANA_CHAIN_ID,
|
|
32
|
+
1337
|
|
33
|
+
// Hyperliquid
|
|
32
34
|
]);
|
|
33
35
|
var isValidDestinationAddress = (address, chainId) => {
|
|
34
36
|
if (chainId === SOLANA_CHAIN_ID) return SOLANA_ADDRESS_REGEX.test(address);
|
|
@@ -265,12 +267,60 @@ function useWithdrawFlow(options) {
|
|
|
265
267
|
};
|
|
266
268
|
}
|
|
267
269
|
|
|
270
|
+
// src/withdraw/use-withdraw-estimate.ts
|
|
271
|
+
import { useMemo as useMemo2 } from "react";
|
|
272
|
+
function useWithdrawEstimate({
|
|
273
|
+
amount,
|
|
274
|
+
selectedToken,
|
|
275
|
+
selectedNetwork
|
|
276
|
+
}) {
|
|
277
|
+
return useMemo2(() => {
|
|
278
|
+
const numAmount = Number(amount);
|
|
279
|
+
if (!amount || isNaN(numAmount) || numAmount <= 0 || !selectedToken || !selectedNetwork) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const network = selectedNetwork.toLowerCase();
|
|
283
|
+
let feeVal = 0.1;
|
|
284
|
+
let reserveVal = 0.2;
|
|
285
|
+
if (network === "1" || network === "mainnet" || network === "ethereum") {
|
|
286
|
+
feeVal = 1.22;
|
|
287
|
+
reserveVal = 0.3;
|
|
288
|
+
} else if (network === "137" || network === "polygon") {
|
|
289
|
+
feeVal = 0.05;
|
|
290
|
+
reserveVal = 0.15;
|
|
291
|
+
} else if (network === "42161" || network === "arbitrum") {
|
|
292
|
+
feeVal = 0.05;
|
|
293
|
+
reserveVal = 0.15;
|
|
294
|
+
} else if (network === "8453" || network === "base") {
|
|
295
|
+
feeVal = 0.05;
|
|
296
|
+
reserveVal = 0.15;
|
|
297
|
+
} else if (network === "56" || network === "bnb" || network === "bsc") {
|
|
298
|
+
feeVal = 0.1;
|
|
299
|
+
reserveVal = 0.2;
|
|
300
|
+
} else if (network === "792703809" || network === "solana") {
|
|
301
|
+
feeVal = 0.01;
|
|
302
|
+
reserveVal = 0.04;
|
|
303
|
+
} else if (network === "1337" || network === "hyperliquid") {
|
|
304
|
+
feeVal = 0.02;
|
|
305
|
+
reserveVal = 0.08;
|
|
306
|
+
}
|
|
307
|
+
const youReceiveVal = Math.max(0, numAmount - feeVal);
|
|
308
|
+
return {
|
|
309
|
+
estimatedFees: `~$${feeVal.toFixed(2)}`,
|
|
310
|
+
networkReserve: `~$${reserveVal.toFixed(2)}`,
|
|
311
|
+
youReceive: `~${youReceiveVal.toFixed(2)} ${selectedToken}`
|
|
312
|
+
};
|
|
313
|
+
}, [amount, selectedToken, selectedNetwork]);
|
|
314
|
+
}
|
|
315
|
+
|
|
268
316
|
// src/withdraw/use-withdrawal-lifecycle.ts
|
|
269
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as
|
|
317
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo3, useRef, useState as useState2 } from "react";
|
|
270
318
|
import { useQueryClient } from "@tanstack/react-query";
|
|
271
319
|
var INITIAL_STATE = {
|
|
272
320
|
pending: true,
|
|
273
321
|
status: null,
|
|
322
|
+
requestedAmountRaw: null,
|
|
323
|
+
completedAmountRaw: null,
|
|
274
324
|
terminal: false,
|
|
275
325
|
lastLeg: null,
|
|
276
326
|
legs: [],
|
|
@@ -301,14 +351,16 @@ var mergeLegs = (prev, snapshot, delta) => {
|
|
|
301
351
|
return next;
|
|
302
352
|
};
|
|
303
353
|
var restToLifecycleState = (response) => {
|
|
304
|
-
var _a;
|
|
354
|
+
var _a, _b;
|
|
305
355
|
return {
|
|
306
356
|
pending: false,
|
|
307
357
|
status: response.status,
|
|
358
|
+
requestedAmountRaw: response.requested.amountRaw,
|
|
359
|
+
completedAmountRaw: (_a = response.completedAmountRaw) != null ? _a : null,
|
|
308
360
|
terminal: response.status === "completed" || response.status === "partial" || response.status === "failed",
|
|
309
361
|
lastLeg: null,
|
|
310
362
|
legs: response.legs.map(restLegToWsLeg),
|
|
311
|
-
errorMessage: (
|
|
363
|
+
errorMessage: (_b = response.errorMessage) != null ? _b : null,
|
|
312
364
|
// No server timestamp on the REST response — we use 0 as "older than any
|
|
313
365
|
// WS timestamp" so a subsequent WS event always wins. Callers that read
|
|
314
366
|
// `timestamp` should treat 0/null interchangeably as "unset".
|
|
@@ -345,17 +397,19 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
345
397
|
cancelled = true;
|
|
346
398
|
};
|
|
347
399
|
}, [client, withdrawalId, wsConnected]);
|
|
348
|
-
const handler =
|
|
400
|
+
const handler = useMemo3(() => {
|
|
349
401
|
if (!withdrawalId) return null;
|
|
350
402
|
return (msg) => {
|
|
351
403
|
if (msg.withdrawalId !== withdrawalId) return;
|
|
352
404
|
setState((prev) => {
|
|
353
|
-
var _a, _b;
|
|
405
|
+
var _a, _b, _c, _d;
|
|
354
406
|
return {
|
|
355
407
|
pending: false,
|
|
356
408
|
status: msg.status,
|
|
409
|
+
requestedAmountRaw: (_a = msg.requestedAmountRaw) != null ? _a : prev.requestedAmountRaw,
|
|
410
|
+
completedAmountRaw: (_b = msg.completedAmountRaw) != null ? _b : prev.completedAmountRaw,
|
|
357
411
|
terminal: msg.terminal,
|
|
358
|
-
lastLeg: (
|
|
412
|
+
lastLeg: (_c = msg.leg) != null ? _c : null,
|
|
359
413
|
// `legs[]` is the cumulative server-known truth. Snapshots
|
|
360
414
|
// (`pending` / terminal rollup) carry a full `legs[]` and replace
|
|
361
415
|
// it. Intermediate per-leg deltas carry only `leg` (no `legs[]`)
|
|
@@ -363,7 +417,7 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
363
417
|
// (sourceChainId, destChainId, type) so the timeline UI doesn't
|
|
364
418
|
// collapse to empty between snapshots.
|
|
365
419
|
legs: mergeLegs(prev.legs, msg.legs, msg.leg),
|
|
366
|
-
errorMessage: (
|
|
420
|
+
errorMessage: (_d = msg.errorMessage) != null ? _d : null,
|
|
367
421
|
timestamp: msg.timestamp
|
|
368
422
|
};
|
|
369
423
|
});
|
|
@@ -375,7 +429,7 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
375
429
|
if (!state.terminal) return;
|
|
376
430
|
if (balanceRefetchedForRef.current === withdrawalId) return;
|
|
377
431
|
balanceRefetchedForRef.current = withdrawalId;
|
|
378
|
-
|
|
432
|
+
invalidateUserMoneyState(queryClient);
|
|
379
433
|
client.syncManagedBalances().catch(() => {
|
|
380
434
|
});
|
|
381
435
|
}, [client, queryClient, state.terminal, withdrawalId]);
|
|
@@ -385,5 +439,6 @@ function useWithdrawalLifecycle(withdrawalId) {
|
|
|
385
439
|
|
|
386
440
|
export {
|
|
387
441
|
useWithdrawFlow,
|
|
442
|
+
useWithdrawEstimate,
|
|
388
443
|
useWithdrawalLifecycle
|
|
389
444
|
};
|
package/dist/deposit.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { U as UseDepositAddressesOptions, u as useDepositAddresses } from './use-deposit-addresses-B9ICS-3U.mjs';
|
|
2
|
-
export { U as UseSyncBalancesOptions, u as useSyncBalances } from './use-sync-balances-
|
|
2
|
+
export { U as UseSyncBalancesOptions, u as useSyncBalances } from './use-sync-balances-CeD8qZWP.mjs';
|
|
3
3
|
import '@tanstack/react-query';
|
|
4
4
|
import '@agg-build/sdk';
|
|
5
5
|
|
|
@@ -121,6 +121,13 @@ interface UseDepositFlowResult {
|
|
|
121
121
|
onWalletAmountChange: (amount: string) => void;
|
|
122
122
|
onWalletMax: () => void;
|
|
123
123
|
onConfirmWalletDeposit: (params: WalletDepositConfirmParams) => Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Clears any in-flight wallet-transaction state so the deposit modal can
|
|
126
|
+
* return the user to the wallet form. Called from the processing step's
|
|
127
|
+
* Cancel affordance when a wallet popup was dismissed silently or a
|
|
128
|
+
* broadcast tx was canceled/replaced without a clean error.
|
|
129
|
+
*/
|
|
130
|
+
onCancelWalletDeposit: () => void;
|
|
124
131
|
onWalletNetworkChange: (chainId: string) => void;
|
|
125
132
|
onWalletTokenChange: (tokenSymbol: string) => void;
|
|
126
133
|
initialWalletChainId: string | undefined;
|
|
@@ -130,7 +137,6 @@ interface UseDepositFlowResult {
|
|
|
130
137
|
connectedWalletKind?: "evm" | "solana";
|
|
131
138
|
sendCryptoConfig: {
|
|
132
139
|
minDeposit: string;
|
|
133
|
-
feeEstimate: string;
|
|
134
140
|
eta: string;
|
|
135
141
|
};
|
|
136
142
|
onDoneSendCrypto: () => void;
|
package/dist/deposit.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { U as UseDepositAddressesOptions, u as useDepositAddresses } from './use-deposit-addresses-B9ICS-3U.js';
|
|
2
|
-
export { U as UseSyncBalancesOptions, u as useSyncBalances } from './use-sync-balances-
|
|
2
|
+
export { U as UseSyncBalancesOptions, u as useSyncBalances } from './use-sync-balances-CeD8qZWP.js';
|
|
3
3
|
import '@tanstack/react-query';
|
|
4
4
|
import '@agg-build/sdk';
|
|
5
5
|
|
|
@@ -121,6 +121,13 @@ interface UseDepositFlowResult {
|
|
|
121
121
|
onWalletAmountChange: (amount: string) => void;
|
|
122
122
|
onWalletMax: () => void;
|
|
123
123
|
onConfirmWalletDeposit: (params: WalletDepositConfirmParams) => Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Clears any in-flight wallet-transaction state so the deposit modal can
|
|
126
|
+
* return the user to the wallet form. Called from the processing step's
|
|
127
|
+
* Cancel affordance when a wallet popup was dismissed silently or a
|
|
128
|
+
* broadcast tx was canceled/replaced without a clean error.
|
|
129
|
+
*/
|
|
130
|
+
onCancelWalletDeposit: () => void;
|
|
124
131
|
onWalletNetworkChange: (chainId: string) => void;
|
|
125
132
|
onWalletTokenChange: (tokenSymbol: string) => void;
|
|
126
133
|
initialWalletChainId: string | undefined;
|
|
@@ -130,7 +137,6 @@ interface UseDepositFlowResult {
|
|
|
130
137
|
connectedWalletKind?: "evm" | "solana";
|
|
131
138
|
sendCryptoConfig: {
|
|
132
139
|
minDeposit: string;
|
|
133
|
-
feeEstimate: string;
|
|
134
140
|
eta: string;
|
|
135
141
|
};
|
|
136
142
|
onDoneSendCrypto: () => void;
|