@orderly.network/ui-transfer 3.0.0-beta.5 → 3.0.0-beta.7

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.d.mts CHANGED
@@ -321,6 +321,7 @@ declare const useConvertFormScript: (options: ConvertFormScriptOptions) => {
321
321
  chain_id?: string | undefined;
322
322
  contract_address?: string | undefined;
323
323
  decimals?: number | undefined;
324
+ exclusive_deposit_supported?: boolean;
324
325
  withdrawal_fee?: number | undefined;
325
326
  chain_name?: string;
326
327
  cross_chain_withdrawal_fee?: number | undefined;
package/dist/index.d.ts CHANGED
@@ -321,6 +321,7 @@ declare const useConvertFormScript: (options: ConvertFormScriptOptions) => {
321
321
  chain_id?: string | undefined;
322
322
  contract_address?: string | undefined;
323
323
  decimals?: number | undefined;
324
+ exclusive_deposit_supported?: boolean;
324
325
  withdrawal_fee?: number | undefined;
325
326
  chain_name?: string;
326
327
  cross_chain_withdrawal_fee?: number | undefined;
package/dist/index.js CHANGED
@@ -805,10 +805,10 @@ var buildExplorerUrl = (baseUrl, txId) => {
805
805
  var useExclusiveDeposit = (options2) => {
806
806
  const active = options2.active ?? true;
807
807
  const confirmed = options2.confirmed ?? true;
808
- const { chainId, explorerBaseUrl } = options2;
808
+ const { chainId, token, explorerBaseUrl } = options2;
809
809
  const { t: t0 } = i18n.useTranslation();
810
810
  const t = t0;
811
- const receiverAddressKey = confirmed && chainId ? `/v1/client/asset/receiver_address?chain_id=${chainId}` : null;
811
+ const receiverAddressKey = confirmed && chainId && token ? `/v1/client/asset/receiver_address?chain_id=${chainId}&token=${token}` : null;
812
812
  const receiverEventsKey = active && confirmed ? "/v1/client/asset/receiver_events" : null;
813
813
  const {
814
814
  data: addressData,
@@ -860,46 +860,87 @@ var useExclusiveDeposit = (options2) => {
860
860
  eventsError
861
861
  };
862
862
  };
863
- var SUPPORTED_CHAINS = {
864
- prod: [42161],
865
- testnet: [421614]
866
- };
867
- var SUPPORTED_TOKENS = ["USDC"];
868
- var useExclusiveDepositOptions = () => {
869
- const env = hooks.useConfig("env");
863
+ var useExclusiveDepositOptions = (params) => {
870
864
  const networkId = hooks.useConfig("networkId");
871
- const [chains, { findByChainId }] = hooks.useChains(networkId, {
865
+ const tokensInfo = hooks.useTokensInfo();
866
+ const selectedNetwork = params?.selectedNetwork;
867
+ const [, { findByChainId }] = hooks.useChains(networkId, {
872
868
  pick: "network_infos"
873
869
  });
874
- const supportedChainIds = env === "prod" ? SUPPORTED_CHAINS.prod : SUPPORTED_CHAINS.testnet;
870
+ const combos = react.useMemo(() => {
871
+ if (!tokensInfo?.length) return [];
872
+ const result = [];
873
+ for (const token of tokensInfo) {
874
+ for (const detail of token.chain_details ?? []) {
875
+ if (detail.exclusive_deposit_supported === true) {
876
+ const chainId = Number(detail.chain_id);
877
+ const chain = findByChainId(chainId);
878
+ result.push({
879
+ chainId,
880
+ chainName: chain?.network_infos?.name ?? `Chain ${chainId}`,
881
+ explorerUrl: chain?.network_infos?.explorer_base_url ?? "",
882
+ tokenSymbol: token.token
883
+ });
884
+ }
885
+ }
886
+ }
887
+ return result;
888
+ }, [tokensInfo, findByChainId]);
875
889
  const networkOptions = react.useMemo(() => {
876
- return supportedChainIds.map((chainId) => {
877
- const chain = findByChainId(chainId);
878
- const name = chain?.network_infos?.name ?? `Chain ${chainId}`;
879
- const explorerUrl = chain?.network_infos?.explorer_base_url ?? "";
880
- return {
881
- label: name,
882
- value: String(chainId),
883
- chainId,
884
- explorerUrl
885
- };
890
+ const seen = /* @__PURE__ */ new Map();
891
+ for (const combo of combos) {
892
+ if (!seen.has(combo.chainId)) {
893
+ seen.set(combo.chainId, {
894
+ label: combo.chainName,
895
+ value: String(combo.chainId),
896
+ chainId: combo.chainId,
897
+ explorerUrl: combo.explorerUrl
898
+ });
899
+ }
900
+ }
901
+ const list = Array.from(seen.values());
902
+ list.sort((a, b) => {
903
+ if (a.chainId === 42161) return -1;
904
+ if (b.chainId === 42161) return 1;
905
+ return 0;
886
906
  });
887
- }, [supportedChainIds, findByChainId]);
907
+ return list;
908
+ }, [combos]);
888
909
  const tokenOptions = react.useMemo(() => {
889
- return SUPPORTED_TOKENS.map((symbol) => ({
890
- label: symbol,
891
- value: symbol
892
- }));
893
- }, []);
894
- return { networkOptions, tokenOptions };
910
+ if (!selectedNetwork) return [];
911
+ const chainId = Number(selectedNetwork);
912
+ const seen = /* @__PURE__ */ new Set();
913
+ const result = [];
914
+ for (const combo of combos) {
915
+ if (combo.chainId === chainId && !seen.has(combo.tokenSymbol)) {
916
+ seen.add(combo.tokenSymbol);
917
+ result.push({ label: combo.tokenSymbol, value: combo.tokenSymbol });
918
+ }
919
+ }
920
+ result.sort((a, b) => {
921
+ if (a.value === "USDC") return -1;
922
+ if (b.value === "USDC") return 1;
923
+ return 0;
924
+ });
925
+ return result;
926
+ }, [combos, selectedNetwork]);
927
+ const isSupported = combos.length > 0;
928
+ return { networkOptions, tokenOptions, isSupported };
895
929
  };
896
930
  var ExclusiveDeposit = ({ active }) => {
897
931
  const { t: t0 } = i18n.useTranslation();
898
932
  const t = t0;
899
933
  const [selectedNetwork, setSelectedNetwork] = react.useState("");
900
934
  const [selectedToken, setSelectedToken] = react.useState("");
901
- const { networkOptions, tokenOptions } = useExclusiveDepositOptions();
935
+ const { networkOptions, tokenOptions} = useExclusiveDepositOptions({
936
+ selectedNetwork
937
+ });
902
938
  const confirmed = !!selectedNetwork && !!selectedToken;
939
+ react.useEffect(() => {
940
+ if (selectedToken && tokenOptions.length > 0 && !tokenOptions.some((t2) => t2.value === selectedToken)) {
941
+ setSelectedToken("");
942
+ }
943
+ }, [selectedNetwork, selectedToken, tokenOptions]);
903
944
  const selectedNetworkOption = selectedNetwork ? networkOptions.find((n) => n.value === selectedNetwork) : void 0;
904
945
  const selectedChainId = selectedNetworkOption?.chainId;
905
946
  const selectedTokenOption = selectedToken ? tokenOptions.find((t2) => t2.value === selectedToken) : void 0;
@@ -915,6 +956,7 @@ var ExclusiveDeposit = ({ active }) => {
915
956
  active,
916
957
  confirmed,
917
958
  chainId: selectedChainId,
959
+ token: selectedToken,
918
960
  explorerBaseUrl: selectedNetworkOption?.explorerUrl ?? ""
919
961
  });
920
962
  const networkName = selectedNetworkOption?.label ?? "";
@@ -932,31 +974,20 @@ var ExclusiveDeposit = ({ active }) => {
932
974
  address && /* @__PURE__ */ jsxRuntime.jsx(CopyAddress, { address })
933
975
  ] }),
934
976
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { direction: "column", gap: 2, className: "oui-mt-5 oui-w-full", children: [
935
- confirmed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
936
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { className: "oui-w-full", justify: "between", itemAlign: "center", children: [
937
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 36, children: t("common.network") }),
938
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, itemAlign: "center", children: [
939
- /* @__PURE__ */ jsxRuntime.jsx(ui.ChainIcon, { chainId: selectedChainId, size: "2xs" }),
940
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 98, children: networkName })
941
- ] })
942
- ] }),
943
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { className: "oui-w-full", justify: "between", itemAlign: "center", children: [
944
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 36, children: t("common.token") }),
945
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, itemAlign: "center", children: [
946
- /* @__PURE__ */ jsxRuntime.jsx(ui.TokenIcon, { name: tokenName, size: "2xs" }),
947
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 98, children: tokenName })
948
- ] })
949
- ] })
950
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(
977
+ /* @__PURE__ */ jsxRuntime.jsx(
951
978
  NetworkTokenSelect,
952
979
  {
953
980
  selectedNetwork,
954
981
  selectedToken,
955
- onNetworkChange: setSelectedNetwork,
982
+ onNetworkChange: (value) => {
983
+ setSelectedNetwork(value);
984
+ setSelectedToken("");
985
+ },
956
986
  onTokenChange: setSelectedToken,
957
987
  networkOptions,
958
988
  tokenOptions
959
- }
989
+ },
990
+ selectedNetwork
960
991
  ),
961
992
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { className: "oui-w-full", justify: "between", children: [
962
993
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xs", intensity: 36, children: t("transfer.exclusiveDeposit.minDeposit") }),