@unifold/connect-react 0.1.48 → 0.1.49

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
@@ -149,6 +149,18 @@ interface WithdrawConfig {
149
149
  sourceTokenSymbol?: string;
150
150
  /** Optional: pre-fill the recipient address the user is withdrawing to */
151
151
  recipientAddress?: string;
152
+ /**
153
+ * Pre-select the destination (receive) token/chain in the withdraw view.
154
+ * All four props are optional. To match a specific token, provide `chainType` + `chainId` + (`symbol` OR `tokenAddress`).
155
+ * If omitted or no match is found in `/supported_destination_tokens`, the first available token and chain are used.
156
+ */
157
+ defaultDestinationChainType?: string;
158
+ /** Destination chain ID (e.g. `"mainnet"`, `"137"`). Must be paired with `defaultDestinationChainType` + symbol or token address. */
159
+ defaultDestinationChainId?: string;
160
+ /** Destination token contract address. Must be paired with `defaultDestinationChainType` + `defaultDestinationChainId`. */
161
+ defaultDestinationTokenAddress?: string;
162
+ /** Destination token symbol (e.g. `"USDC"`). Must be paired with `defaultDestinationChainType` + `defaultDestinationChainId`. */
163
+ defaultDestinationSymbol?: string;
152
164
  /**
153
165
  * The user's wallet address (the sender). Used to:
154
166
  * 1. Fetch balance for quick-select chips (25%/50%/75%/MAX)
package/dist/index.d.ts CHANGED
@@ -149,6 +149,18 @@ interface WithdrawConfig {
149
149
  sourceTokenSymbol?: string;
150
150
  /** Optional: pre-fill the recipient address the user is withdrawing to */
151
151
  recipientAddress?: string;
152
+ /**
153
+ * Pre-select the destination (receive) token/chain in the withdraw view.
154
+ * All four props are optional. To match a specific token, provide `chainType` + `chainId` + (`symbol` OR `tokenAddress`).
155
+ * If omitted or no match is found in `/supported_destination_tokens`, the first available token and chain are used.
156
+ */
157
+ defaultDestinationChainType?: string;
158
+ /** Destination chain ID (e.g. `"mainnet"`, `"137"`). Must be paired with `defaultDestinationChainType` + symbol or token address. */
159
+ defaultDestinationChainId?: string;
160
+ /** Destination token contract address. Must be paired with `defaultDestinationChainType` + `defaultDestinationChainId`. */
161
+ defaultDestinationTokenAddress?: string;
162
+ /** Destination token symbol (e.g. `"USDC"`). Must be paired with `defaultDestinationChainType` + `defaultDestinationChainId`. */
163
+ defaultDestinationSymbol?: string;
152
164
  /**
153
165
  * The user's wallet address (the sender). Used to:
154
166
  * 1. Fetch balance for quick-select chips (25%/50%/75%/MAX)
package/dist/index.js CHANGED
@@ -13783,16 +13783,6 @@ function BuyWithCard({
13783
13783
  window.open(sessionStartUrl, "_blank");
13784
13784
  handleViewChange("onramp");
13785
13785
  };
13786
- const getProviderBadges = (quote, allQuotes) => {
13787
- const badges = [];
13788
- const maxDestination = Math.max(
13789
- ...allQuotes.map((q) => q.destination_amount)
13790
- );
13791
- if (quote.destination_amount === maxDestination) {
13792
- badges.push("Best price");
13793
- }
13794
- return badges;
13795
- };
13796
13786
  const sortedQuotes = [...quotes].sort(
13797
13787
  (a, b) => b.destination_amount - a.destination_amount
13798
13788
  );
@@ -13997,31 +13987,7 @@ function BuyWithCard({
13997
13987
  children: selectedProvider.service_provider_display_name
13998
13988
  }
13999
13989
  ),
14000
- /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: [
14001
- isAutoSelected && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
14002
- "span",
14003
- {
14004
- className: "uf-text-[10px] uf-font-normal",
14005
- style: {
14006
- color: colors2.success,
14007
- fontFamily: fonts.regular
14008
- },
14009
- children: "Best price"
14010
- }
14011
- ),
14012
- isAutoSelected && selectedProvider.low_kyc === false && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
14013
- "span",
14014
- {
14015
- className: "uf-text-[10px]",
14016
- style: {
14017
- color: components.card.labelColor,
14018
- fontFamily: fonts.regular
14019
- },
14020
- children: "\u2022"
14021
- }
14022
- ),
14023
- selectedProvider.low_kyc === false && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "uf-text-[10px] uf-text-muted-foreground uf-font-normal", children: "No document upload" })
14024
- ] })
13990
+ selectedProvider.low_kyc === false && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "uf-text-[10px] uf-text-muted-foreground uf-font-normal", children: "No document upload" }) })
14025
13991
  ] }),
14026
13992
  quotes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
14027
13993
  ChevronRight,
@@ -14085,7 +14051,6 @@ function BuyWithCard({
14085
14051
  {
14086
14052
  className: `uf-transition-all uf-duration-300 uf-min-h-[420px] uf-flex uf-flex-col ${showQuotesView && !showOnrampView ? "uf-opacity-100" : "uf-opacity-0 uf-pointer-events-none uf-absolute uf-inset-0"}`,
14087
14053
  children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "uf-space-y-2 uf-pt-2 uf-pb-8 uf-overflow-y-auto uf-flex-1 uf-min-h-0", children: sortedQuotes.map((quote, index2) => {
14088
- const badges = getProviderBadges(quote, sortedQuotes);
14089
14054
  const displayName = quote.service_provider_display_name;
14090
14055
  const isSelected = selectedProvider?.service_provider === quote.service_provider;
14091
14056
  return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
@@ -14128,39 +14093,17 @@ function BuyWithCard({
14128
14093
  children: displayName
14129
14094
  }
14130
14095
  ),
14131
- /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: [
14132
- badges.map((badge, i) => /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
14133
- "span",
14134
- {
14135
- className: "uf-text-[10px] uf-font-normal",
14136
- style: { color: colors2.success },
14137
- children: [
14138
- badge,
14139
- i < badges.length - 1 && ","
14140
- ]
14096
+ quote.low_kyc === false && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
14097
+ "span",
14098
+ {
14099
+ className: "uf-text-[10px] uf-font-normal",
14100
+ style: {
14101
+ color: components.card.subtextRightColor,
14102
+ fontFamily: fonts.regular
14141
14103
  },
14142
- i
14143
- )),
14144
- quote.low_kyc === false && badges.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
14145
- "span",
14146
- {
14147
- className: "uf-text-[10px]",
14148
- style: { color: components.card.subtextRightColor },
14149
- children: "\u2022"
14150
- }
14151
- ),
14152
- quote.low_kyc === false && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
14153
- "span",
14154
- {
14155
- className: "uf-text-[10px] uf-font-normal",
14156
- style: {
14157
- color: components.card.subtextRightColor,
14158
- fontFamily: fonts.regular
14159
- },
14160
- children: "No document upload"
14161
- }
14162
- )
14163
- ] })
14104
+ children: "No document upload"
14105
+ }
14106
+ ) })
14164
14107
  ] })
14165
14108
  ] }),
14166
14109
  /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: "uf-text-right", children: [
@@ -18776,72 +18719,72 @@ function DepositPollingUi({
18776
18719
  var getChainKey = (chainId, chainType) => {
18777
18720
  return `${chainType}:${chainId}`;
18778
18721
  };
18779
- function resolveSourceToken(supportedTokens, defaultSourceChainType, defaultSourceChainId, defaultSourceTokenAddress, defaultSourceSymbol) {
18780
- if (!supportedTokens.length) return null;
18781
- let selectedTokenData;
18782
- let selectedChainData;
18783
- const hasChainDefaults = defaultSourceChainType && defaultSourceChainId;
18784
- if (defaultSourceTokenAddress && hasChainDefaults) {
18785
- for (const t11 of supportedTokens) {
18722
+ function resolveToken(tokens, defaultChainType, defaultChainId, defaultTokenAddress, defaultSymbol) {
18723
+ if (!tokens.length) return null;
18724
+ let selectedToken;
18725
+ let selectedChain;
18726
+ const hasChainDefaults = defaultChainType && defaultChainId;
18727
+ if (defaultTokenAddress && hasChainDefaults) {
18728
+ for (const t11 of tokens) {
18786
18729
  const matchingChain = t11.chains.find(
18787
- (c) => c.token_address.toLowerCase() === defaultSourceTokenAddress.toLowerCase() && c.chain_type === defaultSourceChainType && c.chain_id === defaultSourceChainId
18730
+ (c) => c.token_address.toLowerCase() === defaultTokenAddress.toLowerCase() && c.chain_type === defaultChainType && c.chain_id === defaultChainId
18788
18731
  );
18789
18732
  if (matchingChain) {
18790
- selectedTokenData = t11;
18791
- selectedChainData = matchingChain;
18733
+ selectedToken = t11;
18734
+ selectedChain = matchingChain;
18792
18735
  break;
18793
18736
  }
18794
18737
  }
18795
18738
  }
18796
- if (!selectedTokenData && defaultSourceSymbol && hasChainDefaults) {
18797
- for (const t11 of supportedTokens) {
18798
- if (t11.symbol !== defaultSourceSymbol) continue;
18739
+ if (!selectedToken && defaultSymbol && hasChainDefaults) {
18740
+ for (const t11 of tokens) {
18741
+ if (t11.symbol !== defaultSymbol) continue;
18799
18742
  const matchedChain = t11.chains.find(
18800
- (c) => c.chain_type === defaultSourceChainType && c.chain_id === defaultSourceChainId
18743
+ (c) => c.chain_type === defaultChainType && c.chain_id === defaultChainId
18801
18744
  );
18802
18745
  if (matchedChain) {
18803
- selectedTokenData = t11;
18804
- selectedChainData = matchedChain;
18746
+ selectedToken = t11;
18747
+ selectedChain = matchedChain;
18805
18748
  break;
18806
18749
  }
18807
18750
  }
18808
18751
  }
18809
- if (!selectedTokenData) {
18810
- for (const t11 of supportedTokens) {
18752
+ if (!selectedToken) {
18753
+ for (const t11 of tokens) {
18811
18754
  if (t11.chains.length > 0) {
18812
- selectedTokenData = t11;
18813
- selectedChainData = t11.chains[0];
18755
+ selectedToken = t11;
18756
+ selectedChain = t11.chains[0];
18814
18757
  break;
18815
18758
  }
18816
18759
  }
18817
18760
  }
18818
- if (selectedTokenData && selectedChainData) {
18819
- return { token: selectedTokenData, chain: selectedChainData };
18761
+ if (selectedToken && selectedChain) {
18762
+ return { token: selectedToken, chain: selectedChain };
18820
18763
  }
18821
18764
  return null;
18822
18765
  }
18823
- function useDefaultSourceToken({
18824
- supportedTokens,
18825
- defaultSourceChainType,
18826
- defaultSourceChainId,
18827
- defaultSourceTokenAddress,
18828
- defaultSourceSymbol
18766
+ function useDefaultToken({
18767
+ tokens,
18768
+ defaultChainType,
18769
+ defaultChainId,
18770
+ defaultTokenAddress,
18771
+ defaultSymbol
18829
18772
  }) {
18830
18773
  const [token, setToken] = (0, import_react22.useState)(null);
18831
18774
  const [chain, setChain] = (0, import_react22.useState)(null);
18832
18775
  const [initialSelectionDone, setInitialSelectionDone] = (0, import_react22.useState)(false);
18833
18776
  const appliedDefaultsRef = (0, import_react22.useRef)("");
18834
18777
  (0, import_react22.useEffect)(() => {
18835
- if (!supportedTokens.length) return;
18836
- const defaultsKey = `${defaultSourceTokenAddress ?? ""}|${defaultSourceSymbol ?? ""}|${defaultSourceChainType ?? ""}|${defaultSourceChainId ?? ""}`;
18778
+ if (!tokens.length) return;
18779
+ const defaultsKey = `${defaultTokenAddress ?? ""}|${defaultSymbol ?? ""}|${defaultChainType ?? ""}|${defaultChainId ?? ""}`;
18837
18780
  const defaultsChanged = appliedDefaultsRef.current !== defaultsKey;
18838
18781
  if (initialSelectionDone && !defaultsChanged) return;
18839
- const result = resolveSourceToken(
18840
- supportedTokens,
18841
- defaultSourceChainType,
18842
- defaultSourceChainId,
18843
- defaultSourceTokenAddress,
18844
- defaultSourceSymbol
18782
+ const result = resolveToken(
18783
+ tokens,
18784
+ defaultChainType,
18785
+ defaultChainId,
18786
+ defaultTokenAddress,
18787
+ defaultSymbol
18845
18788
  );
18846
18789
  if (result) {
18847
18790
  setToken(result.token.symbol);
@@ -18850,16 +18793,16 @@ function useDefaultSourceToken({
18850
18793
  setInitialSelectionDone(true);
18851
18794
  }
18852
18795
  }, [
18853
- supportedTokens,
18854
- defaultSourceTokenAddress,
18855
- defaultSourceSymbol,
18856
- defaultSourceChainType,
18857
- defaultSourceChainId,
18796
+ tokens,
18797
+ defaultTokenAddress,
18798
+ defaultSymbol,
18799
+ defaultChainType,
18800
+ defaultChainId,
18858
18801
  initialSelectionDone
18859
18802
  ]);
18860
18803
  (0, import_react22.useEffect)(() => {
18861
- if (!supportedTokens.length || !token) return;
18862
- const currentToken = supportedTokens.find((t11) => t11.symbol === token);
18804
+ if (!tokens.length || !token) return;
18805
+ const currentToken = tokens.find((t11) => t11.symbol === token);
18863
18806
  if (!currentToken || currentToken.chains.length === 0) return;
18864
18807
  const isChainAvailable = chain && currentToken.chains.some((c) => {
18865
18808
  return getChainKey(c.chain_id, c.chain_type) === chain;
@@ -18868,9 +18811,24 @@ function useDefaultSourceToken({
18868
18811
  const firstChain = currentToken.chains[0];
18869
18812
  setChain(getChainKey(firstChain.chain_id, firstChain.chain_type));
18870
18813
  }
18871
- }, [token, supportedTokens, chain]);
18814
+ }, [token, tokens, chain]);
18872
18815
  return { token, chain, setToken, setChain, initialSelectionDone };
18873
18816
  }
18817
+ function useDefaultSourceToken({
18818
+ supportedTokens,
18819
+ defaultSourceChainType,
18820
+ defaultSourceChainId,
18821
+ defaultSourceTokenAddress,
18822
+ defaultSourceSymbol
18823
+ }) {
18824
+ return useDefaultToken({
18825
+ tokens: supportedTokens,
18826
+ defaultChainType: defaultSourceChainType,
18827
+ defaultChainId: defaultSourceChainId,
18828
+ defaultTokenAddress: defaultSourceTokenAddress,
18829
+ defaultSymbol: defaultSourceSymbol
18830
+ });
18831
+ }
18874
18832
  function DepositFooterLinks({
18875
18833
  onGlossaryClick
18876
18834
  }) {
@@ -23824,6 +23782,21 @@ function useSupportedDestinationTokens(publishableKey, enabled = true) {
23824
23782
  enabled
23825
23783
  });
23826
23784
  }
23785
+ function useDefaultDestinationToken({
23786
+ destinationTokens,
23787
+ defaultDestinationChainType,
23788
+ defaultDestinationChainId,
23789
+ defaultDestinationTokenAddress,
23790
+ defaultDestinationSymbol
23791
+ }) {
23792
+ return useDefaultToken({
23793
+ tokens: destinationTokens,
23794
+ defaultChainType: defaultDestinationChainType,
23795
+ defaultChainId: defaultDestinationChainId,
23796
+ defaultTokenAddress: defaultDestinationTokenAddress,
23797
+ defaultSymbol: defaultDestinationSymbol
23798
+ });
23799
+ }
23827
23800
  function useSourceTokenValidation(params) {
23828
23801
  const {
23829
23802
  sourceChainType,
@@ -25070,6 +25043,10 @@ function WithdrawModal({
25070
25043
  sourceTokenSymbol,
25071
25044
  recipientAddress: recipientAddressProp,
25072
25045
  senderAddress,
25046
+ defaultDestinationChainType,
25047
+ defaultDestinationChainId,
25048
+ defaultDestinationTokenAddress,
25049
+ defaultDestinationSymbol,
25073
25050
  onWithdraw,
25074
25051
  onWithdrawSuccess,
25075
25052
  onWithdrawError,
@@ -25113,8 +25090,21 @@ function WithdrawModal({
25113
25090
  publishableKey,
25114
25091
  enabled: open
25115
25092
  });
25116
- const [selectedToken, setSelectedToken] = (0, import_react27.useState)(null);
25117
- const [selectedChain, setSelectedChain] = (0, import_react27.useState)(null);
25093
+ const {
25094
+ token: selectedTokenSymbol,
25095
+ chain: selectedChainKey,
25096
+ setToken: setSelectedTokenSymbol,
25097
+ setChain: setSelectedChainKey,
25098
+ initialSelectionDone
25099
+ } = useDefaultDestinationToken({
25100
+ destinationTokens,
25101
+ defaultDestinationChainType,
25102
+ defaultDestinationChainId,
25103
+ defaultDestinationTokenAddress,
25104
+ defaultDestinationSymbol
25105
+ });
25106
+ const selectedToken = selectedTokenSymbol ? destinationTokens.find((t11) => t11.symbol === selectedTokenSymbol) ?? null : null;
25107
+ const selectedChain = selectedToken && selectedChainKey ? selectedToken.chains.find((c) => getChainKey5(c.chain_id, c.chain_type) === selectedChainKey) ?? null : null;
25118
25108
  const [view, setView] = (0, import_react27.useState)("form");
25119
25109
  const [withdrawDepositWalletId, setWithdrawDepositWalletId] = (0, import_react27.useState)();
25120
25110
  const [selectedExecution, setSelectedExecution] = (0, import_react27.useState)(null);
@@ -25156,21 +25146,11 @@ function WithdrawModal({
25156
25146
  setSubmittedTxInfo(txInfo);
25157
25147
  setView("confirming");
25158
25148
  }, []);
25159
- (0, import_react27.useEffect)(() => {
25160
- if (!destinationTokens.length || selectedToken) return;
25161
- const first = destinationTokens[0];
25162
- if (first?.chains.length > 0) {
25163
- setSelectedToken(first);
25164
- setSelectedChain(first.chains[0]);
25165
- }
25166
- }, [destinationTokens, selectedToken]);
25167
25149
  const resetViewTimeoutRef = (0, import_react27.useRef)(null);
25168
25150
  const handleClose = (0, import_react27.useCallback)(() => {
25169
25151
  onOpenChange(false);
25170
25152
  if (resetViewTimeoutRef.current) clearTimeout(resetViewTimeoutRef.current);
25171
25153
  resetViewTimeoutRef.current = setTimeout(() => {
25172
- setSelectedToken(null);
25173
- setSelectedChain(null);
25174
25154
  setView("form");
25175
25155
  setSelectedExecution(null);
25176
25156
  setSubmittedTxInfo(null);
@@ -25184,8 +25164,6 @@ function WithdrawModal({
25184
25164
  clearTimeout(resetViewTimeoutRef.current);
25185
25165
  resetViewTimeoutRef.current = null;
25186
25166
  }
25187
- setSelectedToken(null);
25188
- setSelectedChain(null);
25189
25167
  setView("form");
25190
25168
  setSelectedExecution(null);
25191
25169
  setSubmittedTxInfo(null);
@@ -25195,19 +25173,13 @@ function WithdrawModal({
25195
25173
  if (resetViewTimeoutRef.current) clearTimeout(resetViewTimeoutRef.current);
25196
25174
  }, []);
25197
25175
  const handleTokenSymbolChange = (0, import_react27.useCallback)((symbol) => {
25198
- const tok = destinationTokens.find((t11) => t11.symbol === symbol);
25199
- if (tok) {
25200
- setSelectedToken(tok);
25201
- if (tok.chains.length > 0) setSelectedChain(tok.chains[0]);
25202
- }
25203
- }, [destinationTokens]);
25176
+ setSelectedTokenSymbol(symbol);
25177
+ }, [setSelectedTokenSymbol]);
25204
25178
  const handleChainKeyChange = (0, import_react27.useCallback)((chainKey) => {
25205
- if (!selectedToken) return;
25206
- const chain = selectedToken.chains.find((c) => getChainKey5(c.chain_id, c.chain_type) === chainKey);
25207
- if (chain) setSelectedChain(chain);
25208
- }, [selectedToken]);
25179
+ setSelectedChainKey(chainKey);
25180
+ }, [setSelectedChainKey]);
25209
25181
  const isSourceSupported = sourceValidation?.isSupported ?? null;
25210
- const isAnyLoading = tokensLoading || isCheckingSourceToken;
25182
+ const isAnyLoading = tokensLoading || isCheckingSourceToken || destinationTokens.length > 0 && !initialSelectionDone;
25211
25183
  const withdrawPoweredByFooter = /* @__PURE__ */ (0, import_jsx_runtime74.jsx)("div", { className: "uf-pt-3", children: /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(PoweredByUnifold, { color: colors2.foregroundMuted, className: "uf-flex uf-justify-center uf-shrink-0" }) });
25212
25184
  return /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(PortalContainerProvider, { value: hideOverlay ? containerEl : null, children: /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(Dialog2, { open: hideOverlay || open, onOpenChange: hideOverlay ? void 0 : handleClose, modal: !hideOverlay, children: /* @__PURE__ */ (0, import_jsx_runtime74.jsx)(
25213
25185
  DialogContent2,
@@ -25620,6 +25592,10 @@ function UnifoldProvider2({
25620
25592
  sourceTokenAddress: withdrawConfig.sourceTokenAddress,
25621
25593
  sourceTokenSymbol: withdrawConfig.sourceTokenSymbol,
25622
25594
  recipientAddress: withdrawConfig.recipientAddress,
25595
+ defaultDestinationChainType: withdrawConfig.defaultDestinationChainType,
25596
+ defaultDestinationChainId: withdrawConfig.defaultDestinationChainId,
25597
+ defaultDestinationTokenAddress: withdrawConfig.defaultDestinationTokenAddress,
25598
+ defaultDestinationSymbol: withdrawConfig.defaultDestinationSymbol,
25623
25599
  senderAddress: withdrawConfig.senderAddress,
25624
25600
  onWithdraw: withdrawConfig.withdraw,
25625
25601
  onWithdrawSuccess: handleWithdrawSuccess,
package/dist/index.mjs CHANGED
@@ -13772,16 +13772,6 @@ function BuyWithCard({
13772
13772
  window.open(sessionStartUrl, "_blank");
13773
13773
  handleViewChange("onramp");
13774
13774
  };
13775
- const getProviderBadges = (quote, allQuotes) => {
13776
- const badges = [];
13777
- const maxDestination = Math.max(
13778
- ...allQuotes.map((q) => q.destination_amount)
13779
- );
13780
- if (quote.destination_amount === maxDestination) {
13781
- badges.push("Best price");
13782
- }
13783
- return badges;
13784
- };
13785
13775
  const sortedQuotes = [...quotes].sort(
13786
13776
  (a, b) => b.destination_amount - a.destination_amount
13787
13777
  );
@@ -13986,31 +13976,7 @@ function BuyWithCard({
13986
13976
  children: selectedProvider.service_provider_display_name
13987
13977
  }
13988
13978
  ),
13989
- /* @__PURE__ */ jsxs8("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: [
13990
- isAutoSelected && /* @__PURE__ */ jsx102(
13991
- "span",
13992
- {
13993
- className: "uf-text-[10px] uf-font-normal",
13994
- style: {
13995
- color: colors2.success,
13996
- fontFamily: fonts.regular
13997
- },
13998
- children: "Best price"
13999
- }
14000
- ),
14001
- isAutoSelected && selectedProvider.low_kyc === false && /* @__PURE__ */ jsx102(
14002
- "span",
14003
- {
14004
- className: "uf-text-[10px]",
14005
- style: {
14006
- color: components.card.labelColor,
14007
- fontFamily: fonts.regular
14008
- },
14009
- children: "\u2022"
14010
- }
14011
- ),
14012
- selectedProvider.low_kyc === false && /* @__PURE__ */ jsx102("span", { className: "uf-text-[10px] uf-text-muted-foreground uf-font-normal", children: "No document upload" })
14013
- ] })
13979
+ selectedProvider.low_kyc === false && /* @__PURE__ */ jsx102("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: /* @__PURE__ */ jsx102("span", { className: "uf-text-[10px] uf-text-muted-foreground uf-font-normal", children: "No document upload" }) })
14014
13980
  ] }),
14015
13981
  quotes.length > 0 && /* @__PURE__ */ jsx102(
14016
13982
  ChevronRight,
@@ -14074,7 +14040,6 @@ function BuyWithCard({
14074
14040
  {
14075
14041
  className: `uf-transition-all uf-duration-300 uf-min-h-[420px] uf-flex uf-flex-col ${showQuotesView && !showOnrampView ? "uf-opacity-100" : "uf-opacity-0 uf-pointer-events-none uf-absolute uf-inset-0"}`,
14076
14042
  children: /* @__PURE__ */ jsx102("div", { className: "uf-space-y-2 uf-pt-2 uf-pb-8 uf-overflow-y-auto uf-flex-1 uf-min-h-0", children: sortedQuotes.map((quote, index2) => {
14077
- const badges = getProviderBadges(quote, sortedQuotes);
14078
14043
  const displayName = quote.service_provider_display_name;
14079
14044
  const isSelected = selectedProvider?.service_provider === quote.service_provider;
14080
14045
  return /* @__PURE__ */ jsxs8(
@@ -14117,39 +14082,17 @@ function BuyWithCard({
14117
14082
  children: displayName
14118
14083
  }
14119
14084
  ),
14120
- /* @__PURE__ */ jsxs8("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: [
14121
- badges.map((badge, i) => /* @__PURE__ */ jsxs8(
14122
- "span",
14123
- {
14124
- className: "uf-text-[10px] uf-font-normal",
14125
- style: { color: colors2.success },
14126
- children: [
14127
- badge,
14128
- i < badges.length - 1 && ","
14129
- ]
14085
+ quote.low_kyc === false && /* @__PURE__ */ jsx102("div", { className: "uf-flex uf-items-center uf-gap-1.5 uf-mt-0.5", children: /* @__PURE__ */ jsx102(
14086
+ "span",
14087
+ {
14088
+ className: "uf-text-[10px] uf-font-normal",
14089
+ style: {
14090
+ color: components.card.subtextRightColor,
14091
+ fontFamily: fonts.regular
14130
14092
  },
14131
- i
14132
- )),
14133
- quote.low_kyc === false && badges.length > 0 && /* @__PURE__ */ jsx102(
14134
- "span",
14135
- {
14136
- className: "uf-text-[10px]",
14137
- style: { color: components.card.subtextRightColor },
14138
- children: "\u2022"
14139
- }
14140
- ),
14141
- quote.low_kyc === false && /* @__PURE__ */ jsx102(
14142
- "span",
14143
- {
14144
- className: "uf-text-[10px] uf-font-normal",
14145
- style: {
14146
- color: components.card.subtextRightColor,
14147
- fontFamily: fonts.regular
14148
- },
14149
- children: "No document upload"
14150
- }
14151
- )
14152
- ] })
14093
+ children: "No document upload"
14094
+ }
14095
+ ) })
14153
14096
  ] })
14154
14097
  ] }),
14155
14098
  /* @__PURE__ */ jsxs8("div", { className: "uf-text-right", children: [
@@ -18765,72 +18708,72 @@ function DepositPollingUi({
18765
18708
  var getChainKey = (chainId, chainType) => {
18766
18709
  return `${chainType}:${chainId}`;
18767
18710
  };
18768
- function resolveSourceToken(supportedTokens, defaultSourceChainType, defaultSourceChainId, defaultSourceTokenAddress, defaultSourceSymbol) {
18769
- if (!supportedTokens.length) return null;
18770
- let selectedTokenData;
18771
- let selectedChainData;
18772
- const hasChainDefaults = defaultSourceChainType && defaultSourceChainId;
18773
- if (defaultSourceTokenAddress && hasChainDefaults) {
18774
- for (const t11 of supportedTokens) {
18711
+ function resolveToken(tokens, defaultChainType, defaultChainId, defaultTokenAddress, defaultSymbol) {
18712
+ if (!tokens.length) return null;
18713
+ let selectedToken;
18714
+ let selectedChain;
18715
+ const hasChainDefaults = defaultChainType && defaultChainId;
18716
+ if (defaultTokenAddress && hasChainDefaults) {
18717
+ for (const t11 of tokens) {
18775
18718
  const matchingChain = t11.chains.find(
18776
- (c) => c.token_address.toLowerCase() === defaultSourceTokenAddress.toLowerCase() && c.chain_type === defaultSourceChainType && c.chain_id === defaultSourceChainId
18719
+ (c) => c.token_address.toLowerCase() === defaultTokenAddress.toLowerCase() && c.chain_type === defaultChainType && c.chain_id === defaultChainId
18777
18720
  );
18778
18721
  if (matchingChain) {
18779
- selectedTokenData = t11;
18780
- selectedChainData = matchingChain;
18722
+ selectedToken = t11;
18723
+ selectedChain = matchingChain;
18781
18724
  break;
18782
18725
  }
18783
18726
  }
18784
18727
  }
18785
- if (!selectedTokenData && defaultSourceSymbol && hasChainDefaults) {
18786
- for (const t11 of supportedTokens) {
18787
- if (t11.symbol !== defaultSourceSymbol) continue;
18728
+ if (!selectedToken && defaultSymbol && hasChainDefaults) {
18729
+ for (const t11 of tokens) {
18730
+ if (t11.symbol !== defaultSymbol) continue;
18788
18731
  const matchedChain = t11.chains.find(
18789
- (c) => c.chain_type === defaultSourceChainType && c.chain_id === defaultSourceChainId
18732
+ (c) => c.chain_type === defaultChainType && c.chain_id === defaultChainId
18790
18733
  );
18791
18734
  if (matchedChain) {
18792
- selectedTokenData = t11;
18793
- selectedChainData = matchedChain;
18735
+ selectedToken = t11;
18736
+ selectedChain = matchedChain;
18794
18737
  break;
18795
18738
  }
18796
18739
  }
18797
18740
  }
18798
- if (!selectedTokenData) {
18799
- for (const t11 of supportedTokens) {
18741
+ if (!selectedToken) {
18742
+ for (const t11 of tokens) {
18800
18743
  if (t11.chains.length > 0) {
18801
- selectedTokenData = t11;
18802
- selectedChainData = t11.chains[0];
18744
+ selectedToken = t11;
18745
+ selectedChain = t11.chains[0];
18803
18746
  break;
18804
18747
  }
18805
18748
  }
18806
18749
  }
18807
- if (selectedTokenData && selectedChainData) {
18808
- return { token: selectedTokenData, chain: selectedChainData };
18750
+ if (selectedToken && selectedChain) {
18751
+ return { token: selectedToken, chain: selectedChain };
18809
18752
  }
18810
18753
  return null;
18811
18754
  }
18812
- function useDefaultSourceToken({
18813
- supportedTokens,
18814
- defaultSourceChainType,
18815
- defaultSourceChainId,
18816
- defaultSourceTokenAddress,
18817
- defaultSourceSymbol
18755
+ function useDefaultToken({
18756
+ tokens,
18757
+ defaultChainType,
18758
+ defaultChainId,
18759
+ defaultTokenAddress,
18760
+ defaultSymbol
18818
18761
  }) {
18819
18762
  const [token, setToken] = useState192(null);
18820
18763
  const [chain, setChain] = useState192(null);
18821
18764
  const [initialSelectionDone, setInitialSelectionDone] = useState192(false);
18822
18765
  const appliedDefaultsRef = useRef52("");
18823
18766
  useEffect162(() => {
18824
- if (!supportedTokens.length) return;
18825
- const defaultsKey = `${defaultSourceTokenAddress ?? ""}|${defaultSourceSymbol ?? ""}|${defaultSourceChainType ?? ""}|${defaultSourceChainId ?? ""}`;
18767
+ if (!tokens.length) return;
18768
+ const defaultsKey = `${defaultTokenAddress ?? ""}|${defaultSymbol ?? ""}|${defaultChainType ?? ""}|${defaultChainId ?? ""}`;
18826
18769
  const defaultsChanged = appliedDefaultsRef.current !== defaultsKey;
18827
18770
  if (initialSelectionDone && !defaultsChanged) return;
18828
- const result = resolveSourceToken(
18829
- supportedTokens,
18830
- defaultSourceChainType,
18831
- defaultSourceChainId,
18832
- defaultSourceTokenAddress,
18833
- defaultSourceSymbol
18771
+ const result = resolveToken(
18772
+ tokens,
18773
+ defaultChainType,
18774
+ defaultChainId,
18775
+ defaultTokenAddress,
18776
+ defaultSymbol
18834
18777
  );
18835
18778
  if (result) {
18836
18779
  setToken(result.token.symbol);
@@ -18839,16 +18782,16 @@ function useDefaultSourceToken({
18839
18782
  setInitialSelectionDone(true);
18840
18783
  }
18841
18784
  }, [
18842
- supportedTokens,
18843
- defaultSourceTokenAddress,
18844
- defaultSourceSymbol,
18845
- defaultSourceChainType,
18846
- defaultSourceChainId,
18785
+ tokens,
18786
+ defaultTokenAddress,
18787
+ defaultSymbol,
18788
+ defaultChainType,
18789
+ defaultChainId,
18847
18790
  initialSelectionDone
18848
18791
  ]);
18849
18792
  useEffect162(() => {
18850
- if (!supportedTokens.length || !token) return;
18851
- const currentToken = supportedTokens.find((t11) => t11.symbol === token);
18793
+ if (!tokens.length || !token) return;
18794
+ const currentToken = tokens.find((t11) => t11.symbol === token);
18852
18795
  if (!currentToken || currentToken.chains.length === 0) return;
18853
18796
  const isChainAvailable = chain && currentToken.chains.some((c) => {
18854
18797
  return getChainKey(c.chain_id, c.chain_type) === chain;
@@ -18857,9 +18800,24 @@ function useDefaultSourceToken({
18857
18800
  const firstChain = currentToken.chains[0];
18858
18801
  setChain(getChainKey(firstChain.chain_id, firstChain.chain_type));
18859
18802
  }
18860
- }, [token, supportedTokens, chain]);
18803
+ }, [token, tokens, chain]);
18861
18804
  return { token, chain, setToken, setChain, initialSelectionDone };
18862
18805
  }
18806
+ function useDefaultSourceToken({
18807
+ supportedTokens,
18808
+ defaultSourceChainType,
18809
+ defaultSourceChainId,
18810
+ defaultSourceTokenAddress,
18811
+ defaultSourceSymbol
18812
+ }) {
18813
+ return useDefaultToken({
18814
+ tokens: supportedTokens,
18815
+ defaultChainType: defaultSourceChainType,
18816
+ defaultChainId: defaultSourceChainId,
18817
+ defaultTokenAddress: defaultSourceTokenAddress,
18818
+ defaultSymbol: defaultSourceSymbol
18819
+ });
18820
+ }
18863
18821
  function DepositFooterLinks({
18864
18822
  onGlossaryClick
18865
18823
  }) {
@@ -23813,6 +23771,21 @@ function useSupportedDestinationTokens(publishableKey, enabled = true) {
23813
23771
  enabled
23814
23772
  });
23815
23773
  }
23774
+ function useDefaultDestinationToken({
23775
+ destinationTokens,
23776
+ defaultDestinationChainType,
23777
+ defaultDestinationChainId,
23778
+ defaultDestinationTokenAddress,
23779
+ defaultDestinationSymbol
23780
+ }) {
23781
+ return useDefaultToken({
23782
+ tokens: destinationTokens,
23783
+ defaultChainType: defaultDestinationChainType,
23784
+ defaultChainId: defaultDestinationChainId,
23785
+ defaultTokenAddress: defaultDestinationTokenAddress,
23786
+ defaultSymbol: defaultDestinationSymbol
23787
+ });
23788
+ }
23816
23789
  function useSourceTokenValidation(params) {
23817
23790
  const {
23818
23791
  sourceChainType,
@@ -25059,6 +25032,10 @@ function WithdrawModal({
25059
25032
  sourceTokenSymbol,
25060
25033
  recipientAddress: recipientAddressProp,
25061
25034
  senderAddress,
25035
+ defaultDestinationChainType,
25036
+ defaultDestinationChainId,
25037
+ defaultDestinationTokenAddress,
25038
+ defaultDestinationSymbol,
25062
25039
  onWithdraw,
25063
25040
  onWithdrawSuccess,
25064
25041
  onWithdrawError,
@@ -25102,8 +25079,21 @@ function WithdrawModal({
25102
25079
  publishableKey,
25103
25080
  enabled: open
25104
25081
  });
25105
- const [selectedToken, setSelectedToken] = useState32(null);
25106
- const [selectedChain, setSelectedChain] = useState32(null);
25082
+ const {
25083
+ token: selectedTokenSymbol,
25084
+ chain: selectedChainKey,
25085
+ setToken: setSelectedTokenSymbol,
25086
+ setChain: setSelectedChainKey,
25087
+ initialSelectionDone
25088
+ } = useDefaultDestinationToken({
25089
+ destinationTokens,
25090
+ defaultDestinationChainType,
25091
+ defaultDestinationChainId,
25092
+ defaultDestinationTokenAddress,
25093
+ defaultDestinationSymbol
25094
+ });
25095
+ const selectedToken = selectedTokenSymbol ? destinationTokens.find((t11) => t11.symbol === selectedTokenSymbol) ?? null : null;
25096
+ const selectedChain = selectedToken && selectedChainKey ? selectedToken.chains.find((c) => getChainKey5(c.chain_id, c.chain_type) === selectedChainKey) ?? null : null;
25107
25097
  const [view, setView] = useState32("form");
25108
25098
  const [withdrawDepositWalletId, setWithdrawDepositWalletId] = useState32();
25109
25099
  const [selectedExecution, setSelectedExecution] = useState32(null);
@@ -25145,21 +25135,11 @@ function WithdrawModal({
25145
25135
  setSubmittedTxInfo(txInfo);
25146
25136
  setView("confirming");
25147
25137
  }, []);
25148
- useEffect272(() => {
25149
- if (!destinationTokens.length || selectedToken) return;
25150
- const first = destinationTokens[0];
25151
- if (first?.chains.length > 0) {
25152
- setSelectedToken(first);
25153
- setSelectedChain(first.chains[0]);
25154
- }
25155
- }, [destinationTokens, selectedToken]);
25156
25138
  const resetViewTimeoutRef = useRef102(null);
25157
25139
  const handleClose = useCallback72(() => {
25158
25140
  onOpenChange(false);
25159
25141
  if (resetViewTimeoutRef.current) clearTimeout(resetViewTimeoutRef.current);
25160
25142
  resetViewTimeoutRef.current = setTimeout(() => {
25161
- setSelectedToken(null);
25162
- setSelectedChain(null);
25163
25143
  setView("form");
25164
25144
  setSelectedExecution(null);
25165
25145
  setSubmittedTxInfo(null);
@@ -25173,8 +25153,6 @@ function WithdrawModal({
25173
25153
  clearTimeout(resetViewTimeoutRef.current);
25174
25154
  resetViewTimeoutRef.current = null;
25175
25155
  }
25176
- setSelectedToken(null);
25177
- setSelectedChain(null);
25178
25156
  setView("form");
25179
25157
  setSelectedExecution(null);
25180
25158
  setSubmittedTxInfo(null);
@@ -25184,19 +25162,13 @@ function WithdrawModal({
25184
25162
  if (resetViewTimeoutRef.current) clearTimeout(resetViewTimeoutRef.current);
25185
25163
  }, []);
25186
25164
  const handleTokenSymbolChange = useCallback72((symbol) => {
25187
- const tok = destinationTokens.find((t11) => t11.symbol === symbol);
25188
- if (tok) {
25189
- setSelectedToken(tok);
25190
- if (tok.chains.length > 0) setSelectedChain(tok.chains[0]);
25191
- }
25192
- }, [destinationTokens]);
25165
+ setSelectedTokenSymbol(symbol);
25166
+ }, [setSelectedTokenSymbol]);
25193
25167
  const handleChainKeyChange = useCallback72((chainKey) => {
25194
- if (!selectedToken) return;
25195
- const chain = selectedToken.chains.find((c) => getChainKey5(c.chain_id, c.chain_type) === chainKey);
25196
- if (chain) setSelectedChain(chain);
25197
- }, [selectedToken]);
25168
+ setSelectedChainKey(chainKey);
25169
+ }, [setSelectedChainKey]);
25198
25170
  const isSourceSupported = sourceValidation?.isSupported ?? null;
25199
- const isAnyLoading = tokensLoading || isCheckingSourceToken;
25171
+ const isAnyLoading = tokensLoading || isCheckingSourceToken || destinationTokens.length > 0 && !initialSelectionDone;
25200
25172
  const withdrawPoweredByFooter = /* @__PURE__ */ jsx57("div", { className: "uf-pt-3", children: /* @__PURE__ */ jsx57(PoweredByUnifold, { color: colors2.foregroundMuted, className: "uf-flex uf-justify-center uf-shrink-0" }) });
25201
25173
  return /* @__PURE__ */ jsx57(PortalContainerProvider, { value: hideOverlay ? containerEl : null, children: /* @__PURE__ */ jsx57(Dialog2, { open: hideOverlay || open, onOpenChange: hideOverlay ? void 0 : handleClose, modal: !hideOverlay, children: /* @__PURE__ */ jsx57(
25202
25174
  DialogContent2,
@@ -25609,6 +25581,10 @@ function UnifoldProvider2({
25609
25581
  sourceTokenAddress: withdrawConfig.sourceTokenAddress,
25610
25582
  sourceTokenSymbol: withdrawConfig.sourceTokenSymbol,
25611
25583
  recipientAddress: withdrawConfig.recipientAddress,
25584
+ defaultDestinationChainType: withdrawConfig.defaultDestinationChainType,
25585
+ defaultDestinationChainId: withdrawConfig.defaultDestinationChainId,
25586
+ defaultDestinationTokenAddress: withdrawConfig.defaultDestinationTokenAddress,
25587
+ defaultDestinationSymbol: withdrawConfig.defaultDestinationSymbol,
25612
25588
  senderAddress: withdrawConfig.senderAddress,
25613
25589
  onWithdraw: withdrawConfig.withdraw,
25614
25590
  onWithdrawSuccess: handleWithdrawSuccess,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifold/connect-react",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
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",
@@ -26,9 +26,9 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@tanstack/react-query": "^5.90.11",
29
- "@unifold/core": "0.1.48",
30
- "@unifold/react-provider": "0.1.48",
31
- "@unifold/ui-react": "0.1.48"
29
+ "@unifold/core": "0.1.49",
30
+ "@unifold/ui-react": "0.1.49",
31
+ "@unifold/react-provider": "0.1.49"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/react": "^19.0.0",