@trustware/sdk-staging 1.1.12-staging.2 → 1.1.12-staging.3

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.cjs CHANGED
@@ -514,7 +514,7 @@ var init_constants = __esm({
514
514
  "src/constants.ts"() {
515
515
  "use strict";
516
516
  SDK_NAME = "@trustware/sdk";
517
- SDK_VERSION = "1.1.12-staging.2";
517
+ SDK_VERSION = "1.1.12-staging.3";
518
518
  API_ROOT = "https://bv-staging-api.trustware.io";
519
519
  GTM_ID = "GTM-TZDGNCXB";
520
520
  API_PREFIX = "/api";
@@ -5679,6 +5679,15 @@ function isNativeTokenAddress(address, chainType) {
5679
5679
  if (!chainType) return false;
5680
5680
  return normalizeAddress2(address, chainType) === normalizeAddress2(getNativeTokenAddress2(chainType), chainType);
5681
5681
  }
5682
+ function isEvmAddress2(value) {
5683
+ return !!value && EVM_ADDRESS_RE.test(value);
5684
+ }
5685
+ function needsErc20Approval(tokenAddress, chainType) {
5686
+ if (!isEvmAddress2(tokenAddress)) return false;
5687
+ const normalizedType = normalizeChainType2(chainType ?? void 0);
5688
+ if (normalizedType && NON_EVM_CHAIN_TYPES.has(normalizedType)) return false;
5689
+ return !isNativeTokenAddress(tokenAddress, chainType) && !isZeroAddrLike(tokenAddress, chainType);
5690
+ }
5682
5691
  function canonicalTokenAddressForChain(chain, address, chainTokens = []) {
5683
5692
  const chainType = normalizeChainType2(chain);
5684
5693
  const rawAddress = (address ?? "").trim();
@@ -5701,7 +5710,7 @@ function canonicalTokenAddressForChain(chain, address, chainTokens = []) {
5701
5710
  }
5702
5711
  return lowerAddress;
5703
5712
  }
5704
- var NATIVE_EVM2, NATIVE_SOLANA2, CHAIN_TYPE_ALIASES2, SEI_EVM_CHAIN_ID, SEI_COSMOS_CHAIN_ID;
5713
+ var NATIVE_EVM2, NATIVE_SOLANA2, CHAIN_TYPE_ALIASES2, SEI_EVM_CHAIN_ID, SEI_COSMOS_CHAIN_ID, EVM_ADDRESS_RE, NON_EVM_CHAIN_TYPES;
5705
5714
  var init_chainHelpers = __esm({
5706
5715
  "src/widget/helpers/chainHelpers.ts"() {
5707
5716
  "use strict";
@@ -5717,6 +5726,8 @@ var init_chainHelpers = __esm({
5717
5726
  };
5718
5727
  SEI_EVM_CHAIN_ID = "1329";
5719
5728
  SEI_COSMOS_CHAIN_ID = "pacific-1";
5729
+ EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
5730
+ NON_EVM_CHAIN_TYPES = /* @__PURE__ */ new Set(["solana", "bitcoin", "btc"]);
5720
5731
  }
5721
5732
  });
5722
5733
 
@@ -33841,8 +33852,7 @@ function useSwapExecution(fromChain) {
33841
33852
  return;
33842
33853
  }
33843
33854
  const chainType = normalizeChainType2(fromChain);
33844
- const isNative = !fromTokenAddress || isNativeTokenAddress(fromTokenAddress, chainType) || isZeroAddrLike(fromTokenAddress, chainType);
33845
- if (isNative) {
33855
+ if (!needsErc20Approval(fromTokenAddress, chainType)) {
33846
33856
  setState((p) => ({ ...p, allowanceStatus: "sufficient" }));
33847
33857
  return;
33848
33858
  }
@@ -33856,7 +33866,7 @@ function useSwapExecution(fromChain) {
33856
33866
  BigInt(a.amount || "0"),
33857
33867
  amountWei
33858
33868
  );
33859
- if (!token || !a.spender) return [];
33869
+ if (!isEvmAddress2(token) || !isEvmAddress2(a.spender)) return [];
33860
33870
  return [
33861
33871
  {
33862
33872
  chainId: a.chainId || chainIdStr,
@@ -34004,7 +34014,8 @@ function useSwapExecution(fromChain) {
34004
34014
  const requiredApprovals = plannedApprovals.length ? plannedApprovals.flatMap((a, index) => {
34005
34015
  const token = a.tokenAddress ?? fromTokenAddress;
34006
34016
  const approvalSpender = a.spender;
34007
- if (!token || !approvalSpender) return [];
34017
+ if (!isEvmAddress2(token) || !isEvmAddress2(approvalSpender))
34018
+ return [];
34008
34019
  const amountWei = requiredApprovalAmount(
34009
34020
  BigInt(a.amount || "0"),
34010
34021
  fromAmountWei
@@ -34027,7 +34038,8 @@ function useSwapExecution(fromChain) {
34027
34038
  chainId: chainIdStr
34028
34039
  }
34029
34040
  ] : [];
34030
- const ownsApprovals = !isNative && !!walletAddress && !!chainIdStr;
34041
+ const coversEveryPlannedApproval = plannedApprovals.length === 0 || requiredApprovals.length === plannedApprovals.length;
34042
+ const ownsApprovals = coversEveryPlannedApproval && needsErc20Approval(fromTokenAddress, chainType) && !!walletAddress && !!chainIdStr;
34031
34043
  const activeAddress = ownsApprovals ? await requireActiveAddress(wallet, walletAddress) : void 0;
34032
34044
  for (const required of requiredApprovals) {
34033
34045
  if (!ownsApprovals) break;
@@ -36208,6 +36220,10 @@ function SwapMode({
36208
36220
  }, [lockDestToken, fromToken, fromChain, toToken, toChain, route, emitEvent]);
36209
36221
  const fromChainType = normalizeChainType2(fromChain);
36210
36222
  const toChainType = normalizeChainType2(toChain);
36223
+ const canSetMaxApproval = needsErc20Approval(
36224
+ fromToken?.address,
36225
+ fromChainType
36226
+ );
36211
36227
  const needsDestAddress = !!fromChainType && !!toChainType && fromChainType !== toChainType;
36212
36228
  const isValidDestAddress = !needsDestAddress || validateDestAddress(destAddress, toChainType ?? "");
36213
36229
  const handleReview = (0, import_react50.useCallback)(async () => {
@@ -38428,7 +38444,7 @@ function SwapMode({
38428
38444
  }
38429
38445
  )
38430
38446
  ] }),
38431
- /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("div", { style: { marginBottom: spacing[4] }, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(
38447
+ canSetMaxApproval && /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("div", { style: { marginBottom: spacing[4] }, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(
38432
38448
  "div",
38433
38449
  {
38434
38450
  style: {