@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.mjs CHANGED
@@ -492,7 +492,7 @@ var init_constants = __esm({
492
492
  "src/constants.ts"() {
493
493
  "use strict";
494
494
  SDK_NAME = "@trustware/sdk";
495
- SDK_VERSION = "1.1.12-staging.2";
495
+ SDK_VERSION = "1.1.12-staging.3";
496
496
  API_ROOT = "https://bv-staging-api.trustware.io";
497
497
  GTM_ID = "GTM-TZDGNCXB";
498
498
  API_PREFIX = "/api";
@@ -5657,6 +5657,15 @@ function isNativeTokenAddress(address, chainType) {
5657
5657
  if (!chainType) return false;
5658
5658
  return normalizeAddress2(address, chainType) === normalizeAddress2(getNativeTokenAddress2(chainType), chainType);
5659
5659
  }
5660
+ function isEvmAddress2(value) {
5661
+ return !!value && EVM_ADDRESS_RE.test(value);
5662
+ }
5663
+ function needsErc20Approval(tokenAddress, chainType) {
5664
+ if (!isEvmAddress2(tokenAddress)) return false;
5665
+ const normalizedType = normalizeChainType2(chainType ?? void 0);
5666
+ if (normalizedType && NON_EVM_CHAIN_TYPES.has(normalizedType)) return false;
5667
+ return !isNativeTokenAddress(tokenAddress, chainType) && !isZeroAddrLike(tokenAddress, chainType);
5668
+ }
5660
5669
  function canonicalTokenAddressForChain(chain, address, chainTokens = []) {
5661
5670
  const chainType = normalizeChainType2(chain);
5662
5671
  const rawAddress = (address ?? "").trim();
@@ -5679,7 +5688,7 @@ function canonicalTokenAddressForChain(chain, address, chainTokens = []) {
5679
5688
  }
5680
5689
  return lowerAddress;
5681
5690
  }
5682
- var NATIVE_EVM2, NATIVE_SOLANA2, CHAIN_TYPE_ALIASES2, SEI_EVM_CHAIN_ID, SEI_COSMOS_CHAIN_ID;
5691
+ var NATIVE_EVM2, NATIVE_SOLANA2, CHAIN_TYPE_ALIASES2, SEI_EVM_CHAIN_ID, SEI_COSMOS_CHAIN_ID, EVM_ADDRESS_RE, NON_EVM_CHAIN_TYPES;
5683
5692
  var init_chainHelpers = __esm({
5684
5693
  "src/widget/helpers/chainHelpers.ts"() {
5685
5694
  "use strict";
@@ -5695,6 +5704,8 @@ var init_chainHelpers = __esm({
5695
5704
  };
5696
5705
  SEI_EVM_CHAIN_ID = "1329";
5697
5706
  SEI_COSMOS_CHAIN_ID = "pacific-1";
5707
+ EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
5708
+ NON_EVM_CHAIN_TYPES = /* @__PURE__ */ new Set(["solana", "bitcoin", "btc"]);
5698
5709
  }
5699
5710
  });
5700
5711
 
@@ -33784,8 +33795,7 @@ function useSwapExecution(fromChain) {
33784
33795
  return;
33785
33796
  }
33786
33797
  const chainType = normalizeChainType2(fromChain);
33787
- const isNative = !fromTokenAddress || isNativeTokenAddress(fromTokenAddress, chainType) || isZeroAddrLike(fromTokenAddress, chainType);
33788
- if (isNative) {
33798
+ if (!needsErc20Approval(fromTokenAddress, chainType)) {
33789
33799
  setState((p) => ({ ...p, allowanceStatus: "sufficient" }));
33790
33800
  return;
33791
33801
  }
@@ -33799,7 +33809,7 @@ function useSwapExecution(fromChain) {
33799
33809
  BigInt(a.amount || "0"),
33800
33810
  amountWei
33801
33811
  );
33802
- if (!token || !a.spender) return [];
33812
+ if (!isEvmAddress2(token) || !isEvmAddress2(a.spender)) return [];
33803
33813
  return [
33804
33814
  {
33805
33815
  chainId: a.chainId || chainIdStr,
@@ -33947,7 +33957,8 @@ function useSwapExecution(fromChain) {
33947
33957
  const requiredApprovals = plannedApprovals.length ? plannedApprovals.flatMap((a, index) => {
33948
33958
  const token = a.tokenAddress ?? fromTokenAddress;
33949
33959
  const approvalSpender = a.spender;
33950
- if (!token || !approvalSpender) return [];
33960
+ if (!isEvmAddress2(token) || !isEvmAddress2(approvalSpender))
33961
+ return [];
33951
33962
  const amountWei = requiredApprovalAmount(
33952
33963
  BigInt(a.amount || "0"),
33953
33964
  fromAmountWei
@@ -33970,7 +33981,8 @@ function useSwapExecution(fromChain) {
33970
33981
  chainId: chainIdStr
33971
33982
  }
33972
33983
  ] : [];
33973
- const ownsApprovals = !isNative && !!walletAddress && !!chainIdStr;
33984
+ const coversEveryPlannedApproval = plannedApprovals.length === 0 || requiredApprovals.length === plannedApprovals.length;
33985
+ const ownsApprovals = coversEveryPlannedApproval && needsErc20Approval(fromTokenAddress, chainType) && !!walletAddress && !!chainIdStr;
33974
33986
  const activeAddress = ownsApprovals ? await requireActiveAddress(wallet, walletAddress) : void 0;
33975
33987
  for (const required of requiredApprovals) {
33976
33988
  if (!ownsApprovals) break;
@@ -36158,6 +36170,10 @@ function SwapMode({
36158
36170
  }, [lockDestToken, fromToken, fromChain, toToken, toChain, route, emitEvent]);
36159
36171
  const fromChainType = normalizeChainType2(fromChain);
36160
36172
  const toChainType = normalizeChainType2(toChain);
36173
+ const canSetMaxApproval = needsErc20Approval(
36174
+ fromToken?.address,
36175
+ fromChainType
36176
+ );
36161
36177
  const needsDestAddress = !!fromChainType && !!toChainType && fromChainType !== toChainType;
36162
36178
  const isValidDestAddress = !needsDestAddress || validateDestAddress(destAddress, toChainType ?? "");
36163
36179
  const handleReview = useCallback22(async () => {
@@ -38378,7 +38394,7 @@ function SwapMode({
38378
38394
  }
38379
38395
  )
38380
38396
  ] }),
38381
- /* @__PURE__ */ jsx59("div", { style: { marginBottom: spacing[4] }, children: /* @__PURE__ */ jsxs47(
38397
+ canSetMaxApproval && /* @__PURE__ */ jsx59("div", { style: { marginBottom: spacing[4] }, children: /* @__PURE__ */ jsxs47(
38382
38398
  "div",
38383
38399
  {
38384
38400
  style: {