@rash2x/bridge-widget 0.6.80 → 0.6.82

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.
@@ -2849,7 +2849,7 @@ const Tip = (props) => {
2849
2849
  const { children, text } = props;
2850
2850
  return /* @__PURE__ */ jsxRuntime.jsxs(tooltip.Tooltip, { children: [
2851
2851
  /* @__PURE__ */ jsxRuntime.jsx(tooltip.TooltipTrigger, { className: "w-4 h-4 rounded-full bg-muted text-muted-foreground", children }),
2852
- /* @__PURE__ */ jsxRuntime.jsx(tooltip.TooltipContent, { className: "max-w-64", children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: text }) })
2852
+ /* @__PURE__ */ jsxRuntime.jsx(tooltip.TooltipContent, { className: "max-w-64", children: text })
2853
2853
  ] });
2854
2854
  };
2855
2855
  const BASE_URL = "https://icons-ckg.pages.dev/stargate-light/tokens";
@@ -3444,6 +3444,115 @@ async function waitForLayerZeroCompletion(txHash, timeoutMs = 6e5, pollIntervalM
3444
3444
  status: "TIMEOUT"
3445
3445
  };
3446
3446
  }
3447
+ const useBridgeReportStore = zustand.create((set2) => ({
3448
+ config: {
3449
+ enabled: false,
3450
+ authToken: void 0,
3451
+ baseUrl: void 0
3452
+ },
3453
+ setConfig: (config) => {
3454
+ set2({ config });
3455
+ },
3456
+ setAuthToken: (token) => {
3457
+ set2((state2) => ({
3458
+ config: { ...state2.config, authToken: token }
3459
+ }));
3460
+ },
3461
+ setEnabled: (enabled) => {
3462
+ set2((state2) => ({
3463
+ config: { ...state2.config, enabled }
3464
+ }));
3465
+ }
3466
+ }));
3467
+ async function tryFetch(url) {
3468
+ try {
3469
+ const res = await fetch(url);
3470
+ if (!res.ok) return null;
3471
+ return await res.json();
3472
+ } catch {
3473
+ return null;
3474
+ }
3475
+ }
3476
+ function interpretStatus(data) {
3477
+ if (!data) return null;
3478
+ const d3 = Array.isArray(data) ? data[0] : data;
3479
+ const lower2 = JSON.stringify(d3).toLowerCase();
3480
+ const hasDst = d3?.dstTxHash || d3?.dstTx || d3?.destinationTxHash || d3?.dstHash;
3481
+ const delivered = d3?.delivered === true || d3?.status === "delivered" || d3?.status === "completed" || typeof hasDst === "string" && hasDst.length > 0;
3482
+ const failed = d3?.status === "failed" || lower2.includes("failed") || lower2.includes("reverted");
3483
+ if (delivered) return { status: "delivered", srcTxHash: d3?.srcTxHash || d3?.srcTx, dstTxHash: hasDst || void 0, raw: d3 };
3484
+ if (failed) return { status: "failed", srcTxHash: d3?.srcTxHash || d3?.srcTx, raw: d3 };
3485
+ return { status: "pending", srcTxHash: d3?.srcTxHash || d3?.srcTx, raw: d3 };
3486
+ }
3487
+ async function getDeliveryStatus(params) {
3488
+ const query = new URLSearchParams();
3489
+ query.set("srcChainKey", params.srcChainKey);
3490
+ if (params.dstChainKey) query.set("dstChainKey", params.dstChainKey);
3491
+ query.set("srcTxHash", params.srcTxHash);
3492
+ const bases2 = [
3493
+ `https://stargate.finance/api/v1/transactions?${query.toString()}`,
3494
+ `https://stargate.finance/api/v1/txStatus?${query.toString()}`,
3495
+ `https://stargate.finance/api/v1/messageStatus?${query.toString()}`
3496
+ ];
3497
+ for (const url of bases2) {
3498
+ const json = await tryFetch(url);
3499
+ const st2 = interpretStatus(json);
3500
+ if (st2) return st2;
3501
+ }
3502
+ return null;
3503
+ }
3504
+ async function pollUntilDelivered(args) {
3505
+ const { intervalMs = 7e3, timeoutMs = 12 * 60 * 1e3 } = args;
3506
+ const start = Date.now();
3507
+ while (true) {
3508
+ if (args.signal?.aborted) throw new Error("aborted");
3509
+ const st2 = await getDeliveryStatus({
3510
+ srcChainKey: args.srcChainKey,
3511
+ dstChainKey: args.dstChainKey,
3512
+ srcTxHash: args.srcTxHash
3513
+ });
3514
+ if (st2) args.onUpdate?.(st2);
3515
+ if (st2?.status === "delivered") return st2;
3516
+ if (st2?.status === "failed") return st2;
3517
+ if (Date.now() - start > timeoutMs) return { status: "failed", srcTxHash: args.srcTxHash };
3518
+ await new Promise((r2) => setTimeout(r2, intervalMs));
3519
+ }
3520
+ }
3521
+ const DEFAULT_BRIDGE_REPORT_URL = "https://api.evaa.space/query/user/bridge";
3522
+ async function reportBridgeTransaction(params, config) {
3523
+ if (!config.enabled) {
3524
+ return { status: "ok" };
3525
+ }
3526
+ const url = config.baseUrl || DEFAULT_BRIDGE_REPORT_URL;
3527
+ const headers = {
3528
+ "Content-Type": "application/json"
3529
+ };
3530
+ if (config.authToken) {
3531
+ headers["Authorization"] = `Bearer ${config.authToken}`;
3532
+ }
3533
+ try {
3534
+ const res = await fetch(url, {
3535
+ method: "POST",
3536
+ headers,
3537
+ body: JSON.stringify(params)
3538
+ });
3539
+ const data = await res.json();
3540
+ if (!res.ok) {
3541
+ return {
3542
+ status: "error",
3543
+ error: data.error || "Failed to report bridge transaction",
3544
+ messages: data.messages
3545
+ };
3546
+ }
3547
+ return data;
3548
+ } catch (error) {
3549
+ console.error("Failed to report bridge transaction:", error);
3550
+ return {
3551
+ status: "error",
3552
+ error: error instanceof Error ? error.message : "Network error"
3553
+ };
3554
+ }
3555
+ }
3447
3556
  function useBridgeTransaction() {
3448
3557
  const { quote } = useBridgeQuoteStore();
3449
3558
  const { chainRegistry } = useChainStrategies();
@@ -3451,6 +3560,8 @@ function useBridgeTransaction() {
3451
3560
  const { assetMatrix, selectedAssetSymbol, allTokens } = useTokensStore();
3452
3561
  const { chains } = useChainsStore();
3453
3562
  const txStore = useTransactionStore();
3563
+ const { config: bridgeReportConfig } = useBridgeReportStore();
3564
+ const gas = useGasEstimate();
3454
3565
  const srcToken = react.useMemo(
3455
3566
  () => resolveTokenOnChainFromMatrix$2(
3456
3567
  assetMatrix,
@@ -3548,6 +3659,24 @@ function useBridgeTransaction() {
3548
3659
  console.warn("Failed to convert TON message hash to tx hash");
3549
3660
  }
3550
3661
  }
3662
+ if (bridgeReportConfig.enabled) {
3663
+ reportBridgeTransaction(
3664
+ {
3665
+ lz_tx_hash: hashForLayerZero,
3666
+ from_address: srcAddress,
3667
+ to_address: dstAddress,
3668
+ amount: amounts.inputHuman.toString(),
3669
+ token: srcToken?.symbol || quote.srcToken,
3670
+ from_network: srcChain?.name || quote.srcChainKey,
3671
+ to_network: dstChain?.name || quote.dstChainKey,
3672
+ estimated_fee: gas.requiredNative.toString(),
3673
+ sent_at: (/* @__PURE__ */ new Date()).toISOString()
3674
+ },
3675
+ bridgeReportConfig
3676
+ ).catch((err) => {
3677
+ console.warn("Failed to report bridge transaction:", err);
3678
+ });
3679
+ }
3551
3680
  const lzResult = await waitForLayerZeroCompletion(
3552
3681
  hashForLayerZero,
3553
3682
  6e5,
@@ -25726,7 +25855,7 @@ class WalletConnectModal {
25726
25855
  }
25727
25856
  async initUi() {
25728
25857
  if (typeof window !== "undefined") {
25729
- await Promise.resolve().then(() => require("./index-C2fA8rVi.cjs"));
25858
+ await Promise.resolve().then(() => require("./index-BS3qjc1r.cjs"));
25730
25859
  const modal = document.createElement("wcm-modal");
25731
25860
  document.body.insertAdjacentElement("beforeend", modal);
25732
25861
  OptionsCtrl.setIsUiLoaded(true);
@@ -26168,6 +26297,14 @@ function useUrlSync(options) {
26168
26297
  const EvaaBridgeWithProviders = (props) => {
26169
26298
  const [tonConnectUI] = uiReact.useTonConnectUI();
26170
26299
  const tonAddress = uiReact.useTonAddress();
26300
+ const { setConfig: setBridgeReportConfig } = useBridgeReportStore();
26301
+ react.useEffect(() => {
26302
+ if (props.bridgeReport) {
26303
+ setBridgeReportConfig(props.bridgeReport);
26304
+ } else {
26305
+ setBridgeReportConfig({ enabled: false });
26306
+ }
26307
+ }, [props.bridgeReport, setBridgeReportConfig]);
26171
26308
  const { address: evmAddress, isConnected: evmIsConnected } = wagmi.useAccount();
26172
26309
  const { disconnect: evmDisconnect } = wagmi.useDisconnect();
26173
26310
  const { data: walletClient } = wagmi.useWalletClient();
@@ -26404,60 +26541,6 @@ const EvaaBridgeContent = ({
26404
26541
  ] });
26405
26542
  };
26406
26543
  const EvaaBridge = EvaaBridgeWithProviders;
26407
- async function tryFetch(url) {
26408
- try {
26409
- const res = await fetch(url);
26410
- if (!res.ok) return null;
26411
- return await res.json();
26412
- } catch {
26413
- return null;
26414
- }
26415
- }
26416
- function interpretStatus(data) {
26417
- if (!data) return null;
26418
- const d3 = Array.isArray(data) ? data[0] : data;
26419
- const lower2 = JSON.stringify(d3).toLowerCase();
26420
- const hasDst = d3?.dstTxHash || d3?.dstTx || d3?.destinationTxHash || d3?.dstHash;
26421
- const delivered = d3?.delivered === true || d3?.status === "delivered" || d3?.status === "completed" || typeof hasDst === "string" && hasDst.length > 0;
26422
- const failed = d3?.status === "failed" || lower2.includes("failed") || lower2.includes("reverted");
26423
- if (delivered) return { status: "delivered", srcTxHash: d3?.srcTxHash || d3?.srcTx, dstTxHash: hasDst || void 0, raw: d3 };
26424
- if (failed) return { status: "failed", srcTxHash: d3?.srcTxHash || d3?.srcTx, raw: d3 };
26425
- return { status: "pending", srcTxHash: d3?.srcTxHash || d3?.srcTx, raw: d3 };
26426
- }
26427
- async function getDeliveryStatus(params) {
26428
- const query = new URLSearchParams();
26429
- query.set("srcChainKey", params.srcChainKey);
26430
- if (params.dstChainKey) query.set("dstChainKey", params.dstChainKey);
26431
- query.set("srcTxHash", params.srcTxHash);
26432
- const bases2 = [
26433
- `https://stargate.finance/api/v1/transactions?${query.toString()}`,
26434
- `https://stargate.finance/api/v1/txStatus?${query.toString()}`,
26435
- `https://stargate.finance/api/v1/messageStatus?${query.toString()}`
26436
- ];
26437
- for (const url of bases2) {
26438
- const json = await tryFetch(url);
26439
- const st2 = interpretStatus(json);
26440
- if (st2) return st2;
26441
- }
26442
- return null;
26443
- }
26444
- async function pollUntilDelivered(args) {
26445
- const { intervalMs = 7e3, timeoutMs = 12 * 60 * 1e3 } = args;
26446
- const start = Date.now();
26447
- while (true) {
26448
- if (args.signal?.aborted) throw new Error("aborted");
26449
- const st2 = await getDeliveryStatus({
26450
- srcChainKey: args.srcChainKey,
26451
- dstChainKey: args.dstChainKey,
26452
- srcTxHash: args.srcTxHash
26453
- });
26454
- if (st2) args.onUpdate?.(st2);
26455
- if (st2?.status === "delivered") return st2;
26456
- if (st2?.status === "failed") return st2;
26457
- if (Date.now() - start > timeoutMs) return { status: "failed", srcTxHash: args.srcTxHash };
26458
- await new Promise((r2) => setTimeout(r2, intervalMs));
26459
- }
26460
- }
26461
26544
  exports.ConfigCtrl = ConfigCtrl;
26462
26545
  exports.CoreUtil = CoreUtil;
26463
26546
  exports.DEFAULT_SLIPPAGE_BPS = DEFAULT_SLIPPAGE_BPS;
@@ -26504,6 +26587,7 @@ exports.listAssetsForSelect = listAssetsForSelect;
26504
26587
  exports.lookupTokenMeta = lookupTokenMeta;
26505
26588
  exports.normalizeTickerSymbol = normalizeTickerSymbol$1;
26506
26589
  exports.pollUntilDelivered = pollUntilDelivered;
26590
+ exports.reportBridgeTransaction = reportBridgeTransaction;
26507
26591
  exports.resolveTokenOnChain = resolveTokenOnChain;
26508
26592
  exports.resolveTokenOnChainFromMatrix = resolveTokenOnChainFromMatrix$2;
26509
26593
  exports.sumFeeByTokenLD = sumFeeByTokenLD;
@@ -26512,6 +26596,7 @@ exports.tonNorm = tonNorm;
26512
26596
  exports.truncateToDecimals = truncateToDecimals;
26513
26597
  exports.useBridgeExternalData = useBridgeExternalData;
26514
26598
  exports.useBridgeQuoteStore = useBridgeQuoteStore;
26599
+ exports.useBridgeReportStore = useBridgeReportStore;
26515
26600
  exports.useChainsStore = useChainsStore;
26516
26601
  exports.useConnectedWalletsStore = useConnectedWalletsStore;
26517
26602
  exports.useCustomAddressStore = useCustomAddressStore;
@@ -26519,4 +26604,4 @@ exports.useSettingsStore = useSettingsStore;
26519
26604
  exports.useSwapModel = useSwapModel;
26520
26605
  exports.useTokensStore = useTokensStore;
26521
26606
  exports.useTransactionStore = useTransactionStore;
26522
- //# sourceMappingURL=index-CcSC-h6y.cjs.map
26607
+ //# sourceMappingURL=index-BXWxz9wW.cjs.map