@orderly.network/ui-transfer 2.12.4 → 3.0.0-alpha.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/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i18n, useTranslation, Trans } from '@orderly.network/i18n';
2
- import { registerSimpleDialog, registerSimpleSheet, Tabs, TabPanel, ArrowDownSquareFillIcon, ArrowUpSquareFillIcon, ExtensionSlot, ExtensionPositionEnum, Box, textVariants, Flex, toast, Text, cn, Button, Spinner, Select, Input, inputFormatter, useScreen, modal, Tooltip, Tips, AlertDialog, EditIcon, ArrowLeftRightIcon, WalletIcon, DropdownMenuRoot, DropdownMenuTrigger, DropdownMenuPortal, DropdownMenuContent, ScrollArea, ChainIcon, Badge, TokenIcon, CaretUpIcon, CaretDownIcon, SimpleDialog, CloseRoundFillIcon, ExclamationFillIcon, WarningIcon, SelectItem, ChevronRightIcon, Checkbox, CloseIcon } from '@orderly.network/ui';
3
- import { forwardRef, useState, useMemo, useEffect, useCallback, useRef } from 'react';
2
+ import { registerSimpleDialog, registerSimpleSheet, Tabs, TabPanel, ArrowDownSquareFillIcon, ArrowUpSquareFillIcon, ExtensionSlot, ExtensionPositionEnum, Box, textVariants, Flex, toast, Text, cn, Button, 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
+ import { forwardRef, useState, isValidElement, useMemo, useEffect, useCallback, useRef } from 'react';
4
4
  import { useConfig, useWalletConnector, useLocalStorage, useConvert, useOdosQuote, useComputedLTV, useAccount, useAppStore, useTransfer, useSubAccountDataObserver, useSubAccountMaxWithdrawal, useTokensInfo, useEventEmitter, usePositionStream, useIndexPricesStream, useOrderlyContext, useDeposit, useAssetsHistory, useChains, useMemoizedFn, useWithdraw, useWalletTopic, useQuery, useSWR, useTokenInfo, useHoldingStream, useInternalTransfer, useDebouncedCallback, usePrivateQuery, useTransferHistory, useBalanceTopic } from '@orderly.network/hooks';
5
5
  import { Decimal, zero, praseChainIdToNumber, int2hex, toNonExponential, formatWithPrecision, isSolana } from '@orderly.network/utils';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
@@ -13,6 +13,7 @@ import { utils } from '@orderly.network/core';
13
13
  import { ChainSelectorDialogId } from '@orderly.network/ui-chain-selector';
14
14
  import { PublicKey } from '@solana/web3.js';
15
15
  import { ethers } from 'ethers';
16
+ import { injectable } from '@orderly.network/plugin-core';
16
17
  import { DefaultSolanaWalletAdapter } from '@orderly.network/default-solana-adapter';
17
18
 
18
19
  // src/components/depositForm/depositForm.ui.tsx
@@ -802,10 +803,10 @@ var buildExplorerUrl = (baseUrl, txId) => {
802
803
  var useExclusiveDeposit = (options2) => {
803
804
  const active = options2.active ?? true;
804
805
  const confirmed = options2.confirmed ?? true;
805
- const { chainId, explorerBaseUrl } = options2;
806
+ const { chainId, token, explorerBaseUrl } = options2;
806
807
  const { t: t0 } = useTranslation();
807
808
  const t = t0;
808
- const receiverAddressKey = confirmed && chainId ? `/v1/client/asset/receiver_address?chain_id=${chainId}` : null;
809
+ const receiverAddressKey = confirmed && chainId && token ? `/v1/client/asset/receiver_address?chain_id=${chainId}&token=${token}` : null;
809
810
  const receiverEventsKey = active && confirmed ? "/v1/client/asset/receiver_events" : null;
810
811
  const {
811
812
  data: addressData,
@@ -857,46 +858,87 @@ var useExclusiveDeposit = (options2) => {
857
858
  eventsError
858
859
  };
859
860
  };
860
- var SUPPORTED_CHAINS = {
861
- prod: [42161],
862
- testnet: [421614]
863
- };
864
- var SUPPORTED_TOKENS = ["USDC"];
865
- var useExclusiveDepositOptions = () => {
866
- const env = useConfig("env");
861
+ var useExclusiveDepositOptions = (params) => {
867
862
  const networkId = useConfig("networkId");
868
- const [chains, { findByChainId }] = useChains(networkId, {
863
+ const tokensInfo = useTokensInfo();
864
+ const selectedNetwork = params?.selectedNetwork;
865
+ const [, { findByChainId }] = useChains(networkId, {
869
866
  pick: "network_infos"
870
867
  });
871
- const supportedChainIds = env === "prod" ? SUPPORTED_CHAINS.prod : SUPPORTED_CHAINS.testnet;
868
+ const combos = useMemo(() => {
869
+ if (!tokensInfo?.length) return [];
870
+ const result = [];
871
+ for (const token of tokensInfo) {
872
+ for (const detail of token.chain_details ?? []) {
873
+ if (detail.exclusive_deposit_supported === true) {
874
+ const chainId = Number(detail.chain_id);
875
+ const chain = findByChainId(chainId);
876
+ result.push({
877
+ chainId,
878
+ chainName: chain?.network_infos?.name ?? `Chain ${chainId}`,
879
+ explorerUrl: chain?.network_infos?.explorer_base_url ?? "",
880
+ tokenSymbol: token.token
881
+ });
882
+ }
883
+ }
884
+ }
885
+ return result;
886
+ }, [tokensInfo, findByChainId]);
872
887
  const networkOptions = useMemo(() => {
873
- return supportedChainIds.map((chainId) => {
874
- const chain = findByChainId(chainId);
875
- const name = chain?.network_infos?.name ?? `Chain ${chainId}`;
876
- const explorerUrl = chain?.network_infos?.explorer_base_url ?? "";
877
- return {
878
- label: name,
879
- value: String(chainId),
880
- chainId,
881
- explorerUrl
882
- };
888
+ const seen = /* @__PURE__ */ new Map();
889
+ for (const combo of combos) {
890
+ if (!seen.has(combo.chainId)) {
891
+ seen.set(combo.chainId, {
892
+ label: combo.chainName,
893
+ value: String(combo.chainId),
894
+ chainId: combo.chainId,
895
+ explorerUrl: combo.explorerUrl
896
+ });
897
+ }
898
+ }
899
+ const list = Array.from(seen.values());
900
+ list.sort((a, b) => {
901
+ if (a.chainId === 42161) return -1;
902
+ if (b.chainId === 42161) return 1;
903
+ return 0;
883
904
  });
884
- }, [supportedChainIds, findByChainId]);
905
+ return list;
906
+ }, [combos]);
885
907
  const tokenOptions = useMemo(() => {
886
- return SUPPORTED_TOKENS.map((symbol) => ({
887
- label: symbol,
888
- value: symbol
889
- }));
890
- }, []);
891
- return { networkOptions, tokenOptions };
908
+ if (!selectedNetwork) return [];
909
+ const chainId = Number(selectedNetwork);
910
+ const seen = /* @__PURE__ */ new Set();
911
+ const result = [];
912
+ for (const combo of combos) {
913
+ if (combo.chainId === chainId && !seen.has(combo.tokenSymbol)) {
914
+ seen.add(combo.tokenSymbol);
915
+ result.push({ label: combo.tokenSymbol, value: combo.tokenSymbol });
916
+ }
917
+ }
918
+ result.sort((a, b) => {
919
+ if (a.value === "USDC") return -1;
920
+ if (b.value === "USDC") return 1;
921
+ return 0;
922
+ });
923
+ return result;
924
+ }, [combos, selectedNetwork]);
925
+ const isSupported = combos.length > 0;
926
+ return { networkOptions, tokenOptions, isSupported };
892
927
  };
893
928
  var ExclusiveDeposit = ({ active }) => {
894
929
  const { t: t0 } = useTranslation();
895
930
  const t = t0;
896
931
  const [selectedNetwork, setSelectedNetwork] = useState("");
897
932
  const [selectedToken, setSelectedToken] = useState("");
898
- const { networkOptions, tokenOptions } = useExclusiveDepositOptions();
933
+ const { networkOptions, tokenOptions} = useExclusiveDepositOptions({
934
+ selectedNetwork
935
+ });
899
936
  const confirmed = !!selectedNetwork && !!selectedToken;
937
+ useEffect(() => {
938
+ if (selectedToken && tokenOptions.length > 0 && !tokenOptions.some((t2) => t2.value === selectedToken)) {
939
+ setSelectedToken("");
940
+ }
941
+ }, [selectedNetwork, selectedToken, tokenOptions]);
900
942
  const selectedNetworkOption = selectedNetwork ? networkOptions.find((n) => n.value === selectedNetwork) : void 0;
901
943
  const selectedChainId = selectedNetworkOption?.chainId;
902
944
  const selectedTokenOption = selectedToken ? tokenOptions.find((t2) => t2.value === selectedToken) : void 0;
@@ -912,6 +954,7 @@ var ExclusiveDeposit = ({ active }) => {
912
954
  active,
913
955
  confirmed,
914
956
  chainId: selectedChainId,
957
+ token: selectedToken,
915
958
  explorerBaseUrl: selectedNetworkOption?.explorerUrl ?? ""
916
959
  });
917
960
  const networkName = selectedNetworkOption?.label ?? "";
@@ -929,31 +972,20 @@ var ExclusiveDeposit = ({ active }) => {
929
972
  address && /* @__PURE__ */ jsx(CopyAddress, { address })
930
973
  ] }),
931
974
  /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, className: "oui-mt-5 oui-w-full", children: [
932
- confirmed ? /* @__PURE__ */ jsxs(Fragment, { children: [
933
- /* @__PURE__ */ jsxs(Flex, { className: "oui-w-full", justify: "between", itemAlign: "center", children: [
934
- /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 36, children: t("common.network") }),
935
- /* @__PURE__ */ jsxs(Flex, { gap: 1, itemAlign: "center", children: [
936
- /* @__PURE__ */ jsx(ChainIcon, { chainId: selectedChainId, size: "2xs" }),
937
- /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 98, children: networkName })
938
- ] })
939
- ] }),
940
- /* @__PURE__ */ jsxs(Flex, { className: "oui-w-full", justify: "between", itemAlign: "center", children: [
941
- /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 36, children: t("common.token") }),
942
- /* @__PURE__ */ jsxs(Flex, { gap: 1, itemAlign: "center", children: [
943
- /* @__PURE__ */ jsx(TokenIcon, { name: tokenName, size: "2xs" }),
944
- /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 98, children: tokenName })
945
- ] })
946
- ] })
947
- ] }) : /* @__PURE__ */ jsx(
975
+ /* @__PURE__ */ jsx(
948
976
  NetworkTokenSelect,
949
977
  {
950
978
  selectedNetwork,
951
979
  selectedToken,
952
- onNetworkChange: setSelectedNetwork,
980
+ onNetworkChange: (value) => {
981
+ setSelectedNetwork(value);
982
+ setSelectedToken("");
983
+ },
953
984
  onTokenChange: setSelectedToken,
954
985
  networkOptions,
955
986
  tokenOptions
956
- }
987
+ },
988
+ selectedNetwork
957
989
  ),
