@unifold/connect-react 0.1.40 → 0.1.41

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
@@ -1219,11 +1219,11 @@ function useUnifold() {
1219
1219
 
1220
1220
  // ../ui-react/dist/index.mjs
1221
1221
  import {
1222
- useState as useState26,
1223
- useEffect as useEffect20,
1222
+ useState as useState27,
1223
+ useEffect as useEffect21,
1224
1224
  useLayoutEffect as useLayoutEffect22,
1225
1225
  useCallback as useCallback42,
1226
- useRef as useRef52,
1226
+ useRef as useRef62,
1227
1227
  useMemo as useMemo92
1228
1228
  } from "react";
1229
1229
 
@@ -6854,7 +6854,7 @@ import { useQuery as useQuery5 } from "@tanstack/react-query";
6854
6854
  import { useQuery as useQuery6 } from "@tanstack/react-query";
6855
6855
  import { useQuery as useQuery7 } from "@tanstack/react-query";
6856
6856
  import { useQuery as useQuery8 } from "@tanstack/react-query";
6857
- import { useState as useState212, useEffect as useEffect162, useMemo as useMemo52 } from "react";
6857
+ import { useState as useState222, useEffect as useEffect172, useMemo as useMemo52 } from "react";
6858
6858
  var import_qr_code_styling = __toESM(require_qr_code_styling(), 1);
6859
6859
  import { useEffect as useEffect122, useRef as useRef42 } from "react";
6860
6860
  import { jsx as jsx322 } from "react/jsx-runtime";
@@ -6866,9 +6866,10 @@ import { Fragment as Fragment32, jsx as jsx35, jsxs as jsxs30 } from "react/jsx-
6866
6866
  import { useState as useState182, useMemo as useMemo42, useEffect as useEffect152 } from "react";
6867
6867
  import { jsx as jsx36, jsxs as jsxs31 } from "react/jsx-runtime";
6868
6868
  import { jsx as jsx37, jsxs as jsxs322 } from "react/jsx-runtime";
6869
+ import { useState as useState192, useEffect as useEffect162, useRef as useRef52 } from "react";
6869
6870
  import { jsx as jsx38, jsxs as jsxs33 } from "react/jsx-runtime";
6870
6871
  import { jsx as jsx39, jsxs as jsxs34 } from "react/jsx-runtime";
6871
- import { useState as useState192 } from "react";
6872
+ import { useState as useState202 } from "react";
6872
6873
  import * as React242 from "react";
6873
6874
 
6874
6875
  // ../../node_modules/.pnpm/@radix-ui+react-tooltip@1.2.8_@types+react-dom@19.2.3_@types+react@19.2.9__@types+react@19.2._aqltx4jspgwttwvtzmq3z5uagy/node_modules/@radix-ui/react-tooltip/dist/index.mjs
@@ -9608,7 +9609,7 @@ var Content22 = TooltipContent;
9608
9609
  // ../ui-react/dist/index.mjs
9609
9610
  import { jsx as jsx40 } from "react/jsx-runtime";
9610
9611
  import { Fragment as Fragment42, jsx as jsx41, jsxs as jsxs35 } from "react/jsx-runtime";
9611
- import { useState as useState222, useEffect as useEffect172, useMemo as useMemo62 } from "react";
9612
+ import { useState as useState232, useEffect as useEffect182, useMemo as useMemo62 } from "react";
9612
9613
  import * as React252 from "react";
9613
9614
 
9614
9615
  // ../../node_modules/.pnpm/@radix-ui+react-select@2.2.6_@types+react-dom@19.2.3_@types+react@19.2.9__@types+react@19.2.9_5n4syhs66qrtkkphe44qzgdimq/node_modules/@radix-ui/react-select/dist/index.mjs
@@ -10851,7 +10852,7 @@ import { jsx as jsx44 } from "react/jsx-runtime";
10851
10852
  import { jsx as jsx45, jsxs as jsxs38 } from "react/jsx-runtime";
10852
10853
  import { Fragment as Fragment52, jsx as jsx46, jsxs as jsxs39 } from "react/jsx-runtime";
10853
10854
  import { Fragment as Fragment62, jsx as jsx47, jsxs as jsxs40 } from "react/jsx-runtime";
10854
- import { useCallback as useCallback22, useState as useState232 } from "react";
10855
+ import { useCallback as useCallback22, useState as useState242 } from "react";
10855
10856
  import { Fragment as Fragment72, jsx as jsx48, jsxs as jsxs41 } from "react/jsx-runtime";
10856
10857
  import { Fragment as Fragment82, jsx as jsx49, jsxs as jsxs422 } from "react/jsx-runtime";
10857
10858
  import * as React272 from "react";
@@ -18480,6 +18481,104 @@ function DepositPollingUi({
18480
18481
  }
18481
18482
  return null;
18482
18483
  }
18484
+ var getChainKey = (chainId, chainType) => {
18485
+ return `${chainType}:${chainId}`;
18486
+ };
18487
+ function resolveSourceToken(supportedTokens, defaultSourceChainType, defaultSourceChainId, defaultSourceTokenAddress, defaultSourceSymbol) {
18488
+ if (!supportedTokens.length) return null;
18489
+ let selectedTokenData;
18490
+ let selectedChainData;
18491
+ const hasChainDefaults = defaultSourceChainType && defaultSourceChainId;
18492
+ if (defaultSourceTokenAddress && hasChainDefaults) {
18493
+ for (const t7 of supportedTokens) {
18494
+ const matchingChain = t7.chains.find(
18495
+ (c) => c.token_address.toLowerCase() === defaultSourceTokenAddress.toLowerCase() && c.chain_type === defaultSourceChainType && c.chain_id === defaultSourceChainId
18496
+ );
18497
+ if (matchingChain) {
18498
+ selectedTokenData = t7;
18499
+ selectedChainData = matchingChain;
18500
+ break;
18501
+ }
18502
+ }
18503
+ }
18504
+ if (!selectedTokenData && defaultSourceSymbol && hasChainDefaults) {
18505
+ for (const t7 of supportedTokens) {
18506
+ if (t7.symbol !== defaultSourceSymbol) continue;
18507
+ const matchedChain = t7.chains.find(
18508
+ (c) => c.chain_type === defaultSourceChainType && c.chain_id === defaultSourceChainId
18509
+ );
18510
+ if (matchedChain) {
18511
+ selectedTokenData = t7;
18512
+ selectedChainData = matchedChain;
18513
+ break;
18514
+ }
18515
+ }
18516
+ }
18517
+ if (!selectedTokenData) {
18518
+ for (const t7 of supportedTokens) {
18519
+ if (t7.chains.length > 0) {
18520
+ selectedTokenData = t7;
18521
+ selectedChainData = t7.chains[0];
18522
+ break;
18523
+ }
18524
+ }
18525
+ }
18526
+ if (selectedTokenData && selectedChainData) {
18527
+ return { token: selectedTokenData, chain: selectedChainData };
18528
+ }
18529
+ return null;
18530
+ }
18531
+ function useDefaultSourceToken({
18532
+ supportedTokens,
18533
+ defaultSourceChainType,
18534
+ defaultSourceChainId,
18535
+ defaultSourceTokenAddress,
18536
+ defaultSourceSymbol
18537
+ }) {
18538
+ const [token, setToken] = useState192(null);
18539
+ const [chain, setChain] = useState192(null);
18540
+ const [initialSelectionDone, setInitialSelectionDone] = useState192(false);
18541
+ const appliedDefaultsRef = useRef52("");
18542
+ useEffect162(() => {
18543
+ if (!supportedTokens.length) return;
18544
+ const defaultsKey = `${defaultSourceTokenAddress ?? ""}|${defaultSourceSymbol ?? ""}|${defaultSourceChainType ?? ""}|${defaultSourceChainId ?? ""}`;
18545
+ const defaultsChanged = appliedDefaultsRef.current !== defaultsKey;
18546
+ if (initialSelectionDone && !defaultsChanged) return;
18547
+ const result = resolveSourceToken(
18548
+ supportedTokens,
18549
+ defaultSourceChainType,
18550
+ defaultSourceChainId,
18551
+ defaultSourceTokenAddress,
18552
+ defaultSourceSymbol
18553
+ );
18554
+ if (result) {
18555
+ setToken(result.token.symbol);
18556
+ setChain(getChainKey(result.chain.chain_id, result.chain.chain_type));
18557
+ appliedDefaultsRef.current = defaultsKey;
18558
+ setInitialSelectionDone(true);
18559
+ }
18560
+ }, [
18561
+ supportedTokens,
18562
+ defaultSourceTokenAddress,
18563
+ defaultSourceSymbol,
18564
+ defaultSourceChainType,
18565
+ defaultSourceChainId,
18566
+ initialSelectionDone
18567
+ ]);
18568
+ useEffect162(() => {
18569
+ if (!supportedTokens.length || !token) return;
18570
+ const currentToken = supportedTokens.find((t7) => t7.symbol === token);
18571
+ if (!currentToken || currentToken.chains.length === 0) return;
18572
+ const isChainAvailable = chain && currentToken.chains.some((c) => {
18573
+ return getChainKey(c.chain_id, c.chain_type) === chain;
18574
+ });
18575
+ if (!isChainAvailable) {
18576
+ const firstChain = currentToken.chains[0];
18577
+ setChain(getChainKey(firstChain.chain_id, firstChain.chain_type));
18578
+ }
18579
+ }, [token, supportedTokens, chain]);
18580
+ return { token, chain, setToken, setChain, initialSelectionDone };
18581
+ }
18483
18582
  function DepositFooterLinks({
18484
18583
  onGlossaryClick
18485
18584
  }) {
@@ -18639,7 +18738,7 @@ function GlossaryModal({
18639
18738
  ) });
18640
18739
  }
