@trustware/sdk-staging 1.1.12-staging.6 → 1.1.12-staging.7
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.cjs +166 -59
- package/dist/core.cjs.map +1 -1
- package/dist/core.mjs +166 -59
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +254 -114
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +254 -114
- package/dist/index.mjs.map +1 -1
- package/dist/smart-account.cjs +1 -1
- package/dist/smart-account.mjs +1 -1
- package/dist/wallet.cjs +54 -45
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.mjs +54 -45
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +253 -111
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +253 -111
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -312,9 +312,107 @@ var init_bridges = __esm({
|
|
|
312
312
|
}
|
|
313
313
|
});
|
|
314
314
|
|
|
315
|
+
// src/wallets/chainParams.ts
|
|
316
|
+
function chainParamsFor(chainId) {
|
|
317
|
+
return registered.get(chainId) ?? BUILTIN_CHAIN_PARAMS[chainId];
|
|
318
|
+
}
|
|
319
|
+
function registerChainParams(chainId, params) {
|
|
320
|
+
registered.set(chainId, params);
|
|
321
|
+
}
|
|
322
|
+
function usableRpcUrls(chain) {
|
|
323
|
+
const candidates = [
|
|
324
|
+
...Array.isArray(chain.rpcList) ? chain.rpcList : [],
|
|
325
|
+
...chain.rpc ? [chain.rpc] : []
|
|
326
|
+
];
|
|
327
|
+
const seen = /* @__PURE__ */ new Set();
|
|
328
|
+
const out = [];
|
|
329
|
+
for (const raw of candidates) {
|
|
330
|
+
const url = String(raw ?? "").trim();
|
|
331
|
+
if (!/^https?:\/\//i.test(url) || seen.has(url)) continue;
|
|
332
|
+
seen.add(url);
|
|
333
|
+
out.push(url);
|
|
334
|
+
}
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
function chainParamsFromChainDef(chain) {
|
|
338
|
+
const chainType = String(
|
|
339
|
+
chain.chainType ?? chain.type ?? "evm"
|
|
340
|
+
).toLowerCase();
|
|
341
|
+
if (chainType !== "evm") return void 0;
|
|
342
|
+
const numericId = Number(chain.chainId ?? chain.id);
|
|
343
|
+
if (!Number.isSafeInteger(numericId) || numericId <= 0) return void 0;
|
|
344
|
+
const rpcUrls = usableRpcUrls(chain);
|
|
345
|
+
if (rpcUrls.length === 0) return void 0;
|
|
346
|
+
const native = chain.nativeCurrency;
|
|
347
|
+
const symbol = String(native?.symbol ?? "").trim();
|
|
348
|
+
if (!symbol) return void 0;
|
|
349
|
+
const decimals = Number(native?.decimals);
|
|
350
|
+
const chainName = String(
|
|
351
|
+
chain.networkName ?? chain.axelarChainName ?? chain.networkIdentifier ?? ""
|
|
352
|
+
).trim();
|
|
353
|
+
const explorers = (chain.blockExplorerUrls ?? []).filter(
|
|
354
|
+
(u) => /^https?:\/\//i.test(String(u ?? ""))
|
|
355
|
+
);
|
|
356
|
+
return {
|
|
357
|
+
chainIdHex: `0x${numericId.toString(16)}`,
|
|
358
|
+
chainName: chainName || `Chain ${numericId}`,
|
|
359
|
+
rpcUrls,
|
|
360
|
+
nativeCurrency: {
|
|
361
|
+
name: String(native?.name ?? symbol),
|
|
362
|
+
symbol,
|
|
363
|
+
decimals: Number.isFinite(decimals) ? decimals : 18
|
|
364
|
+
},
|
|
365
|
+
...explorers.length > 0 ? { blockExplorerUrls: explorers } : {}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
var BUILTIN_CHAIN_PARAMS, registered;
|
|
369
|
+
var init_chainParams = __esm({
|
|
370
|
+
"src/wallets/chainParams.ts"() {
|
|
371
|
+
"use strict";
|
|
372
|
+
BUILTIN_CHAIN_PARAMS = {
|
|
373
|
+
1: {
|
|
374
|
+
chainIdHex: "0x1",
|
|
375
|
+
chainName: "Ethereum",
|
|
376
|
+
rpcUrls: ["https://eth.llamarpc.com"],
|
|
377
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
378
|
+
blockExplorerUrls: ["https://etherscan.io"]
|
|
379
|
+
},
|
|
380
|
+
137: {
|
|
381
|
+
chainIdHex: "0x89",
|
|
382
|
+
chainName: "Polygon",
|
|
383
|
+
rpcUrls: ["https://polygon-rpc.com"],
|
|
384
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
385
|
+
blockExplorerUrls: ["https://polygonscan.com"]
|
|
386
|
+
},
|
|
387
|
+
8453: {
|
|
388
|
+
chainIdHex: "0x2105",
|
|
389
|
+
chainName: "Base",
|
|
390
|
+
rpcUrls: ["https://mainnet.base.org"],
|
|
391
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
392
|
+
blockExplorerUrls: ["https://basescan.org"]
|
|
393
|
+
},
|
|
394
|
+
42161: {
|
|
395
|
+
chainIdHex: "0xa4b1",
|
|
396
|
+
chainName: "Arbitrum One",
|
|
397
|
+
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
398
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
399
|
+
blockExplorerUrls: ["https://arbiscan.io"]
|
|
400
|
+
},
|
|
401
|
+
43114: {
|
|
402
|
+
chainIdHex: "0xa86a",
|
|
403
|
+
chainName: "Avalanche C-Chain",
|
|
404
|
+
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
405
|
+
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
406
|
+
blockExplorerUrls: ["https://snowtrace.io"]
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
registered = /* @__PURE__ */ new Map();
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
315
413
|
// src/wallets/eipWallets.ts
|
|
316
414
|
async function addThenSwitch(eth, chainId) {
|
|
317
|
-
const p =
|
|
415
|
+
const p = chainParamsFor(chainId);
|
|
318
416
|
if (!p) throw new Error(`Unknown chain ${chainId} (no params to add)`);
|
|
319
417
|
await eth.request({ method: "wallet_addEthereumChain", params: [p] });
|
|
320
418
|
await eth.request({
|
|
@@ -342,7 +440,7 @@ function useEIP1193(eth) {
|
|
|
342
440
|
async switchChain(chainId) {
|
|
343
441
|
if (switching) return;
|
|
344
442
|
switching = true;
|
|
345
|
-
const hex =
|
|
443
|
+
const hex = chainParamsFor(chainId)?.chainIdHex ?? `0x${chainId.toString(16)}`;
|
|
346
444
|
try {
|
|
347
445
|
await eth.request({
|
|
348
446
|
method: "wallet_switchEthereumChain",
|
|
@@ -351,7 +449,6 @@ function useEIP1193(eth) {
|
|
|
351
449
|
} catch (e2) {
|
|
352
450
|
if (e2?.code === 4902) {
|
|
353
451
|
await addThenSwitch(eth, chainId);
|
|
354
|
-
} else if (e2?.code === 4001) {
|
|
355
452
|
} else {
|
|
356
453
|
throw e2;
|
|
357
454
|
}
|
|
@@ -393,15 +490,13 @@ function useWagmi(client) {
|
|
|
393
490
|
const eth = globalThis.ethereum;
|
|
394
491
|
if (!eth?.request) throw new Error("switchChain not available");
|
|
395
492
|
try {
|
|
396
|
-
const hex =
|
|
493
|
+
const hex = chainParamsFor(target)?.chainIdHex ?? `0x${target.toString(16)}`;
|
|
397
494
|
await eth.request({
|
|
398
495
|
method: "wallet_switchEthereumChain",
|
|
399
496
|
params: [{ chainId: hex }]
|
|
400
497
|
});
|
|
401
498
|
} catch (e2) {
|
|
402
499
|
if (e2?.code === 4902) await addThenSwitch(eth, target);
|
|
403
|
-
else if (e2?.code === 4001)
|
|
404
|
-
;
|
|
405
500
|
else throw e2;
|
|
406
501
|
}
|
|
407
502
|
} finally {
|
|
@@ -442,47 +537,10 @@ function useWagmi(client) {
|
|
|
442
537
|
sendTransaction: sendTransaction2
|
|
443
538
|
};
|
|
444
539
|
}
|
|
445
|
-
var CHAIN_PARAMS;
|
|
446
540
|
var init_eipWallets = __esm({
|
|
447
541
|
"src/wallets/eipWallets.ts"() {
|
|
448
542
|
"use strict";
|
|
449
|
-
|
|
450
|
-
1: {
|
|
451
|
-
chainIdHex: "0x1",
|
|
452
|
-
chainName: "Ethereum",
|
|
453
|
-
rpcUrls: ["https://eth.llamarpc.com"],
|
|
454
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
455
|
-
blockExplorerUrls: ["https://etherscan.io"]
|
|
456
|
-
},
|
|
457
|
-
137: {
|
|
458
|
-
chainIdHex: "0x89",
|
|
459
|
-
chainName: "Polygon",
|
|
460
|
-
rpcUrls: ["https://polygon-rpc.com"],
|
|
461
|
-
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
462
|
-
blockExplorerUrls: ["https://polygonscan.com"]
|
|
463
|
-
},
|
|
464
|
-
8453: {
|
|
465
|
-
chainIdHex: "0x2105",
|
|
466
|
-
chainName: "Base",
|
|
467
|
-
rpcUrls: ["https://mainnet.base.org"],
|
|
468
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
469
|
-
blockExplorerUrls: ["https://basescan.org"]
|
|
470
|
-
},
|
|
471
|
-
42161: {
|
|
472
|
-
chainIdHex: "0xa4b1",
|
|
473
|
-
chainName: "Arbitrum One",
|
|
474
|
-
rpcUrls: ["https://arb1.arbitrum.io/rpc"],
|
|
475
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
476
|
-
blockExplorerUrls: ["https://arbiscan.io"]
|
|
477
|
-
},
|
|
478
|
-
43114: {
|
|
479
|
-
chainIdHex: "0xa86a",
|
|
480
|
-
chainName: "Avalanche C-Chain",
|
|
481
|
-
rpcUrls: ["https://api.avax.network/ext/bc/C/rpc"],
|
|
482
|
-
nativeCurrency: { name: "Avalanche", symbol: "AVAX", decimals: 18 },
|
|
483
|
-
blockExplorerUrls: ["https://snowtrace.io"]
|
|
484
|
-
}
|
|
485
|
-
};
|
|
543
|
+
init_chainParams();
|
|
486
544
|
}
|
|
487
545
|
});
|
|
488
546
|
|
|
@@ -492,7 +550,7 @@ var init_constants = __esm({
|
|
|
492
550
|
"src/constants.ts"() {
|
|
493
551
|
"use strict";
|
|
494
552
|
SDK_NAME = "@trustware/sdk";
|
|
495
|
-
SDK_VERSION = "1.1.12-staging.
|
|
553
|
+
SDK_VERSION = "1.1.12-staging.7";
|
|
496
554
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
497
555
|
GTM_ID = "GTM-TZDGNCXB";
|
|
498
556
|
API_PREFIX = "/api";
|
|
@@ -4826,6 +4884,7 @@ var init_registry = __esm({
|
|
|
4826
4884
|
"use strict";
|
|
4827
4885
|
init_store();
|
|
4828
4886
|
init_chains();
|
|
4887
|
+
init_chainParams();
|
|
4829
4888
|
NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
4830
4889
|
PAGE_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
4831
4890
|
PAGE_CACHE_LIMIT = 100;
|
|
@@ -4904,6 +4963,10 @@ var init_registry = __esm({
|
|
|
4904
4963
|
for (const alias of getChainAliases(normalized)) {
|
|
4905
4964
|
this._chainAliases.set(alias, canonicalKey);
|
|
4906
4965
|
}
|
|
4966
|
+
const addParams = chainParamsFromChainDef(normalized);
|
|
4967
|
+
if (addParams) {
|
|
4968
|
+
registerChainParams(Number(normalized.chainId ?? canonical), addParams);
|
|
4969
|
+
}
|
|
4907
4970
|
}
|
|
4908
4971
|
storeTokenForAlias(chainKey, token) {
|
|
4909
4972
|
const key = tokenKey(token);
|
|
@@ -5488,6 +5551,25 @@ function backendChainId(chain, fallback) {
|
|
|
5488
5551
|
function sleep2(ms) {
|
|
5489
5552
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5490
5553
|
}
|
|
5554
|
+
async function ensureWalletOnChain(wallet, target) {
|
|
5555
|
+
if (!Number.isSafeInteger(target) || target <= 0) {
|
|
5556
|
+
throw new Error(`Invalid chain id: ${target}`);
|
|
5557
|
+
}
|
|
5558
|
+
if (await wallet.getChainId() === target) return;
|
|
5559
|
+
let switchError;
|
|
5560
|
+
try {
|
|
5561
|
+
await wallet.switchChain(target);
|
|
5562
|
+
} catch (e2) {
|
|
5563
|
+
switchError = e2;
|
|
5564
|
+
}
|
|
5565
|
+
if (await wallet.getChainId() === target) return;
|
|
5566
|
+
if (switchError && isUserRejected(switchError)) {
|
|
5567
|
+
throw switchError;
|
|
5568
|
+
}
|
|
5569
|
+
throw new Error(
|
|
5570
|
+
`Wallet is on the wrong network. Switch to chain ${target} and try again.`
|
|
5571
|
+
);
|
|
5572
|
+
}
|
|
5491
5573
|
async function sendEvmTx(w, tx) {
|
|
5492
5574
|
if (w.type === "eip1193") {
|
|
5493
5575
|
const from = await w.getAddress();
|
|
@@ -5514,19 +5596,37 @@ async function sendEvmTx(w, tx) {
|
|
|
5514
5596
|
});
|
|
5515
5597
|
return response.hash;
|
|
5516
5598
|
}
|
|
5517
|
-
async function
|
|
5518
|
-
const
|
|
5519
|
-
|
|
5599
|
+
async function waitForEvmTxConfirmation(chainId, txHash, label, options = {}) {
|
|
5600
|
+
const {
|
|
5601
|
+
readStatus = getEVMTxStatus,
|
|
5602
|
+
timeoutMs = 12e4,
|
|
5603
|
+
intervalMs = 2e3,
|
|
5604
|
+
notFoundGraceMs = NOT_FOUND_GRACE_MS
|
|
5605
|
+
} = options;
|
|
5520
5606
|
const started = Date.now();
|
|
5607
|
+
let notFoundSince = null;
|
|
5521
5608
|
while (Date.now() - started < timeoutMs) {
|
|
5522
|
-
const status = await
|
|
5609
|
+
const status = await readStatus({ chainId, txHash });
|
|
5523
5610
|
if (status.status === "success") return;
|
|
5524
5611
|
if (status.status === "reverted") {
|
|
5525
|
-
throw new Error(
|
|
5612
|
+
throw new Error(`${label} transaction reverted`);
|
|
5613
|
+
}
|
|
5614
|
+
if (status.status === "not_found") {
|
|
5615
|
+
notFoundSince ?? (notFoundSince = Date.now());
|
|
5616
|
+
if (Date.now() - notFoundSince >= notFoundGraceMs) {
|
|
5617
|
+
throw new Error(
|
|
5618
|
+
`${label} transaction ${txHash} was not found on chain ${chainId}. It may have been sent on a different network \u2014 check your wallet's selected network and try again.`
|
|
5619
|
+
);
|
|
5620
|
+
}
|
|
5621
|
+
} else {
|
|
5622
|
+
notFoundSince = null;
|
|
5526
5623
|
}
|
|
5527
5624
|
await sleep2(intervalMs);
|
|
5528
5625
|
}
|
|
5529
|
-
throw new Error(
|
|
5626
|
+
throw new Error(`Timed out waiting for ${label.toLowerCase()} confirmation`);
|
|
5627
|
+
}
|
|
5628
|
+
function waitForApprovalConfirmation(chainId, txHash, options) {
|
|
5629
|
+
return waitForEvmTxConfirmation(chainId, txHash, "Approval", options);
|
|
5530
5630
|
}
|
|
5531
5631
|
function requiredApprovalAmount(planAmountWei, routeAmountWei) {
|
|
5532
5632
|
if (planAmountWei >= UNLIMITED_APPROVAL_FLOOR && routeAmountWei !== void 0 && routeAmountWei > 0n) {
|
|
@@ -5566,17 +5666,22 @@ async function ensureApprovals(w, approvals, fallbackChainId, intentId, routeAmo
|
|
|
5566
5666
|
functionName: "approve",
|
|
5567
5667
|
args: [spender, amountWei]
|
|
5568
5668
|
});
|
|
5669
|
+
const approvalChainId = Number(chainId);
|
|
5670
|
+
if (!Number.isSafeInteger(approvalChainId) || approvalChainId <= 0) {
|
|
5671
|
+
throw new Error(`Approval has an invalid chain id: ${chainId}`);
|
|
5672
|
+
}
|
|
5673
|
+
await ensureWalletOnChain(w, approvalChainId);
|
|
5569
5674
|
const hash = await sendEvmTx(w, {
|
|
5570
5675
|
to: tokenAddress,
|
|
5571
5676
|
data,
|
|
5572
5677
|
value: 0n,
|
|
5573
|
-
chainId:
|
|
5678
|
+
chainId: approvalChainId
|
|
5574
5679
|
});
|
|
5575
5680
|
if (intentId) {
|
|
5576
5681
|
void submitStepReceipt(intentId, stepIndex, hash).catch(() => {
|
|
5577
5682
|
});
|
|
5578
5683
|
}
|
|
5579
|
-
await
|
|
5684
|
+
await waitForApprovalConfirmation(chainId, hash);
|
|
5580
5685
|
}
|
|
5581
5686
|
}
|
|
5582
5687
|
function isUserRejected(e2) {
|
|
@@ -5603,15 +5708,14 @@ async function sendRouteTransaction(b, fallbackChainId, options) {
|
|
|
5603
5708
|
validatedSponsorship = b.sponsorship;
|
|
5604
5709
|
}
|
|
5605
5710
|
}
|
|
5606
|
-
if (Number.
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
}
|
|
5613
|
-
}
|
|
5711
|
+
if (!Number.isSafeInteger(target) || target <= 0) {
|
|
5712
|
+
throw new Error(
|
|
5713
|
+
`Route is missing a usable chain id (got ${String(
|
|
5714
|
+
txReq.chainId ?? fallbackChainId
|
|
5715
|
+
)}).`
|
|
5716
|
+
);
|
|
5614
5717
|
}
|
|
5718
|
+
await ensureWalletOnChain(w, target);
|
|
5615
5719
|
if (!validatedSponsorship && !options?.approvalsEnsured) {
|
|
5616
5720
|
await ensureApprovals(
|
|
5617
5721
|
w,
|
|
@@ -5717,7 +5821,7 @@ async function runTopUp(params) {
|
|
|
5717
5821
|
}
|
|
5718
5822
|
}
|
|
5719
5823
|
}
|
|
5720
|
-
var erc20ApproveAbi, UNLIMITED_APPROVAL_FLOOR;
|
|
5824
|
+
var erc20ApproveAbi, NOT_FOUND_GRACE_MS, UNLIMITED_APPROVAL_FLOOR;
|
|
5721
5825
|
var init_tx = __esm({
|
|
5722
5826
|
"src/core/tx.ts"() {
|
|
5723
5827
|
"use strict";
|
|
@@ -5727,6 +5831,7 @@ var init_tx = __esm({
|
|
|
5727
5831
|
erc20ApproveAbi = parseAbi([
|
|
5728
5832
|
"function approve(address spender, uint256 amount) returns (bool)"
|
|
5729
5833
|
]);
|
|
5834
|
+
NOT_FOUND_GRACE_MS = 2e4;
|
|
5730
5835
|
UNLIMITED_APPROVAL_FLOOR = 1n << 255n;
|
|
5731
5836
|
}
|
|
5732
5837
|
});
|
|
@@ -33715,6 +33820,35 @@ var init_useSwapRoute = __esm({
|
|
|
33715
33820
|
}
|
|
33716
33821
|
});
|
|
33717
33822
|
|
|
33823
|
+
// src/modes/swap/routeValue.ts
|
|
33824
|
+
function parseUsd(value) {
|
|
33825
|
+
if (value == null) return null;
|
|
33826
|
+
const n = parseFloat(value);
|
|
33827
|
+
return Number.isFinite(n) ? n : null;
|
|
33828
|
+
}
|
|
33829
|
+
function routeNetUsd(estimate) {
|
|
33830
|
+
if (!estimate) return null;
|
|
33831
|
+
const toUsd = parseUsd(estimate.toAmountUsd);
|
|
33832
|
+
const feesUsd = parseUsd(estimate.totalFeesUsd);
|
|
33833
|
+
if (toUsd == null || feesUsd == null) return null;
|
|
33834
|
+
return toUsd - feesUsd;
|
|
33835
|
+
}
|
|
33836
|
+
function isValueDestroying(estimate) {
|
|
33837
|
+
const net = routeNetUsd(estimate);
|
|
33838
|
+
if (net == null) return false;
|
|
33839
|
+
const toUsd = parseUsd(estimate?.toAmountUsd) ?? 0;
|
|
33840
|
+
const feesUsd = parseUsd(estimate?.totalFeesUsd) ?? 0;
|
|
33841
|
+
if (toUsd < USD_NOISE_FLOOR && feesUsd < USD_NOISE_FLOOR) return false;
|
|
33842
|
+
return net < 0;
|
|
33843
|
+
}
|
|
33844
|
+
var USD_NOISE_FLOOR;
|
|
33845
|
+
var init_routeValue = __esm({
|
|
33846
|
+
"src/modes/swap/routeValue.ts"() {
|
|
33847
|
+
"use strict";
|
|
33848
|
+
USD_NOISE_FLOOR = 5e-3;
|
|
33849
|
+
}
|
|
33850
|
+
});
|
|
33851
|
+
|
|
33718
33852
|
// src/modes/swap/hooks/useSwapExecution.ts
|
|
33719
33853
|
import { useCallback as useCallback21, useRef as useRef16, useState as useState29 } from "react";
|
|
33720
33854
|
import { encodeFunctionData as encodeFunctionData10, erc20Abi as erc20Abi2 } from "viem";
|
|
@@ -33728,9 +33862,6 @@ function normalizeTx(raw) {
|
|
|
33728
33862
|
toChainTxUrl: r.toChainTxUrl || r.to_chain_tx_url || void 0
|
|
33729
33863
|
};
|
|
33730
33864
|
}
|
|
33731
|
-
function sleep4(ms) {
|
|
33732
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33733
|
-
}
|
|
33734
33865
|
function isUserRejection(err) {
|
|
33735
33866
|
if (!err) return false;
|
|
33736
33867
|
const e2 = err;
|
|
@@ -33739,17 +33870,6 @@ function isUserRejection(err) {
|
|
|
33739
33870
|
const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
|
|
33740
33871
|
return msg.includes("user rejected") || msg.includes("user denied") || msg.includes("cancelled");
|
|
33741
33872
|
}
|
|
33742
|
-
async function waitForApprovalConfirmation(chainId, txHash) {
|
|
33743
|
-
const started = Date.now();
|
|
33744
|
-
while (Date.now() - started < 12e4) {
|
|
33745
|
-
const status = await getEVMTxStatus({ chainId, txHash });
|
|
33746
|
-
if (status.status === "success") return;
|
|
33747
|
-
if (status.status === "reverted")
|
|
33748
|
-
throw new Error("Approval transaction reverted");
|
|
33749
|
-
await sleep4(2e3);
|
|
33750
|
-
}
|
|
33751
|
-
throw new Error("Timed out waiting for approval confirmation");
|
|
33752
|
-
}
|
|
33753
33873
|
async function requireActiveAddress(wallet, plannedFor) {
|
|
33754
33874
|
if (!wallet) throw new Error("Wallet not connected. Please reconnect.");
|
|
33755
33875
|
const active = await wallet.getAddress();
|
|
@@ -33913,6 +34033,12 @@ function useSwapExecution(fromChain) {
|
|
|
33913
34033
|
onError(msg);
|
|
33914
34034
|
return;
|
|
33915
34035
|
}
|
|
34036
|
+
if (isValueDestroying(routeResult.route?.estimate)) {
|
|
34037
|
+
const msg = "This route now costs more in fees than it delivers. Get a new quote.";
|
|
34038
|
+
setState((p) => ({ ...p, txStatus: "error", errorMessage: msg }));
|
|
34039
|
+
onError(msg);
|
|
34040
|
+
return;
|
|
34041
|
+
}
|
|
33916
34042
|
setState((p) => ({
|
|
33917
34043
|
...p,
|
|
33918
34044
|
isSubmitting: true,
|
|
@@ -34054,15 +34180,10 @@ function useSwapExecution(fromChain) {
|
|
|
34054
34180
|
throw new Error("Invalid chain ID for token approval");
|
|
34055
34181
|
}
|
|
34056
34182
|
const targetChain = Number(required.chainId ?? txReq.chainId);
|
|
34057
|
-
if (Number.isFinite(targetChain)) {
|
|
34058
|
-
|
|
34059
|
-
if (current !== targetChain) {
|
|
34060
|
-
try {
|
|
34061
|
-
await wallet.switchChain(targetChain);
|
|
34062
|
-
} catch {
|
|
34063
|
-
}
|
|
34064
|
-
}
|
|
34183
|
+
if (!Number.isFinite(targetChain)) {
|
|
34184
|
+
throw new Error("Invalid chain ID for token approval");
|
|
34065
34185
|
}
|
|
34186
|
+
await ensureWalletOnChain(wallet, targetChain);
|
|
34066
34187
|
const approveAmount = maxApproval ? BigInt(
|
|
34067
34188
|
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
|
|
34068
34189
|
) : required.amountWei;
|
|
@@ -34188,6 +34309,7 @@ var init_useSwapExecution = __esm({
|
|
|
34188
34309
|
init_failure();
|
|
34189
34310
|
init_tx();
|
|
34190
34311
|
init_sdkRpc();
|
|
34312
|
+
init_routeValue();
|
|
34191
34313
|
init_chainHelpers();
|
|
34192
34314
|
FAST_POLL_MS = 1500;
|
|
34193
34315
|
SLOW_POLL_MS = 2500;
|
|
@@ -38133,8 +38255,9 @@ function SwapMode({
|
|
|
38133
38255
|
}
|
|
38134
38256
|
) });
|
|
38135
38257
|
}
|
|
38136
|
-
const
|
|
38137
|
-
const
|
|
38258
|
+
const feesExceedOutput = isValueDestroying(route.data?.route?.estimate);
|
|
38259
|
+
const ctaLabel = !hasTokens ? "Get started" : !hasAmount ? "Enter an amount" : insufficient ? `Insufficient ${fromToken?.symbol} balance` : !isConnected ? "Connect Wallet" : needsDestAddress && !isValidDestAddress ? `Enter ${toChain?.networkName ?? "destination"} address` : route.loading ? "Getting quote..." : feesExceedOutput ? "Fees exceed amount received" : "Review";
|
|
38260
|
+
const ctaDisabled = !hasTokens || !hasAmount || insufficient || isConnected && needsDestAddress && !isValidDestAddress || route.loading || feesExceedOutput;
|
|
38138
38261
|
const ctaAction = !isConnected ? handleConnectAndReview : () => void handleReview();
|
|
38139
38262
|
const showRateRow = hasTokens && exchangeRate !== null;
|
|
38140
38263
|
return /* @__PURE__ */ jsx59(WidgetContainer, { theme: resolvedTheme, style, children: /* @__PURE__ */ jsxs47(
|
|
@@ -39236,35 +39359,51 @@ function SwapMode({
|
|
|
39236
39359
|
]
|
|
39237
39360
|
}
|
|
39238
39361
|
),
|
|
39239
|
-
/* @__PURE__ */
|
|
39240
|
-
|
|
39241
|
-
|
|
39242
|
-
|
|
39243
|
-
|
|
39244
|
-
|
|
39245
|
-
|
|
39246
|
-
|
|
39247
|
-
|
|
39248
|
-
|
|
39249
|
-
|
|
39250
|
-
|
|
39251
|
-
|
|
39252
|
-
|
|
39253
|
-
|
|
39362
|
+
/* @__PURE__ */ jsxs47("div", { style: { padding: `${spacing[2]} ${spacing[3]} 0` }, children: [
|
|
39363
|
+
/* @__PURE__ */ jsx59(
|
|
39364
|
+
"button",
|
|
39365
|
+
{
|
|
39366
|
+
disabled: ctaDisabled,
|
|
39367
|
+
onClick: ctaAction,
|
|
39368
|
+
style: mergeStyles(
|
|
39369
|
+
{
|
|
39370
|
+
width: "100%",
|
|
39371
|
+
height: "3.5rem",
|
|
39372
|
+
borderRadius: "1.5rem",
|
|
39373
|
+
fontSize: fontSize.base,
|
|
39374
|
+
fontWeight: fontWeight.semibold,
|
|
39375
|
+
border: 0,
|
|
39376
|
+
transition: "all 0.2s",
|
|
39377
|
+
marginBottom: spacing[3]
|
|
39378
|
+
},
|
|
39379
|
+
!ctaDisabled ? {
|
|
39380
|
+
backgroundColor: colors.primary,
|
|
39381
|
+
color: colors.primaryForeground,
|
|
39382
|
+
cursor: "pointer"
|
|
39383
|
+
} : {
|
|
39384
|
+
backgroundColor: "hsl(var(--tw-muted))",
|
|
39385
|
+
color: colors.mutedForeground,
|
|
39386
|
+
cursor: "default"
|
|
39387
|
+
}
|
|
39388
|
+
),
|
|
39389
|
+
children: ctaLabel
|
|
39390
|
+
}
|
|
39391
|
+
),
|
|
39392
|
+
feesExceedOutput && /* @__PURE__ */ jsx59(
|
|
39393
|
+
"div",
|
|
39394
|
+
{
|
|
39395
|
+
style: {
|
|
39396
|
+
marginTop: `-${spacing[2]}`,
|
|
39397
|
+
marginBottom: spacing[3],
|
|
39398
|
+
fontSize: fontSize.xs,
|
|
39399
|
+
lineHeight: 1.4,
|
|
39400
|
+
color: "#f87171",
|
|
39401
|
+
textAlign: "center"
|
|
39254
39402
|
},
|
|
39255
|
-
|
|
39256
|
-
|
|
39257
|
-
|
|
39258
|
-
|
|
39259
|
-
} : {
|
|
39260
|
-
backgroundColor: "hsl(var(--tw-muted))",
|
|
39261
|
-
color: colors.mutedForeground,
|
|
39262
|
-
cursor: "default"
|
|
39263
|
-
}
|
|
39264
|
-
),
|
|
39265
|
-
children: ctaLabel
|
|
39266
|
-
}
|
|
39267
|
-
) }),
|
|
39403
|
+
children: "This route costs more in fees than it delivers. Try a larger amount, or a different token or network."
|
|
39404
|
+
}
|
|
39405
|
+
)
|
|
39406
|
+
] }),
|
|
39268
39407
|
showRateRow && /* @__PURE__ */ jsxs47(
|
|
39269
39408
|
"div",
|
|
39270
39409
|
{
|
|
@@ -40109,6 +40248,7 @@ var init_SwapMode = __esm({
|
|
|
40109
40248
|
init_provider();
|
|
40110
40249
|
init_useSwapRoute();
|
|
40111
40250
|
init_useSwapExecution();
|
|
40251
|
+
init_routeValue();
|
|
40112
40252
|
init_useForex();
|
|
40113
40253
|
init_SwapTokenSelect();
|
|
40114
40254
|
init_currency();
|