@orderly.network/ui-transfer 3.1.8 → 3.1.9-alpha.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/index.js +73 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -17
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i18n, useTranslation, Trans } from '@orderly.network/i18n';
|
|
2
|
-
import { registerSimpleDialog, registerSimpleSheet, Tabs, TabPanel, ArrowDownSquareFillIcon, ArrowUpSquareFillIcon, ExtensionSlot, ExtensionPositionEnum, toast, Box,
|
|
2
|
+
import { registerSimpleDialog, registerSimpleSheet, Tabs, TabPanel, ArrowDownSquareFillIcon, ArrowUpSquareFillIcon, ExtensionSlot, ExtensionPositionEnum, toast, Box, Flex, textVariants, Text, cn, Button, useDocumentDirection, Spinner, Select, Input, inputFormatter, useScreen, modal, Tooltip, Tips, AlertDialog, EditIcon, ArrowLeftRightIcon, WalletIcon, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuContent, ScrollArea, ChainIcon, Badge, CaretUpIcon, CaretDownIcon, SimpleDialog, CloseRoundFillIcon, ExclamationFillIcon, TokenIcon, WarningIcon, SelectItem, ChevronRightIcon, Checkbox, CloseIcon } from '@orderly.network/ui';
|
|
3
3
|
import { forwardRef, useState, isValidElement, useMemo, useEffect, useCallback, useRef } from 'react';
|
|
4
4
|
import { useConfig, useWalletConnector, useLocalStorage, useConvert, useSwapQuote as useSwapQuote$1, useComputedLTV, useAccount, useAppStore, useTransfer, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useMainTokenStore, useEventEmitter, usePositionStream, useIndexPricesStream, useOrderlyContext, useDeposit, useAssetsHistory, useChains, useMemoizedFn, useWithdraw, useWalletTopic, useQuery, useSWR, useTokenInfo, useTokensInfo, useHoldingStream, useInternalTransfer, useDebouncedCallback, usePrivateQuery, useTransferHistory, useBalanceTopic } from '@orderly.network/hooks';
|
|
5
5
|
import { Decimal, zero, praseChainIdToNumber, int2hex, toNonExponential, formatWithPrecision, isSolana } from '@orderly.network/utils';
|
|
@@ -2393,11 +2393,16 @@ function useDepositAction(options2) {
|
|
|
2393
2393
|
const { quantity, approve, deposit, swapDeposit, onSuccess, needSwap } = options2;
|
|
2394
2394
|
const [isMutating, setIsMutating] = useState(false);
|
|
2395
2395
|
const [depositError, setDepositError] = useState("");
|
|
2396
|
+
const mutationLock = useRef(false);
|
|
2396
2397
|
const ee = useEventEmitter();
|
|
2397
2398
|
const { t } = useTranslation();
|
|
2398
|
-
const
|
|
2399
|
+
const runDeposit = useCallback(async () => {
|
|
2399
2400
|
try {
|
|
2400
|
-
|
|
2401
|
+
if (needSwap) {
|
|
2402
|
+
await swapDeposit?.();
|
|
2403
|
+
} else {
|
|
2404
|
+
await deposit();
|
|
2405
|
+
}
|
|
2401
2406
|
setDepositError("");
|
|
2402
2407
|
} catch (err) {
|
|
2403
2408
|
console.error("orderly deposit error", err);
|
|
@@ -2420,57 +2425,94 @@ function useDepositAction(options2) {
|
|
|
2420
2425
|
}
|
|
2421
2426
|
throw err;
|
|
2422
2427
|
}
|
|
2423
|
-
}, [deposit,
|
|
2424
|
-
const
|
|
2428
|
+
}, [deposit, needSwap, swapDeposit, t]);
|
|
2429
|
+
const runApprove = useCallback(async () => {
|
|
2430
|
+
try {
|
|
2431
|
+
await approve(quantity);
|
|
2432
|
+
toast.success(t("transfer.deposit.approve.success"));
|
|
2433
|
+
} catch (err) {
|
|
2434
|
+
console.error("approve error", err);
|
|
2435
|
+
toast.error(
|
|
2436
|
+
err.message || err?.errorCode || t("transfer.deposit.approve.failed")
|
|
2437
|
+
);
|
|
2438
|
+
throw err;
|
|
2439
|
+
}
|
|
2440
|
+
}, [approve, quantity, t]);
|
|
2441
|
+
const isValidQuantity = useCallback(() => {
|
|
2425
2442
|
const num = Number(quantity);
|
|
2426
2443
|
if (isNaN(num) || num <= 0) {
|
|
2427
2444
|
toast.error(t("transfer.quantity.invalid"));
|
|
2428
|
-
return;
|
|
2445
|
+
return false;
|
|
2446
|
+
}
|
|
2447
|
+
return true;
|
|
2448
|
+
}, [quantity, t]);
|
|
2449
|
+
const startMutation = useCallback(() => {
|
|
2450
|
+
if (mutationLock.current) {
|
|
2451
|
+
return false;
|
|
2429
2452
|
}
|
|
2430
|
-
|
|
2453
|
+
mutationLock.current = true;
|
|
2431
2454
|
setIsMutating(true);
|
|
2455
|
+
return true;
|
|
2456
|
+
}, []);
|
|
2457
|
+
const finishMutation = useCallback(() => {
|
|
2458
|
+
mutationLock.current = false;
|
|
2459
|
+
setIsMutating(false);
|
|
2460
|
+
}, []);
|
|
2461
|
+
const onDeposit = useCallback(async () => {
|
|
2462
|
+
if (mutationLock.current) return;
|
|
2463
|
+
if (!isValidQuantity() || !startMutation()) {
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2432
2466
|
try {
|
|
2433
|
-
|
|
2434
|
-
await swapDeposit?.();
|
|
2435
|
-
} else {
|
|
2436
|
-
await doDeposit();
|
|
2437
|
-
}
|
|
2467
|
+
await runDeposit();
|
|
2438
2468
|
toast.success(t("transfer.deposit.requested"));
|
|
2439
2469
|
ee.emit("deposit:requested");
|
|
2440
2470
|
onSuccess?.();
|
|
2441
2471
|
} catch (err) {
|
|
2442
2472
|
} finally {
|
|
2443
|
-
|
|
2473
|
+
finishMutation();
|
|
2444
2474
|
}
|
|
2445
|
-
}, [
|
|
2475
|
+
}, [
|
|
2476
|
+
ee,
|
|
2477
|
+
finishMutation,
|
|
2478
|
+
isValidQuantity,
|
|
2479
|
+
onSuccess,
|
|
2480
|
+
runDeposit,
|
|
2481
|
+
startMutation,
|
|
2482
|
+
t
|
|
2483
|
+
]);
|
|
2446
2484
|
const onApprove = useCallback(async () => {
|
|
2447
|
-
if (
|
|
2448
|
-
setIsMutating(true);
|
|
2485
|
+
if (!startMutation()) return;
|
|
2449
2486
|
try {
|
|
2450
|
-
await
|
|
2451
|
-
toast.success(t("transfer.deposit.approve.success"));
|
|
2452
|
-
} catch (err) {
|
|
2453
|
-
console.error("approve error", err);
|
|
2454
|
-
toast.error(
|
|
2455
|
-
err.message || err?.errorCode || t("transfer.deposit.approve.failed")
|
|
2456
|
-
);
|
|
2457
|
-
throw err;
|
|
2487
|
+
await runApprove();
|
|
2458
2488
|
} finally {
|
|
2459
|
-
|
|
2489
|
+
finishMutation();
|
|
2460
2490
|
}
|
|
2461
|
-
}, [
|
|
2491
|
+
}, [finishMutation, runApprove, startMutation]);
|
|
2462
2492
|
const onApproveAndDeposit = useCallback(async () => {
|
|
2463
|
-
if (
|
|
2464
|
-
|
|
2493
|
+
if (mutationLock.current) return;
|
|
2494
|
+
if (!isValidQuantity() || !startMutation()) return;
|
|
2465
2495
|
try {
|
|
2466
|
-
await
|
|
2467
|
-
await
|
|
2496
|
+
await runApprove();
|
|
2497
|
+
await runDeposit();
|
|
2498
|
+
toast.success(t("transfer.deposit.requested"));
|
|
2499
|
+
ee.emit("deposit:requested");
|
|
2500
|
+
onSuccess?.();
|
|
2468
2501
|
} catch (err) {
|
|
2469
2502
|
console.error("approve and deposit error", err);
|
|
2470
2503
|
} finally {
|
|
2471
|
-
|
|
2504
|
+
finishMutation();
|
|
2472
2505
|
}
|
|
2473
|
-
}, [
|
|
2506
|
+
}, [
|
|
2507
|
+
ee,
|
|
2508
|
+
finishMutation,
|
|
2509
|
+
isValidQuantity,
|
|
2510
|
+
onSuccess,
|
|
2511
|
+
runApprove,
|
|
2512
|
+
runDeposit,
|
|
2513
|
+
startMutation,
|
|
2514
|
+
t
|
|
2515
|
+
]);
|
|
2474
2516
|
return {
|
|
2475
2517
|
isMutating,
|
|
2476
2518
|
depositError,
|