958
990
  /* @__PURE__ */ jsxs(Flex, { className: "oui-w-full", justify: "between", children: [
959
991
  /* @__PURE__ */ jsx(Text, { size: "xs", intensity: 36, children: t("transfer.exclusiveDeposit.minDeposit") }),
@@ -6409,10 +6441,14 @@ var WithdrawSlot = (props) => {
6409
6441
  var DepositAndWithdrawWithDialogId = "DepositAndWithdrawWithDialogId";
6410
6442
  var DepositAndWithdrawWithSheetId = "DepositAndWithdrawWithSheetId";
6411
6443
  var DepositAndWithdraw = (props) => {
6444
+ const { extraTabs = [] } = props;
6412
6445
  const [activeTab, setActiveTab] = useState(
6413
6446
  props.activeTab || "deposit"
6414
6447
  );
6415
6448
  const { t } = useTranslation();
6449
+ const sortedExtra = [...extraTabs].sort(
6450
+ (a, b) => (a.order ?? 100) - (b.order ?? 100)
6451
+ );
6416
6452
  return /* @__PURE__ */ jsxs(
6417
6453
  Tabs,
6418
6454
  {
@@ -6442,18 +6478,39 @@ var DepositAndWithdraw = (props) => {
6442
6478
  value: "withdraw",
6443
6479
  children: /* @__PURE__ */ jsx(WithdrawSlot, { close: props.close })
6444
6480
  }
6445
- )
6481
+ ),
6482
+ sortedExtra.map((tab) => /* @__PURE__ */ jsx(
6483
+ TabPanel,
6484
+ {
6485
+ title: tab.title,
6486
+ icon: isValidElement(tab.icon) ? tab.icon : void 0,
6487
+ value: tab.id,
6488
+ children: /* @__PURE__ */ jsx(tab.component, { close: props.close })
6489
+ },
6490
+ tab.id
6491
+ ))
6446
6492
  ]
6447
6493
  }
6448
6494
  );
6449
6495
  };
6450
- registerSimpleDialog(DepositAndWithdrawWithDialogId, DepositAndWithdraw, {
6451
- size: "md",
6452
- classNames: {
6453
- content: "oui-border oui-border-line-6"
6496
+ var InjectableDepositAndWithdraw = injectable(
6497
+ DepositAndWithdraw,
6498
+ "Transfer.DepositAndWithdraw"
6499
+ );
6500
+ registerSimpleDialog(
6501
+ DepositAndWithdrawWithDialogId,
6502
+ InjectableDepositAndWithdraw,
6503
+ {
6504
+ size: "md",
6505
+ classNames: {
6506
+ content: "oui-border oui-border-line-6"
6507
+ }
6454
6508
  }
6455
- });
6456
- registerSimpleSheet(DepositAndWithdrawWithSheetId, DepositAndWithdraw);
6509
+ );
6510
+ registerSimpleSheet(
6511
+ DepositAndWithdrawWithSheetId,
6512
+ InjectableDepositAndWithdraw
6513
+ );
6457
6514
  var AccountSelect = (props) => {
6458
6515
  const { subAccounts = [], value } = props;
6459
6516
  const [open, setOpen] = useState(false);
@@ -8291,6 +8348,6 @@ var DepositStatusWidget = (props) => {
8291
8348
  return /* @__PURE__ */ jsx(DepositStatus, { ...state, ...props });
8292
8349
  };
8293
8350
 
8294
- export { ActionButton, AvailableQuantity, BrokerWallet, ChainSelect, ConvertFormUI, ConvertFormWidget, DEPOSIT_ERROR_CODE_MAP, DepositAction, DepositAndWithdraw, DepositAndWithdrawWithDialogId, DepositAndWithdrawWithSheetId, DepositForm, DepositFormWidget, DepositStatus, DepositStatusWidget, ExchangeDivider, Fee, QuantityInput, SwapCoin, TransferDialogId, TransferForm, TransferFormWidget, TransferSheetId, TransferWidget, Web3Wallet, WithdrawForm, WithdrawFormWidget, WithdrawTo, YIELD_BEARING_ASSETS, YieldBearingReminder, checkIsAccountId, feeDecimalsOffset, getDepositKnownErrorMessage, getTransferErrorMessage, getUSDCToken, getYieldBearingAsset, isYieldBearingAsset, sortTokensWithUSDCFirst, useConvertFormScript as useConvertForm, useDepositFormScript, useDepositStatusScript, useTransferFormScript, useWithdrawFormScript };
8351
+ export { ActionButton, AvailableQuantity, BrokerWallet, ChainSelect, ConvertFormUI, ConvertFormWidget, DEPOSIT_ERROR_CODE_MAP, DepositAction, DepositAndWithdraw, DepositAndWithdrawWithDialogId, DepositAndWithdrawWithSheetId, DepositForm, DepositFormWidget, DepositStatus, DepositStatusWidget, ExchangeDivider, Fee, InjectableDepositAndWithdraw, QuantityInput, SwapCoin, TransferDialogId, TransferForm, TransferFormWidget, TransferSheetId, TransferWidget, Web3Wallet, WithdrawForm, WithdrawFormWidget, WithdrawTo, YIELD_BEARING_ASSETS, YieldBearingReminder, checkIsAccountId, feeDecimalsOffset, getDepositKnownErrorMessage, getTransferErrorMessage, getUSDCToken, getYieldBearingAsset, isYieldBearingAsset, sortTokensWithUSDCFirst, useConvertFormScript as useConvertForm, useDepositFormScript, useDepositStatusScript, useTransferFormScript, useWithdrawFormScript };
8295
8352
  //# sourceMappingURL=index.mjs.map
8296
8353
  //# sourceMappingURL=index.mjs.map