@trustware/sdk-staging 1.1.12-staging.1 → 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/wallet.cjs CHANGED
@@ -264,7 +264,7 @@ var init_constants = __esm({
264
264
  "src/constants.ts"() {
265
265
  "use strict";
266
266
  SDK_NAME = "@trustware/sdk";
267
- SDK_VERSION = "1.1.12-staging.1";
267
+ SDK_VERSION = "1.1.12-staging.3";
268
268
  API_ROOT = "https://bv-staging-api.trustware.io";
269
269
  API_PREFIX = "/api";
270
270
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
package/dist/wallet.mjs CHANGED
@@ -238,7 +238,7 @@ var init_constants = __esm({
238
238
  "src/constants.ts"() {
239
239
  "use strict";
240
240
  SDK_NAME = "@trustware/sdk";
241
- SDK_VERSION = "1.1.12-staging.1";
241
+ SDK_VERSION = "1.1.12-staging.3";
242
242
  API_ROOT = "https://bv-staging-api.trustware.io";
243
243
  API_PREFIX = "/api";
244
244
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
package/dist/widget.cjs CHANGED
@@ -593,7 +593,7 @@ var init_constants = __esm({
593
593
  "src/constants.ts"() {
594
594
  "use strict";
595
595
  SDK_NAME = "@trustware/sdk";
596
- SDK_VERSION = "1.1.12-staging.1";
596
+ SDK_VERSION = "1.1.12-staging.3";
597
597
  API_ROOT = "https://bv-staging-api.trustware.io";
598
598
  GTM_ID = "GTM-TZDGNCXB";
599
599
  API_PREFIX = "/api";
@@ -3232,6 +3232,15 @@ function isNativeTokenAddress(address, chainType) {
3232
3232
  if (!chainType) return false;
3233
3233
  return normalizeAddress2(address, chainType) === normalizeAddress2(getNativeTokenAddress2(chainType), chainType);
3234
3234
  }
3235
+ function isEvmAddress2(value) {
3236
+ return !!value && EVM_ADDRESS_RE.test(value);
3237
+ }
3238
+ function needsErc20Approval(tokenAddress, chainType) {
3239
+ if (!isEvmAddress2(tokenAddress)) return false;
3240
+ const normalizedType = normalizeChainType2(chainType ?? void 0);
3241
+ if (normalizedType && NON_EVM_CHAIN_TYPES.has(normalizedType)) return false;
3242
+ return !isNativeTokenAddress(tokenAddress, chainType) && !isZeroAddrLike(tokenAddress, chainType);
3243
+ }
3235
3244
  function canonicalTokenAddressForChain(chain, address, chainTokens = []) {
3236
3245
  const chainType = normalizeChainType2(chain);
3237
3246
  const rawAddress = (address ?? "").trim();
@@ -3254,7 +3263,7 @@ function canonicalTokenAddressForChain(chain, address, chainTokens = []) {
3254
3263
  }
3255
3264
  return lowerAddress;
3256
3265
  }
3257
- var NATIVE_EVM2, NATIVE_SOLANA2, CHAIN_TYPE_ALIASES2, SEI_EVM_CHAIN_ID, SEI_COSMOS_CHAIN_ID;
3266
+ var NATIVE_EVM2, NATIVE_SOLANA2, CHAIN_TYPE_ALIASES2, SEI_EVM_CHAIN_ID, SEI_COSMOS_CHAIN_ID, EVM_ADDRESS_RE, NON_EVM_CHAIN_TYPES;
3258
3267
  var init_chainHelpers = __esm({
3259
3268
  "src/widget/helpers/chainHelpers.ts"() {
3260
3269
  "use strict";
@@ -3270,6 +3279,8 @@ var init_chainHelpers = __esm({
3270
3279
  };
3271
3280
  SEI_EVM_CHAIN_ID = "1329";
3272
3281
  SEI_COSMOS_CHAIN_ID = "pacific-1";
3282
+ EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
3283
+ NON_EVM_CHAIN_TYPES = /* @__PURE__ */ new Set(["solana", "bitcoin", "btc"]);
3273
3284
  }
3274
3285
  });
3275
3286
 
@@ -31719,7 +31730,18 @@ async function sendRouteAsUserOperation(params) {
31719
31730
  );
31720
31731
  }
31721
31732
  console.debug("[send] UserOp included", { userOpHash, txHash });
31722
- await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
31733
+ try {
31734
+ void submitReceipt(
31735
+ intentId,
31736
+ txHash,
31737
+ getSponsorshipRequestId(),
31738
+ eoaAddress
31739
+ ).catch((err) => {
31740
+ console.debug("[send] receipt submission failed (non-fatal)", err);
31741
+ });
31742
+ } catch (err) {
31743
+ console.debug("[send] receipt submission failed (non-fatal)", err);
31744
+ }
31723
31745
  return { userOpHash, txHash, intentId };
31724
31746
  }
31725
31747
  var NATIVE_ADDRS;
@@ -33667,8 +33689,7 @@ function useSwapExecution(fromChain) {
33667
33689
  return;
33668
33690
  }
33669
33691
  const chainType = normalizeChainType2(fromChain);
33670
- const isNative = !fromTokenAddress || isNativeTokenAddress(fromTokenAddress, chainType) || isZeroAddrLike(fromTokenAddress, chainType);
33671
- if (isNative) {
33692
+ if (!needsErc20Approval(fromTokenAddress, chainType)) {
33672
33693
  setState((p) => ({ ...p, allowanceStatus: "sufficient" }));
33673
33694
  return;
33674
33695
  }
@@ -33682,7 +33703,7 @@ function useSwapExecution(fromChain) {
33682
33703
  BigInt(a.amount || "0"),
33683
33704
  amountWei
33684
33705
  );
33685
- if (!token || !a.spender) return [];
33706
+ if (!isEvmAddress2(token) || !isEvmAddress2(a.spender)) return [];
33686
33707
  return [
33687
33708
  {
33688
33709
  chainId: a.chainId || chainIdStr,
@@ -33830,7 +33851,8 @@ function useSwapExecution(fromChain) {
33830
33851
  const requiredApprovals = plannedApprovals.length ? plannedApprovals.flatMap((a, index) => {
33831
33852
  const token = a.tokenAddress ?? fromTokenAddress;
33832
33853
  const approvalSpender = a.spender;
33833
- if (!token || !approvalSpender) return [];
33854
+ if (!isEvmAddress2(token) || !isEvmAddress2(approvalSpender))
33855
+ return [];
33834
33856
  const amountWei = requiredApprovalAmount(
33835
33857
  BigInt(a.amount || "0"),
33836
33858
  fromAmountWei
@@ -33853,7 +33875,8 @@ function useSwapExecution(fromChain) {
33853
33875
  chainId: chainIdStr
33854
33876
  }
33855
33877
  ] : [];
33856
- const ownsApprovals = !isNative && !!walletAddress && !!chainIdStr;
33878
+ const coversEveryPlannedApproval = plannedApprovals.length === 0 || requiredApprovals.length === plannedApprovals.length;
33879
+ const ownsApprovals = coversEveryPlannedApproval && needsErc20Approval(fromTokenAddress, chainType) && !!walletAddress && !!chainIdStr;
33857
33880
  const activeAddress = ownsApprovals ? await requireActiveAddress(wallet, walletAddress) : void 0;
33858
33881
  for (const required of requiredApprovals) {
33859
33882
  if (!ownsApprovals) break;
@@ -33943,10 +33966,6 @@ function useSwapExecution(fromChain) {
33943
33966
  numericChainId,
33944
33967
  { approvalsEnsured: ownsApprovals }
33945
33968
  );
33946
- try {
33947
- await submitReceipt(routeResult.intentId, hash);
33948
- } catch {
33949
- }
33950
33969
  setState((p) => ({
33951
33970
  ...p,
33952
33971
  isSubmitting: false,
@@ -33955,6 +33974,8 @@ function useSwapExecution(fromChain) {
33955
33974
  txStatus: "processing"
33956
33975
  }));
33957
33976
  startPolling(routeResult.intentId, onSuccess, onError);
33977
+ void submitReceipt(routeResult.intentId, hash).catch(() => {
33978
+ });
33958
33979
  } catch (err) {
33959
33980
  const msg = mapTxError(err);
33960
33981
  setState((p) => ({
@@ -36036,6 +36057,10 @@ function SwapMode({
36036
36057
  }, [lockDestToken, fromToken, fromChain, toToken, toChain, route, emitEvent]);
36037
36058
  const fromChainType = normalizeChainType2(fromChain);
36038
36059
  const toChainType = normalizeChainType2(toChain);
36060
+ const canSetMaxApproval = needsErc20Approval(
36061
+ fromToken?.address,
36062
+ fromChainType
36063
+ );
36039
36064
  const needsDestAddress = !!fromChainType && !!toChainType && fromChainType !== toChainType;
36040
36065
  const isValidDestAddress = !needsDestAddress || validateDestAddress(destAddress, toChainType ?? "");
36041
36066
  const handleReview = (0, import_react50.useCallback)(async () => {
@@ -36390,6 +36415,7 @@ function SwapMode({
36390
36415
  }, [route.loading]);
36391
36416
  (0, import_react50.useEffect)(() => {
36392
36417
  if (!route.data) return;
36418
+ if (stage !== "home" && stage !== "review") return;
36393
36419
  const id = setInterval(() => {
36394
36420
  const ts = quoteTimestampRef.current;
36395
36421
  if (ts === null) return;
@@ -36401,7 +36427,11 @@ function SwapMode({
36401
36427
  }
36402
36428
  }, 1e3);
36403
36429
  return () => clearInterval(id);
36404
- }, [route.data]);
36430
+ }, [route.data, stage]);
36431
+ const handleRetryQuote = (0, import_react50.useCallback)(() => {
36432
+ if (!latestFetchParamsRef.current) return;
36433
+ void fetchRef.current(latestFetchParamsRef.current);
36434
+ }, []);
36405
36435
  (0, import_react50.useEffect)(() => {
36406
36436
  if (stage !== "review") return;
36407
36437
  if (!route.data || !walletAddress) return;
@@ -37930,6 +37960,10 @@ function SwapMode({
37930
37960
  txStatus: execution.txStatus,
37931
37961
  isSubmitting: execution.isSubmitting,
37932
37962
  isGasSponsored,
37963
+ hasQuote: !!route.data,
37964
+ isQuoteRefreshing: route.loading,
37965
+ quoteError: route.error,
37966
+ onRetryQuote: handleRetryQuote,
37933
37967
  onExecute: () => void handleExecute()
37934
37968
  }
37935
37969
  )
@@ -38247,7 +38281,7 @@ function SwapMode({
38247
38281
  }
38248
38282
  )
38249
38283
  ] }),
38250
- /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("div", { style: { marginBottom: spacing[4] }, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(
38284
+ canSetMaxApproval && /* @__PURE__ */ (0, import_jsx_runtime59.jsx)("div", { style: { marginBottom: spacing[4] }, children: /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(
38251
38285
  "div",
38252
38286
  {
38253
38287
  style: {
@@ -39266,10 +39300,15 @@ function SwapActionArea({
39266
39300
  txStatus,
39267
39301
  isSubmitting,
39268
39302
  isGasSponsored,
39303
+ hasQuote,
39304
+ isQuoteRefreshing,
39305
+ quoteError,
39306
+ onRetryQuote,
39269
39307
  onExecute
39270
39308
  }) {
39271
39309
  const needsApproval = allowanceStatus === "needed" && !isGasSponsored;
39272
39310
  const isChecking = allowanceStatus === "checking";
39311
+ const quoteUnavailable = !hasQuote && !isQuoteRefreshing && !isSubmitting && txStatus === "idle";
39273
39312
  let label;
39274
39313
  if (isChecking) {
39275
39314
  label = "Checking approval...";
@@ -39277,12 +39316,14 @@ function SwapActionArea({
39277
39316
  label = `Approving ${fromTokenSymbol}...`;
39278
39317
  } else if (isSubmitting) {
39279
39318
  label = "Confirm in wallet...";
39319
+ } else if (isQuoteRefreshing) {
39320
+ label = "Refreshing quote...";
39280
39321
  } else if (needsApproval) {
39281
39322
  label = `Approve ${fromTokenSymbol}`;
39282
39323
  } else {
39283
39324
  label = "Swap";
39284
39325
  }
39285
- const isDisabled = isSubmitting || isChecking;
39326
+ const isDisabled = isSubmitting || isChecking || isQuoteRefreshing || !hasQuote;
39286
39327
  return /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)("div", { style: { marginTop: spacing[6] }, children: [
39287
39328
  isGasSponsored && !isSubmitting && /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(
39288
39329
  "div",
@@ -39322,7 +39363,38 @@ function SwapActionArea({
39322
39363
  ]
39323
39364
  }
39324
39365
  ),
39325
- /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39366
+ quoteUnavailable ? /* @__PURE__ */ (0, import_jsx_runtime59.jsxs)(import_jsx_runtime59.Fragment, { children: [
39367
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39368
+ "p",
39369
+ {
39370
+ style: {
39371
+ fontSize: fontSize.xs,
39372
+ color: colors.destructive,
39373
+ textAlign: "center",
39374
+ marginBottom: spacing[3]
39375
+ },
39376
+ children: quoteError ?? "This quote expired."
39377
+ }
39378
+ ),
39379
+ /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39380
+ "button",
39381
+ {
39382
+ onClick: onRetryQuote,
39383
+ style: {
39384
+ width: "100%",
39385
+ height: "3.5rem",
39386
+ borderRadius: "1.5rem",
39387
+ backgroundColor: colors.primary,
39388
+ color: colors.primaryForeground,
39389
+ fontSize: fontSize.base,
39390
+ fontWeight: fontWeight.semibold,
39391
+ border: 0,
39392
+ cursor: "pointer"
39393
+ },
39394
+ children: "Get a new quote"
39395
+ }
39396
+ )
39397
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime59.jsx)(
39326
39398
  "button",
39327
39399
  {
39328
39400
  onClick: onExecute,