18641
18740
  function useCopyAddress() {
18642
- const [copied, setCopied] = useState192(false);
18741
+ const [copied, setCopied] = useState202(false);
18643
18742
  const handleCopy = (address) => {
18644
18743
  if (!address) return;
18645
18744
  navigator.clipboard.writeText(address);
@@ -18685,7 +18784,7 @@ var TooltipContent2 = React242.forwardRef(({ className, sideOffset = 4, ...props
18685
18784
  });
18686
18785
  TooltipContent2.displayName = Content22.displayName;
18687
18786
  var t4 = i18n2.transferCrypto;
18688
- var getChainKey = (chainId, chainType) => {
18787
+ var getChainKey2 = (chainId, chainType) => {
18689
18788
  return `${chainType}:${chainId}`;
18690
18789
  };
18691
18790
  var parseChainKey = (chainKey) => {
@@ -18699,6 +18798,10 @@ function TransferCryptoSingleInput({
18699
18798
  destinationChainType,
18700
18799
  destinationChainId,
18701
18800
  destinationTokenAddress,
18801
+ defaultSourceChainType,
18802
+ defaultSourceChainId,
18803
+ defaultSourceTokenAddress,
18804
+ defaultSourceSymbol,
18702
18805
  depositConfirmationMode = "auto_ui",
18703
18806
  onExecutionsChange,
18704
18807
  onDepositSuccess,
@@ -18707,21 +18810,25 @@ function TransferCryptoSingleInput({
18707
18810
  }) {
18708
18811
  const { themeClass, colors: colors2, fonts, components } = useTheme();
18709
18812
  const isDarkMode = themeClass.includes("uf-dark");
18710
- const [token, setToken] = useState212("USDC");
18711
- const [chain, setChain] = useState212("solana:mainnet");
18712
- const [copied, setCopied] = useState212(false);
18813
+ const [copied, setCopied] = useState222(false);
18713
18814
  const { copied: copiedRecipient, handleCopy: handleCopyRecipientAddress } = useCopyAddress();
18714
- const [glossaryOpen, setGlossaryOpen] = useState212(false);
18715
- const [detailsExpanded, setDetailsExpanded] = useState212(false);
18716
- const [depositsModalOpen, setDepositsModalOpen] = useState212(false);
18717
- const [tokenSelectorOpen, setTokenSelectorOpen] = useState212(false);
18718
- const [initialSelectionDone, setInitialSelectionDone] = useState212(false);
18815
+ const [glossaryOpen, setGlossaryOpen] = useState222(false);
18816
+ const [detailsExpanded, setDetailsExpanded] = useState222(false);
18817
+ const [depositsModalOpen, setDepositsModalOpen] = useState222(false);
18818
+ const [tokenSelectorOpen, setTokenSelectorOpen] = useState222(false);
18719
18819
  const { data: tokensResponse, isLoading: tokensLoading } = useSupportedDepositTokens(publishableKey, {
18720
18820
  destination_token_address: destinationTokenAddress,
18721
18821
  destination_chain_id: destinationChainId,
18722
18822
  destination_chain_type: destinationChainType
18723
18823
  });
18724
18824
  const supportedTokens = tokensResponse?.data ?? [];
18825
+ const { token, chain, setToken, setChain, initialSelectionDone } = useDefaultSourceToken({
18826
+ supportedTokens,
18827
+ defaultSourceChainType,
18828
+ defaultSourceChainId,
18829
+ defaultSourceTokenAddress,
18830
+ defaultSourceSymbol
18831
+ });
18725
18832
  const {
18726
18833
  data: depositAddressResponse,
18727
18834
  isLoading: walletsLoading,
@@ -18751,10 +18858,10 @@ function TransferCryptoSingleInput({
18751
18858
  });
18752
18859
  return Array.from(chainsMap.values());
18753
18860
  }, [supportedTokens]);
18754
- const currentChainCombo = parseChainKey(chain);
18755
- const currentChainData = allAvailableChains.find(
18861
+ const currentChainCombo = chain ? parseChainKey(chain) : null;
18862
+ const currentChainData = currentChainCombo ? allAvailableChains.find(
18756
18863
  (c) => c.chain_type === currentChainCombo.chainType && c.chain_id === currentChainCombo.chainId
18757
- );
18864
+ ) : void 0;
18758
18865
  const currentChainType = currentChainData?.chain_type || "ethereum";
18759
18866
  const currentWallet = getWalletByChainType(wallets, currentChainType);
18760
18867
  const depositAddress = currentWallet?.address || "";
@@ -18772,78 +18879,20 @@ function TransferCryptoSingleInput({
18772
18879
  onDepositSuccess,
18773
18880
  onDepositError
18774
18881
  });
18775
- useEffect162(() => {
18776
- if (!supportedTokens.length || initialSelectionDone) return;
18777
- let selectedTokenData;
18778
- let selectedChainData;
18779
- if (destinationTokenAddress) {
18780
- for (const t7 of supportedTokens) {
18781
- const matchingChain = t7.chains.find(
18782
- (c) => c.token_address.toLowerCase() === destinationTokenAddress.toLowerCase()
18783
- );
18784
- if (matchingChain) {
18785
- selectedTokenData = t7;
18786
- selectedChainData = matchingChain;
18787
- break;
18788
- }
18789
- }
18790
- }
18791
- if (!selectedTokenData) {
18792
- selectedTokenData = supportedTokens.find((t7) => t7.symbol === "USDC");
18793
- if (selectedTokenData && selectedTokenData.chains.length > 0) {
18794
- selectedChainData = selectedTokenData.chains[0];
18795
- }
18796
- }
18797
- if (!selectedTokenData) {
18798
- selectedTokenData = supportedTokens.find((t7) => t7.symbol === "USDT");
18799
- if (selectedTokenData && selectedTokenData.chains.length > 0) {
18800
- selectedChainData = selectedTokenData.chains[0];
18801
- }
18802
- }
18803
- if (!selectedTokenData) {
18804
- selectedTokenData = supportedTokens[0];
18805
- if (selectedTokenData.chains.length > 0) {
18806
- selectedChainData = selectedTokenData.chains[0];
18807
- }
18808
- }
18809
- if (selectedTokenData) {
18810
- setToken(selectedTokenData.symbol);
18811
- }
18812
- if (selectedChainData) {
18813
- setChain(
18814
- getChainKey(selectedChainData.chain_id, selectedChainData.chain_type)
18815
- );
18816
- }
18817
- setInitialSelectionDone(true);
18818
- }, [supportedTokens, destinationTokenAddress, initialSelectionDone]);
18819
- useEffect162(() => {
18882
+ useEffect172(() => {
18820
18883
  if (onExecutionsChange) {
18821
18884
  onExecutionsChange(depositExecutions);
18822
18885
  }
18823
18886
  }, [depositExecutions, onExecutionsChange]);
18824
- useEffect162(() => {
18825
- if (!supportedTokens.length) return;
18826
- const currentToken = supportedTokens.find((t7) => t7.symbol === token);
18827
- if (!currentToken || currentToken.chains.length === 0) return;
18828
- const isChainAvailable = currentToken.chains.some((c) => {
18829
- const key = getChainKey(c.chain_id, c.chain_type);
18830
- return key === chain;
18831
- });
18832
- if (!isChainAvailable) {
18833
- const firstChain = currentToken.chains[0];
18834
- const newChain = getChainKey(firstChain.chain_id, firstChain.chain_type);
18835
- setChain(newChain);
18836
- }
18837
- }, [token, supportedTokens, chain]);
18838
- const selectedToken = supportedTokens.find((t7) => t7.symbol === token);
18887
+ const selectedToken = token ? supportedTokens.find((t7) => t7.symbol === token) : void 0;
18839
18888
  const availableChainsForToken = selectedToken?.chains || [];
18840
- const currentChainFromBackend = availableChainsForToken.find((c) => {
18841
- const key = getChainKey(c.chain_id, c.chain_type);
18889
+ const currentChainFromBackend = chain ? availableChainsForToken.find((c) => {
18890
+ const key = getChainKey2(c.chain_id, c.chain_type);
18842
18891
  return key === chain;
18843
18892
  }) || allAvailableChains.find((c) => {
18844
- const key = getChainKey(c.chain_id, c.chain_type);
18893
+ const key = getChainKey2(c.chain_id, c.chain_type);
18845
18894
  return key === chain;
18846
- });
18895
+ }) : void 0;
18847
18896
  const handleCopyAddress = () => {
18848
18897
  navigator.clipboard.writeText(depositAddress);
18849
18898
  setCopied(true);
@@ -18878,10 +18927,10 @@ function TransferCryptoSingleInput({
18878
18927
  "button",
18879
18928
  {
18880
18929
  onClick: () => setTokenSelectorOpen(true),
18881
- disabled: tokensLoading || supportedTokens.length === 0,
18930
+ disabled: tokensLoading || !token || supportedTokens.length === 0,
18882
18931
  className: "uf-w-full hover:uf-bg-accent uf-p-3 uf-flex uf-items-center uf-gap-3 uf-transition-colors disabled:uf-opacity-50 disabled:uf-cursor-not-allowed",
18883
18932
  style: { backgroundColor: components.card.backgroundColor, borderRadius: components.card.borderRadius, border: `${components.card.borderWidth}px solid ${components.card.borderColor}` },
18884
- children: tokensLoading ? /* @__PURE__ */ jsxs35("div", { className: "uf-flex uf-items-center uf-gap-3 uf-animate-pulse", children: [
18933
+ children: tokensLoading || !token ? /* @__PURE__ */ jsxs35("div", { className: "uf-flex uf-items-center uf-gap-3 uf-animate-pulse", children: [
18885
18934
  /* @__PURE__ */ jsx41("div", { className: "uf-w-10 uf-h-10 uf-rounded-full uf-bg-muted" }),
18886
18935
  /* @__PURE__ */ jsxs35("div", { className: "uf-flex-1", children: [
18887
18936
  /* @__PURE__ */ jsx41("div", { className: "uf-h-4 uf-w-16 uf-bg-muted uf-rounded uf-mb-1" }),
@@ -18955,8 +19004,8 @@ function TransferCryptoSingleInput({
18955
19004
  open: tokenSelectorOpen,
18956
19005
  onOpenChange: setTokenSelectorOpen,
18957
19006
  tokens: supportedTokens,
18958
- selectedToken: token,
18959
- selectedChainKey: chain,
19007
+ selectedToken: token ?? "",
19008
+ selectedChainKey: chain ?? "",
18960
19009
  onSelect: (newToken, newChain) => {
18961
19010
  setToken(newToken);
18962
19011
  setChain(newChain);
@@ -19294,7 +19343,7 @@ var SelectSeparator2 = React252.forwardRef(({ className, ...props }, ref) => /*
19294
19343
  ));
19295
19344
  SelectSeparator2.displayName = Separator.displayName;
19296
19345
  var t5 = i18n2.transferCrypto;
19297
- var getChainKey2 = (chainId, chainType) => {
19346
+ var getChainKey3 = (chainId, chainType) => {
19298
19347
  return `${chainType}:${chainId}`;
19299
19348
  };
19300
19349
  var parseChainKey2 = (chainKey) => {
@@ -19308,6 +19357,10 @@ function TransferCryptoDoubleInput({
19308
19357
  destinationChainType,
19309
19358
  destinationChainId,
19310
19359
  destinationTokenAddress,
19360
+ defaultSourceChainType,
19361
+ defaultSourceChainId,
19362
+ defaultSourceTokenAddress,
19363
+ defaultSourceSymbol,
19311
19364
  depositConfirmationMode = "auto_ui",
19312
19365
  onExecutionsChange,
19313
19366
  onDepositSuccess,
@@ -19316,20 +19369,24 @@ function TransferCryptoDoubleInput({
19316
19369
  }) {
19317
19370
  const { themeClass, colors: colors2, fonts, components } = useTheme();
19318
19371
  const isDarkMode = themeClass.includes("uf-dark");
19319
- const [token, setToken] = useState222("USDC");
19320
- const [chain, setChain] = useState222("solana:mainnet");
19321
- const [copied, setCopied] = useState222(false);
19372
+ const [copied, setCopied] = useState232(false);
19322
19373
  const { copied: copiedRecipient, handleCopy: handleCopyRecipientAddress } = useCopyAddress();
19323
- const [glossaryOpen, setGlossaryOpen] = useState222(false);
19324
- const [detailsExpanded, setDetailsExpanded] = useState222(false);
19325
- const [depositsModalOpen, setDepositsModalOpen] = useState222(false);
19326
- const [initialSelectionDone, setInitialSelectionDone] = useState222(false);
19374
+ const [glossaryOpen, setGlossaryOpen] = useState232(false);
19375
+ const [detailsExpanded, setDetailsExpanded] = useState232(false);
19376
+ const [depositsModalOpen, setDepositsModalOpen] = useState232(false);
19327
19377
  const { data: tokensResponse, isLoading: tokensLoading } = useSupportedDepositTokens(publishableKey, {
19328
19378
  destination_token_address: destinationTokenAddress,
19329
19379
  destination_chain_id: destinationChainId,
19330
19380
  destination_chain_type: destinationChainType
19331
19381
  });
19332
19382
  const supportedTokens = tokensResponse?.data ?? [];
19383
+ const { token, chain, setToken, setChain, initialSelectionDone } = useDefaultSourceToken({
19384
+ supportedTokens,
19385
+ defaultSourceChainType,
19386
+ defaultSourceChainId,
19387
+ defaultSourceTokenAddress,
19388
+ defaultSourceSymbol
19389
+ });
19333
19390
  const {
19334
19391
  data: depositAddressResponse,
19335
19392
  isLoading: walletsLoading,
@@ -19359,10 +19416,10 @@ function TransferCryptoDoubleInput({
19359
19416
  });
19360
19417
  return Array.from(chainsMap.values());
19361
19418
  }, [supportedTokens]);
19362
- const currentChainCombo = parseChainKey2(chain);
19363
- const currentChainData = allAvailableChains.find(
19419
+ const currentChainCombo = chain ? parseChainKey2(chain) : null;
19420
+ const currentChainData = currentChainCombo ? allAvailableChains.find(
19364
19421
  (c) => c.chain_type === currentChainCombo.chainType && c.chain_id === currentChainCombo.chainId
19365
- );
19422
+ ) : void 0;
19366
19423
  const currentChainType = currentChainData?.chain_type || "ethereum";
19367
19424
  const currentWallet = getWalletByChainType(wallets, currentChainType);
19368
19425
  const depositAddress = currentWallet?.address || "";
@@ -19380,51 +19437,20 @@ function TransferCryptoDoubleInput({
19380
19437
  onDepositSuccess,
19381
19438
  onDepositError
19382
19439
  });
19383
- useEffect172(() => {
19384
- if (!supportedTokens.length || initialSelectionDone) return;
19385
- const allChains = /* @__PURE__ */ new Set();
19386
- supportedTokens.forEach((t7) => {
19387
- t7.chains.forEach((c) => {
19388
- allChains.add(getChainKey2(c.chain_id, c.chain_type));
19389
- });
19390
- });
19391
- if (!allChains.has(chain)) {
19392
- const firstToken = supportedTokens[0];
19393
- if (firstToken.chains.length > 0) {
19394
- const firstChain = firstToken.chains[0];
19395
- setChain(getChainKey2(firstChain.chain_id, firstChain.chain_type));
19396
- }
19397
- }
19398
- setInitialSelectionDone(true);
19399
- }, [supportedTokens, chain, initialSelectionDone]);
19400
- useEffect172(() => {
19440
+ useEffect182(() => {
19401
19441
  if (onExecutionsChange) {
19402
19442
  onExecutionsChange(depositExecutions);
19403
19443
  }
19404
19444
  }, [depositExecutions, onExecutionsChange]);
19405
- useEffect172(() => {
19406
- if (!supportedTokens.length) return;
19407
- const currentToken = supportedTokens.find((t7) => t7.symbol === token);
19408
- if (!currentToken || currentToken.chains.length === 0) return;
19409
- const isChainAvailable = currentToken.chains.some((c) => {
19410
- const key = getChainKey2(c.chain_id, c.chain_type);
19411
- return key === chain;
19412
- });
19413
- if (!isChainAvailable) {
19414
- const firstChain = currentToken.chains[0];
19415
- const newChain = getChainKey2(firstChain.chain_id, firstChain.chain_type);
19416
- setChain(newChain);
19417
- }
19418
- }, [token, supportedTokens, chain]);
19419
- const selectedToken = supportedTokens.find((t7) => t7.symbol === token);
19445
+ const selectedToken = token ? supportedTokens.find((t7) => t7.symbol === token) : void 0;
19420
19446
  const availableChainsForToken = selectedToken?.chains || [];
19421
- const currentChainFromBackend = availableChainsForToken.find((c) => {
19422
- const key = getChainKey2(c.chain_id, c.chain_type);
19447
+ const currentChainFromBackend = chain ? availableChainsForToken.find((c) => {
19448
+ const key = getChainKey3(c.chain_id, c.chain_type);
19423
19449
  return key === chain;
19424
19450
  }) || allAvailableChains.find((c) => {
19425
- const key = getChainKey2(c.chain_id, c.chain_type);
19451
+ const key = getChainKey3(c.chain_id, c.chain_type);
19426
19452
  return key === chain;
19427
- });
19453
+ }) : void 0;
19428
19454
  const handleCopyAddress = () => {
19429
19455
  navigator.clipboard.writeText(depositAddress);
19430
19456
  setCopied(true);
@@ -19498,11 +19524,11 @@ function TransferCryptoDoubleInput({
19498
19524
  /* @__PURE__ */ jsxs37(
19499
19525
  Select2,
19500
19526
  {
19501
- value: token,
19527
+ value: token ?? "",
19502
19528
  onValueChange: setToken,
19503
- disabled: tokensLoading || supportedTokens.length === 0,
19529
+ disabled: tokensLoading || !token || supportedTokens.length === 0,
19504
19530
  children: [
19505
- /* @__PURE__ */ jsx43(SelectTrigger2, { className: "uf-h-10 hover:uf-opacity-90 uf-text-foreground disabled:uf-opacity-50", style: { backgroundColor: components.card.backgroundColor, border: `${components.card.borderWidth}px solid ${components.card.borderColor}` }, children: /* @__PURE__ */ jsx43(SelectValue2, { children: tokensLoading ? /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-light uf-text-muted-foreground", children: t5.loading }) }) : selectedToken ? renderTokenItem(selectedToken) : /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-normal", children: token }) }) }) }),
19531
+ /* @__PURE__ */ jsx43(SelectTrigger2, { className: "uf-h-10 hover:uf-opacity-90 uf-text-foreground disabled:uf-opacity-50", style: { backgroundColor: components.card.backgroundColor, border: `${components.card.borderWidth}px solid ${components.card.borderColor}` }, children: /* @__PURE__ */ jsx43(SelectValue2, { children: tokensLoading || !token ? /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-light uf-text-muted-foreground", children: t5.loading }) }) : selectedToken ? renderTokenItem(selectedToken) : /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-normal", children: token }) }) }) }),
19506
19532
  /* @__PURE__ */ jsx43(SelectContent2, { className: "uf-bg-secondary uf-border uf-text-foreground uf-max-h-[300px]", style: { border: `1px solid ${isDarkMode ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)"}`, ...fonts.regular ? { "--uf-font-family": fonts.regular } : {} }, children: supportedTokens.map((tokenData) => /* @__PURE__ */ jsx43(
19507
19533
  SelectItem2,
19508
19534
  {
@@ -19529,11 +19555,11 @@ function TransferCryptoDoubleInput({
19529
19555
  /* @__PURE__ */ jsxs37(
19530
19556
  Select2,
19531
19557
  {
19532
- value: chain,
19558
+ value: chain ?? "",
19533
19559
  onValueChange: setChain,
19534
- disabled: tokensLoading || availableChainsForToken.length === 0,
19560
+ disabled: tokensLoading || !chain || availableChainsForToken.length === 0,
19535
19561
  children: [
19536
- /* @__PURE__ */ jsx43(SelectTrigger2, { className: "uf-h-10 hover:uf-opacity-90 uf-text-foreground disabled:uf-opacity-50", style: { backgroundColor: components.card.backgroundColor, border: `${components.card.borderWidth}px solid ${components.card.borderColor}` }, children: /* @__PURE__ */ jsx43(SelectValue2, { children: tokensLoading ? /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-light uf-text-muted-foreground", children: t5.loading }) }) : currentChainFromBackend ? renderChainItem(currentChainFromBackend) : currentChainData ? renderChainItem(currentChainData) : /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-normal", children: chain }) }) }) }),
19562
+ /* @__PURE__ */ jsx43(SelectTrigger2, { className: "uf-h-10 hover:uf-opacity-90 uf-text-foreground disabled:uf-opacity-50", style: { backgroundColor: components.card.backgroundColor, border: `${components.card.borderWidth}px solid ${components.card.borderColor}` }, children: /* @__PURE__ */ jsx43(SelectValue2, { children: tokensLoading || !chain ? /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-light uf-text-muted-foreground", children: t5.loading }) }) : currentChainFromBackend ? renderChainItem(currentChainFromBackend) : currentChainData ? renderChainItem(currentChainData) : /* @__PURE__ */ jsx43("div", { className: "uf-flex uf-items-center uf-gap-2", children: /* @__PURE__ */ jsx43("span", { className: "uf-text-xs uf-font-normal", children: chain }) }) }) }),
19537
19563
  /* @__PURE__ */ jsx43(
19538
19564
  SelectContent2,
19539
19565
  {
@@ -19541,7 +19567,7 @@ function TransferCryptoDoubleInput({
19541
19567
  className: "uf-bg-secondary uf-border uf-text-foreground uf-max-h-[300px] uf-min-w-[200px]",
19542
19568
  style: { border: `1px solid ${isDarkMode ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.15)"}`, ...fonts.regular ? { "--uf-font-family": fonts.regular } : {} },
19543
19569
  children: availableChainsForToken.length === 0 ? /* @__PURE__ */ jsx43("div", { className: "uf-px-2 uf-py-3 uf-text-xs uf-text-muted-foreground uf-text-center", children: t5.noChainsAvailable }) : availableChainsForToken.map((chainData) => {
19544
- const chainKey = getChainKey2(
19570
+ const chainKey = getChainKey3(
19545
19571
  chainData.chain_id,
19546
19572
  chainData.chain_type
19547
19573
  );
@@ -20536,7 +20562,7 @@ function ConfirmingView({
20536
20562
  isPolling = false
20537
20563
  }) {
20538
20564
  const { colors: colors2, fonts } = useTheme();
20539
- const [containerEl, setContainerEl] = useState232(null);
20565
+ const [containerEl, setContainerEl] = useState242(null);
20540
20566
  const containerCallbackRef = useCallback22((el) => {
20541
20567
  setContainerEl(el);
20542
20568
  }, []);
@@ -21909,6 +21935,10 @@ function DepositModal({
21909
21935
  destinationChainType,
21910
21936
  destinationChainId,
21911
21937
  destinationTokenAddress,
21938
+ defaultSourceChainType,
21939
+ defaultSourceChainId,
21940
+ defaultSourceTokenAddress,
21941
+ defaultSourceSymbol,
21912
21942
  hideDepositTracker = false,
21913
21943
  showBalanceHeader = false,
21914
21944
  transferInputVariant = "double_input",
@@ -21935,28 +21965,28 @@ function DepositModal({
21935
21965
  if (s === "tracker" && hideDepositTracker) return "main";
21936
21966
  return s;
21937
21967
  }, [initialScreen, hideDepositTracker]);
21938
- const [containerEl, setContainerEl] = useState26(null);
21968
+ const [containerEl, setContainerEl] = useState27(null);
21939
21969
  const containerCallbackRef = useCallback42((el) => {
21940
21970
  setContainerEl(el);
21941
21971
  }, []);
21942
- const [view, setView] = useState26(
21972
+ const [view, setView] = useState27(
21943
21973
  effectiveInitialScreen
21944
21974
  );
21945
- const resetViewTimeoutRef = useRef52(null);
21946
- const [cardView, setCardView] = useState26(
21975
+ const resetViewTimeoutRef = useRef62(null);
21976
+ const [cardView, setCardView] = useState27(
21947
21977
  "amount"
21948
21978
  );
21949
- const [exchangeView, setExchangeView] = useState26(
21979
+ const [exchangeView, setExchangeView] = useState27(
21950
21980
  "providers"
21951
21981
  );
21952
- const [browserWalletModalOpen, setBrowserWalletModalOpen] = useState26(false);
21953
- const [browserWalletInfo, setBrowserWalletInfo] = useState26(null);
21954
- const [walletSelectionModalOpen, setWalletSelectionModalOpen] = useState26(false);
21955
- const [browserWalletChainType, setBrowserWalletChainType] = useState26(() => getStoredWalletChainType());
21956
- const [quotesCount, setQuotesCount] = useState26(0);
21957
- const [allExecutions, setAllExecutions] = useState26([]);
21958
- const [selectedExecution, setSelectedExecution] = useState26(null);
21959
- const [depositExecutions, setDepositExecutions] = useState26([]);
21982
+ const [browserWalletModalOpen, setBrowserWalletModalOpen] = useState27(false);
21983
+ const [browserWalletInfo, setBrowserWalletInfo] = useState27(null);
21984
+ const [walletSelectionModalOpen, setWalletSelectionModalOpen] = useState27(false);
21985
+ const [browserWalletChainType, setBrowserWalletChainType] = useState27(() => getStoredWalletChainType());
21986
+ const [quotesCount, setQuotesCount] = useState27(0);
21987
+ const [allExecutions, setAllExecutions] = useState27([]);
21988
+ const [selectedExecution, setSelectedExecution] = useState27(null);
21989
+ const [depositExecutions, setDepositExecutions] = useState27([]);
21960
21990
  const isMobileView = useIsMobileViewport();
21961
21991
  const { data: depositAddressResponse, isLoading: walletsLoading } = useDepositAddress({
21962
21992
  userId,
@@ -21969,10 +21999,10 @@ function DepositModal({
21969
21999
  // Only fetch when modal is open
21970
22000
  });
21971
22001
  const wallets = depositAddressResponse?.data ?? [];
21972
- const [resolvedTheme, setResolvedTheme] = useState26(
22002
+ const [resolvedTheme, setResolvedTheme] = useState27(
21973
22003
  theme === "auto" ? "dark" : theme
21974
22004
  );
21975
- useEffect20(() => {
22005
+ useEffect21(() => {
21976
22006
  if (theme === "auto") {
21977
22007
  const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
21978
22008
  setResolvedTheme(mediaQuery.matches ? "dark" : "light");
@@ -22001,7 +22031,7 @@ function DepositModal({
22001
22031
  chainType: destinationChainType,
22002
22032
  enabled: open
22003
22033
  });
22004
- useEffect20(() => {
22034
+ useEffect21(() => {
22005
22035
  if (view !== "tracker" || !userId) return;
22006
22036
  const fetchExecutions = async () => {
22007
22037
  try {
@@ -22022,7 +22052,7 @@ function DepositModal({
22022
22052
  clearInterval(pollInterval);
22023
22053
  };
22024
22054
  }, [view, userId, publishableKey]);
22025
- useEffect20(() => {
22055
+ useEffect21(() => {
22026
22056
  if (view !== "tracker") {
22027
22057
  setSelectedExecution(null);
22028
22058
  }
@@ -22132,7 +22162,7 @@ function DepositModal({
22132
22162
  setBrowserWalletInfo(null);
22133
22163
  setSelectedExecution(null);
22134
22164
  }, [open, effectiveInitialScreen]);
22135
- useEffect20(
22165
+ useEffect21(
22136
22166
  () => () => {
22137
22167
  if (resetViewTimeoutRef.current) {
22138
22168
  clearTimeout(resetViewTimeoutRef.current);
@@ -22341,6 +22371,10 @@ function DepositModal({
22341
22371
  destinationChainType,
22342
22372
  destinationChainId,
22343
22373
  destinationTokenAddress,
22374
+ defaultSourceChainType,
22375
+ defaultSourceChainId,
22376
+ defaultSourceTokenAddress,
22377
+ defaultSourceSymbol,
22344
22378
  depositConfirmationMode,
22345
22379
  onExecutionsChange: setDepositExecutions,
22346
22380
  onDepositSuccess,
@@ -22356,6 +22390,10 @@ function DepositModal({
22356
22390
  destinationChainType,
22357
22391
  destinationChainId,
22358
22392
  destinationTokenAddress,
22393
+ defaultSourceChainType,
22394
+ defaultSourceChainId,
22395
+ defaultSourceTokenAddress,
22396
+ defaultSourceSymbol,
22359
22397
  depositConfirmationMode,
22360
22398
  onExecutionsChange: setDepositExecutions,
22361
22399
  onDepositSuccess,
@@ -22651,6 +22689,10 @@ function UnifoldProvider2({
22651
22689
  destinationChainType: depositConfig.destinationChainType,
22652
22690
  destinationChainId: depositConfig.destinationChainId,
22653
22691
  destinationTokenAddress: depositConfig.destinationTokenAddress,
22692
+ defaultSourceChainType: depositConfig.defaultSourceChainType,
22693
+ defaultSourceChainId: depositConfig.defaultSourceChainId,
22694
+ defaultSourceTokenAddress: depositConfig.defaultSourceTokenAddress,
22695
+ defaultSourceSymbol: depositConfig.defaultSourceSymbol,
22654
22696
  depositConfirmationMode: depositConfig.depositConfirmationMode ?? "auto_ui",
22655
22697
  hideDepositTracker: config?.hideDepositTracker,
22656
22698
  showBalanceHeader: config?.showBalanceHeader,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifold/connect-react",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "description": "Unifold Connect React - Complete React SDK with UI components for crypto deposits",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@tanstack/react-query": "^5.90.11",
34
- "@unifold/core": "0.1.40",
35
- "@unifold/ui-react": "0.1.40",
36
- "@unifold/react-provider": "0.1.40"
34
+ "@unifold/core": "0.1.41",
35
+ "@unifold/react-provider": "0.1.41",
36
+ "@unifold/ui-react": "0.1.41"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/react": "^19.0.0",