@skip-go/widget 3.12.1 → 3.12.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.
@@ -1,5 +1,5 @@
1
1
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
2
- import o, { useContext, useState, useMemo, useEffect, useRef, useDebugValue, createElement, useCallback, Fragment as Fragment$1, memo, forwardRef } from "react";
2
+ import o, { useContext, useState, useMemo, useEffect, useRef, useDebugValue, createElement, useCallback, Fragment as Fragment$1, memo, startTransition, forwardRef, Suspense } from "react";
3
3
  import { Scope } from "react-shadow-scope";
4
4
  import { atom as atom$1, useAtomValue, useAtom, useSetAtom, createStore, Provider } from "jotai";
5
5
  import NiceModal, { useModal } from "@ebay/nice-modal-react";
@@ -5040,61 +5040,6 @@ function atomWithDebounce(delayMilliseconds = 250) {
5040
5040
  };
5041
5041
  }
5042
5042
  const callbacksAtom = atom$1();
5043
- const openDb = () => {
5044
- return new Promise((resolve, reject) => {
5045
- const request = indexedDB.open("skip-go-widget", 1);
5046
- request.onupgradeneeded = () => {
5047
- request.result.createObjectStore("atoms");
5048
- };
5049
- request.onsuccess = () => resolve(request.result);
5050
- request.onerror = () => reject(request.error);
5051
- });
5052
- };
5053
- const idbGet = async (key) => {
5054
- const db = await openDb();
5055
- return await new Promise((resolve, reject) => {
5056
- const tx = db.transaction("atoms", "readonly");
5057
- const store = tx.objectStore("atoms");
5058
- const request = store.get(key);
5059
- request.onsuccess = () => resolve(request.result);
5060
- request.onerror = () => reject(request.error);
5061
- });
5062
- };
5063
- const idbSet = async (key, value) => {
5064
- const db = await openDb();
5065
- return await new Promise((resolve, reject) => {
5066
- const tx = db.transaction("atoms", "readwrite");
5067
- const store = tx.objectStore("atoms");
5068
- const request = store.put(value, key);
5069
- request.onsuccess = () => resolve();
5070
- request.onerror = () => reject(request.error);
5071
- });
5072
- };
5073
- const idbDelete = async (key) => {
5074
- const db = await openDb();
5075
- return await new Promise((resolve, reject) => {
5076
- const tx = db.transaction("atoms", "readwrite");
5077
- const store = tx.objectStore("atoms");
5078
- const request = store.delete(key);
5079
- request.onsuccess = () => resolve();
5080
- request.onerror = () => reject(request.error);
5081
- });
5082
- };
5083
- function atomWithIndexedDBStorage(storageKey, initialValue) {
5084
- const defaultStorage2 = {
5085
- getItem: async (key) => {
5086
- const value = await idbGet(key);
5087
- return value ?? initialValue;
5088
- },
5089
- setItem: async (key, newValue) => {
5090
- await idbSet(key, newValue);
5091
- },
5092
- removeItem: async (key) => {
5093
- await idbDelete(key);
5094
- }
5095
- };
5096
- return atomWithStorage(storageKey, initialValue, defaultStorage2, { getOnInit: true });
5097
- }
5098
5043
  function atomWithStorageNoCrossTabSync(storageKey, initialValue) {
5099
5044
  const defaultStorage2 = {
5100
5045
  getItem: (key) => {
@@ -5182,6 +5127,7 @@ var LOCAL_STORAGE_KEYS = /* @__PURE__ */ ((LOCAL_STORAGE_KEYS2) => {
5182
5127
  LOCAL_STORAGE_KEYS2["sourceAsset"] = "sourceAsset";
5183
5128
  LOCAL_STORAGE_KEYS2["destinationAsset"] = "destinationAsset";
5184
5129
  LOCAL_STORAGE_KEYS2["transactionHistory"] = "transactionHistory";
5130
+ LOCAL_STORAGE_KEYS2["transactionHistoryVersion"] = "transactionHistoryVersion";
5185
5131
  LOCAL_STORAGE_KEYS2["swapExecutionState"] = "swapExecutionState";
5186
5132
  LOCAL_STORAGE_KEYS2["extraCosmosChainIdsToConnectPerWallet"] = "extraCosmosChainIdsToConnectPerWallet";
5187
5133
  return LOCAL_STORAGE_KEYS2;
@@ -41379,14 +41325,22 @@ const setRouteToDefaultRouteAtom = atom$1(null, (get, set, assets2) => {
41379
41325
  set(destinationAssetAmountAtom, amountOut == null ? void 0 : amountOut.toString());
41380
41326
  }
41381
41327
  });
41382
- const transactionHistoryAtom = atomWithIndexedDBStorage(
41328
+ var HISTORY_VERSION = /* @__PURE__ */ ((HISTORY_VERSION2) => {
41329
+ HISTORY_VERSION2[HISTORY_VERSION2["camelCase"] = 0] = "camelCase";
41330
+ return HISTORY_VERSION2;
41331
+ })(HISTORY_VERSION || {});
41332
+ const transactionHistoryVersionAtom = atomWithStorage(
41333
+ LOCAL_STORAGE_KEYS.transactionHistoryVersion,
41334
+ void 0
41335
+ );
41336
+ const transactionHistoryAtom = atomWithStorage(
41383
41337
  LOCAL_STORAGE_KEYS.transactionHistory,
41384
41338
  []
41385
41339
  );
41386
41340
  const setTransactionHistoryAtom = atom$1(
41387
41341
  null,
41388
- async (get, set, historyItem) => {
41389
- const history = await get(transactionHistoryAtom);
41342
+ (get, set, historyItem) => {
41343
+ const history = get(transactionHistoryAtom);
41390
41344
  const index = history.findIndex((item) => item.timestamp === historyItem.timestamp);
41391
41345
  const newHistory = [...history];
41392
41346
  if (index !== -1) {
@@ -41398,8 +41352,8 @@ const setTransactionHistoryAtom = atom$1(
41398
41352
  set(transactionHistoryAtom, newHistory);
41399
41353
  }
41400
41354
  );
41401
- const lastTransactionInTimeAtom = atom$1(async (get) => {
41402
- const history = await get(transactionHistoryAtom);
41355
+ const lastTransactionInTimeAtom = atom$1((get) => {
41356
+ const history = get(transactionHistoryAtom);
41403
41357
  if (history.length === 0) return;
41404
41358
  const sorted = [...history].sort((a, b) => b.timestamp - a.timestamp);
41405
41359
  const lastTx = sorted[0];
@@ -41409,8 +41363,8 @@ const lastTransactionInTimeAtom = atom$1(async (get) => {
41409
41363
  index: originalIndex
41410
41364
  };
41411
41365
  });
41412
- const removeTransactionHistoryItemAtom = atom$1(null, async (get, set, timestamp) => {
41413
- const history = await get(transactionHistoryAtom);
41366
+ const removeTransactionHistoryItemAtom = atom$1(null, (get, set, timestamp) => {
41367
+ const history = get(transactionHistoryAtom);
41414
41368
  if (!history || isNaN(timestamp)) return;
41415
41369
  const newHistory = history.filter((item) => item.timestamp !== timestamp);
41416
41370
  set(transactionHistoryAtom, newHistory);
@@ -45340,7 +45294,7 @@ function walletConnect(parameters) {
45340
45294
  const optionalChains = config2.chains.map((x2) => x2.id);
45341
45295
  if (!optionalChains.length)
45342
45296
  return;
45343
- const { EthereumProvider } = await import("./index.es-Cu1s5TVX.js");
45297
+ const { EthereumProvider } = await import("./index.es-DrM_N5rw.js");
45344
45298
  return await EthereumProvider.init({
45345
45299
  ...parameters,
45346
45300
  disableProviderPing: true,
@@ -45736,6 +45690,11 @@ const setSwapExecutionStateAtom = atom$1(null, (get, set) => {
45736
45690
  timestamp: Date.now()
45737
45691
  });
45738
45692
  set(submitSwapExecutionCallbacksAtom, {
45693
+ onTransactionSignRequested: async (props) => {
45694
+ var _a2;
45695
+ track("execute route: transaction sign requested", { props });
45696
+ (_a2 = callbacks == null ? void 0 : callbacks.onTransactionSignRequested) == null ? void 0 : _a2.call(callbacks, props);
45697
+ },
45739
45698
  onTransactionUpdated: (txInfo) => {
45740
45699
  var _a2;
45741
45700
  track("execute route: transaction updated", { txInfo });
@@ -52568,14 +52527,14 @@ const TrackLatestTxHistoryItemStatus = memo(() => {
52568
52527
  }
52569
52528
  return null;
52570
52529
  });
52571
- const noHistoryItemsAtom = atom$1(async (get) => {
52572
- const txHistoryItems = await get(transactionHistoryAtom);
52530
+ const noHistoryItemsAtom = atom$1((get) => {
52531
+ const txHistoryItems = get(transactionHistoryAtom);
52573
52532
  return (txHistoryItems == null ? void 0 : txHistoryItems.length) === 0;
52574
52533
  });
52575
- const isFetchingLastTransactionStatusAtom = atom$1(async (get) => {
52534
+ const isFetchingLastTransactionStatusAtom = atom$1((get) => {
52576
52535
  var _a, _b, _c;
52577
52536
  const { overallStatus, route: route2, transactionsSigned } = get(swapExecutionStateAtom);
52578
- const lastTxHistoryItemInTime = await get(lastTransactionInTimeAtom);
52537
+ const lastTxHistoryItemInTime = get(lastTransactionInTimeAtom);
52579
52538
  return overallStatus === "pending" && transactionsSigned === (route2 == null ? void 0 : route2.txsRequired) || ((_a = lastTxHistoryItemInTime == null ? void 0 : lastTxHistoryItemInTime.transactionHistoryItem) == null ? void 0 : _a.isSettled) !== true && ((_c = (_b = lastTxHistoryItemInTime == null ? void 0 : lastTxHistoryItemInTime.transactionHistoryItem) == null ? void 0 : _b.route) == null ? void 0 : _c.txsRequired) === 1;
52580
52539
  });
52581
52540
  const useConnectToMissingCosmosChain = () => {
@@ -52831,6 +52790,19 @@ const SwapPage = () => {
52831
52790
  routePreference,
52832
52791
  slippage
52833
52792
  });
52793
+ const navigateToSwapExecutionPage = () => {
52794
+ startTransition(() => {
52795
+ setError(void 0);
52796
+ setChainAddresses({});
52797
+ setSwapExecutionState();
52798
+ setUser({ username: sourceAccount == null ? void 0 : sourceAccount.address });
52799
+ if (sourceAccount == null ? void 0 : sourceAccount.address) {
52800
+ const replay = getReplay();
52801
+ replay == null ? void 0 : replay.start();
52802
+ }
52803
+ setCurrentPage(Routes.SwapExecutionPage);
52804
+ });
52805
+ };
52834
52806
  setUserId(sourceAccount == null ? void 0 : sourceAccount.address);
52835
52807
  if (showCosmosLedgerWarning) {
52836
52808
  track("warning page: cosmos ledger", { route: route2 });
@@ -52847,10 +52819,7 @@ const SwapPage = () => {
52847
52819
  setError({
52848
52820
  errorWarningType: ErrorWarningType.BadPriceWarning,
52849
52821
  onClickContinue: () => {
52850
- setError(void 0);
52851
- setChainAddresses({});
52852
- setCurrentPage(Routes.SwapExecutionPage);
52853
- setSwapExecutionState();
52822
+ navigateToSwapExecutionPage();
52854
52823
  },
52855
52824
  onClickBack: () => {
52856
52825
  setError(void 0);
@@ -52864,10 +52833,7 @@ const SwapPage = () => {
52864
52833
  setError({
52865
52834
  errorWarningType: ErrorWarningType.LowInfoWarning,
52866
52835
  onClickContinue: () => {
52867
- setError(void 0);
52868
- setChainAddresses({});
52869
- setCurrentPage(Routes.SwapExecutionPage);
52870
- setSwapExecutionState();
52836
+ navigateToSwapExecutionPage();
52871
52837
  },
52872
52838
  onClickBack: () => {
52873
52839
  setError(void 0);
@@ -52881,10 +52847,7 @@ const SwapPage = () => {
52881
52847
  setError({
52882
52848
  errorWarningType: ErrorWarningType.GoFastWarning,
52883
52849
  onClickContinue: () => {
52884
- setError(void 0);
52885
- setChainAddresses({});
52886
- setCurrentPage(Routes.SwapExecutionPage);
52887
- setSwapExecutionState();
52850
+ navigateToSwapExecutionPage();
52888
52851
  },
52889
52852
  onClickBack: () => {
52890
52853
  setCurrentPage(Routes.SwapPage);
@@ -52893,14 +52856,7 @@ const SwapPage = () => {
52893
52856
  });
52894
52857
  return;
52895
52858
  }
52896
- setChainAddresses({});
52897
- setCurrentPage(Routes.SwapExecutionPage);
52898
- setUser({ username: sourceAccount == null ? void 0 : sourceAccount.address });
52899
- if (sourceAccount == null ? void 0 : sourceAccount.address) {
52900
- const replay = getReplay();
52901
- replay == null ? void 0 : replay.start();
52902
- }
52903
- setSwapExecutionState();
52859
+ navigateToSwapExecutionPage();
52904
52860
  };
52905
52861
  return /* @__PURE__ */ jsx(
52906
52862
  MainButton,
@@ -54087,7 +54043,7 @@ const Router = () => {
54087
54043
  }
54088
54044
  switch (currentPage) {
54089
54045
  case Routes.SwapPage:
54090
- return /* @__PURE__ */ jsx(
54046
+ return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
54091
54047
  ErrorBoundary,
54092
54048
  {
54093
54049
  fallback: null,
@@ -54097,9 +54053,9 @@ const Router = () => {
54097
54053
  },
54098
54054
  children: /* @__PURE__ */ jsx(SwapPage, {})
54099
54055
  }
54100
- );
54056
+ ) });
54101
54057
  case Routes.SwapExecutionPage:
54102
- return /* @__PURE__ */ jsx(
54058
+ return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
54103
54059
  ErrorBoundary,
54104
54060
  {
54105
54061
  fallback: null,
@@ -54109,9 +54065,9 @@ const Router = () => {
54109
54065
  },
54110
54066
  children: /* @__PURE__ */ jsx(SwapExecutionPage, {})
54111
54067
  }
54112
- );
54068
+ ) });
54113
54069
  case Routes.TransactionHistoryPage:
54114
- return /* @__PURE__ */ jsx(
54070
+ return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(
54115
54071
  ErrorBoundary,
54116
54072
  {
54117
54073
  fallback: null,
@@ -54123,7 +54079,7 @@ const Router = () => {
54123
54079
  },
54124
54080
  children: /* @__PURE__ */ jsx(TransactionHistoryPage, {})
54125
54081
  }
54126
- );
54082
+ ) });
54127
54083
  }
54128
54084
  };
54129
54085
  const useInitDefaultRoute = (defaultRoute) => {
@@ -54166,7 +54122,7 @@ const initSentry = () => {
54166
54122
  };
54167
54123
  const name = "@skip-go/widget";
54168
54124
  const description = "Swap widget";
54169
- const version = "3.12.1";
54125
+ const version = "3.12.3";
54170
54126
  const repository = {
54171
54127
  url: "https://github.com/skip-mev/skip-go",
54172
54128
  directory: "packages/widget"
@@ -54475,7 +54431,8 @@ const useInitWidget = (props) => {
54475
54431
  onRouteUpdated: props.onRouteUpdated,
54476
54432
  onSourceAndDestinationSwapped: props.onSourceAndDestinationSwapped,
54477
54433
  onSourceAssetUpdated: props.onSourceAssetUpdated,
54478
- onDestinationAssetUpdated: props.onDestinationAssetUpdated
54434
+ onDestinationAssetUpdated: props.onDestinationAssetUpdated,
54435
+ onTransactionSignRequested: props.onTransactionSignRequested
54479
54436
  };
54480
54437
  if (Object.values(callbacks).some((callback) => callback !== void 0)) {
54481
54438
  setCallbacks(callbacks);
@@ -54517,7 +54474,8 @@ const useInitWidget = (props) => {
54517
54474
  props.onSourceAssetUpdated,
54518
54475
  props.onDestinationAssetUpdated,
54519
54476
  props.batchSignTxs,
54520
- setBatchSignTxs
54477
+ setBatchSignTxs,
54478
+ props.onTransactionSignRequested
54521
54479
  ]);
54522
54480
  return { theme: mergedTheme };
54523
54481
  };
@@ -54536,19 +54494,45 @@ const useInitGetSigners = (props) => {
54536
54494
  }));
54537
54495
  }, [props.getCosmosSigner, props.getEvmSigner, props.getSvmSigner, setGetSigners]);
54538
54496
  };
54539
- const migrateHistoryFromLocalStorageToIndexedDB = async () => {
54497
+ const migrateOldLocalStorageValues = () => {
54540
54498
  if (typeof window === "undefined") return;
54541
- try {
54542
- const raw = localStorage.getItem(LOCAL_STORAGE_KEYS.transactionHistory);
54543
- if (!raw) return;
54544
- const parsed = JSON.parse(raw);
54545
- const transformed = toCamelCase(parsed);
54546
- await idbSet(LOCAL_STORAGE_KEYS.transactionHistory, transformed);
54547
- localStorage.removeItem(LOCAL_STORAGE_KEYS.transactionHistory);
54548
- console.info("✅ Migrated transactionHistory from localStorage to IndexedDB");
54549
- } catch (err) {
54550
- console.warn("⚠️ Failed to migrate transactionHistory", err);
54551
- }
54499
+ const { set } = jotaiStore;
54500
+ const transactionHistoryVersion = localStorage.getItem(
54501
+ LOCAL_STORAGE_KEYS.transactionHistoryVersion
54502
+ );
54503
+ console.info(`loaded transactionHistory version ${transactionHistoryVersion}`);
54504
+ Object.values(LOCAL_STORAGE_KEYS).forEach((key) => {
54505
+ try {
54506
+ const raw = localStorage.getItem(key);
54507
+ if (!raw) return;
54508
+ const parsed = JSON.parse(raw);
54509
+ let newLocalStorageValue = toCamelCase(parsed);
54510
+ if (key === LOCAL_STORAGE_KEYS.transactionHistory) {
54511
+ newLocalStorageValue = newLocalStorageValue.filter(
54512
+ (txHistoryItem) => {
54513
+ var _a, _b, _c, _d;
54514
+ const chainId = (_b = (_a = txHistoryItem == null ? void 0 : txHistoryItem.transactionDetails) == null ? void 0 : _a[0]) == null ? void 0 : _b.chainId;
54515
+ const txHash = (_d = (_c = txHistoryItem == null ? void 0 : txHistoryItem.transactionDetails) == null ? void 0 : _c[0]) == null ? void 0 : _d.txHash;
54516
+ if (chainId !== void 0 && txHash !== void 0) {
54517
+ return true;
54518
+ }
54519
+ }
54520
+ );
54521
+ }
54522
+ if (!transactionHistoryVersion && key === LOCAL_STORAGE_KEYS.transactionHistory) {
54523
+ localStorage.setItem(key, JSON.stringify(newLocalStorageValue));
54524
+ console.info(
54525
+ `updated from transactionHistoryVersion ${transactionHistoryVersion} to ${HISTORY_VERSION.camelCase}`
54526
+ );
54527
+ set(transactionHistoryVersionAtom, HISTORY_VERSION.camelCase);
54528
+ } else if (JSON.stringify(parsed) !== JSON.stringify(newLocalStorageValue)) {
54529
+ localStorage.setItem(key, JSON.stringify(newLocalStorageValue));
54530
+ console.info(`updated old localStorage value for ${key}`);
54531
+ }
54532
+ } catch (err) {
54533
+ console.warn(`Failed to migrate localStorage key "${key}":`, err);
54534
+ }
54535
+ });
54552
54536
  };
54553
54537
  function toCamelCase(obj) {
54554
54538
  return convertKeys(obj, (key) => {
@@ -54640,7 +54624,7 @@ const SolanaProvider = ({ children }) => {
54640
54624
  };
54641
54625
  const queryClient = new QueryClient();
54642
54626
  const jotaiStore = createStore();
54643
- migrateHistoryFromLocalStorageToIndexedDB();
54627
+ migrateOldLocalStorageValues();
54644
54628
  const Widget = (props) => {
54645
54629
  return /* @__PURE__ */ jsx(Provider, { store: jotaiStore, children: /* @__PURE__ */ jsx(WidgetWithinProvider, { props }) });
54646
54630
  };
package/build/index.d.ts CHANGED
@@ -12,6 +12,7 @@ import { WalletConnectModalConfig } from '@walletconnect/modal';
12
12
  declare type Callbacks = {
13
13
  onWalletConnected?: (props: onWalletConnectedProps) => void;
14
14
  onWalletDisconnected?: (props: onWalletDisconnectedProps) => void;
15
+ onTransactionSignRequested?: (props: onTransactionSignRequestedProps) => void;
15
16
  onTransactionBroadcasted?: (props: onTransactionBroadcastedProps) => void;
16
17
  onTransactionComplete?: (props: onTransactionCompleteProps) => void;
17
18
  onTransactionFailed?: (props: onTransactionFailedProps) => void;
@@ -166,6 +167,12 @@ declare type onTransactionFailedProps = {
166
167
  error: string;
167
168
  };
168
169
 
170
+ declare type onTransactionSignRequestedProps = {
171
+ chainId: string;
172
+ signerAddress?: string;
173
+ txIndex: number;
174
+ };
175
+
169
176
  declare type onWalletConnectedProps = {
170
177
  walletName: string;
171
178
  chainIdToAddressMap?: Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { g as getAugmentedNamespace, c as commonjsGlobal, a as getDefaultExportFromCjs, p as process$1 } from "./index-BRlzKaV6.js";
1
+ import { g as getAugmentedNamespace, c as commonjsGlobal, a as getDefaultExportFromCjs, p as process$1 } from "./index-BkuAy8zJ.js";
2
2
  import qg, { PROPOSAL_EXPIRY_MESSAGE } from "@walletconnect/sign-client";
3
3
  const global = globalThis || void 0 || self;
4
4
  var buffer$1 = {};
package/build/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { W, d, l, o, r, s } from "./index-BRlzKaV6.js";
1
+ import { W, d, l, o, r, s } from "./index-BkuAy8zJ.js";
2
2
  export {
3
3
  W as Widget,
4
4
  d as defaultTheme,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@skip-go/widget",
3
3
  "description": "Swap widget",
4
- "version": "3.12.1",
4
+ "version": "3.12.3",
5
5
  "repository": {
6
6
  "url": "https://github.com/skip-mev/skip-go",
7
7
  "directory": "packages/widget"
@@ -42,7 +42,7 @@
42
42
  "@penumbra-zone/transport-dom": "^7.5.0",
43
43
  "@r2wc/react-to-web-component": "^2.0.3",
44
44
  "@sentry/react": "^8.46.0",
45
- "@skip-go/client": "1.3.0",
45
+ "@skip-go/client": "1.3.1",
46
46
  "@solana/spl-token": "^0.4.8",
47
47
  "@solana/wallet-adapter-ledger": "^0.9.25",
48
48
  "@solana/wallet-adapter-react": "^0.15.39",