@trustware/sdk-staging 1.1.9-staging.7 → 1.1.11-staging.1
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/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-DzqVEWwP.d.ts → core-BgYLe9Q7.d.ts} +15 -2
- package/dist/{core-gNyi5xsp.d.cts → core-fLSt4qD2.d.cts} +15 -2
- package/dist/core.cjs +318 -145
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +318 -144
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +407 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +433 -140
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-Dn4muk74.d.ts → manager-BY3NHAks.d.ts} +138 -2
- package/dist/{manager-DWFNyouP.d.cts → manager-DT8enQbE.d.cts} +138 -2
- package/dist/{detect-Cprq6X9o.d.ts → metadata-BPvFYMlc.d.ts} +5 -2
- package/dist/{detect-DWL4uExV.d.cts → metadata-DyxUcKHk.d.cts} +5 -2
- package/dist/smart-account.cjs +1 -1
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.d.cts +247 -234
- package/dist/smart-account.d.ts +247 -234
- package/dist/smart-account.mjs +1 -1
- package/dist/smart-account.mjs.map +1 -1
- package/dist/wallet.cjs +15 -1
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +4 -7
- package/dist/wallet.d.ts +4 -7
- package/dist/wallet.mjs +15 -1
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +381 -113
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +409 -139
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -442,6 +442,20 @@ var init_eipWallets = __esm({
|
|
|
442
442
|
"src/wallets/eipWallets.ts"() {
|
|
443
443
|
"use strict";
|
|
444
444
|
CHAIN_PARAMS = {
|
|
445
|
+
1: {
|
|
446
|
+
chainIdHex: "0x1",
|
|
447
|
+
chainName: "Ethereum",
|
|
448
|
+
rpcUrls: ["https://eth.llamarpc.com"],
|
|
449
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
450
|
+
blockExplorerUrls: ["https://etherscan.io"]
|
|
451
|
+
},
|
|
452
|
+
137: {
|
|
453
|
+
chainIdHex: "0x89",
|
|
454
|
+
chainName: "Polygon",
|
|
455
|
+
rpcUrls: ["https://polygon-rpc.com"],
|
|
456
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
457
|
+
blockExplorerUrls: ["https://polygonscan.com"]
|
|
458
|
+
},
|
|
445
459
|
8453: {
|
|
446
460
|
chainIdHex: "0x2105",
|
|
447
461
|
chainName: "Base",
|
|
@@ -473,7 +487,7 @@ var init_constants = __esm({
|
|
|
473
487
|
"src/constants.ts"() {
|
|
474
488
|
"use strict";
|
|
475
489
|
SDK_NAME = "@trustware/sdk";
|
|
476
|
-
SDK_VERSION = "1.1.
|
|
490
|
+
SDK_VERSION = "1.1.11-staging.1";
|
|
477
491
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
478
492
|
GTM_ID = "GTM-TZDGNCXB";
|
|
479
493
|
API_PREFIX = "/api";
|
|
@@ -517,6 +531,9 @@ async function assertOK(r) {
|
|
|
517
531
|
}
|
|
518
532
|
throw new Error(`HTTP ${r.status}: ${msg}`);
|
|
519
533
|
}
|
|
534
|
+
function isNotFoundError(err) {
|
|
535
|
+
return err instanceof Error && err.message.startsWith("HTTP 404");
|
|
536
|
+
}
|
|
520
537
|
async function validateSdkAccess() {
|
|
521
538
|
const r = await fetch(`${apiBase()}/sdk/validate`, {
|
|
522
539
|
method: "GET",
|
|
@@ -1114,12 +1131,33 @@ var init_deepLink = __esm({
|
|
|
1114
1131
|
});
|
|
1115
1132
|
|
|
1116
1133
|
// src/wallets/metadata.ts
|
|
1117
|
-
var WALLETS;
|
|
1134
|
+
var POPULAR_ORDER, WALLETS;
|
|
1118
1135
|
var init_metadata = __esm({
|
|
1119
1136
|
"src/wallets/metadata.ts"() {
|
|
1120
1137
|
"use strict";
|
|
1121
1138
|
init_deepLink();
|
|
1122
1139
|
init_constants();
|
|
1140
|
+
POPULAR_ORDER = [
|
|
1141
|
+
"rabby",
|
|
1142
|
+
"metamask",
|
|
1143
|
+
"walletconnect",
|
|
1144
|
+
"rainbow",
|
|
1145
|
+
"phantom-evm",
|
|
1146
|
+
"phantom-solana",
|
|
1147
|
+
"metamask-solana",
|
|
1148
|
+
"solflare",
|
|
1149
|
+
"okx",
|
|
1150
|
+
"brave",
|
|
1151
|
+
"coinbase",
|
|
1152
|
+
"zerion",
|
|
1153
|
+
"taho",
|
|
1154
|
+
"trust",
|
|
1155
|
+
"bitget",
|
|
1156
|
+
"backpack",
|
|
1157
|
+
"imtoken",
|
|
1158
|
+
"safe",
|
|
1159
|
+
"kucoin"
|
|
1160
|
+
];
|
|
1123
1161
|
WALLETS = [
|
|
1124
1162
|
{
|
|
1125
1163
|
id: "metamask",
|
|
@@ -4356,6 +4394,27 @@ var init_wallets = __esm({
|
|
|
4356
4394
|
});
|
|
4357
4395
|
|
|
4358
4396
|
// src/core/routes.ts
|
|
4397
|
+
function assertValidPostHook(hooks) {
|
|
4398
|
+
const postHook = hooks?.postHook;
|
|
4399
|
+
if (!postHook) return;
|
|
4400
|
+
if (!postHook.target?.trim()) {
|
|
4401
|
+
throw new Error("hooks.postHook.target is required.");
|
|
4402
|
+
}
|
|
4403
|
+
if (!postHook.callData?.trim()) {
|
|
4404
|
+
throw new Error("hooks.postHook.callData is required.");
|
|
4405
|
+
}
|
|
4406
|
+
if (postHook.fullAmount) {
|
|
4407
|
+
if (postHook.amountInputPos === void 0) {
|
|
4408
|
+
throw new Error(
|
|
4409
|
+
"hooks.postHook.amountInputPos is required when fullAmount is true."
|
|
4410
|
+
);
|
|
4411
|
+
}
|
|
4412
|
+
} else if (!postHook.fundAmount?.trim()) {
|
|
4413
|
+
throw new Error(
|
|
4414
|
+
"hooks.postHook.fundAmount is required unless fullAmount is set."
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4417
|
+
}
|
|
4359
4418
|
function isEvmTxRequest(txReq) {
|
|
4360
4419
|
return Boolean(txReq?.data && (txReq.to || txReq.target));
|
|
4361
4420
|
}
|
|
@@ -4374,6 +4433,7 @@ async function buildRoute(body, signal) {
|
|
|
4374
4433
|
if (!addressValidation.isValid) {
|
|
4375
4434
|
throw new Error(addressValidation.error || "Invalid route addresses.");
|
|
4376
4435
|
}
|
|
4436
|
+
assertValidPostHook(body.hooks);
|
|
4377
4437
|
const cfg = TrustwareConfigStore.get();
|
|
4378
4438
|
const url = `${apiBase()}/v1/routes/route`;
|
|
4379
4439
|
const payload = {
|
|
@@ -4412,6 +4472,7 @@ async function buildRoute(body, signal) {
|
|
|
4412
4472
|
return { intentId, txReq, actions, finalExchangeRate, route, sponsorship };
|
|
4413
4473
|
}
|
|
4414
4474
|
async function buildDepositAddress(body, signal) {
|
|
4475
|
+
assertValidPostHook(body.hooks);
|
|
4415
4476
|
const cfg = TrustwareConfigStore.get();
|
|
4416
4477
|
const url = `${apiBase()}/v1/routes/deposit-address`;
|
|
4417
4478
|
const payload = {
|
|
@@ -4470,6 +4531,19 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress)
|
|
|
4470
4531
|
const j = await r.json();
|
|
4471
4532
|
return j.data;
|
|
4472
4533
|
}
|
|
4534
|
+
async function submitStepReceipt(intentId, stepIndex, txHash) {
|
|
4535
|
+
const r = await rateLimitedFetch(
|
|
4536
|
+
`${apiBase()}/v1/route-intent/${intentId}/steps/${stepIndex}/receipt`,
|
|
4537
|
+
{
|
|
4538
|
+
method: "POST",
|
|
4539
|
+
headers: jsonHeaders({ "Idempotency-Key": txHash }),
|
|
4540
|
+
body: JSON.stringify({ txHash })
|
|
4541
|
+
}
|
|
4542
|
+
);
|
|
4543
|
+
await assertOK(r);
|
|
4544
|
+
const j = await r.json();
|
|
4545
|
+
return j.data;
|
|
4546
|
+
}
|
|
4473
4547
|
async function getStatus(intentId) {
|
|
4474
4548
|
const r = await rateLimitedFetch(
|
|
4475
4549
|
`${apiBase()}/v1/route-intent/${intentId}/status`,
|
|
@@ -5160,18 +5234,112 @@ var init_registryClient = __esm({
|
|
|
5160
5234
|
});
|
|
5161
5235
|
|
|
5162
5236
|
// src/core/tx.ts
|
|
5163
|
-
import { keccak256 } from "viem";
|
|
5237
|
+
import { keccak256, encodeFunctionData, parseAbi } from "viem";
|
|
5164
5238
|
function backendChainId(chain, fallback) {
|
|
5165
5239
|
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
5166
5240
|
return String(preferred ?? fallback ?? "");
|
|
5167
5241
|
}
|
|
5242
|
+
function sleep2(ms) {
|
|
5243
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5244
|
+
}
|
|
5245
|
+
async function sendEvmTx(w, tx) {
|
|
5246
|
+
if (w.type === "eip1193") {
|
|
5247
|
+
const from = await w.getAddress();
|
|
5248
|
+
const params = {
|
|
5249
|
+
from,
|
|
5250
|
+
to: tx.to,
|
|
5251
|
+
data: tx.data,
|
|
5252
|
+
value: tx.value ? `0x${tx.value.toString(16)}` : "0x0"
|
|
5253
|
+
};
|
|
5254
|
+
if (tx.chainId !== void 0) {
|
|
5255
|
+
params.chainId = `0x${tx.chainId.toString(16)}`;
|
|
5256
|
+
}
|
|
5257
|
+
const hash = await w.request({
|
|
5258
|
+
method: "eth_sendTransaction",
|
|
5259
|
+
params: [params]
|
|
5260
|
+
});
|
|
5261
|
+
return hash;
|
|
5262
|
+
}
|
|
5263
|
+
const response = await w.sendTransaction({
|
|
5264
|
+
to: tx.to,
|
|
5265
|
+
data: tx.data,
|
|
5266
|
+
value: tx.value,
|
|
5267
|
+
chainId: tx.chainId
|
|
5268
|
+
});
|
|
5269
|
+
return response.hash;
|
|
5270
|
+
}
|
|
5271
|
+
async function waitForTxConfirmation(chainId, txHash) {
|
|
5272
|
+
const timeoutMs = 12e4;
|
|
5273
|
+
const intervalMs = 2e3;
|
|
5274
|
+
const started = Date.now();
|
|
5275
|
+
while (Date.now() - started < timeoutMs) {
|
|
5276
|
+
const status = await getEVMTxStatus({ chainId, txHash });
|
|
5277
|
+
if (status.status === "success") return;
|
|
5278
|
+
if (status.status === "reverted") {
|
|
5279
|
+
throw new Error("Approval transaction reverted");
|
|
5280
|
+
}
|
|
5281
|
+
await sleep2(intervalMs);
|
|
5282
|
+
}
|
|
5283
|
+
throw new Error("Timed out waiting for approval confirmation");
|
|
5284
|
+
}
|
|
5285
|
+
function requiredApprovalAmount(planAmountWei, routeAmountWei) {
|
|
5286
|
+
if (planAmountWei >= UNLIMITED_APPROVAL_FLOOR && routeAmountWei !== void 0 && routeAmountWei > 0n) {
|
|
5287
|
+
return routeAmountWei;
|
|
5288
|
+
}
|
|
5289
|
+
return planAmountWei;
|
|
5290
|
+
}
|
|
5291
|
+
function approvalSatisfied(currentAllowance, requiredWei) {
|
|
5292
|
+
if (requiredWei === 0n) return currentAllowance === 0n;
|
|
5293
|
+
return currentAllowance >= requiredWei;
|
|
5294
|
+
}
|
|
5295
|
+
async function ensureApprovals(w, approvals, fallbackChainId, intentId, routeAmountWei) {
|
|
5296
|
+
if (!approvals || approvals.length === 0) return;
|
|
5297
|
+
const owner = await w.getAddress();
|
|
5298
|
+
for (const [stepIndex, approval] of approvals.entries()) {
|
|
5299
|
+
const spender = approval.spender;
|
|
5300
|
+
const tokenAddress = approval.tokenAddress;
|
|
5301
|
+
const amount = approval.amount;
|
|
5302
|
+
if (!spender || !tokenAddress || !amount) continue;
|
|
5303
|
+
const chainId = approval.chainId || String(fallbackChainId ?? "");
|
|
5304
|
+
if (!chainId) continue;
|
|
5305
|
+
const amountWei = requiredApprovalAmount(BigInt(amount), routeAmountWei);
|
|
5306
|
+
let currentAllowance = 0n;
|
|
5307
|
+
try {
|
|
5308
|
+
const { allowance } = await getEVMAllowance({
|
|
5309
|
+
chainId,
|
|
5310
|
+
tokenAddress,
|
|
5311
|
+
ownerAddress: owner,
|
|
5312
|
+
spenderAddress: spender
|
|
5313
|
+
});
|
|
5314
|
+
currentAllowance = BigInt(allowance || "0");
|
|
5315
|
+
} catch {
|
|
5316
|
+
}
|
|
5317
|
+
if (approvalSatisfied(currentAllowance, amountWei)) continue;
|
|
5318
|
+
const data = encodeFunctionData({
|
|
5319
|
+
abi: erc20ApproveAbi,
|
|
5320
|
+
functionName: "approve",
|
|
5321
|
+
args: [spender, amountWei]
|
|
5322
|
+
});
|
|
5323
|
+
const hash = await sendEvmTx(w, {
|
|
5324
|
+
to: tokenAddress,
|
|
5325
|
+
data,
|
|
5326
|
+
value: 0n,
|
|
5327
|
+
chainId: Number.isFinite(Number(chainId)) ? Number(chainId) : void 0
|
|
5328
|
+
});
|
|
5329
|
+
if (intentId) {
|
|
5330
|
+
void submitStepReceipt(intentId, stepIndex, hash).catch(() => {
|
|
5331
|
+
});
|
|
5332
|
+
}
|
|
5333
|
+
await waitForTxConfirmation(chainId, hash);
|
|
5334
|
+
}
|
|
5335
|
+
}
|
|
5168
5336
|
function isUserRejected(e2) {
|
|
5169
5337
|
const code = e2?.code ?? e2?.data?.code;
|
|
5170
5338
|
if (code === 4001) return true;
|
|
5171
5339
|
const msg = String(e2?.message || e2)?.toLowerCase?.() || "";
|
|
5172
5340
|
return msg.includes("user rejected") || msg.includes("user denied");
|
|
5173
5341
|
}
|
|
5174
|
-
async function sendRouteTransaction(b, fallbackChainId) {
|
|
5342
|
+
async function sendRouteTransaction(b, fallbackChainId, options) {
|
|
5175
5343
|
const w = walletManager.wallet;
|
|
5176
5344
|
if (!w) throw new Error("Trustware.wallet not configured");
|
|
5177
5345
|
const txReq = b.txReq;
|
|
@@ -5198,6 +5366,15 @@ async function sendRouteTransaction(b, fallbackChainId) {
|
|
|
5198
5366
|
}
|
|
5199
5367
|
}
|
|
5200
5368
|
}
|
|
5369
|
+
if (!validatedSponsorship && !options?.approvalsEnsured) {
|
|
5370
|
+
await ensureApprovals(
|
|
5371
|
+
w,
|
|
5372
|
+
b.route?.execution?.approvals,
|
|
5373
|
+
Number.isFinite(target) ? target : void 0,
|
|
5374
|
+
b.intentId,
|
|
5375
|
+
BigInt(b.route?.estimate?.fromAmount ?? "0")
|
|
5376
|
+
);
|
|
5377
|
+
}
|
|
5201
5378
|
if (w.type === "eip1193") {
|
|
5202
5379
|
const from = await w.getAddress();
|
|
5203
5380
|
const hexValue = value ? `0x${value.toString(16)}` : "0x0";
|
|
@@ -5294,11 +5471,17 @@ async function runTopUp(params) {
|
|
|
5294
5471
|
}
|
|
5295
5472
|
}
|
|
5296
5473
|
}
|
|
5474
|
+
var erc20ApproveAbi, UNLIMITED_APPROVAL_FLOOR;
|
|
5297
5475
|
var init_tx = __esm({
|
|
5298
5476
|
"src/core/tx.ts"() {
|
|
5299
5477
|
"use strict";
|
|
5300
5478
|
init_wallets();
|
|
5301
5479
|
init_routes();
|
|
5480
|
+
init_sdkRpc();
|
|
5481
|
+
erc20ApproveAbi = parseAbi([
|
|
5482
|
+
"function approve(address spender, uint256 amount) returns (bool)"
|
|
5483
|
+
]);
|
|
5484
|
+
UNLIMITED_APPROVAL_FLOOR = 1n << 255n;
|
|
5302
5485
|
}
|
|
5303
5486
|
});
|
|
5304
5487
|
|
|
@@ -7572,6 +7755,7 @@ var init_core = __esm({
|
|
|
7572
7755
|
buildRoute,
|
|
7573
7756
|
buildDepositAddress,
|
|
7574
7757
|
submitReceipt,
|
|
7758
|
+
submitStepReceipt,
|
|
7575
7759
|
getStatus,
|
|
7576
7760
|
pollStatus,
|
|
7577
7761
|
getBalances,
|
|
@@ -8802,75 +8986,17 @@ var init_useTransactionSubmit = __esm({
|
|
|
8802
8986
|
|
|
8803
8987
|
// src/hooks/useGTM.ts
|
|
8804
8988
|
import { useEffect as useEffect11, useRef as useRef3, useCallback as useCallback8 } from "react";
|
|
8805
|
-
function
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
}
|
|
8814
|
-
}, []);
|
|
8815
|
-
useEffect11(() => {
|
|
8816
|
-
if (!isGA4Allowed()) {
|
|
8817
|
-
console.warn(
|
|
8818
|
-
"useGTM: GA4 tracking is disabled or Trustware config not initialized."
|
|
8819
|
-
);
|
|
8820
|
-
return;
|
|
8821
|
-
}
|
|
8822
|
-
if (!gtmId || typeof gtmId !== "string") {
|
|
8823
|
-
console.error(
|
|
8824
|
-
"useGTM: A valid GTM Container ID is required (format: GTM-XXXXX)."
|
|
8825
|
-
);
|
|
8826
|
-
return;
|
|
8827
|
-
}
|
|
8828
|
-
if (isInitialized.current) return;
|
|
8829
|
-
const alreadyLoaded = document.querySelector(
|
|
8830
|
-
`script[src*="googletagmanager.com/gtm.js?id=${gtmId}"]`
|
|
8831
|
-
);
|
|
8832
|
-
if (alreadyLoaded) {
|
|
8833
|
-
window.dataLayer = window.dataLayer || [];
|
|
8834
|
-
isInitialized.current = true;
|
|
8835
|
-
return;
|
|
8836
|
-
}
|
|
8837
|
-
window.dataLayer = window.dataLayer || [];
|
|
8838
|
-
window.dataLayer.push({
|
|
8839
|
-
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
8840
|
-
event: "gtm.js"
|
|
8841
|
-
});
|
|
8842
|
-
const firstScript = document.getElementsByTagName("script")[0];
|
|
8843
|
-
const script = document.createElement("script");
|
|
8844
|
-
script.async = true;
|
|
8845
|
-
script.src = `https://www.googletagmanager.com/gtm.js?id=${gtmId}`;
|
|
8846
|
-
firstScript.parentNode?.insertBefore(script, firstScript);
|
|
8847
|
-
scriptRef.current = script;
|
|
8848
|
-
isInitialized.current = true;
|
|
8849
|
-
return () => {
|
|
8850
|
-
if (scriptRef.current) {
|
|
8851
|
-
scriptRef.current.parentNode?.removeChild(scriptRef.current);
|
|
8852
|
-
scriptRef.current = null;
|
|
8853
|
-
}
|
|
8854
|
-
isInitialized.current = false;
|
|
8855
|
-
};
|
|
8856
|
-
}, [gtmId, isGA4Allowed]);
|
|
8857
|
-
const addNoscriptIframe = useCallback8(() => {
|
|
8858
|
-
if (!isGA4Allowed()) return;
|
|
8859
|
-
if (document.querySelector('iframe[src*="googletagmanager.com/ns.html"]'))
|
|
8860
|
-
return;
|
|
8861
|
-
const noscript = document.createElement("noscript");
|
|
8862
|
-
const iframe = document.createElement("iframe");
|
|
8863
|
-
iframe.src = `https://www.googletagmanager.com/ns.html?id=${gtmId}`;
|
|
8864
|
-
iframe.height = "0";
|
|
8865
|
-
iframe.width = "0";
|
|
8866
|
-
iframe.style.display = "none";
|
|
8867
|
-
iframe.style.visibility = "hidden";
|
|
8868
|
-
noscript.appendChild(iframe);
|
|
8869
|
-
document.body.insertBefore(noscript, document.body.firstChild);
|
|
8870
|
-
}, [gtmId, isGA4Allowed]);
|
|
8989
|
+
function isGA4Allowed() {
|
|
8990
|
+
try {
|
|
8991
|
+
return Trustware.getConfig().features.shouldAllowGA4;
|
|
8992
|
+
} catch {
|
|
8993
|
+
return false;
|
|
8994
|
+
}
|
|
8995
|
+
}
|
|
8996
|
+
function useGTMTracker() {
|
|
8871
8997
|
const trackEvent = useCallback8(
|
|
8872
8998
|
(eventName, eventParams = {}) => {
|
|
8873
|
-
if (!
|
|
8999
|
+
if (!isContainerInitialized) {
|
|
8874
9000
|
console.warn(
|
|
8875
9001
|
"useGTM: Not initialized. Ensure a valid GTM Container ID was provided."
|
|
8876
9002
|
);
|
|
@@ -8897,7 +9023,7 @@ function useGTM(gtmId) {
|
|
|
8897
9023
|
);
|
|
8898
9024
|
const setUserProperty = useCallback8(
|
|
8899
9025
|
(propertyName, value) => {
|
|
8900
|
-
if (!
|
|
9026
|
+
if (!isContainerInitialized) {
|
|
8901
9027
|
console.warn(
|
|
8902
9028
|
"useGTM: Not initialized. Ensure a valid GTM Container ID was provided."
|
|
8903
9029
|
);
|
|
@@ -8923,20 +9049,77 @@ function useGTM(gtmId) {
|
|
|
8923
9049
|
}
|
|
8924
9050
|
window.gtag(command, ...args);
|
|
8925
9051
|
},
|
|
8926
|
-
[
|
|
9052
|
+
[]
|
|
8927
9053
|
);
|
|
8928
|
-
return {
|
|
8929
|
-
trackEvent,
|
|
8930
|
-
trackPageView,
|
|
8931
|
-
setUserProperty,
|
|
8932
|
-
directGtag,
|
|
8933
|
-
addNoscriptIframe
|
|
8934
|
-
};
|
|
9054
|
+
return { trackEvent, trackPageView, setUserProperty, directGtag };
|
|
8935
9055
|
}
|
|
9056
|
+
function useGTM(gtmId) {
|
|
9057
|
+
const scriptRef = useRef3(null);
|
|
9058
|
+
const tracker = useGTMTracker();
|
|
9059
|
+
useEffect11(() => {
|
|
9060
|
+
if (!isGA4Allowed()) {
|
|
9061
|
+
console.warn(
|
|
9062
|
+
"useGTM: GA4 tracking is disabled or Trustware config not initialized."
|
|
9063
|
+
);
|
|
9064
|
+
return;
|
|
9065
|
+
}
|
|
9066
|
+
if (!gtmId || typeof gtmId !== "string") {
|
|
9067
|
+
console.error(
|
|
9068
|
+
"useGTM: A valid GTM Container ID is required (format: GTM-XXXXX)."
|
|
9069
|
+
);
|
|
9070
|
+
return;
|
|
9071
|
+
}
|
|
9072
|
+
if (isContainerInitialized) return;
|
|
9073
|
+
const alreadyLoaded = document.querySelector(
|
|
9074
|
+
`script[src*="googletagmanager.com/gtm.js?id=${gtmId}"]`
|
|
9075
|
+
);
|
|
9076
|
+
if (alreadyLoaded) {
|
|
9077
|
+
window.dataLayer = window.dataLayer || [];
|
|
9078
|
+
isContainerInitialized = true;
|
|
9079
|
+
return;
|
|
9080
|
+
}
|
|
9081
|
+
window.dataLayer = window.dataLayer || [];
|
|
9082
|
+
window.dataLayer.push({
|
|
9083
|
+
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
9084
|
+
event: "gtm.js"
|
|
9085
|
+
});
|
|
9086
|
+
const firstScript = document.getElementsByTagName("script")[0];
|
|
9087
|
+
const script = document.createElement("script");
|
|
9088
|
+
script.async = true;
|
|
9089
|
+
script.src = `https://www.googletagmanager.com/gtm.js?id=${gtmId}`;
|
|
9090
|
+
firstScript.parentNode?.insertBefore(script, firstScript);
|
|
9091
|
+
scriptRef.current = script;
|
|
9092
|
+
isContainerInitialized = true;
|
|
9093
|
+
return () => {
|
|
9094
|
+
if (scriptRef.current) {
|
|
9095
|
+
scriptRef.current.parentNode?.removeChild(scriptRef.current);
|
|
9096
|
+
scriptRef.current = null;
|
|
9097
|
+
}
|
|
9098
|
+
isContainerInitialized = false;
|
|
9099
|
+
};
|
|
9100
|
+
}, [gtmId]);
|
|
9101
|
+
const addNoscriptIframe = useCallback8(() => {
|
|
9102
|
+
if (!isGA4Allowed()) return;
|
|
9103
|
+
if (document.querySelector('iframe[src*="googletagmanager.com/ns.html"]'))
|
|
9104
|
+
return;
|
|
9105
|
+
const noscript = document.createElement("noscript");
|
|
9106
|
+
const iframe = document.createElement("iframe");
|
|
9107
|
+
iframe.src = `https://www.googletagmanager.com/ns.html?id=${gtmId}`;
|
|
9108
|
+
iframe.height = "0";
|
|
9109
|
+
iframe.width = "0";
|
|
9110
|
+
iframe.style.display = "none";
|
|
9111
|
+
iframe.style.visibility = "hidden";
|
|
9112
|
+
noscript.appendChild(iframe);
|
|
9113
|
+
document.body.insertBefore(noscript, document.body.firstChild);
|
|
9114
|
+
}, [gtmId]);
|
|
9115
|
+
return { ...tracker, addNoscriptIframe };
|
|
9116
|
+
}
|
|
9117
|
+
var isContainerInitialized;
|
|
8936
9118
|
var init_useGTM = __esm({
|
|
8937
9119
|
"src/hooks/useGTM.ts"() {
|
|
8938
9120
|
"use strict";
|
|
8939
9121
|
init_core2();
|
|
9122
|
+
isContainerInitialized = false;
|
|
8940
9123
|
}
|
|
8941
9124
|
});
|
|
8942
9125
|
|
|
@@ -8963,7 +9146,7 @@ function useTransactionPolling() {
|
|
|
8963
9146
|
return void 0;
|
|
8964
9147
|
}
|
|
8965
9148
|
})();
|
|
8966
|
-
const { trackEvent } =
|
|
9149
|
+
const { trackEvent } = useGTMTracker();
|
|
8967
9150
|
const [state, setState] = useState13({
|
|
8968
9151
|
isPolling: false,
|
|
8969
9152
|
apiStatus: null,
|
|
@@ -9063,8 +9246,21 @@ function useTransactionPolling() {
|
|
|
9063
9246
|
pollCountRef.current += 1;
|
|
9064
9247
|
const pollInterval = pollCountRef.current <= 10 ? FAST_POLL_INTERVAL_MS : NORMAL_POLL_INTERVAL_MS;
|
|
9065
9248
|
pollingRef.current = setTimeout(poll, pollInterval);
|
|
9066
|
-
} catch {
|
|
9249
|
+
} catch (err) {
|
|
9067
9250
|
if (abortRef.current) return;
|
|
9251
|
+
if (isNotFoundError(err)) {
|
|
9252
|
+
clearPolling();
|
|
9253
|
+
const notFoundError = "Transaction session expired. Please try again.";
|
|
9254
|
+
setState((prev) => ({
|
|
9255
|
+
...prev,
|
|
9256
|
+
isPolling: false,
|
|
9257
|
+
error: notFoundError
|
|
9258
|
+
}));
|
|
9259
|
+
setErrorMessage(notFoundError);
|
|
9260
|
+
setTransactionStatus("error");
|
|
9261
|
+
setCurrentStep("error");
|
|
9262
|
+
return;
|
|
9263
|
+
}
|
|
9068
9264
|
const elapsed = Date.now() - startTimeRef.current;
|
|
9069
9265
|
if (elapsed > POLL_TIMEOUT_MS) {
|
|
9070
9266
|
clearPolling();
|
|
@@ -9200,10 +9396,10 @@ var init_useTransactionPolling = __esm({
|
|
|
9200
9396
|
"use strict";
|
|
9201
9397
|
"use client";
|
|
9202
9398
|
init_routes();
|
|
9399
|
+
init_http();
|
|
9203
9400
|
init_DepositContext();
|
|
9204
9401
|
init_provider();
|
|
9205
9402
|
init_core2();
|
|
9206
|
-
init_constants();
|
|
9207
9403
|
init_hooks();
|
|
9208
9404
|
FAST_POLL_INTERVAL_MS = 1500;
|
|
9209
9405
|
NORMAL_POLL_INTERVAL_MS = 2500;
|
|
@@ -28385,7 +28581,7 @@ var init_utils5 = __esm({
|
|
|
28385
28581
|
});
|
|
28386
28582
|
|
|
28387
28583
|
// node_modules/@account-kit/smart-contracts/dist/esm/src/light-account/accounts/base.js
|
|
28388
|
-
import { concat as concat5, encodeFunctionData, fromHex as fromHex4, hashMessage, hashTypedData, trim } from "viem";
|
|
28584
|
+
import { concat as concat5, encodeFunctionData as encodeFunctionData2, fromHex as fromHex4, hashMessage, hashTypedData, trim } from "viem";
|
|
28389
28585
|
async function createLightAccountBase({ transport, chain, signer, abi, version, type, entryPoint, accountAddress, getAccountInitCode }) {
|
|
28390
28586
|
const client = createBundlerClient({
|
|
28391
28587
|
transport,
|
|
@@ -28404,7 +28600,7 @@ async function createLightAccountBase({ transport, chain, signer, abi, version,
|
|
|
28404
28600
|
if (fromHex4(storage, "number") !== 0 && !implementationAddresses.some((x) => x === trim(storage))) {
|
|
28405
28601
|
throw new Error(`could not determine if smart account implementation is ${type} ${String(version)}`);
|
|
28406
28602
|
}
|
|
28407
|
-
return
|
|
28603
|
+
return encodeFunctionData2({
|
|
28408
28604
|
abi,
|
|
28409
28605
|
functionName: "upgradeToAndCall",
|
|
28410
28606
|
args: [upgradeToAddress, upgradeToInitData]
|
|
@@ -28463,7 +28659,7 @@ async function createLightAccountBase({ transport, chain, signer, abi, version,
|
|
|
28463
28659
|
prepareSign,
|
|
28464
28660
|
formatSign,
|
|
28465
28661
|
encodeExecute: async ({ target, data, value }) => {
|
|
28466
|
-
return
|
|
28662
|
+
return encodeFunctionData2({
|
|
28467
28663
|
abi,
|
|
28468
28664
|
functionName: "execute",
|
|
28469
28665
|
args: [target, value ?? 0n, data]
|
|
@@ -28476,7 +28672,7 @@ async function createLightAccountBase({ transport, chain, signer, abi, version,
|
|
|
28476
28672
|
accum[2].push(curr.data);
|
|
28477
28673
|
return accum;
|
|
28478
28674
|
}, [[], [], []]);
|
|
28479
|
-
return
|
|
28675
|
+
return encodeFunctionData2({
|
|
28480
28676
|
abi,
|
|
28481
28677
|
functionName: "executeBatch",
|
|
28482
28678
|
args: [targets, values, datas]
|
|
@@ -28570,7 +28766,7 @@ var init_OZ_ERC1967Proxy = __esm({
|
|
|
28570
28766
|
});
|
|
28571
28767
|
|
|
28572
28768
|
// node_modules/@account-kit/smart-contracts/dist/esm/src/light-account/accounts/predictAddress.js
|
|
28573
|
-
import { encodeAbiParameters as encodeAbiParameters4, encodeDeployData, keccak256 as keccak2565, getContractAddress, toHex as toHex6, encodeFunctionData as
|
|
28769
|
+
import { encodeAbiParameters as encodeAbiParameters4, encodeDeployData, keccak256 as keccak2565, getContractAddress, toHex as toHex6, encodeFunctionData as encodeFunctionData3 } from "viem";
|
|
28574
28770
|
function predictLightAccountAddress({ factoryAddress, salt, ownerAddress, version }) {
|
|
28575
28771
|
const implementationAddress = (
|
|
28576
28772
|
// If we aren't using the default factory address, we compute the implementation address from the factory's `create` deployment.
|
|
@@ -28594,7 +28790,7 @@ function predictLightAccountAddress({ factoryAddress, salt, ownerAddress, versio
|
|
|
28594
28790
|
abi: OZ_ERC1967Proxy_ConstructorAbi,
|
|
28595
28791
|
args: [
|
|
28596
28792
|
implementationAddress,
|
|
28597
|
-
|
|
28793
|
+
encodeFunctionData3({
|
|
28598
28794
|
abi: LightAccountAbi_v1,
|
|
28599
28795
|
functionName: "initialize",
|
|
28600
28796
|
args: [ownerAddress]
|
|
@@ -28631,7 +28827,7 @@ var init_predictAddress = __esm({
|
|
|
28631
28827
|
});
|
|
28632
28828
|
|
|
28633
28829
|
// node_modules/@account-kit/smart-contracts/dist/esm/src/light-account/accounts/account.js
|
|
28634
|
-
import { concatHex as concatHex2, encodeFunctionData as
|
|
28830
|
+
import { concatHex as concatHex2, encodeFunctionData as encodeFunctionData4 } from "viem";
|
|
28635
28831
|
async function createLightAccount({ transport, chain, signer, initCode, version = defaultLightAccountVersion(), entryPoint = getEntryPoint(chain, {
|
|
28636
28832
|
version: AccountVersionRegistry["LightAccount"][version].entryPointVersion
|
|
28637
28833
|
}), accountAddress, factoryAddress = getDefaultLightAccountFactoryAddress(chain, version), salt: salt_ = 0n }) {
|
|
@@ -28648,7 +28844,7 @@ async function createLightAccount({ transport, chain, signer, initCode, version
|
|
|
28648
28844
|
return initCode;
|
|
28649
28845
|
return concatHex2([
|
|
28650
28846
|
factoryAddress,
|
|
28651
|
-
|
|
28847
|
+
encodeFunctionData4({
|
|
28652
28848
|
abi: factoryAbi,
|
|
28653
28849
|
functionName: "createAccount",
|
|
28654
28850
|
args: [signerAddress, salt]
|
|
@@ -28675,7 +28871,7 @@ async function createLightAccount({ transport, chain, signer, initCode, version
|
|
|
28675
28871
|
return {
|
|
28676
28872
|
...account,
|
|
28677
28873
|
encodeTransferOwnership: (newOwner) => {
|
|
28678
|
-
return
|
|
28874
|
+
return encodeFunctionData4({
|
|
28679
28875
|
abi: accountAbi,
|
|
28680
28876
|
functionName: "transferOwnership",
|
|
28681
28877
|
args: [newOwner]
|
|
@@ -29983,7 +30179,7 @@ var init_feeEstimator2 = __esm({
|
|
|
29983
30179
|
});
|
|
29984
30180
|
|
|
29985
30181
|
// node_modules/@account-kit/infra/dist/esm/gas-manager.js
|
|
29986
|
-
import { encodeFunctionData as
|
|
30182
|
+
import { encodeFunctionData as encodeFunctionData5 } from "viem";
|
|
29987
30183
|
var AlchemyPaymasterAddressV06Unify, AlchemyPaymasterAddressV07Unify, AlchemyPaymasterAddressV4, AlchemyPaymasterAddressV3, AlchemyPaymasterAddressV2, ArbSepoliaPaymasterAddress, AlchemyPaymasterAddressV1, AlchemyPaymasterAddressV07V2, AlchemyPaymasterAddressV07V1, getAlchemyPaymasterAddress, PermitTypes, ERC20Abis, EIP7597Abis;
|
|
29988
30184
|
var init_gas_manager = __esm({
|
|
29989
30185
|
"node_modules/@account-kit/infra/dist/esm/gas-manager.js"() {
|
|
@@ -30172,7 +30368,7 @@ var init_invalidSignedPermit = __esm({
|
|
|
30172
30368
|
});
|
|
30173
30369
|
|
|
30174
30370
|
// node_modules/@account-kit/infra/dist/esm/middleware/gasManager.js
|
|
30175
|
-
import { fromHex as fromHex5, isHex as isHex2, encodeAbiParameters as encodeAbiParameters5, encodeFunctionData as
|
|
30371
|
+
import { fromHex as fromHex5, isHex as isHex2, encodeAbiParameters as encodeAbiParameters5, encodeFunctionData as encodeFunctionData6, parseAbi as parseAbi2 } from "viem";
|
|
30176
30372
|
function alchemyGasManagerMiddleware(policyId, policyToken, webhookData) {
|
|
30177
30373
|
const buildContext = async (args) => {
|
|
30178
30374
|
const context = { policyId };
|
|
@@ -30354,16 +30550,16 @@ var init_gasManager = __esm({
|
|
|
30354
30550
|
}
|
|
30355
30551
|
let allowanceFuture = client.call({
|
|
30356
30552
|
to: policyToken.address,
|
|
30357
|
-
data:
|
|
30358
|
-
abi:
|
|
30553
|
+
data: encodeFunctionData6({
|
|
30554
|
+
abi: parseAbi2(ERC20Abis),
|
|
30359
30555
|
functionName: "allowance",
|
|
30360
30556
|
args: [account.address, paymasterAddress]
|
|
30361
30557
|
})
|
|
30362
30558
|
});
|
|
30363
30559
|
let nonceFuture = client.call({
|
|
30364
30560
|
to: policyToken.address,
|
|
30365
|
-
data:
|
|
30366
|
-
abi:
|
|
30561
|
+
data: encodeFunctionData6({
|
|
30562
|
+
abi: parseAbi2(EIP7597Abis),
|
|
30367
30563
|
functionName: "nonces",
|
|
30368
30564
|
args: [account.address]
|
|
30369
30565
|
})
|
|
@@ -30816,7 +31012,7 @@ var init_fee_utils = __esm({
|
|
|
30816
31012
|
|
|
30817
31013
|
// src/smart-account/permit2.ts
|
|
30818
31014
|
import {
|
|
30819
|
-
encodeFunctionData as
|
|
31015
|
+
encodeFunctionData as encodeFunctionData7,
|
|
30820
31016
|
keccak256 as keccak2567,
|
|
30821
31017
|
encodeAbiParameters as encodeAbiParameters6,
|
|
30822
31018
|
concat as concat6,
|
|
@@ -30940,7 +31136,7 @@ async function signPermit2(eip1193Request, params) {
|
|
|
30940
31136
|
return sig;
|
|
30941
31137
|
}
|
|
30942
31138
|
function encodePermitTransferFrom(token, amount, nonce, deadline, saAddress, eoaAddress, sig) {
|
|
30943
|
-
return
|
|
31139
|
+
return encodeFunctionData7({
|
|
30944
31140
|
abi: PERMIT2_ABI,
|
|
30945
31141
|
functionName: "permitTransferFrom",
|
|
30946
31142
|
args: [
|
|
@@ -30952,28 +31148,28 @@ function encodePermitTransferFrom(token, amount, nonce, deadline, saAddress, eoa
|
|
|
30952
31148
|
});
|
|
30953
31149
|
}
|
|
30954
31150
|
function encodeErc20Approve(spender, amount) {
|
|
30955
|
-
return
|
|
31151
|
+
return encodeFunctionData7({
|
|
30956
31152
|
abi: ERC20_APPROVE_ABI,
|
|
30957
31153
|
functionName: "approve",
|
|
30958
31154
|
args: [spender, amount]
|
|
30959
31155
|
});
|
|
30960
31156
|
}
|
|
30961
31157
|
function encodeErc20Allowance(owner, spender) {
|
|
30962
|
-
return
|
|
31158
|
+
return encodeFunctionData7({
|
|
30963
31159
|
abi: ERC20_ALLOWANCE_ABI,
|
|
30964
31160
|
functionName: "allowance",
|
|
30965
31161
|
args: [owner, spender]
|
|
30966
31162
|
});
|
|
30967
31163
|
}
|
|
30968
31164
|
function encodeErc20BalanceOf(owner) {
|
|
30969
|
-
return
|
|
31165
|
+
return encodeFunctionData7({
|
|
30970
31166
|
abi: ERC20_BALANCE_OF_ABI,
|
|
30971
31167
|
functionName: "balanceOf",
|
|
30972
31168
|
args: [owner]
|
|
30973
31169
|
});
|
|
30974
31170
|
}
|
|
30975
31171
|
function encodeWethWithdraw(amount) {
|
|
30976
|
-
return
|
|
31172
|
+
return encodeFunctionData7({
|
|
30977
31173
|
abi: WETH_ABI,
|
|
30978
31174
|
functionName: "withdraw",
|
|
30979
31175
|
args: [amount]
|
|
@@ -31066,9 +31262,9 @@ var init_permit2 = __esm({
|
|
|
31066
31262
|
});
|
|
31067
31263
|
|
|
31068
31264
|
// src/smart-account/uniswap.ts
|
|
31069
|
-
import { encodeFunctionData as
|
|
31265
|
+
import { encodeFunctionData as encodeFunctionData8 } from "viem";
|
|
31070
31266
|
function encodeUniswapExactOutputSingle(tokenIn, tokenOut, fee, recipient, amountOut, amountInMaximum) {
|
|
31071
|
-
return
|
|
31267
|
+
return encodeFunctionData8({
|
|
31072
31268
|
abi: SWAP_ROUTER_ABI,
|
|
31073
31269
|
functionName: "exactOutputSingle",
|
|
31074
31270
|
args: [
|
|
@@ -31596,14 +31792,14 @@ var init_smart_account2 = __esm({
|
|
|
31596
31792
|
|
|
31597
31793
|
// src/widget/features/transaction/hooks/useTransactionActionModel.ts
|
|
31598
31794
|
import { useCallback as useCallback19, useEffect as useEffect26, useMemo as useMemo20, useRef as useRef13, useState as useState26 } from "react";
|
|
31599
|
-
import { encodeFunctionData as
|
|
31795
|
+
import { encodeFunctionData as encodeFunctionData9, erc20Abi } from "viem";
|
|
31600
31796
|
function normalizeTokenAddressForCompare(chain, addr) {
|
|
31601
31797
|
const chainType = (chain.type ?? chain.chainType ?? "").toLowerCase();
|
|
31602
31798
|
const value = (addr ?? "").trim();
|
|
31603
31799
|
if (chainType === "solana") return value;
|
|
31604
31800
|
return value.toLowerCase();
|
|
31605
31801
|
}
|
|
31606
|
-
function
|
|
31802
|
+
function sleep3(ms) {
|
|
31607
31803
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
31608
31804
|
}
|
|
31609
31805
|
function useTransactionActionModel({
|
|
@@ -31619,7 +31815,7 @@ function useTransactionActionModel({
|
|
|
31619
31815
|
}) {
|
|
31620
31816
|
const feeDataCacheRef = useRef13({});
|
|
31621
31817
|
const { isSubmitting, submitTransaction } = useTransactionSubmit();
|
|
31622
|
-
const { trackEvent } =
|
|
31818
|
+
const { trackEvent } = useGTMTracker();
|
|
31623
31819
|
const destinationConfig = (() => {
|
|
31624
31820
|
try {
|
|
31625
31821
|
return Trustware.getConfig();
|
|
@@ -31721,7 +31917,7 @@ function useTransactionActionModel({
|
|
|
31721
31917
|
if (status.status === "reverted") {
|
|
31722
31918
|
throw new Error("Approval transaction reverted");
|
|
31723
31919
|
}
|
|
31724
|
-
await
|
|
31920
|
+
await sleep3(intervalMs);
|
|
31725
31921
|
}
|
|
31726
31922
|
throw new Error("Timed out waiting for approval confirmation");
|
|
31727
31923
|
},
|
|
@@ -31761,7 +31957,7 @@ function useTransactionActionModel({
|
|
|
31761
31957
|
}
|
|
31762
31958
|
}
|
|
31763
31959
|
}
|
|
31764
|
-
const data =
|
|
31960
|
+
const data = encodeFunctionData9({
|
|
31765
31961
|
abi: erc20Abi,
|
|
31766
31962
|
functionName: "approve",
|
|
31767
31963
|
args: [spender, amountWei]
|
|
@@ -32052,7 +32248,6 @@ var init_useTransactionActionModel = __esm({
|
|
|
32052
32248
|
init_chainHelpers();
|
|
32053
32249
|
init_utils();
|
|
32054
32250
|
init_hooks();
|
|
32055
|
-
init_constants();
|
|
32056
32251
|
}
|
|
32057
32252
|
});
|
|
32058
32253
|
|
|
@@ -33371,7 +33566,7 @@ var init_useSwapRoute = __esm({
|
|
|
33371
33566
|
|
|
33372
33567
|
// src/modes/swap/hooks/useSwapExecution.ts
|
|
33373
33568
|
import { useCallback as useCallback21, useRef as useRef16, useState as useState29 } from "react";
|
|
33374
|
-
import { encodeFunctionData as
|
|
33569
|
+
import { encodeFunctionData as encodeFunctionData10, erc20Abi as erc20Abi2 } from "viem";
|
|
33375
33570
|
function normalizeTx(raw) {
|
|
33376
33571
|
const r = raw;
|
|
33377
33572
|
return {
|
|
@@ -33382,7 +33577,7 @@ function normalizeTx(raw) {
|
|
|
33382
33577
|
toChainTxUrl: r.toChainTxUrl || r.to_chain_tx_url || void 0
|
|
33383
33578
|
};
|
|
33384
33579
|
}
|
|
33385
|
-
function
|
|
33580
|
+
function sleep4(ms) {
|
|
33386
33581
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33387
33582
|
}
|
|
33388
33583
|
function isUserRejection(err) {
|
|
@@ -33400,10 +33595,20 @@ async function waitForApprovalConfirmation(chainId, txHash) {
|
|
|
33400
33595
|
if (status.status === "success") return;
|
|
33401
33596
|
if (status.status === "reverted")
|
|
33402
33597
|
throw new Error("Approval transaction reverted");
|
|
33403
|
-
await
|
|
33598
|
+
await sleep4(2e3);
|
|
33404
33599
|
}
|
|
33405
33600
|
throw new Error("Timed out waiting for approval confirmation");
|
|
33406
33601
|
}
|
|
33602
|
+
async function requireActiveAddress(wallet, plannedFor) {
|
|
33603
|
+
if (!wallet) throw new Error("Wallet not connected. Please reconnect.");
|
|
33604
|
+
const active = await wallet.getAddress();
|
|
33605
|
+
if (active?.toLowerCase() !== plannedFor?.toLowerCase()) {
|
|
33606
|
+
throw new Error(
|
|
33607
|
+
"Wallet account changed. Please review and confirm the swap again."
|
|
33608
|
+
);
|
|
33609
|
+
}
|
|
33610
|
+
return active;
|
|
33611
|
+
}
|
|
33407
33612
|
function useSwapExecution(fromChain) {
|
|
33408
33613
|
const [state, setState] = useState29({
|
|
33409
33614
|
txStatus: "idle",
|
|
@@ -33460,7 +33665,15 @@ function useSwapExecution(fromChain) {
|
|
|
33460
33665
|
if (tx.status === "bridging") {
|
|
33461
33666
|
setState((p) => ({ ...p, txStatus: "bridging" }));
|
|
33462
33667
|
}
|
|
33463
|
-
} catch {
|
|
33668
|
+
} catch (err) {
|
|
33669
|
+
if (abortRef.current) return;
|
|
33670
|
+
if (isNotFoundError(err)) {
|
|
33671
|
+
clearPolling();
|
|
33672
|
+
const msg = "Transaction session expired. Please try again.";
|
|
33673
|
+
setState((p) => ({ ...p, txStatus: "error", errorMessage: msg }));
|
|
33674
|
+
onError(msg);
|
|
33675
|
+
return;
|
|
33676
|
+
}
|
|
33464
33677
|
}
|
|
33465
33678
|
if (abortRef.current) return;
|
|
33466
33679
|
pollCountRef.current += 1;
|
|
@@ -33486,24 +33699,55 @@ function useSwapExecution(fromChain) {
|
|
|
33486
33699
|
}
|
|
33487
33700
|
const txReq = routeResult.txReq;
|
|
33488
33701
|
const chainIdStr = String(txReq?.chainId ?? fromChain?.chainId ?? "");
|
|
33489
|
-
const spender = txReq?.to ?? txReq?.target;
|
|
33490
33702
|
const amountWei = BigInt(routeResult.route?.estimate?.fromAmount ?? "0");
|
|
33491
|
-
|
|
33703
|
+
const plannedApprovals = routeResult.route?.execution?.approvals ?? [];
|
|
33704
|
+
const toCheck = plannedApprovals.length ? plannedApprovals.flatMap((a) => {
|
|
33705
|
+
const token = a.tokenAddress ?? fromTokenAddress;
|
|
33706
|
+
const required = requiredApprovalAmount(
|
|
33707
|
+
BigInt(a.amount || "0"),
|
|
33708
|
+
amountWei
|
|
33709
|
+
);
|
|
33710
|
+
if (!token || !a.spender) return [];
|
|
33711
|
+
return [
|
|
33712
|
+
{
|
|
33713
|
+
chainId: a.chainId || chainIdStr,
|
|
33714
|
+
token,
|
|
33715
|
+
spender: a.spender,
|
|
33716
|
+
required
|
|
33717
|
+
}
|
|
33718
|
+
];
|
|
33719
|
+
}) : (() => {
|
|
33720
|
+
const spender = txReq?.to ?? txReq?.target;
|
|
33721
|
+
if (!spender) return [];
|
|
33722
|
+
return [
|
|
33723
|
+
{
|
|
33724
|
+
chainId: chainIdStr,
|
|
33725
|
+
token: fromTokenAddress,
|
|
33726
|
+
spender,
|
|
33727
|
+
required: amountWei
|
|
33728
|
+
}
|
|
33729
|
+
];
|
|
33730
|
+
})();
|
|
33731
|
+
if (toCheck.length === 0 || !chainIdStr || amountWei === 0n) {
|
|
33492
33732
|
setState((p) => ({ ...p, allowanceStatus: "unknown" }));
|
|
33493
33733
|
return;
|
|
33494
33734
|
}
|
|
33495
33735
|
setState((p) => ({ ...p, allowanceStatus: "checking" }));
|
|
33496
33736
|
try {
|
|
33497
|
-
const
|
|
33498
|
-
|
|
33499
|
-
|
|
33500
|
-
|
|
33501
|
-
|
|
33502
|
-
|
|
33503
|
-
|
|
33737
|
+
const results = await Promise.all(
|
|
33738
|
+
toCheck.map(async (c) => {
|
|
33739
|
+
const { allowance } = await getEVMAllowance({
|
|
33740
|
+
chainId: c.chainId,
|
|
33741
|
+
tokenAddress: c.token,
|
|
33742
|
+
ownerAddress: walletAddress,
|
|
33743
|
+
spenderAddress: c.spender
|
|
33744
|
+
});
|
|
33745
|
+
return approvalSatisfied(BigInt(allowance || "0"), c.required);
|
|
33746
|
+
})
|
|
33747
|
+
);
|
|
33504
33748
|
setState((p) => ({
|
|
33505
33749
|
...p,
|
|
33506
|
-
allowanceStatus:
|
|
33750
|
+
allowanceStatus: results.every(Boolean) ? "sufficient" : "needed"
|
|
33507
33751
|
}));
|
|
33508
33752
|
} catch {
|
|
33509
33753
|
setState((p) => ({ ...p, allowanceStatus: "needed" }));
|
|
@@ -33607,19 +33851,49 @@ function useSwapExecution(fromChain) {
|
|
|
33607
33851
|
}
|
|
33608
33852
|
}
|
|
33609
33853
|
try {
|
|
33610
|
-
|
|
33854
|
+
const plannedApprovals = routeResult.route?.execution?.approvals ?? [];
|
|
33855
|
+
const requiredApprovals = plannedApprovals.length ? plannedApprovals.flatMap((a, index) => {
|
|
33856
|
+
const token = a.tokenAddress ?? fromTokenAddress;
|
|
33857
|
+
const approvalSpender = a.spender;
|
|
33858
|
+
if (!token || !approvalSpender) return [];
|
|
33859
|
+
const amountWei = requiredApprovalAmount(
|
|
33860
|
+
BigInt(a.amount || "0"),
|
|
33861
|
+
fromAmountWei
|
|
33862
|
+
);
|
|
33863
|
+
return [
|
|
33864
|
+
{
|
|
33865
|
+
stepIndex: index,
|
|
33866
|
+
token,
|
|
33867
|
+
spender: approvalSpender,
|
|
33868
|
+
amountWei,
|
|
33869
|
+
chainId: a.chainId || chainIdStr
|
|
33870
|
+
}
|
|
33871
|
+
];
|
|
33872
|
+
}) : spender && fromTokenAddress ? [
|
|
33873
|
+
{
|
|
33874
|
+
stepIndex: null,
|
|
33875
|
+
token: fromTokenAddress,
|
|
33876
|
+
spender,
|
|
33877
|
+
amountWei: fromAmountWei,
|
|
33878
|
+
chainId: chainIdStr
|
|
33879
|
+
}
|
|
33880
|
+
] : [];
|
|
33881
|
+
const ownsApprovals = !isNative && !!walletAddress && !!chainIdStr;
|
|
33882
|
+
const activeAddress = ownsApprovals ? await requireActiveAddress(wallet, walletAddress) : void 0;
|
|
33883
|
+
for (const required of requiredApprovals) {
|
|
33884
|
+
if (!ownsApprovals) break;
|
|
33611
33885
|
let allowanceWei = 0n;
|
|
33612
33886
|
try {
|
|
33613
33887
|
const { allowance } = await getEVMAllowance({
|
|
33614
|
-
chainId:
|
|
33615
|
-
tokenAddress:
|
|
33616
|
-
ownerAddress:
|
|
33617
|
-
spenderAddress: spender
|
|
33888
|
+
chainId: required.chainId,
|
|
33889
|
+
tokenAddress: required.token,
|
|
33890
|
+
ownerAddress: activeAddress,
|
|
33891
|
+
spenderAddress: required.spender
|
|
33618
33892
|
});
|
|
33619
33893
|
allowanceWei = BigInt(allowance || "0");
|
|
33620
33894
|
} catch {
|
|
33621
33895
|
}
|
|
33622
|
-
if (allowanceWei
|
|
33896
|
+
if (!approvalSatisfied(allowanceWei, required.amountWei)) {
|
|
33623
33897
|
setState((p) => ({ ...p, txStatus: "approving" }));
|
|
33624
33898
|
if (!wallet || wallet.ecosystem !== "evm") {
|
|
33625
33899
|
throw new Error("EVM wallet required for token approval");
|
|
@@ -33627,7 +33901,7 @@ function useSwapExecution(fromChain) {
|
|
|
33627
33901
|
if (!chainIdStr || chainIdStr === "0") {
|
|
33628
33902
|
throw new Error("Invalid chain ID for token approval");
|
|
33629
33903
|
}
|
|
33630
|
-
const targetChain = Number(
|
|
33904
|
+
const targetChain = Number(required.chainId ?? txReq.chainId);
|
|
33631
33905
|
if (Number.isFinite(targetChain)) {
|
|
33632
33906
|
const current = await wallet.getChainId();
|
|
33633
33907
|
if (current !== targetChain) {
|
|
@@ -33639,18 +33913,18 @@ function useSwapExecution(fromChain) {
|
|
|
33639
33913
|
}
|
|
33640
33914
|
const approveAmount = maxApproval ? BigInt(
|
|
33641
33915
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
33642
|
-
) :
|
|
33643
|
-
const data =
|
|
33916
|
+
) : required.amountWei;
|
|
33917
|
+
const data = encodeFunctionData10({
|
|
33644
33918
|
abi: erc20Abi2,
|
|
33645
33919
|
functionName: "approve",
|
|
33646
|
-
args: [spender, approveAmount]
|
|
33920
|
+
args: [required.spender, approveAmount]
|
|
33647
33921
|
});
|
|
33648
33922
|
let approvalHash;
|
|
33649
33923
|
if (wallet.type === "eip1193") {
|
|
33650
33924
|
const from = await wallet.getAddress();
|
|
33651
33925
|
const params = {
|
|
33652
33926
|
from,
|
|
33653
|
-
to:
|
|
33927
|
+
to: required.token,
|
|
33654
33928
|
data,
|
|
33655
33929
|
value: "0x0"
|
|
33656
33930
|
};
|
|
@@ -33663,14 +33937,22 @@ function useSwapExecution(fromChain) {
|
|
|
33663
33937
|
});
|
|
33664
33938
|
} else {
|
|
33665
33939
|
const response = await wallet.sendTransaction({
|
|
33666
|
-
to:
|
|
33940
|
+
to: required.token,
|
|
33667
33941
|
data,
|
|
33668
33942
|
value: 0n,
|
|
33669
33943
|
chainId: Number.isFinite(targetChain) ? targetChain : void 0
|
|
33670
33944
|
});
|
|
33671
33945
|
approvalHash = response.hash;
|
|
33672
33946
|
}
|
|
33673
|
-
|
|
33947
|
+
if (required.stepIndex !== null) {
|
|
33948
|
+
void submitStepReceipt(
|
|
33949
|
+
routeResult.intentId,
|
|
33950
|
+
required.stepIndex,
|
|
33951
|
+
approvalHash
|
|
33952
|
+
).catch(() => {
|
|
33953
|
+
});
|
|
33954
|
+
}
|
|
33955
|
+
await waitForApprovalConfirmation(required.chainId, approvalHash);
|
|
33674
33956
|
setState((p) => ({
|
|
33675
33957
|
...p,
|
|
33676
33958
|
txStatus: "confirming",
|
|
@@ -33678,9 +33960,13 @@ function useSwapExecution(fromChain) {
|
|
|
33678
33960
|
}));
|
|
33679
33961
|
}
|
|
33680
33962
|
}
|
|
33963
|
+
if (ownsApprovals) {
|
|
33964
|
+
await requireActiveAddress(wallet, walletAddress);
|
|
33965
|
+
}
|
|
33681
33966
|
const hash = await Trustware.sendRouteTransaction(
|
|
33682
33967
|
routeResult,
|
|
33683
|
-
numericChainId
|
|
33968
|
+
numericChainId,
|
|
33969
|
+
{ approvalsEnsured: ownsApprovals }
|
|
33684
33970
|
);
|
|
33685
33971
|
try {
|
|
33686
33972
|
await submitReceipt(routeResult.intentId, hash);
|
|
@@ -33748,6 +34034,8 @@ var init_useSwapExecution = __esm({
|
|
|
33748
34034
|
"use client";
|
|
33749
34035
|
init_core2();
|
|
33750
34036
|
init_routes();
|
|
34037
|
+
init_http();
|
|
34038
|
+
init_tx();
|
|
33751
34039
|
init_sdkRpc();
|
|
33752
34040
|
init_chainHelpers();
|
|
33753
34041
|
FAST_POLL_MS = 1500;
|
|
@@ -39712,6 +40000,7 @@ function WidgetInner({
|
|
|
39712
40000
|
const { resolvedTheme } = useDepositUi();
|
|
39713
40001
|
const { status, revalidate, errors } = useTrustware();
|
|
39714
40002
|
const [showConfirmDialog, setShowConfirmDialog] = useState35(false);
|
|
40003
|
+
useGTM(GTM_ID);
|
|
39715
40004
|
const handleCloseRequest = useCallback23(() => {
|
|
39716
40005
|
if (ACTIVE_TRANSACTION_STATUSES.includes(transactionStatus)) {
|
|
39717
40006
|
setShowConfirmDialog(true);
|
|
@@ -39785,6 +40074,8 @@ var init_TrustwareWidgetV2 = __esm({
|
|
|
39785
40074
|
init_provider();
|
|
39786
40075
|
init_manager();
|
|
39787
40076
|
init_useTrustwareConfig();
|
|
40077
|
+
init_hooks();
|
|
40078
|
+
init_constants();
|
|
39788
40079
|
init_swap();
|
|
39789
40080
|
widgetContentContainerStyle = {
|
|
39790
40081
|
position: "relative",
|
|
@@ -39945,6 +40236,7 @@ export {
|
|
|
39945
40236
|
DEFAULT_SLIPPAGE2 as DEFAULT_SLIPPAGE,
|
|
39946
40237
|
GTM_ID,
|
|
39947
40238
|
IdentityStore,
|
|
40239
|
+
POPULAR_ORDER,
|
|
39948
40240
|
RateLimitError,
|
|
39949
40241
|
SDK_NAME,
|
|
39950
40242
|
SDK_VERSION,
|
|
@@ -39953,6 +40245,7 @@ export {
|
|
|
39953
40245
|
TrustwareProvider,
|
|
39954
40246
|
TrustwareWidgetV2 as TrustwareWidget,
|
|
39955
40247
|
WALLETCONNECT_PROJECT_ID,
|
|
40248
|
+
WALLETS,
|
|
39956
40249
|
buildWalletIdentityAddress,
|
|
39957
40250
|
connectDetectedWallet,
|
|
39958
40251
|
createWalletIdentity,
|