@embarkai/ui-kit 0.4.46 → 0.4.48

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/index.js CHANGED
@@ -1168,52 +1168,48 @@ var init_helpers = __esm({
1168
1168
  });
1169
1169
 
1170
1170
  // src/internal/components/ChainSync/ChainSync.tsx
1171
- import {
1172
- DEFAULT_CHAIN_ID,
1173
- getChainConfig,
1174
- isChainSupported
1175
- } from "@embarkai/core/read";
1171
+ import { DEFAULT_CHAIN_ID, getChainConfig, isChainSupported } from "@embarkai/core/read";
1176
1172
  import { useMutation, useQueryClient } from "@tanstack/react-query";
1177
1173
  import { throttle } from "lodash-es";
1178
1174
  import { useCallback, useEffect as useEffect2, useRef } from "react";
1179
1175
  function ChainSync() {
1180
1176
  const { config, callbacksRef } = useProviderConfig();
1181
1177
  const qc = useQueryClient();
1182
- const setPage = useLayoutDataStore((st) => st.setPage);
1183
- const { address, session, activeChainId, setAddress, setSession, setActiveChain, setIsLoading, setStatus, setError } = useSession();
1178
+ const address = useSession((st) => st.address);
1179
+ const session = useSession((st) => st.session);
1180
+ const activeChainId = useSession((st) => st.activeChainId);
1184
1181
  const prevChainId = useRef(null);
1185
- const isReverting = useRef(false);
1186
1182
  const { mutate: updateChain } = useMutation({
1187
- mutationFn: async (selectedChainId) => {
1183
+ mutationFn: async (toChainId) => {
1184
+ if (!toChainId) {
1185
+ console.warn("[CHAIN_SYNC] No target chainId provided, skipping chain update");
1186
+ return { skip: true };
1187
+ }
1188
+ console.warn("[CHAIN_SYNC] Attempting:", toChainId);
1188
1189
  if (!session?.ownerAddress) {
1189
1190
  console.warn("[CHAIN_SYNC] No session owner address, aborting chain update");
1190
- throw new Error("No session owner");
1191
+ return { skip: true };
1191
1192
  }
1192
- if (prevChainId.current === activeChainId) {
1193
- console.info("[CHAIN_SYNC] Current chain:", activeChainId);
1194
- return { skip: true, targetChainId: activeChainId };
1193
+ if (prevChainId.current === toChainId) {
1194
+ console.info("[CHAIN_SYNC] Chain already selected:", toChainId);
1195
+ return { skip: true };
1195
1196
  }
1196
- console.info("[CHAIN_SYNC]", prevChainId.current, "->", activeChainId);
1197
- setIsLoading(true);
1197
+ console.info("[CHAIN_SYNC] syncing to: ", toChainId);
1198
+ const { setIsLoading, setStatus } = useSession.getState();
1198
1199
  let targetChainId = null;
1199
1200
  switch (true) {
1200
- case (!!selectedChainId && !!isChainSupported(selectedChainId)):
1201
- targetChainId = selectedChainId;
1201
+ case (!!toChainId && !!isChainSupported(toChainId)):
1202
+ targetChainId = toChainId;
1202
1203
  break;
1203
- case (!!selectedChainId && !isChainSupported(selectedChainId)):
1204
- console.warn(`[EMBARKAI] Current activeChainId ${selectedChainId} is not supported. Checking for fallback`);
1205
- // no break, fallthrough to next case
1206
- case (!!config.current?.network?.chainId && !!isChainSupported(config.current.network.chainId)):
1207
- targetChainId = config.current.network.chainId;
1208
- console.info(`[EMBARKAI] Config chainId ${config.current.network.chainId} will be used.`);
1204
+ case (!!toChainId && !isChainSupported(toChainId)):
1205
+ console.warn(`[EMBARKAI] Chain ${toChainId} is not supported. Checking for fallback`);
1206
+ targetChainId = DEFAULT_CHAIN_ID;
1209
1207
  break;
1210
- case (!!config.current?.network?.chainId && !isChainSupported(config.current.network.chainId)):
1211
- console.warn(`No Fallback ChainID Found. Using default chain ${DEFAULT_CHAIN_ID} instead.`);
1212
- // no break, fallthrough to next case
1213
1208
  default:
1214
1209
  targetChainId = DEFAULT_CHAIN_ID;
1215
1210
  break;
1216
1211
  }
1212
+ setIsLoading(true);
1217
1213
  setStatus(`Re-calculating address for chain ${targetChainId}...`);
1218
1214
  const chainConfig = getChainConfig(targetChainId);
1219
1215
  const chainParams = getChainParams(chainConfig);
@@ -1231,9 +1227,9 @@ function ChainSync() {
1231
1227
  };
1232
1228
  },
1233
1229
  onSuccess: async ({ skip, targetChainId, smartAccountAddress, chainParams }) => {
1234
- if (skip) return;
1230
+ if (skip || !smartAccountAddress || !chainParams) return;
1235
1231
  const { chainConfig } = chainParams;
1236
- console.info("[CHAIN_SYNC] Address recalculated for chain", targetChainId, ":", smartAccountAddress);
1232
+ const { setIsLoading, setStatus, setActiveChain, setAddress, setSession } = useSession.getState();
1237
1233
  setActiveChain(chainParams);
1238
1234
  setAddress(smartAccountAddress);
1239
1235
  setSession({
@@ -1242,45 +1238,52 @@ function ChainSync() {
1242
1238
  address: smartAccountAddress,
1243
1239
  factoryAddress: chainConfig.factoryAddress
1244
1240
  });
1245
- await callbacksRef.current?.onChainChange?.({
1241
+ callbacksRef.current?.onChainChange?.({
1246
1242
  chainId: targetChainId,
1247
1243
  previousChainId: prevChainId.current
1248
1244
  });
1249
- if (!config.current?.network?.forceChain && targetChainId !== config.current?.network?.chainId) {
1250
- console.info("[CHAIN_SYNC] Dapp chain request:", targetChainId, "->", config.current?.network?.chainId);
1251
- setPage("chain-switch-request" /* CHAIN_SWITCH_REQUEST */);
1252
- }
1253
1245
  prevChainId.current = targetChainId;
1254
- await qc.invalidateQueries();
1246
+ qc.invalidateQueries();
1255
1247
  setStatus("idle");
1256
1248
  setIsLoading(false);
1257
1249
  },
1258
1250
  onError: (error, selectedChainId) => {
1259
1251
  console.error("[CHAIN_SYNC] Failed to switch chain into ", selectedChainId, ":", error);
1252
+ const { setIsLoading, setStatus, setError } = useSession.getState();
1260
1253
  setStatus("idle");
1261
1254
  setError(error.message);
1262
1255
  setIsLoading(false);
1263
1256
  }
1264
1257
  });
1265
- const updateChainRelaxed = useCallback(throttle(updateChain, 3e3), []);
1258
+ const updateChainRelaxed = useCallback(throttle(updateChain, 2e3), []);
1266
1259
  useEffect2(() => {
1267
- if (!address) return;
1268
- if (prevChainId.current === activeChainId) return;
1269
- if (isReverting.current) {
1270
- isReverting.current = false;
1271
- return;
1272
- }
1260
+ if (!address || !activeChainId) return;
1273
1261
  updateChainRelaxed(activeChainId);
1274
1262
  }, [address, activeChainId]);
1263
+ useEffect2(() => {
1264
+ if (!address || !activeChainId) return;
1265
+ const shouldSwitchRequest = !config.current?.network?.forceChain && activeChainId !== config.current?.network?.chainId;
1266
+ async function showSwitchChainRequest() {
1267
+ const stats = await getShareRecoveryStats();
1268
+ const hasRecoveryData = !!stats && (!!stats.created || stats.devices && stats.devices.length > 0);
1269
+ const jwt = jwtTokenManager2.getTokens();
1270
+ const isNewUser = !hasRecoveryData && !!jwt?.isNewUser;
1271
+ if (isNewUser || !shouldSwitchRequest) return;
1272
+ useLayoutDataStore.getState().setPage("chain-switch-request" /* CHAIN_SWITCH_REQUEST */);
1273
+ }
1274
+ showSwitchChainRequest();
1275
+ }, [address, activeChainId]);
1275
1276
  return null;
1276
1277
  }
1277
1278
  var init_ChainSync = __esm({
1278
1279
  "src/internal/components/ChainSync/ChainSync.tsx"() {
1279
1280
  init_ProviderContext();
1280
1281
  init_SessionContext();
1282
+ init_auth();
1281
1283
  init_constants2();
1282
1284
  init_helpers();
1283
1285
  init_useLayoutDataStore();
1286
+ init_vaultClient();
1284
1287
  }
1285
1288
  });
1286
1289
 
@@ -2421,34 +2424,37 @@ var init_useAutoConnect = __esm({
2421
2424
  import { useMutation as useMutation2 } from "@tanstack/react-query";
2422
2425
  import { useEffect as useEffect4 } from "react";
2423
2426
  function useBackupStatusChanges() {
2424
- const setHasServerVault = useSession((st) => st.setHasServerVault);
2425
- const setPage = useLayoutDataStore((st) => st.setPage);
2426
2427
  const { mutate: handleBackupStatusChanged } = useMutation2({
2427
2428
  mutationFn: async (event) => {
2428
2429
  const customEvent = event;
2429
2430
  console.log("[BACKUP STATUS] changed:", customEvent?.detail);
2430
- return { stats: await getShareRecoveryStats(), detail: customEvent?.detail };
2431
+ return {
2432
+ stats: await getShareRecoveryStats(),
2433
+ detail: customEvent?.detail
2434
+ };
2431
2435
  },
2432
2436
  onSuccess: ({ stats, detail }) => {
2437
+ const { setHasServerVault } = useSession.getState();
2433
2438
  const hasRecoveryData = stats && (!!stats.created || !!stats?.devices?.length);
2434
2439
  if (!!hasRecoveryData) {
2435
- console.log(
2436
- "[BACKUP STATUS] Recovery data found after backup status change.\n Redirect to main menu:",
2437
- detail?.navigateToMainMenu
2438
- );
2439
2440
  setHasServerVault(true);
2440
- if (!!detail?.navigateToMainMenu) {
2441
- setTimeout(() => setPage(null), 1e3);
2441
+ const jwt = jwtTokenManager2.getTokens();
2442
+ const isNewUserTouched = localStorage.getItem(NEW_USER_TOUCHED_KEY) === "true";
2443
+ if (!isNewUserTouched && !!jwt?.isNewUser) {
2444
+ localStorage.setItem(NEW_USER_TOUCHED_KEY, "true");
2445
+ useLayoutDataStore.getState().setPage("nickname-settings" /* NICKNAME_SETTINGS */);
2446
+ }
2447
+ if (!!isNewUserTouched && !jwt?.isNewUser) {
2448
+ localStorage.removeItem(NEW_USER_TOUCHED_KEY);
2442
2449
  }
2443
- console.info("[BACKUP STATUS] Recovery data found in vault, marking as has-server-vault");
2444
2450
  } else {
2445
2451
  setHasServerVault(false);
2446
- setPage("keysare-backup" /* KEYSARE_BACKUP */);
2452
+ useLayoutDataStore.getState().setPage("keysare-backup" /* KEYSARE_BACKUP */);
2447
2453
  console.warn("[BACKUP STATUS] No recovery data found in vault, marking as no-server-vault");
2448
2454
  }
2449
2455
  },
2450
2456
  onError: (error) => {
2451
- setHasServerVault(false);
2457
+ useSession.getState().setHasServerVault(false);
2452
2458
  console.warn("[BACKUP STATUS] Failed to fetch initial vault status:", error);
2453
2459
  }
2454
2460
  });
@@ -2459,11 +2465,14 @@ function useBackupStatusChanges() {
2459
2465
  };
2460
2466
  }, []);
2461
2467
  }
2468
+ var NEW_USER_TOUCHED_KEY;
2462
2469
  var init_useBackupStatusChanges = __esm({
2463
2470
  "src/internal/hooks/useBackupStatusChanges.ts"() {
2464
2471
  init_SessionContext();
2472
+ init_auth();
2465
2473
  init_vaultClient();
2466
2474
  init_useLayoutDataStore();
2475
+ NEW_USER_TOUCHED_KEY = "embarkai-is-new-user-touhced";
2467
2476
  }
2468
2477
  });
2469
2478
 
@@ -7586,25 +7595,15 @@ function useAuthMenuHandlers() {
7586
7595
  const { config, callbacksRef } = useProviderConfig();
7587
7596
  const qc = useQueryClient2();
7588
7597
  const pendingLoginResponseRef = useRef6(null);
7589
- const setPage = useLayoutDataStore((st) => st.setPage);
7590
- const setIsDialogForced = useLayoutStore((st) => st.setIsDialogForced);
7591
7598
  const [telegramCleanup, setTelegramCleanup] = useState2(null);
7592
- const {
7593
- usePaymaster,
7594
- publicClient,
7595
- activeChainId,
7596
- setError,
7597
- setStatus,
7598
- setSession,
7599
- setAddress,
7600
- setRecoveryUserId,
7601
- setHasServerVault,
7602
- setIsLoading
7603
- } = useSession();
7599
+ const usePaymaster = useSession((st) => st.usePaymaster);
7600
+ const publicClient = useSession((st) => st.publicClient);
7601
+ const activeChainId = useSession((st) => st.activeChainId);
7604
7602
  const setStep = useAuthStore((st) => st.setStep);
7605
7603
  const setAlert = useAuthStore((st) => st.setAlert);
7606
7604
  const createSessionWithKeyshare = useCallback8(
7607
7605
  async (userId, hasServerKeyshare, isNewUser) => {
7606
+ const { setStatus } = useSession.getState();
7608
7607
  try {
7609
7608
  try {
7610
7609
  callbacksRef.current?.onConnecting?.({ method: "wallet" });
@@ -7642,9 +7641,19 @@ function useAuthMenuHandlers() {
7642
7641
  throw error;
7643
7642
  }
7644
7643
  },
7645
- [setStatus, usePaymaster, activeChainId]
7644
+ [usePaymaster, activeChainId]
7646
7645
  );
7647
7646
  const onAuthSuccess = useCallback8(async () => {
7647
+ const {
7648
+ //
7649
+ setSession,
7650
+ setAddress,
7651
+ setStatus,
7652
+ setIsLoading,
7653
+ setError,
7654
+ setHasServerVault,
7655
+ setRecoveryUserId
7656
+ } = useSession.getState();
7648
7657
  setIsLoading(true);
7649
7658
  setStep("loading");
7650
7659
  const loginResponse = pendingLoginResponseRef.current;
@@ -7708,11 +7717,11 @@ function useAuthMenuHandlers() {
7708
7717
  if (!!jwt?.isNewUser || !hasKeyshareVaultBackup) {
7709
7718
  if (!!jwt?.isNewUser) console.log("[AuthMenu] New user detected - forcing backup flow");
7710
7719
  if (!hasKeyshareVaultBackup) console.log("[AuthMenu] No recovery data found - forcing backup flow");
7711
- setIsDialogForced(true);
7712
- setPage("keysare-backup" /* KEYSARE_BACKUP */);
7720
+ useLayoutStore.getState().setIsDialogForced(true);
7721
+ useLayoutDataStore.getState().setPage("keysare-backup" /* KEYSARE_BACKUP */);
7713
7722
  } else {
7714
- setIsDialogForced(false);
7715
- setPage(null);
7723
+ useLayoutStore.getState().setIsDialogForced(false);
7724
+ useLayoutDataStore.getState().setPage(null);
7716
7725
  }
7717
7726
  }, 100);
7718
7727
  } catch (error) {
@@ -7724,9 +7733,7 @@ function useAuthMenuHandlers() {
7724
7733
  setAddress(null);
7725
7734
  setRecoveryUserId(userId);
7726
7735
  setStatus("recovery_needed");
7727
- setTimeout(() => {
7728
- setPage("keyshare-restore" /* KEYSHARE_RESTORE */);
7729
- }, 100);
7736
+ setTimeout(() => useLayoutDataStore.getState().setPage("keyshare-restore" /* KEYSHARE_RESTORE */), 100);
7730
7737
  } else {
7731
7738
  pendingLoginResponseRef.current = null;
7732
7739
  await jwtTokenManager2.clearTokens();
@@ -7742,20 +7749,7 @@ function useAuthMenuHandlers() {
7742
7749
  setIsLoading(false);
7743
7750
  setStep("signin");
7744
7751
  }
7745
- }, [
7746
- qc,
7747
- setStep,
7748
- setPage,
7749
- setError,
7750
- setStatus,
7751
- setSession,
7752
- setAlert,
7753
- setAddress,
7754
- setRecoveryUserId,
7755
- setHasServerVault,
7756
- setIsDialogForced,
7757
- createSessionWithKeyshare
7758
- ]);
7752
+ }, [qc, setStep, setAlert, createSessionWithKeyshare]);
7759
7753
  const goBackToSignIn = useCallback8(() => {
7760
7754
  setStep("signin");
7761
7755
  setAlert(null);
@@ -11590,75 +11584,51 @@ var init_LumiaIcon2 = __esm({
11590
11584
  }
11591
11585
  });
11592
11586
 
11593
- // src/config/networks.ts
11587
+ // src/internal/assets/networks/index.ts
11594
11588
  import {
11595
11589
  ARBITRUM_SEPOLIA_CHAIN_ID,
11596
11590
  BASE_SEPOLIA_CHAIN_ID,
11591
+ BSC_MAINNET_CHAIN_ID,
11597
11592
  BSC_TESTNET_CHAIN_ID as BSC_TESTNET_CHAIN_ID3,
11598
- LUMIA_PULSAR_TESTNET_CHAIN_ID,
11599
11593
  LUMIA_MAINNET_CHAIN_ID as LUMIA_MAINNET_CHAIN_ID3,
11600
- LUMIA_TESTNET_CHAIN_ID as LUMIA_TESTNET_CHAIN_ID3,
11601
- SEPOLIA_CHAIN_ID
11594
+ LUMIA_PULSAR_TESTNET_CHAIN_ID,
11595
+ LUMIA_TESTNET_CHAIN_ID as LUMIA_TESTNET_CHAIN_ID3
11602
11596
  } from "@embarkai/core/read";
11603
- var NETWORK_OPTIONS;
11597
+ var NETWORKS_ICONS;
11604
11598
  var init_networks3 = __esm({
11605
- "src/config/networks.ts"() {
11599
+ "src/internal/assets/networks/index.ts"() {
11606
11600
  init_ArbitrumIcon();
11607
11601
  init_BaseIcon();
11608
11602
  init_BscIcon();
11609
11603
  init_EthereumIcon();
11610
11604
  init_LumiaIcon2();
11611
- NETWORK_OPTIONS = [
11612
- {
11613
- chainId: LUMIA_TESTNET_CHAIN_ID3,
11614
- name: "Lumia Beam",
11615
- badge: "TESTNET",
11616
- Icon: LumiaIcon2,
11617
- isActive: true
11618
- },
11619
- {
11620
- chainId: LUMIA_MAINNET_CHAIN_ID3,
11621
- name: "Lumia Prism",
11622
- badge: "MAINNET",
11623
- Icon: LumiaIcon2,
11624
- isActive: true
11625
- },
11626
- {
11627
- chainId: SEPOLIA_CHAIN_ID,
11628
- name: "Sepolia",
11629
- badge: "TESTNET",
11630
- Icon: EthereumIcon,
11631
- isActive: true
11632
- },
11633
- {
11634
- chainId: BSC_TESTNET_CHAIN_ID3,
11635
- name: "BSC Testnet",
11636
- badge: "TESTNET",
11637
- Icon: BSCIcon,
11638
- isActive: true
11639
- },
11640
- {
11641
- chainId: ARBITRUM_SEPOLIA_CHAIN_ID,
11642
- name: "Arbitrum Sepolia",
11643
- badge: "TESTNET",
11644
- Icon: ArbitrumIcon,
11645
- isActive: true
11646
- },
11647
- {
11648
- chainId: BASE_SEPOLIA_CHAIN_ID,
11649
- name: "Base Sepolia",
11650
- badge: "TESTNET",
11651
- Icon: BaseIcon,
11652
- isActive: true
11653
- },
11654
- {
11655
- chainId: LUMIA_PULSAR_TESTNET_CHAIN_ID,
11656
- name: "Lumia Pulsar Testnet",
11657
- badge: "TESTNET",
11658
- Icon: LumiaIcon2,
11659
- isActive: true
11660
- }
11661
- ];
11605
+ NETWORKS_ICONS = {
11606
+ [LUMIA_MAINNET_CHAIN_ID3]: LumiaIcon2,
11607
+ [LUMIA_TESTNET_CHAIN_ID3]: LumiaIcon2,
11608
+ [LUMIA_PULSAR_TESTNET_CHAIN_ID]: LumiaIcon2,
11609
+ [BASE_SEPOLIA_CHAIN_ID]: BaseIcon,
11610
+ [BSC_MAINNET_CHAIN_ID]: BSCIcon,
11611
+ [BSC_TESTNET_CHAIN_ID3]: BSCIcon,
11612
+ 1: EthereumIcon,
11613
+ [ARBITRUM_SEPOLIA_CHAIN_ID]: ArbitrumIcon
11614
+ };
11615
+ }
11616
+ });
11617
+
11618
+ // src/config/networks.ts
11619
+ import { SUPPORTED_CHAINS, SUPPORTED_MAINNETS } from "@embarkai/core/read";
11620
+ var NETWORK_OPTIONS;
11621
+ var init_networks4 = __esm({
11622
+ "src/config/networks.ts"() {
11623
+ init_networks3();
11624
+ init_EmbarkIcon();
11625
+ NETWORK_OPTIONS = [...SUPPORTED_CHAINS].map(([chainId, chain]) => ({
11626
+ chainId,
11627
+ name: chain.name,
11628
+ badge: SUPPORTED_MAINNETS.includes(chainId) ? "MAINNET" : "TESTNET",
11629
+ Icon: NETWORKS_ICONS[chainId] || EmbarkIcon,
11630
+ isActive: true
11631
+ }));
11662
11632
  }
11663
11633
  });
11664
11634
 
@@ -11855,7 +11825,7 @@ function ChainsMenu() {
11855
11825
  }
11856
11826
  var init_ChainsMenu = __esm({
11857
11827
  "src/internal/components/ChainsMenu/ChainsMenu.tsx"() {
11858
- init_networks3();
11828
+ init_networks4();
11859
11829
  init_ProviderContext();
11860
11830
  init_SessionContext();
11861
11831
  init_useT();
@@ -11873,7 +11843,6 @@ var init_ChainsMenu = __esm({
11873
11843
 
11874
11844
  // src/internal/components/ChainsMenu/ChainSwitchRequest.tsx
11875
11845
  import { ArrowLeft as ArrowLeft5, Info as Info2, Loader as Loader7 } from "lucide-react";
11876
- import { useEffect as useEffect18, useRef as useRef12 } from "react";
11877
11846
  import { Trans } from "react-i18next";
11878
11847
  import { jsx as jsx49, jsxs as jsxs44 } from "react/jsx-runtime";
11879
11848
  function ChainSwitchRequest() {
@@ -11881,17 +11850,7 @@ function ChainSwitchRequest() {
11881
11850
  const config = useProviderConfig().config;
11882
11851
  const isLoading = useSession((st) => st.isLoading);
11883
11852
  const chainConfig = useSession((st) => st.chainConfig);
11884
- const setActiveChainId = useSession((st) => st.setActiveChainId);
11885
- const setPage = useLayoutDataStore((st) => st.setPage);
11886
11853
  const maxScrollHeight = useLayoutStore((st) => st.maxScrollHeight);
11887
- const changeTouchedRef = useRef12(false);
11888
- useEffect18(() => {
11889
- if (!changeTouchedRef.current || chainConfig?.id !== config.current?.network?.chainId) return;
11890
- setPage(null);
11891
- return () => {
11892
- changeTouchedRef.current = false;
11893
- };
11894
- }, [chainConfig, setPage]);
11895
11854
  const prefferedChain = NETWORK_OPTIONS.find((ch) => ch.chainId === config.current?.network?.chainId) || null;
11896
11855
  const PrefferedChainIcon = prefferedChain?.Icon || (() => null);
11897
11856
  return /* @__PURE__ */ jsx49(
@@ -11910,7 +11869,7 @@ function ChainSwitchRequest() {
11910
11869
  size: "icon",
11911
11870
  variant: "ghost",
11912
11871
  title: t("passport:common.back"),
11913
- onClick: () => setPage("settings" /* SETTINGS */),
11872
+ onClick: () => useLayoutDataStore.getState().setPage("settings" /* SETTINGS */),
11914
11873
  children: /* @__PURE__ */ jsx49(ArrowLeft5, { className: "h-4 w-4" })
11915
11874
  }
11916
11875
  ),
@@ -11942,8 +11901,8 @@ function ChainSwitchRequest() {
11942
11901
  disabled: isLoading,
11943
11902
  onClick: () => {
11944
11903
  if (!config.current?.network?.chainId) return;
11945
- changeTouchedRef.current = true;
11946
- setActiveChainId(config.current.network.chainId);
11904
+ useSession.getState().setActiveChainId(config.current.network.chainId);
11905
+ useLayoutDataStore.getState().setPage("chain" /* CHAIN */);
11947
11906
  },
11948
11907
  children: [
11949
11908
  isLoading ? /* @__PURE__ */ jsx49(Loader7, { className: "w-6 h-6 animate-spin" }) : /* @__PURE__ */ jsx49(PrefferedChainIcon, { className: "w-6 h-6" }),
@@ -11959,7 +11918,7 @@ function ChainSwitchRequest() {
11959
11918
  }
11960
11919
  var init_ChainSwitchRequest = __esm({
11961
11920
  "src/internal/components/ChainsMenu/ChainSwitchRequest.tsx"() {
11962
- init_networks3();
11921
+ init_networks4();
11963
11922
  init_ProviderContext();
11964
11923
  init_SessionContext();
11965
11924
  init_useT();
@@ -12641,7 +12600,7 @@ var init_guardian_backup = __esm({
12641
12600
  });
12642
12601
 
12643
12602
  // src/internal/components/DevicesMenu/DeviceManageScreen.tsx
12644
- import { useCallback as useCallback14, useEffect as useEffect19, useRef as useRef13, useState as useState11 } from "react";
12603
+ import { useCallback as useCallback14, useEffect as useEffect18, useRef as useRef12, useState as useState11 } from "react";
12645
12604
  import { ArrowLeft as ArrowLeft7, Cpu, Download, HardDrive, Loader2 as Loader23, Trash2, Upload } from "lucide-react";
12646
12605
  import { Fragment as Fragment15, jsx as jsx51, jsxs as jsxs46 } from "react/jsx-runtime";
12647
12606
  function formatSize(bytes) {
@@ -12656,19 +12615,19 @@ function DeviceManageScreen() {
12656
12615
  const userId = session?.mpcUserId || "";
12657
12616
  const deviceId = pageParams?.deviceId;
12658
12617
  const deviceName = pageParams?.deviceName;
12659
- const guardianRef = useRef13(null);
12618
+ const guardianRef = useRef12(null);
12660
12619
  const [screen, setScreen] = useState11({ step: "connecting" });
12661
12620
  const [actionState, setActionState] = useState11(null);
12662
12621
  const [password, setPassword] = useState11("");
12663
12622
  const [statusMessage, setStatusMessage] = useState11(null);
12664
12623
  const [errorMessage, setErrorMessage] = useState11(null);
12665
12624
  const [waitingConfirm, setWaitingConfirm] = useState11(false);
12666
- useEffect19(() => {
12625
+ useEffect18(() => {
12667
12626
  if (!statusMessage) return;
12668
12627
  const t = setTimeout(() => setStatusMessage(null), 3e3);
12669
12628
  return () => clearTimeout(t);
12670
12629
  }, [statusMessage]);
12671
- useEffect19(() => {
12630
+ useEffect18(() => {
12672
12631
  if (!deviceId || !isWebSerialAvailable()) {
12673
12632
  setScreen({ step: "error", message: "WebSerial not available" });
12674
12633
  return;
@@ -13187,12 +13146,43 @@ var init_DevicesMenu = __esm({
13187
13146
  }
13188
13147
  });
13189
13148
 
13190
- // src/internal/components/KeyshareRestoreMenu/hooks/useRestoreStore.ts
13149
+ // src/internal/stores/useExternalWalletStore.ts
13191
13150
  import { create as create6 } from "zustand";
13151
+ var useExternalWalletStore;
13152
+ var init_useExternalWalletStore = __esm({
13153
+ "src/internal/stores/useExternalWalletStore.ts"() {
13154
+ useExternalWalletStore = create6((set) => ({
13155
+ configMode: "linked",
13156
+ activeMode: "linked",
13157
+ externalAddress: null,
13158
+ externalChainId: null,
13159
+ isExternalConnected: false,
13160
+ connectorName: null,
13161
+ setConfigMode: (mode) => set({ configMode: mode }),
13162
+ setActiveMode: (mode) => set({ activeMode: mode }),
13163
+ setExternalWallet: ({ address, chainId, connectorName }) => set({
13164
+ externalAddress: address,
13165
+ externalChainId: chainId,
13166
+ isExternalConnected: true,
13167
+ connectorName
13168
+ }),
13169
+ clearExternalWallet: () => set({
13170
+ externalAddress: null,
13171
+ externalChainId: null,
13172
+ isExternalConnected: false,
13173
+ connectorName: null
13174
+ }),
13175
+ setExternalChainId: (chainId) => set({ externalChainId: chainId })
13176
+ }));
13177
+ }
13178
+ });
13179
+
13180
+ // src/internal/components/KeyshareRestoreMenu/hooks/useRestoreStore.ts
13181
+ import { create as create7 } from "zustand";
13192
13182
  var useRestoreStore;
13193
13183
  var init_useRestoreStore = __esm({
13194
13184
  "src/internal/components/KeyshareRestoreMenu/hooks/useRestoreStore.ts"() {
13195
- useRestoreStore = create6((set) => ({
13185
+ useRestoreStore = create7((set) => ({
13196
13186
  method: null,
13197
13187
  // recoveryData: null,
13198
13188
  showPassword: false,
@@ -13765,42 +13755,43 @@ var init_cloudStorage = __esm({
13765
13755
 
13766
13756
  // src/internal/components/KeyshareRestoreMenu/hooks/useCreateBackup.ts
13767
13757
  import { useMutation as useMutation9, useQueryClient as useQueryClient9 } from "@tanstack/react-query";
13768
- import { useEffect as useEffect20 } from "react";
13758
+ import { useCallback as useCallback17, useEffect as useEffect19 } from "react";
13769
13759
  function useCreateBackup() {
13770
13760
  const qc = useQueryClient9();
13771
13761
  const session = useSession((st) => st.session);
13772
13762
  const address = useSession((st) => st.address);
13773
13763
  const hasServerVault = useSession((st) => st.hasServerVault);
13774
- const setIsDialogForced = useLayoutStore((st) => st.setIsDialogForced);
13775
- const { usePasskey, restorePassword, selectedCloudProvider, setSuccess, setError, setMethod, setIsCreatingPasskey } = useRestoreStore();
13776
- useEffect20(() => {
13764
+ const usePasskey = useRestoreStore((st) => st.usePasskey);
13765
+ const restorePassword = useRestoreStore((st) => st.restorePassword);
13766
+ const selectedCloudProvider = useRestoreStore((st) => st.selectedCloudProvider);
13767
+ useEffect19(() => {
13777
13768
  if (!hasServerVault) {
13778
- setMethod("server");
13779
- setIsDialogForced(true);
13769
+ useRestoreStore.getState().setMethod("server");
13770
+ useLayoutStore.getState().setIsDialogForced(true);
13780
13771
  }
13781
- }, [hasServerVault, setIsDialogForced, setMethod]);
13772
+ }, [hasServerVault]);
13782
13773
  const recoveryUserId = useSession((st) => st.recoveryUserId);
13783
13774
  const passportUserId = session?.mpcUserId || recoveryUserId || "";
13784
- const onBackupSuccess = () => console.log("[ConnectWalletButton] Backup created successfully");
13775
+ const onBackupSuccess = useCallback17(() => {
13776
+ console.log("[EMBARKAI BACKUP] Backup created successfully");
13777
+ }, [hasServerVault]);
13785
13778
  const { mutate: createPasswordBackup, isPending: isPasswordBackupCreating } = useMutation9({
13786
13779
  mutationFn: async () => {
13787
13780
  const iframeManager = getIframeManager();
13788
13781
  if (!iframeManager) {
13789
13782
  throw new Error("Iframe manager not initialized");
13790
13783
  }
13791
- const jwt = await Promise.resolve().then(() => (init_auth(), auth_exports)).then((m) => m.jwtTokenManager.getTokens());
13784
+ const jwt = jwtTokenManager2.getTokens();
13792
13785
  if (!usePasskey && !restorePassword) {
13793
13786
  throw new Error("Please provide a password for the backup");
13794
13787
  }
13795
13788
  const password = !usePasskey ? restorePassword : void 0;
13796
- const navigateToMainMenu = jwt.isNewUser || !hasServerVault;
13797
- console.log("[BACKUP STATUS] is new user:", jwt.isNewUser, !hasServerVault, "usePasskey:", usePasskey);
13798
13789
  return {
13799
- response: await iframeManager.createBackup(passportUserId, { method: "server", password }, jwt.accessToken),
13800
- navigateToMainMenu
13790
+ response: await iframeManager.createBackup(passportUserId, { method: "server", password }, jwt.accessToken)
13801
13791
  };
13802
13792
  },
13803
- onSuccess: async ({ response, navigateToMainMenu }) => {
13793
+ onSuccess: async ({ response }) => {
13794
+ const { setError, setSuccess } = useRestoreStore.getState();
13804
13795
  qc.invalidateQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY, address] });
13805
13796
  if (response.success) {
13806
13797
  setError("");
@@ -13808,7 +13799,7 @@ function useCreateBackup() {
13808
13799
  if (typeof window !== "undefined") {
13809
13800
  window.dispatchEvent(
13810
13801
  new CustomEvent("lumia-passport-backup-status-changed", {
13811
- detail: { method: "server", success: true, navigateToMainMenu }
13802
+ detail: { method: "server", success: true }
13812
13803
  })
13813
13804
  );
13814
13805
  }
@@ -13816,9 +13807,10 @@ function useCreateBackup() {
13816
13807
  } else {
13817
13808
  setError(response.error || "Server backup failed");
13818
13809
  }
13819
- setIsDialogForced(false);
13810
+ useLayoutStore.getState().setIsDialogForced(false);
13820
13811
  },
13821
13812
  onError: async (error) => {
13813
+ const { setError, setSuccess } = useRestoreStore.getState();
13822
13814
  setSuccess("");
13823
13815
  if (error?.name === "NotAllowedError" || error?.message?.includes("timed out or was not allowed")) {
13824
13816
  setError("Passkey selection was cancelled. Please try again or create a new passkey.");
@@ -13847,7 +13839,7 @@ function useCreateBackup() {
13847
13839
  },
13848
13840
  onSuccess: async () => {
13849
13841
  qc.invalidateQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY, address] });
13850
- setSuccess("Backup file downloaded successfully");
13842
+ useRestoreStore.getState().setSuccess("Backup file downloaded successfully");
13851
13843
  if (typeof window !== "undefined") {
13852
13844
  window.dispatchEvent(
13853
13845
  new CustomEvent("lumia-passport-backup-status-changed", {
@@ -13858,13 +13850,13 @@ function useCreateBackup() {
13858
13850
  onBackupSuccess();
13859
13851
  },
13860
13852
  onError: async (error) => {
13861
- setError(error?.message || "Backup creation failed");
13853
+ useRestoreStore.getState().setError(error?.message || "Backup creation failed");
13862
13854
  qc.invalidateQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY, address] });
13863
13855
  }
13864
13856
  });
13865
13857
  const { mutate: createPasskey, isPending: isPasskeyCreating } = useMutation9({
13866
13858
  mutationFn: async () => {
13867
- setIsCreatingPasskey(true);
13859
+ useRestoreStore.getState().setIsCreatingPasskey(true);
13868
13860
  const { linkPasskeyWithWebAuthn: linkPasskeyWithWebAuthn2 } = await Promise.resolve().then(() => (init_passkey2(), passkey_exports2));
13869
13861
  const { createPasskeyHelpers: createPasskeyHelpers2 } = await Promise.resolve().then(() => (init_passkey(), passkey_exports));
13870
13862
  const { credentialId, rawId } = await linkPasskeyWithWebAuthn2();
@@ -13874,11 +13866,13 @@ function useCreateBackup() {
13874
13866
  return { credentialId, rawId };
13875
13867
  },
13876
13868
  onSuccess: async () => {
13869
+ const { setError, setSuccess, setIsCreatingPasskey } = useRestoreStore.getState();
13877
13870
  setIsCreatingPasskey(false);
13878
13871
  setError(null);
13879
13872
  setSuccess("Passkey created successfully. You can now create a backup.");
13880
13873
  },
13881
13874
  onError: async (error) => {
13875
+ const { setError, setIsCreatingPasskey } = useRestoreStore.getState();
13882
13876
  setIsCreatingPasskey(false);
13883
13877
  if (error.name === "NotAllowedError") {
13884
13878
  setError("Passkey creation cancelled. Please try again.");
@@ -13911,7 +13905,7 @@ function useCreateBackup() {
13911
13905
  },
13912
13906
  onSuccess: async ({ provider, uploadResult }) => {
13913
13907
  console.log("[KeyshareBackup] Cloud backup upload result:", uploadResult);
13914
- setSuccess(`Successfully created cloud backup on ${provider.name}`);
13908
+ useRestoreStore.getState().setSuccess(`Successfully created cloud backup on ${provider.name}`);
13915
13909
  qc.invalidateQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY, address] });
13916
13910
  if (typeof window !== "undefined") {
13917
13911
  window.dispatchEvent(
@@ -13923,7 +13917,7 @@ function useCreateBackup() {
13923
13917
  onBackupSuccess();
13924
13918
  },
13925
13919
  onError: async (error) => {
13926
- setError(error?.message || "Backup creation failed");
13920
+ useRestoreStore.getState().setError(error?.message || "Backup creation failed");
13927
13921
  qc.invalidateQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY, address] });
13928
13922
  }
13929
13923
  });
@@ -13941,6 +13935,7 @@ function useCreateBackup() {
13941
13935
  var init_useCreateBackup = __esm({
13942
13936
  "src/internal/components/KeyshareRestoreMenu/hooks/useCreateBackup.ts"() {
13943
13937
  init_SessionContext();
13938
+ init_auth();
13944
13939
  init_useLayoutStore();
13945
13940
  init_iframe_manager();
13946
13941
  init_constants4();
@@ -14064,7 +14059,7 @@ var init_useRestoreAccount = __esm({
14064
14059
  });
14065
14060
 
14066
14061
  // src/internal/components/KeyshareRestoreMenu/hooks/useValidateFileBackup.ts
14067
- import { useEffect as useEffect21 } from "react";
14062
+ import { useEffect as useEffect20 } from "react";
14068
14063
  function validateRestoreFileFormat(parsedData) {
14069
14064
  if (typeof parsedData !== "object" || parsedData === null) return false;
14070
14065
  const data = parsedData;
@@ -14074,7 +14069,7 @@ function useValidateFileBackup() {
14074
14069
  const restoreFile = useRestoreStore((st) => st.restoreFile);
14075
14070
  const setError = useRestoreStore((st) => st.setError);
14076
14071
  const setUsePasskey = useRestoreStore((st) => st.setUsePasskey);
14077
- useEffect21(() => {
14072
+ useEffect20(() => {
14078
14073
  if (!restoreFile) {
14079
14074
  return;
14080
14075
  }
@@ -14200,7 +14195,7 @@ var init_MethodSelector = __esm({
14200
14195
 
14201
14196
  // src/internal/components/KeyshareRestoreMenu/components/PasswordPasskey.tsx
14202
14197
  import { ChevronRight as ChevronRight2, Eye, EyeOff, Info as Info3, Key as Key4, Loader as Loader8, Plus } from "lucide-react";
14203
- import { useEffect as useEffect22, useRef as useRef14 } from "react";
14198
+ import { useEffect as useEffect21, useRef as useRef13 } from "react";
14204
14199
  import { Fragment as Fragment18, jsx as jsx55, jsxs as jsxs50 } from "react/jsx-runtime";
14205
14200
  function PasswordPasskey(props) {
14206
14201
  const { t } = useT();
@@ -14215,7 +14210,7 @@ function PasswordPasskey(props) {
14215
14210
  onCreatePasskey
14216
14211
  } = props;
14217
14212
  const hasServerVault = useSession((st) => st.hasServerVault);
14218
- const actionRef = useRef14(null);
14213
+ const actionRef = useRef13(null);
14219
14214
  const {
14220
14215
  showPassword,
14221
14216
  restorePassword,
@@ -14229,7 +14224,7 @@ function PasswordPasskey(props) {
14229
14224
  } = useRestoreStore();
14230
14225
  const { config } = useProviderConfig();
14231
14226
  const isPasskeyEnabled = config.current.passkey.enabled;
14232
- useEffect22(() => {
14227
+ useEffect21(() => {
14233
14228
  if (!isPasskeyEnabled && usePasskey) setUsePasskey(false);
14234
14229
  }, [isPasskeyEnabled, usePasskey]);
14235
14230
  return /* @__PURE__ */ jsxs50(Fragment18, { children: [
@@ -14557,7 +14552,7 @@ var init_File = __esm({
14557
14552
  import { useQueryClient as useQueryClient10 } from "@tanstack/react-query";
14558
14553
  import dayjs3 from "dayjs";
14559
14554
  import { Download as Download3, Key as Key5, Upload as Upload3 } from "lucide-react";
14560
- import { useEffect as useEffect23 } from "react";
14555
+ import { useEffect as useEffect22 } from "react";
14561
14556
  import { Fragment as Fragment21, jsx as jsx58, jsxs as jsxs53 } from "react/jsx-runtime";
14562
14557
  function Server(props) {
14563
14558
  const { isLoading, mode = "restore", serverHandler, createPasskeyHandler } = props;
@@ -14567,7 +14562,7 @@ function Server(props) {
14567
14562
  const usePasskey = useRestoreStore((st) => st.usePasskey);
14568
14563
  const setUsePasskey = useRestoreStore((st) => st.setUsePasskey);
14569
14564
  const serverRecoveryStatus = qc.getQueryData([CHECK_BACKUP_QUERY_KEY, address]);
14570
- useEffect23(() => {
14565
+ useEffect22(() => {
14571
14566
  if (mode === "backup" || !serverRecoveryStatus?.created?.encryptionMethod) return;
14572
14567
  setUsePasskey(serverRecoveryStatus.created.encryptionMethod === "passkey");
14573
14568
  }, [mode, serverRecoveryStatus, setUsePasskey]);
@@ -14590,7 +14585,7 @@ function Server(props) {
14590
14585
  ) : t("passport:backupMenu.vaultRestore")
14591
14586
  }
14592
14587
  ),
14593
- !!serverRecoveryStatus?.created?.at && /* @__PURE__ */ jsxs53(Highlight, { type: "success", className: "flex gap-[var(--ui-kit-gap)]", children: [
14588
+ !!serverRecoveryStatus?.created?.at && /* @__PURE__ */ jsxs53(Highlight, { type: "info", className: "flex gap-[var(--ui-kit-gap)]", children: [
14594
14589
  serverRecoveryStatus.created.encryptionMethod === "password" ? /* @__PURE__ */ jsx58(OtpIcon, { className: "w-4 h-4" }) : /* @__PURE__ */ jsx58(Key5, { className: "w-4 h-4" }),
14595
14590
  /* @__PURE__ */ jsxs53("span", { className: "flex-1 block", children: [
14596
14591
  t("passport:backupMenu.vaultRecoveryStatus"),
@@ -14750,7 +14745,7 @@ var init_select = __esm({
14750
14745
  // src/internal/components/KeyshareRestoreMenu/methods/Cloud.tsx
14751
14746
  import { useQuery as useQuery6 } from "@tanstack/react-query";
14752
14747
  import { ArrowLeft as ArrowLeft10, CloudDownload, CloudUpload, Loader as Loader9 } from "lucide-react";
14753
- import { useEffect as useEffect24 } from "react";
14748
+ import { useEffect as useEffect23 } from "react";
14754
14749
  import { Fragment as Fragment22, jsx as jsx60, jsxs as jsxs55 } from "react/jsx-runtime";
14755
14750
  function Cloud2(props) {
14756
14751
  const { isLoading, mode = "restore", cloudHandler } = props;
@@ -14771,7 +14766,7 @@ function Cloud2(props) {
14771
14766
  return availableProviders.map((p) => ({ id: p.id, name: p.name, available: p.isAvailable() }));
14772
14767
  }
14773
14768
  });
14774
- useEffect24(() => {
14769
+ useEffect23(() => {
14775
14770
  if (isCloudProvidersLoading) return;
14776
14771
  if (!!cloudProvidersError) {
14777
14772
  console.error("[KeyshareBackup] Failed to load cloud providers:", cloudProvidersError);
@@ -15011,7 +15006,8 @@ var init_methods = __esm({
15011
15006
  // src/internal/components/KeyshareRestoreMenu/KeyshareRestoreMenu.tsx
15012
15007
  import { useMutation as useMutation11, useQuery as useQuery7, useQueryClient as useQueryClient11 } from "@tanstack/react-query";
15013
15008
  import { AlertCircle as AlertCircle2, CheckCircle2, CloudDownload as CloudDownload2, Loader as Loader10, UserCircle as UserCircle2 } from "lucide-react";
15014
- import { useEffect as useEffect25 } from "react";
15009
+ import { useEffect as useEffect24 } from "react";
15010
+ import { useDisconnect } from "wagmi";
15015
15011
  import { Fragment as Fragment24, jsx as jsx62, jsxs as jsxs57 } from "react/jsx-runtime";
15016
15012
  var RESTORE_COMPONENTS, KeyshareRestoreMenu;
15017
15013
  var init_KeyshareRestoreMenu = __esm({
@@ -15021,6 +15017,7 @@ var init_KeyshareRestoreMenu = __esm({
15021
15017
  init_i18n();
15022
15018
  init_useLayoutDataStore();
15023
15019
  init_useLayoutStore();
15020
+ init_useExternalWalletStore();
15024
15021
  init_vaultClient();
15025
15022
  init_Expandable2();
15026
15023
  init_button();
@@ -15041,23 +15038,14 @@ var init_KeyshareRestoreMenu = __esm({
15041
15038
  const qc = useQueryClient11();
15042
15039
  const { callbacksRef } = useProviderConfig();
15043
15040
  const { t } = useT();
15044
- const { address, setSession, setAddress, setStatus, setIsLoading } = useSession();
15041
+ const address = useSession((st) => st.address);
15045
15042
  const maxScrollHeight = useLayoutStore((st) => st.maxScrollHeight);
15046
- const setIsDialogForced = useLayoutStore((st) => st.setIsDialogForced);
15047
- const setPage = useLayoutDataStore((st) => st.setPage);
15048
- const {
15049
- method: currentRestoreMethod,
15050
- error,
15051
- success,
15052
- setError,
15053
- setShowPassword,
15054
- setUsePasskey,
15055
- setRestoreFile,
15056
- setRestorePassword,
15057
- setSuccess,
15058
- setMethod
15059
- } = useRestoreStore();
15060
- useEffect25(() => {
15043
+ const error = useRestoreStore((st) => st.error);
15044
+ const success = useRestoreStore((st) => st.success);
15045
+ const currentRestoreMethod = useRestoreStore((st) => st.method);
15046
+ useEffect24(() => {
15047
+ const { setIsDialogForced } = useLayoutStore.getState();
15048
+ const { setRestorePassword, setRestoreFile, setShowPassword, setUsePasskey, setMethod } = useRestoreStore.getState();
15061
15049
  setIsDialogForced(true);
15062
15050
  return () => {
15063
15051
  setRestorePassword("");
@@ -15068,6 +15056,18 @@ var init_KeyshareRestoreMenu = __esm({
15068
15056
  setIsDialogForced(false);
15069
15057
  };
15070
15058
  }, []);
15059
+ const { disconnect: wagmiDisconnect } = useDisconnect({
15060
+ mutation: {
15061
+ onSuccess: () => {
15062
+ useExternalWalletStore.getState().clearExternalWallet();
15063
+ useExternalWalletStore.getState().setExternalChainId(null);
15064
+ console.log("[ExternalWalletStore] Disconnected from external wallet");
15065
+ },
15066
+ onError: (err) => {
15067
+ console.error("[ExternalWalletStore] Error disconnecting from external wallet:", err);
15068
+ }
15069
+ }
15070
+ });
15071
15071
  const { onRestoreSuccess } = useOnRestoreSuccess();
15072
15072
  const {
15073
15073
  restoreFromServer: restoreFromServer2,
@@ -15083,15 +15083,18 @@ var init_KeyshareRestoreMenu = __esm({
15083
15083
  queryFn: async () => await getShareRecoveryStats()
15084
15084
  });
15085
15085
  const hasServerBackup = serverRecoveryStatus?.created || serverRecoveryStatus?.devices?.length > 0;
15086
- useEffect25(() => {
15087
- if (!!hasServerBackup) setMethod("server");
15086
+ useEffect24(() => {
15087
+ if (!!hasServerBackup) useRestoreStore.getState().setMethod("server");
15088
15088
  }, [hasServerBackup]);
15089
15089
  const { mutate: disconnect, isPending: isDisconnecting } = useMutation11({
15090
15090
  mutationFn: async () => {
15091
+ const { setStatus, setIsLoading } = useSession.getState();
15092
+ const { setError, setMethod } = useRestoreStore.getState();
15091
15093
  setError(null);
15092
15094
  setMethod(null);
15093
15095
  setStatus("disconnecting");
15094
15096
  setIsLoading(true);
15097
+ useLayoutStore.getState().setIsDialogForced(true);
15095
15098
  const { jwtTokenManager: jwtTokenManager4 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
15096
15099
  const userId = jwtTokenManager4.getUserId() || null;
15097
15100
  const { logout: logout2 } = await Promise.resolve().then(() => (init_auth(), auth_exports));
@@ -15100,20 +15103,23 @@ var init_KeyshareRestoreMenu = __esm({
15100
15103
  },
15101
15104
  onSuccess: async ({ disconnectedUserId }) => {
15102
15105
  await qc.resetQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY] });
15106
+ if (!!useExternalWalletStore.getState().externalAddress) wagmiDisconnect();
15107
+ const { setStatus, setIsLoading, setSession, setAddress } = useSession.getState();
15103
15108
  setSession(null);
15104
15109
  setAddress(null);
15105
- setError(null);
15106
15110
  setStatus("idle");
15107
15111
  setIsLoading(false);
15108
- setIsDialogForced(false);
15112
+ useRestoreStore.getState().setError(null);
15113
+ useLayoutStore.getState().setIsDialogForced(false);
15109
15114
  callbacksRef.current?.onDisconnect?.({ address: "0x", userId: disconnectedUserId });
15110
- setTimeout(() => setPage("auth" /* AUTH */), 50);
15115
+ setTimeout(() => useLayoutDataStore.getState().setPage("auth" /* AUTH */), 50);
15111
15116
  },
15112
15117
  onError: (err) => {
15113
- setError(err.message || "An unknown error occurred during sign out");
15118
+ const { setStatus, setIsLoading } = useSession.getState();
15114
15119
  setStatus("idle");
15115
15120
  setIsLoading(false);
15116
- setIsDialogForced(false);
15121
+ useRestoreStore.getState().setError(err.message || "An unknown error occurred during sign out");
15122
+ useLayoutStore.getState().setIsDialogForced(false);
15117
15123
  }
15118
15124
  });
15119
15125
  const RestoreComponent = currentRestoreMethod ? RESTORE_COMPONENTS[currentRestoreMethod] : null;
@@ -15147,6 +15153,7 @@ var init_KeyshareRestoreMenu = __esm({
15147
15153
  labels: { checked: t("passport:common.standard"), unchecked: t("passport:common.advanced") },
15148
15154
  checked: currentRestoreMethod !== "server",
15149
15155
  onChange: () => {
15156
+ const { setError, setRestorePassword, setRestoreFile, setMethod } = useRestoreStore.getState();
15150
15157
  if (!!error) setError(null);
15151
15158
  if (currentRestoreMethod === "server") {
15152
15159
  setRestorePassword("");
@@ -15176,6 +15183,15 @@ var init_KeyshareRestoreMenu = __esm({
15176
15183
  size: "large",
15177
15184
  variant: "ghost",
15178
15185
  onClick: () => {
15186
+ const {
15187
+ setError,
15188
+ setShowPassword,
15189
+ setUsePasskey,
15190
+ setRestoreFile,
15191
+ setRestorePassword,
15192
+ setSuccess,
15193
+ setMethod
15194
+ } = useRestoreStore.getState();
15179
15195
  setError(null);
15180
15196
  setShowPassword(false);
15181
15197
  setUsePasskey(false);
@@ -15214,7 +15230,7 @@ var init_KeyshareRestoreMenu = __esm({
15214
15230
  // src/internal/components/KeyshareRestoreMenu/KeyshareBackupMenu.tsx
15215
15231
  import { useQuery as useQuery8 } from "@tanstack/react-query";
15216
15232
  import { AlertCircle as AlertCircle3, ArrowLeft as ArrowLeft11, CheckCircle2 as CheckCircle22, Loader as Loader11, LockIcon } from "lucide-react";
15217
- import { useEffect as useEffect26 } from "react";
15233
+ import { useEffect as useEffect25 } from "react";
15218
15234
  import { Fragment as Fragment25, jsx as jsx63, jsxs as jsxs58 } from "react/jsx-runtime";
15219
15235
  function KeyshareBackupMenu() {
15220
15236
  const address = useSession((st) => st.address);
@@ -15222,20 +15238,11 @@ function KeyshareBackupMenu() {
15222
15238
  const { t } = useT();
15223
15239
  const setPage = useLayoutDataStore((st) => st.setPage);
15224
15240
  const maxScrollHeight = useLayoutStore((st) => st.maxScrollHeight);
15225
- const {
15226
- method: currentBackupMethod,
15227
- error,
15228
- success,
15229
- setSelectedCloudProvider,
15230
- setSuccess,
15231
- setError,
15232
- setRestorePassword,
15233
- setRestoreFile,
15234
- setShowPassword,
15235
- setUsePasskey,
15236
- setMethod
15237
- } = useRestoreStore();
15238
- useEffect26(() => {
15241
+ const currentBackupMethod = useRestoreStore((st) => st.method);
15242
+ const error = useRestoreStore((st) => st.error);
15243
+ const success = useRestoreStore((st) => st.success);
15244
+ useEffect25(() => {
15245
+ const { setSuccess, setError, setRestorePassword, setRestoreFile, setShowPassword, setUsePasskey, setMethod } = useRestoreStore.getState();
15239
15246
  return () => {
15240
15247
  setSuccess(null);
15241
15248
  setError(null);
@@ -15249,13 +15256,12 @@ function KeyshareBackupMenu() {
15249
15256
  const { data: serverRecoveryStatus, isLoading: isRecoveryLoading } = useQuery8({
15250
15257
  retry: false,
15251
15258
  enabled: !!address,
15252
- // Prevent query from running with undefined address
15253
15259
  queryKey: [CHECK_BACKUP_QUERY_KEY, address],
15254
15260
  queryFn: async () => await getShareRecoveryStats()
15255
15261
  });
15256
15262
  const hasRecoveryData = serverRecoveryStatus?.created || serverRecoveryStatus?.devices?.length > 0;
15257
- useEffect26(() => {
15258
- if (!!hasRecoveryData) setMethod("server");
15263
+ useEffect25(() => {
15264
+ if (!!hasRecoveryData) useRestoreStore.getState().setMethod("server");
15259
15265
  }, [hasRecoveryData]);
15260
15266
  const {
15261
15267
  isPasswordBackupCreating,
@@ -15288,6 +15294,16 @@ function KeyshareBackupMenu() {
15288
15294
  size: "icon",
15289
15295
  title: "Back",
15290
15296
  onClick: () => {
15297
+ const {
15298
+ setSuccess,
15299
+ setError,
15300
+ setRestorePassword,
15301
+ setRestoreFile,
15302
+ setShowPassword,
15303
+ setUsePasskey,
15304
+ setMethod,
15305
+ setSelectedCloudProvider
15306
+ } = useRestoreStore.getState();
15291
15307
  setRestorePassword("");
15292
15308
  setRestoreFile(null);
15293
15309
  setShowPassword(false);
@@ -15310,6 +15326,7 @@ function KeyshareBackupMenu() {
15310
15326
  labels: { checked: t("passport:common.standard"), unchecked: t("passport:common.advanced") },
15311
15327
  checked: currentBackupMethod !== "server",
15312
15328
  onChange: () => {
15329
+ const { setError, setRestorePassword, setRestoreFile, setMethod } = useRestoreStore.getState();
15313
15330
  if (!!error) setError(null);
15314
15331
  if (currentBackupMethod === "server") {
15315
15332
  setRestorePassword("");
@@ -15342,8 +15359,8 @@ function KeyshareBackupMenu() {
15342
15359
  /* @__PURE__ */ jsx63(AlertCircle3, { className: "h-4 w-4 flex-shrink-0" }),
15343
15360
  /* @__PURE__ */ jsx63("span", { className: "block w-full flex-1", children: error })
15344
15361
  ] }),
15345
- success && /* @__PURE__ */ jsxs58(Fragment25, { children: [
15346
- /* @__PURE__ */ jsxs58(Highlight, { type: "success", className: "flex gap-[var(--ui-kit-gap)]", children: [
15362
+ success && /* @__PURE__ */ jsxs58(Highlight, { type: "success", className: "w-full flex flex-col gap-[var(--ui-kit-gap)]", children: [
15363
+ /* @__PURE__ */ jsxs58("div", { className: "w-full flex gap-[var(--ui-kit-gap)]", children: [
15347
15364
  /* @__PURE__ */ jsx63(CheckCircle22, { className: "h-4 w-4 flex-shrink-0" }),
15348
15365
  /* @__PURE__ */ jsx63("span", { className: "block w-full flex-1", children: success })
15349
15366
  ] }),
@@ -15353,8 +15370,8 @@ function KeyshareBackupMenu() {
15353
15370
  variant: "default",
15354
15371
  size: "large",
15355
15372
  className: "w-full",
15356
- onClick: () => setPage("settings" /* SETTINGS */),
15357
- children: "Done"
15373
+ onClick: () => useRestoreStore.getState().setSuccess(null),
15374
+ children: t("passport:common.continue")
15358
15375
  }
15359
15376
  )
15360
15377
  ] })
@@ -15396,7 +15413,7 @@ var init_KeyshareRestoreMenu2 = __esm({
15396
15413
  });
15397
15414
 
15398
15415
  // src/hooks/useColorMode.ts
15399
- import { useCallback as useCallback17, useEffect as useEffect27 } from "react";
15416
+ import { useCallback as useCallback18, useEffect as useEffect26 } from "react";
15400
15417
  function useColorMode() {
15401
15418
  const {
15402
15419
  config: { current: config }
@@ -15404,14 +15421,14 @@ function useColorMode() {
15404
15421
  const preferedColorMode = config?.preferedColorMode;
15405
15422
  const colorMode = useLayoutStore((st) => st.colorMode);
15406
15423
  const handleStoreColorMode = useLayoutStore((st) => st.setColorMode);
15407
- const setColorMode = useCallback17(
15424
+ const setColorMode = useCallback18(
15408
15425
  (mode) => {
15409
15426
  localStorage.setItem(LOCAL_COLOR_MODE_KEY, mode);
15410
15427
  handleStoreColorMode(mode);
15411
15428
  },
15412
15429
  [handleStoreColorMode]
15413
15430
  );
15414
- useEffect27(() => {
15431
+ useEffect26(() => {
15415
15432
  let targetColorMode = localStorage.getItem(LOCAL_COLOR_MODE_KEY);
15416
15433
  if (!targetColorMode && !preferedColorMode) {
15417
15434
  const systemMode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
@@ -15526,17 +15543,17 @@ var init_SumsubIframeManager = __esm({
15526
15543
  });
15527
15544
 
15528
15545
  // src/internal/components/KYC/useSumsubIframe.ts
15529
- import { useEffect as useEffect28, useRef as useRef15, useState as useState16 } from "react";
15546
+ import { useEffect as useEffect27, useRef as useRef14, useState as useState16 } from "react";
15530
15547
  function useSumsubIframe({ iframeUrl }) {
15531
15548
  const config = useProviderConfig().config;
15532
15549
  const { colorMode } = useColorMode();
15533
- const iframeRef = useRef15(null);
15550
+ const iframeRef = useRef14(null);
15534
15551
  const [isLoading, setIsLoading] = useState16(true);
15535
15552
  const [error, setError] = useState16(null);
15536
15553
  const [height, setHeight] = useState16(0);
15537
15554
  const [status, setStatus] = useState16("");
15538
15555
  const levelName = config.current?.kyc?.options?.levelName;
15539
- useEffect28(() => {
15556
+ useEffect27(() => {
15540
15557
  setError(null);
15541
15558
  setIsLoading(true);
15542
15559
  setStatus("Preparing verification...");
@@ -15848,14 +15865,14 @@ var init_useProvidersList = __esm({
15848
15865
 
15849
15866
  // src/internal/components/MainMenu/MainMenu.tsx
15850
15867
  import { ChevronLeft, ChevronRight as ChevronRight3, DollarSign as DollarSign2, Wallet2 as Wallet23 } from "lucide-react";
15851
- import { useEffect as useEffect29 } from "react";
15868
+ import { useEffect as useEffect28 } from "react";
15852
15869
  import { jsx as jsx68, jsxs as jsxs63 } from "react/jsx-runtime";
15853
15870
  function MainMenu() {
15854
15871
  const address = useSession((st) => st.address);
15855
15872
  const { t } = useT();
15856
15873
  const setPage = useLayoutDataStore((st) => st.setPage);
15857
15874
  const setTransitionPageHeight = useLayoutDataStore((st) => st.setTransitionPageHeight);
15858
- useEffect29(() => setTransitionPageHeight(DEFAULT_MAIN_MENU_HEIGHT), []);
15875
+ useEffect28(() => setTransitionPageHeight(DEFAULT_MAIN_MENU_HEIGHT), []);
15859
15876
  useProvidersList();
15860
15877
  return /* @__PURE__ */ jsx68("div", { className: "w-full p-[var(--ui-kit-pd)] flex flex-col gap-[var(--ui-kit-gap)]", children: /* @__PURE__ */ jsx68("div", { className: "w-full grid grid-cols-4 gap-0 md:gap-[var(--ui-kit-gap)] py-[10px] md:py-1", children: MAIN_MENU_BUTTONS.map(({ id, label, icon: Icon2 }) => /* @__PURE__ */ jsxs63(
15861
15878
  Button,
@@ -15900,7 +15917,7 @@ var init_MainMenu2 = __esm({
15900
15917
 
15901
15918
  // src/modules/linkedProfiles.ts
15902
15919
  import { useQuery as useQuery11, useQueryClient as useQueryClient12 } from "@tanstack/react-query";
15903
- import { useCallback as useCallback18 } from "react";
15920
+ import { useCallback as useCallback19 } from "react";
15904
15921
  function useLinkedProfiles() {
15905
15922
  const qc = useQueryClient12();
15906
15923
  const address = useSession((st) => st.address);
@@ -15924,7 +15941,7 @@ function useLinkedProfiles() {
15924
15941
  }
15925
15942
  });
15926
15943
  const { profiles = [], avatar = null } = data || {};
15927
- const refresh = useCallback18(async () => {
15944
+ const refresh = useCallback19(async () => {
15928
15945
  await qc.invalidateQueries({ queryKey: [LINKED_PROFILES_QUERY_KEY, address] });
15929
15946
  }, [qc, address]);
15930
15947
  return { profiles, avatar, isLoading, isFetching, error, refresh };
@@ -15941,11 +15958,11 @@ var init_linkedProfiles = __esm({
15941
15958
  });
15942
15959
 
15943
15960
  // src/internal/components/ManageWalletMenu/hooks/useStore.ts
15944
- import { create as create7 } from "zustand";
15961
+ import { create as create8 } from "zustand";
15945
15962
  var useManageWalletStore;
15946
15963
  var init_useStore = __esm({
15947
15964
  "src/internal/components/ManageWalletMenu/hooks/useStore.ts"() {
15948
- useManageWalletStore = create7((set) => ({
15965
+ useManageWalletStore = create8((set) => ({
15949
15966
  alert: null,
15950
15967
  emailStep: "input",
15951
15968
  email: "",
@@ -16402,7 +16419,7 @@ var init_EmailNotConnectedWarning = __esm({
16402
16419
 
16403
16420
  // src/internal/components/ManageWalletMenu/hooks/useLinkSocial.ts
16404
16421
  import { useQueryClient as useQueryClient15 } from "@tanstack/react-query";
16405
- import React5, { useEffect as useEffect30 } from "react";
16422
+ import React5, { useEffect as useEffect29 } from "react";
16406
16423
  function normalizeSocialLinkError(message) {
16407
16424
  if (message === "X_ALREADY_LINKED") {
16408
16425
  return "This X account is already linked to another account";
@@ -16478,7 +16495,7 @@ function useLinkSocial() {
16478
16495
  [config.social?.providers]
16479
16496
  );
16480
16497
  const [socialLinkStarted, setSocialLinkStarted] = React5.useState(false);
16481
- useEffect30(() => {
16498
+ useEffect29(() => {
16482
16499
  const key = providerType?.toLowerCase();
16483
16500
  console.log("[useLinkSocial] Effect triggered:", { key, linkIsLoading, socialLinkStarted, isWalletLinking });
16484
16501
  if (isWalletLinking) {
@@ -16561,7 +16578,7 @@ var init_telegram2 = __esm({
16561
16578
 
16562
16579
  // src/internal/components/ManageWalletMenu/hooks/useLinkTelegram.ts
16563
16580
  import { useQueryClient as useQueryClient16 } from "@tanstack/react-query";
16564
- import { useCallback as useCallback19, useEffect as useEffect31, useState as useState17 } from "react";
16581
+ import { useCallback as useCallback20, useEffect as useEffect30, useState as useState17 } from "react";
16565
16582
  function useLinkTelegram() {
16566
16583
  const {
16567
16584
  config: { current: config },
@@ -16572,7 +16589,7 @@ function useLinkTelegram() {
16572
16589
  const isWalletLinking = useLayoutDataStore((st) => st.isWalletLinking);
16573
16590
  const { providerType, linkIsLoading, setLinkIsLoading, setProviderType, setAlert } = useManageWalletStore();
16574
16591
  const setPage = useLayoutDataStore((st) => st.setPage);
16575
- const handleLinkTelegram = useCallback19(async () => {
16592
+ const handleLinkTelegram = useCallback20(async () => {
16576
16593
  try {
16577
16594
  if (shouldBlockSocialAuthInTelegram("telegram")) {
16578
16595
  setAlert(buildTelegramBrowserRestriction("Telegram", "linking"));
@@ -16620,7 +16637,7 @@ function useLinkTelegram() {
16620
16637
  }
16621
16638
  }, [config.social?.providers]);
16622
16639
  const [telegramLinkStarted, setTelegramLinkStarted] = useState17(false);
16623
- useEffect31(() => {
16640
+ useEffect30(() => {
16624
16641
  console.log("[useLinkTelegram] Effect triggered:", {
16625
16642
  providerType,
16626
16643
  linkIsLoading,
@@ -16637,7 +16654,7 @@ function useLinkTelegram() {
16637
16654
  handleLinkTelegram();
16638
16655
  }
16639
16656
  }, [providerType, handleLinkTelegram, linkIsLoading, telegramLinkStarted, isWalletLinking]);
16640
- useEffect31(() => {
16657
+ useEffect30(() => {
16641
16658
  if (providerType !== "telegram") {
16642
16659
  setTelegramLinkStarted(false);
16643
16660
  }
@@ -16937,48 +16954,17 @@ var init_ManageWallet = __esm({
16937
16954
  }
16938
16955
  });
16939
16956
 
16940
- // src/internal/stores/useExternalWalletStore.ts
16941
- import { create as create8 } from "zustand";
16942
- var useExternalWalletStore;
16943
- var init_useExternalWalletStore = __esm({
16944
- "src/internal/stores/useExternalWalletStore.ts"() {
16945
- useExternalWalletStore = create8((set) => ({
16946
- configMode: "linked",
16947
- activeMode: "linked",
16948
- externalAddress: null,
16949
- externalChainId: null,
16950
- isExternalConnected: false,
16951
- connectorName: null,
16952
- setConfigMode: (mode) => set({ configMode: mode }),
16953
- setActiveMode: (mode) => set({ activeMode: mode }),
16954
- setExternalWallet: ({ address, chainId, connectorName }) => set({
16955
- externalAddress: address,
16956
- externalChainId: chainId,
16957
- isExternalConnected: true,
16958
- connectorName
16959
- }),
16960
- clearExternalWallet: () => set({
16961
- externalAddress: null,
16962
- externalChainId: null,
16963
- isExternalConnected: false,
16964
- connectorName: null
16965
- }),
16966
- setExternalChainId: (chainId) => set({ externalChainId: chainId })
16967
- }));
16968
- }
16969
- });
16970
-
16971
16957
  // src/internal/components/ManageWalletMenu/UnlinkProviderMenu.tsx
16972
16958
  import { useMutation as useMutation15, useQueryClient as useQueryClient17 } from "@tanstack/react-query";
16973
16959
  import { Key as Key6, Loader as Loader15 } from "lucide-react";
16974
16960
  import { useState as useState18 } from "react";
16975
- import { useDisconnect } from "wagmi";
16961
+ import { useDisconnect as useDisconnect2 } from "wagmi";
16976
16962
  import { jsx as jsx74, jsxs as jsxs69 } from "react/jsx-runtime";
16977
16963
  function UnlinkProviderMenu() {
16978
16964
  const qc = useQueryClient17();
16979
16965
  const address = useSession((st) => st.address);
16980
16966
  const { callbacksRef } = useProviderConfig();
16981
- const { disconnect: disconnectExternalWallet } = useDisconnect();
16967
+ const { disconnect: disconnectExternalWallet } = useDisconnect2();
16982
16968
  const isExternalConnected = useExternalWalletStore((st) => st.isExternalConnected);
16983
16969
  const { t } = useT();
16984
16970
  const setPage = useLayoutDataStore((st) => st.setPage);
@@ -17212,7 +17198,7 @@ var init_nickname_validation = __esm({
17212
17198
  // src/internal/components/NicknameMenu/NicknameEditForm.tsx
17213
17199
  import { useMutation as useMutation16, useQueryClient as useQueryClient18 } from "@tanstack/react-query";
17214
17200
  import { AtSign, Check as Check2, ChevronRight as ChevronRight5, Copy as Copy2, Loader as Loader17 } from "lucide-react";
17215
- import { useCallback as useCallback20, useState as useState19 } from "react";
17201
+ import { useCallback as useCallback21, useState as useState19 } from "react";
17216
17202
  import { Fragment as Fragment29, jsx as jsx76, jsxs as jsxs71 } from "react/jsx-runtime";
17217
17203
  function NicknameEditForm(props) {
17218
17204
  const {
@@ -17263,7 +17249,7 @@ function NicknameEditForm(props) {
17263
17249
  );
17264
17250
  }
17265
17251
  });
17266
- const handleInputChange = useCallback20(
17252
+ const handleInputChange = useCallback21(
17267
17253
  (e) => {
17268
17254
  const value = e.target.value;
17269
17255
  setInputValue(value);
@@ -17277,7 +17263,7 @@ function NicknameEditForm(props) {
17277
17263
  },
17278
17264
  [clientError, isNicknameChangeError, isNicknameChangeSuccess, reset, t]
17279
17265
  );
17280
- const handleSubmit = useCallback20(
17266
+ const handleSubmit = useCallback21(
17281
17267
  (e) => {
17282
17268
  if (!canChange) return;
17283
17269
  e.preventDefault();
@@ -17360,19 +17346,19 @@ var init_NicknameEditForm = __esm({
17360
17346
 
17361
17347
  // src/internal/components/NicknameMenu/useNickname.ts
17362
17348
  import { useQuery as useQuery12 } from "@tanstack/react-query";
17363
- import { useEffect as useEffect32, useState as useState20 } from "react";
17349
+ import { useEffect as useEffect31, useState as useState20 } from "react";
17364
17350
  function useNicknameForm(currentNickname) {
17365
17351
  const [inputValue, setInputValue] = useState20("");
17366
17352
  const normalizedInputValue = normalizeNickname(inputValue);
17367
17353
  const validation = validateNickname(inputValue);
17368
17354
  const isValidForCheck = validation.valid && normalizedInputValue.length > 0;
17369
- useEffect32(() => {
17355
+ useEffect31(() => {
17370
17356
  setInputValue(currentNickname);
17371
17357
  }, [currentNickname]);
17372
17358
  const [queryInputValue, setQueryInputValue] = useState20("");
17373
17359
  const isSameAsCurrentNickname = normalizedInputValue === currentNickname.toLowerCase();
17374
17360
  const shouldCheckAvailability = validation.valid && !isSameAsCurrentNickname && inputValue.length > 0;
17375
- useEffect32(() => {
17361
+ useEffect31(() => {
17376
17362
  if (!isValidForCheck || !shouldCheckAvailability) {
17377
17363
  setQueryInputValue("");
17378
17364
  return;
@@ -17679,7 +17665,7 @@ var init_useWatchTokens = __esm({
17679
17665
  // src/internal/hooks/useBlockscoutAssets.ts
17680
17666
  import { createBlockscoutClient } from "@embarkai/core/clients";
17681
17667
  import { useQuery as useQuery15 } from "@tanstack/react-query";
17682
- import { useCallback as useCallback21, useMemo as useMemo9, useRef as useRef16 } from "react";
17668
+ import { useCallback as useCallback22, useMemo as useMemo9, useRef as useRef15 } from "react";
17683
17669
  import { formatEther, formatUnits as formatUnits3 } from "viem";
17684
17670
  function resolveIpfsUri(uri) {
17685
17671
  if (!uri) return "";
@@ -17815,7 +17801,7 @@ function useBlockscoutAssets(options) {
17815
17801
  () => blockscoutApiUrl ? createBlockscoutClient({ baseUrl: blockscoutApiUrl }) : null,
17816
17802
  [blockscoutApiUrl]
17817
17803
  );
17818
- const lastRefreshRef = useRef16(0);
17804
+ const lastRefreshRef = useRef15(0);
17819
17805
  const {
17820
17806
  assets: watchTokenAssets,
17821
17807
  isLoading: watchTokensLoading,
@@ -17986,7 +17972,7 @@ function useBlockscoutAssets(options) {
17986
17972
  if (!tokensError) return null;
17987
17973
  return createError(tokensError);
17988
17974
  }, [tokensError]);
17989
- const refreshBalances = useCallback21(async () => {
17975
+ const refreshBalances = useCallback22(async () => {
17990
17976
  const now = Date.now();
17991
17977
  if (now - lastRefreshRef.current < BLOCKSCOUT_REFRESH_DEBOUNCE) {
17992
17978
  return;
@@ -17994,7 +17980,7 @@ function useBlockscoutAssets(options) {
17994
17980
  lastRefreshRef.current = now;
17995
17981
  await Promise.all([refetchNative(), refetchTokens(), refetchNfts(), refetchWatchTokens()]);
17996
17982
  }, [refetchNative, refetchTokens, refetchNfts, refetchWatchTokens]);
17997
- const getTokenBalance = useCallback21(
17983
+ const getTokenBalance = useCallback22(
17998
17984
  (tokenAddress) => {
17999
17985
  return assets.find((a) => a.address?.toLowerCase() === tokenAddress.toLowerCase()) || null;
18000
17986
  },
@@ -18270,7 +18256,7 @@ var init_PortfolioItem = __esm({
18270
18256
  // src/internal/components/PortfolioMenu/PortfolioMenu.tsx
18271
18257
  import { useQueryClient as useQueryClient20 } from "@tanstack/react-query";
18272
18258
  import { AlertCircle as AlertCircle4, ArrowLeft as ArrowLeft16, Gem, Loader as Loader20, RefreshCw as RefreshCw2 } from "lucide-react";
18273
- import { useCallback as useCallback22 } from "react";
18259
+ import { useCallback as useCallback23 } from "react";
18274
18260
  import { jsx as jsx80, jsxs as jsxs75 } from "react/jsx-runtime";
18275
18261
  function PortfolioMenu() {
18276
18262
  const { assets: projectAssets = [] } = useProviderConfig().config.current?.projectAssets || {};
@@ -18290,7 +18276,7 @@ function PortfolioMenu() {
18290
18276
  enabled: !!address
18291
18277
  });
18292
18278
  const shownProjectAssests = projectAssets.filter((asset) => !asset.hideInPortfolio);
18293
- const refreshAllAssetsBalances = useCallback22(() => {
18279
+ const refreshAllAssetsBalances = useCallback23(() => {
18294
18280
  Promise.all(shownProjectAssests.map((asset) => qc.invalidateQueries({ queryKey: asset.balanceQueryKey })));
18295
18281
  refreshBlockscoutBalances();
18296
18282
  }, [qc, shownProjectAssests, refreshBlockscoutBalances]);
@@ -18445,7 +18431,7 @@ var init_nickname_fingerprint = __esm({
18445
18431
  // src/internal/components/ReceiveMenu/ReceiveMenu.tsx
18446
18432
  import { ArrowLeft as ArrowLeft17, CheckCircle2 as CheckCircle23, Copy as Copy3, Info as Info5, Loader as Loader21, Shield } from "lucide-react";
18447
18433
  import QRCode from "qrcode";
18448
- import { useCallback as useCallback23, useEffect as useEffect33, useMemo as useMemo10, useState as useState23 } from "react";
18434
+ import { useCallback as useCallback24, useEffect as useEffect32, useMemo as useMemo10, useState as useState23 } from "react";
18449
18435
  import { Fragment as Fragment31, jsx as jsx81, jsxs as jsxs76 } from "react/jsx-runtime";
18450
18436
  function ReceiveMenu() {
18451
18437
  const session = useSession((st) => st.session);
@@ -18467,7 +18453,7 @@ function ReceiveMenu() {
18467
18453
  return null;
18468
18454
  }
18469
18455
  }, [session?.ownerAddress]);
18470
- useEffect33(() => {
18456
+ useEffect32(() => {
18471
18457
  if (open && address) {
18472
18458
  QRCode.toDataURL(address, {
18473
18459
  width: 200,
@@ -18480,7 +18466,7 @@ function ReceiveMenu() {
18480
18466
  });
18481
18467
  }
18482
18468
  }, [open, address]);
18483
- const handleCopy = useCallback23(async () => {
18469
+ const handleCopy = useCallback24(async () => {
18484
18470
  if (!address) return;
18485
18471
  try {
18486
18472
  await navigator.clipboard.writeText(address);
@@ -18490,7 +18476,7 @@ function ReceiveMenu() {
18490
18476
  console.error("Failed to copy address:", error);
18491
18477
  }
18492
18478
  }, [address]);
18493
- const handleCopyFingerprint = useCallback23(async () => {
18479
+ const handleCopyFingerprint = useCallback24(async () => {
18494
18480
  if (!fingerprint) return;
18495
18481
  try {
18496
18482
  await navigator.clipboard.writeText(fingerprint);
@@ -19362,7 +19348,7 @@ var init_useBridgeStore = __esm({
19362
19348
  // src/internal/components/SendMenu/hyperbridge/components/SenderSelector.tsx
19363
19349
  import { useConnectModal } from "@rainbow-me/rainbowkit";
19364
19350
  import { useMutation as useMutation18 } from "@tanstack/react-query";
19365
- import { useEffect as useEffect34, useRef as useRef17, useState as useState25 } from "react";
19351
+ import { useEffect as useEffect33, useRef as useRef16, useState as useState25 } from "react";
19366
19352
  import { useSignMessage } from "wagmi";
19367
19353
  import { jsx as jsx89, jsxs as jsxs84 } from "react/jsx-runtime";
19368
19354
  function SenderSelector(props) {
@@ -19373,12 +19359,12 @@ function SenderSelector(props) {
19373
19359
  const { openConnectModal } = useConnectModal();
19374
19360
  const directWalletAddress = useExternalWalletStore((st) => st.externalAddress);
19375
19361
  const directWalletIsConnected = useExternalWalletStore((st) => st.isExternalConnected);
19376
- const pendingWalletRef = useRef17(null);
19362
+ const pendingWalletRef = useRef16(null);
19377
19363
  const originChain = useBridgeStore((st) => st.originChain);
19378
19364
  const bridgeSender = useBridgeStore((st) => st.bridgeSender);
19379
19365
  const bridgeSenders = useBridgeStore((st) => st.bridgeSenders);
19380
19366
  const [walletMessage, setWalletMessage] = useState25(null);
19381
- useEffect34(() => {
19367
+ useEffect33(() => {
19382
19368
  useFlowSelectorStore.getState().setRenderKey(`sender-selected-${Date.now()}`);
19383
19369
  }, [walletMessage]);
19384
19370
  const { mutate: loginDirectWallet, isPending: isDirectWalletLoggingIn } = useMutation18({
@@ -19434,7 +19420,7 @@ function SenderSelector(props) {
19434
19420
  setWalletMessage(error instanceof Error ? error.message : "Wallet login failed. Please try again.");
19435
19421
  }
19436
19422
  });
19437
- useEffect34(() => {
19423
+ useEffect33(() => {
19438
19424
  const pendingProfile = pendingWalletRef.current;
19439
19425
  if (!pendingProfile || !directWalletIsConnected || !directWalletAddress) return;
19440
19426
  if (directWalletAddress.toLowerCase() !== pendingProfile.externalId?.toLowerCase()) return;
@@ -19619,12 +19605,12 @@ var init_wallets = __esm({
19619
19605
  });
19620
19606
 
19621
19607
  // src/internal/components/SendMenu/hyperbridge/hooks/useAvailableSenders.ts
19622
- import { useEffect as useEffect35, useRef as useRef18 } from "react";
19608
+ import { useEffect as useEffect34, useRef as useRef17 } from "react";
19623
19609
  function useAvailableSenders() {
19624
19610
  const address = useSession((st) => st.address);
19625
19611
  const { profiles } = useLinkedProfiles();
19626
- const lastCalcedSenders = useRef18([]);
19627
- useEffect35(() => {
19612
+ const lastCalcedSenders = useRef17([]);
19613
+ useEffect34(() => {
19628
19614
  const sendersAccumulator = [
19629
19615
  {
19630
19616
  type: "embarkai-wallet",
@@ -19979,7 +19965,7 @@ function isOririnChainEmbarkSupported(originChain) {
19979
19965
  }
19980
19966
  var init_utils8 = __esm({
19981
19967
  "src/internal/components/SendMenu/hyperbridge/utils.ts"() {
19982
- init_networks3();
19968
+ init_networks4();
19983
19969
  init_chains();
19984
19970
  }
19985
19971
  });
@@ -19987,7 +19973,7 @@ var init_utils8 = __esm({
19987
19973
  // src/internal/components/SendMenu/hyperbridge/hooks/useHyperlaneHistory.ts
19988
19974
  import { useInfiniteQuery as useInfiniteQuery3 } from "@tanstack/react-query";
19989
19975
  import { debounce as debounce6 } from "lodash-es";
19990
- import { useCallback as useCallback24, useEffect as useEffect36, useMemo as useMemo11 } from "react";
19976
+ import { useCallback as useCallback25, useEffect as useEffect35, useMemo as useMemo11 } from "react";
19991
19977
  function useHyperlaneHistory() {
19992
19978
  const address = useSession((st) => st.address);
19993
19979
  const page = useLayoutDataStore((st) => st.page);
@@ -20007,13 +19993,13 @@ function useHyperlaneHistory() {
20007
19993
  () => txHistoryData?.pages?.map((p) => p.data).flat(Infinity) || [],
20008
19994
  [txHistoryData]
20009
19995
  );
20010
- const updateExpandable = useCallback24(
19996
+ const updateExpandable = useCallback25(
20011
19997
  debounce6(() => {
20012
19998
  useFlowSelectorStore.getState().setRenderKey(`hyperlane-history-loaded-${Date.now()}`);
20013
19999
  }, 250),
20014
20000
  []
20015
20001
  );
20016
- useEffect36(() => {
20002
+ useEffect35(() => {
20017
20003
  if (isBridgeTxHistoryLoading || txList.length === 0) return;
20018
20004
  updateExpandable();
20019
20005
  }, [isBridgeTxHistoryLoading, txList]);
@@ -20049,7 +20035,7 @@ var init_useOperationHashesStore = __esm({
20049
20035
 
20050
20036
  // src/internal/components/SendMenu/hyperbridge/hooks/useBridge.ts
20051
20037
  import { useMutation as useMutation19, useQueryClient as useQueryClient22 } from "@tanstack/react-query";
20052
- import { useCallback as useCallback25 } from "react";
20038
+ import { useCallback as useCallback26 } from "react";
20053
20039
  import { useSwitchChain, useWalletClient } from "wagmi";
20054
20040
  function useBridge() {
20055
20041
  const qc = useQueryClient22();
@@ -20057,7 +20043,7 @@ function useBridge() {
20057
20043
  const address = useSession((st) => st.address);
20058
20044
  const { data: walletClient } = useWalletClient();
20059
20045
  const { switchChainAsync } = useSwitchChain();
20060
- const swapDirection = useCallback25(() => {
20046
+ const swapDirection = useCallback26(() => {
20061
20047
  const {
20062
20048
  bridgeStep,
20063
20049
  originChain,
@@ -20109,7 +20095,7 @@ function useBridge() {
20109
20095
  useFlowSelectorStore.getState().setError(error instanceof Error ? error.message : String(error));
20110
20096
  }
20111
20097
  });
20112
- const handleQuoteEstimation = useCallback25((amnt) => {
20098
+ const handleQuoteEstimation = useCallback26((amnt) => {
20113
20099
  const { originChain, destinationChain, bridgeSender } = useBridgeStore.getState();
20114
20100
  if (!amnt || !Number(amnt)) {
20115
20101
  useBridgeStore.getState().setQuote(null);
@@ -20253,7 +20239,7 @@ var init_useBridge = __esm({
20253
20239
 
20254
20240
  // src/internal/components/SendMenu/hyperbridge/hooks/useHyperlaneRoutes.ts
20255
20241
  import { useQuery as useQuery19 } from "@tanstack/react-query";
20256
- import { useEffect as useEffect37 } from "react";
20242
+ import { useEffect as useEffect36 } from "react";
20257
20243
  function useHyperlaneRoutes() {
20258
20244
  const address = useSession((st) => st.address);
20259
20245
  const page = useLayoutDataStore((st) => st.page);
@@ -20269,7 +20255,7 @@ function useHyperlaneRoutes() {
20269
20255
  queryKey: [HYPERLANE_WARP_ROUTES_QUERY_KEY, address],
20270
20256
  queryFn: async () => getHyperlaneWarpRoutes()
20271
20257
  });
20272
- useEffect37(() => {
20258
+ useEffect36(() => {
20273
20259
  if (!errorWarpRoutes) return;
20274
20260
  useFlowSelectorStore.getState().setError(errorWarpRoutes.message);
20275
20261
  const { resetSelections, setRecipient, setOriginChain, setDestinationChain } = useBridgeStore.getState();
@@ -20278,7 +20264,7 @@ function useHyperlaneRoutes() {
20278
20264
  setOriginChain(null);
20279
20265
  setDestinationChain(null);
20280
20266
  }, [errorWarpRoutes]);
20281
- useEffect37(() => {
20267
+ useEffect36(() => {
20282
20268
  if (!!hyperRoute || !hyperlaneWarpRoutes.length) return;
20283
20269
  const warpRouteToAutoSelect = hyperlaneWarpRoutes.find((route) => route.routeId === hyperRoute);
20284
20270
  if (!warpRouteToAutoSelect) return;
@@ -20311,13 +20297,13 @@ var init_useHyperlaneRoutes = __esm({
20311
20297
  });
20312
20298
 
20313
20299
  // src/internal/components/SendMenu/hyperbridge/hooks/useMenuTitle.ts
20314
- import { useEffect as useEffect38 } from "react";
20300
+ import { useEffect as useEffect37 } from "react";
20315
20301
  function useMenuTitle(warpRoutes) {
20316
20302
  const { t } = useT();
20317
20303
  const bridgeStep = useBridgeStore((st) => st.bridgeStep);
20318
20304
  const hyperRoute = useBridgeStore((st) => st.hyperRoute);
20319
20305
  const hyperRouteMeta = warpRoutes?.length ? warpRoutes.find((route) => route.routeId === hyperRoute) : null;
20320
- useEffect38(() => {
20306
+ useEffect37(() => {
20321
20307
  const updateMenuTitle = useFlowSelectorStore.getState().setMenuTitle;
20322
20308
  switch (true) {
20323
20309
  case bridgeStep === "sender-selector":
@@ -20369,7 +20355,7 @@ var init_ResolveChainIcon = __esm({
20369
20355
  // src/internal/components/SendMenu/hyperbridge/hooks/useBridgeBalance.ts
20370
20356
  import { CHAINS_BROWSERS_TRANSPORTS as CHAINS_BROWSERS_TRANSPORTS2 } from "@embarkai/core";
20371
20357
  import { useQuery as useQuery20, useQueryClient as useQueryClient23 } from "@tanstack/react-query";
20372
- import { useCallback as useCallback26, useEffect as useEffect39 } from "react";
20358
+ import { useCallback as useCallback27, useEffect as useEffect38 } from "react";
20373
20359
  import { createPublicClient as createPublicClient2, erc20Abi as erc20Abi2, formatUnits as formatUnits7, http as http3 } from "viem";
20374
20360
  import { useSwitchChain as useSwitchChain2 } from "wagmi";
20375
20361
  function useBridgeBalance(hyperlaneWarpRoutes) {
@@ -20458,7 +20444,7 @@ function useBridgeBalance(hyperlaneWarpRoutes) {
20458
20444
  };
20459
20445
  }
20460
20446
  });
20461
- const refreshRouteTokenBalance = useCallback26(
20447
+ const refreshRouteTokenBalance = useCallback27(
20462
20448
  (senderWallet) => {
20463
20449
  switch (true) {
20464
20450
  case senderWallet === "embarkai-wallet":
@@ -20474,7 +20460,7 @@ function useBridgeBalance(hyperlaneWarpRoutes) {
20474
20460
  },
20475
20461
  [refreshBalances, qc]
20476
20462
  );
20477
- useEffect39(() => {
20463
+ useEffect38(() => {
20478
20464
  if (!bridgeSender || !originChain) return;
20479
20465
  switch (bridgeSender) {
20480
20466
  case "embarkai-wallet":
@@ -21429,7 +21415,7 @@ var init_steps = __esm({
21429
21415
  });
21430
21416
 
21431
21417
  // src/internal/components/SendMenu/hyperbridge/HyperlaneBridge.tsx
21432
- import { useEffect as useEffect40 } from "react";
21418
+ import { useEffect as useEffect39 } from "react";
21433
21419
  import { Fragment as Fragment38, jsx as jsx99, jsxs as jsxs91 } from "react/jsx-runtime";
21434
21420
  function HyperlaneBridge() {
21435
21421
  const bridgeStep = useBridgeStore((st) => st.bridgeStep);
@@ -21437,7 +21423,7 @@ function HyperlaneBridge() {
21437
21423
  const { hyperlaneWarpRoutes, isLoadingWarpRoutes } = useHyperlaneRoutes();
21438
21424
  const { directWalletProfile } = useAvailableSenders();
21439
21425
  useMenuTitle(hyperlaneWarpRoutes);
21440
- useEffect40(
21426
+ useEffect39(
21441
21427
  () => () => {
21442
21428
  useBridgeStore.getState().resetSelections();
21443
21429
  },
@@ -21484,14 +21470,14 @@ var init_HyperlaneBridge = __esm({
21484
21470
  });
21485
21471
 
21486
21472
  // src/internal/components/SendMenu/hyperbridge/components/HistorySwitch.tsx
21487
- import { useRef as useRef19 } from "react";
21473
+ import { useRef as useRef18 } from "react";
21488
21474
  import { jsx as jsx100 } from "react/jsx-runtime";
21489
21475
  function BridgeHistorySwitch(props) {
21490
21476
  const { disabled } = props;
21491
21477
  const selectorFlow = useFlowSelectorStore((st) => st.flow);
21492
21478
  const isUiLocked = useFlowSelectorStore((st) => st.isUiLocked);
21493
21479
  const bridgeStep = useBridgeStore((st) => st.bridgeStep);
21494
- const lastBridgeStepRef = useRef19(null);
21480
+ const lastBridgeStepRef = useRef18(null);
21495
21481
  if (selectorFlow !== "bridge" || bridgeStep === "confirm" || bridgeStep === "success" || bridgeStep === "sender-selector" || bridgeStep === "select-token" || bridgeStep === "tx-history-details") {
21496
21482
  return null;
21497
21483
  }
@@ -21593,7 +21579,7 @@ var init_useErc3643Compliance = __esm({
21593
21579
 
21594
21580
  // src/hooks/useNicknameResolve.ts
21595
21581
  import { useQuery as useQuery21 } from "@tanstack/react-query";
21596
- import { useState as useState28, useEffect as useEffect41, useMemo as useMemo13 } from "react";
21582
+ import { useState as useState28, useEffect as useEffect40, useMemo as useMemo13 } from "react";
21597
21583
  function looksLikeNickname(input) {
21598
21584
  if (!input) return false;
21599
21585
  if (input.startsWith("0x")) return false;
@@ -21607,7 +21593,7 @@ function useNicknameResolve(input, options) {
21607
21593
  const [isDebouncing, setIsDebouncing] = useState28(false);
21608
21594
  const normalized = normalizeNickname(input);
21609
21595
  const isNicknameInput = looksLikeNickname(input) && normalized.length >= 3;
21610
- useEffect41(() => {
21596
+ useEffect40(() => {
21611
21597
  if (!isNicknameInput || !enabled) {
21612
21598
  setDebouncedInput("");
21613
21599
  setIsDebouncing(false);
@@ -21667,7 +21653,7 @@ var init_useNicknameResolve = __esm({
21667
21653
  });
21668
21654
 
21669
21655
  // src/hooks/useSendTransaction.ts
21670
- import { useCallback as useCallback27, useState as useState29 } from "react";
21656
+ import { useCallback as useCallback28, useState as useState29 } from "react";
21671
21657
  import { encodeFunctionData as encodeFunctionData2, isAddress, parseEther as parseEther2, parseUnits } from "viem";
21672
21658
  function useSendTransaction() {
21673
21659
  const session = useSession((st) => st.session);
@@ -21675,7 +21661,7 @@ function useSendTransaction() {
21675
21661
  const [isLoading, setIsLoading] = useState29(false);
21676
21662
  const [error, setError] = useState29(null);
21677
21663
  const [userOpHash, setUserOpHash] = useState29(null);
21678
- const sendTransaction = useCallback27(
21664
+ const sendTransaction = useCallback28(
21679
21665
  async (params) => {
21680
21666
  if (!session || !address) {
21681
21667
  setError("No active session");
@@ -21772,7 +21758,7 @@ function useSendTransaction() {
21772
21758
  },
21773
21759
  [session, address]
21774
21760
  );
21775
- const reset = useCallback27(() => {
21761
+ const reset = useCallback28(() => {
21776
21762
  setError(null);
21777
21763
  setUserOpHash(null);
21778
21764
  setIsLoading(false);
@@ -22595,7 +22581,7 @@ var init_sendSteps = __esm({
22595
22581
 
22596
22582
  // src/internal/components/SendMenu/send/SendMenu.tsx
22597
22583
  import { CheckCircle2 as CheckCircle26, Loader as Loader31 } from "lucide-react";
22598
- import { useEffect as useEffect42, useMemo as useMemo14 } from "react";
22584
+ import { useEffect as useEffect41, useMemo as useMemo14 } from "react";
22599
22585
  import { parseUnits as parseUnits2 } from "viem";
22600
22586
  import { Fragment as Fragment42, jsx as jsx107, jsxs as jsxs98 } from "react/jsx-runtime";
22601
22587
  function SendMenu() {
@@ -22617,10 +22603,10 @@ function SendMenu() {
22617
22603
  userOpHash,
22618
22604
  reset
22619
22605
  } = useSendTransaction();
22620
- useEffect42(() => {
22606
+ useEffect41(() => {
22621
22607
  useFlowSelectorStore.getState().setIsUiLocked(isAssetsLoading || isTransactionPending);
22622
22608
  }, [isAssetsLoading, isTransactionPending]);
22623
- useEffect42(() => {
22609
+ useEffect41(() => {
22624
22610
  useFlowSelectorStore.getState().setError(sendTransactionError || null);
22625
22611
  }, [sendTransactionError]);
22626
22612
  const {
@@ -22635,7 +22621,7 @@ function SendMenu() {
22635
22621
  } = useSendStore();
22636
22622
  const isNft = isNftAsset3(selectedAsset);
22637
22623
  const isSecurity = isSecurityToken2(selectedAsset);
22638
- useEffect42(
22624
+ useEffect41(
22639
22625
  () => () => {
22640
22626
  setSelectedAsset(null);
22641
22627
  setRecipient("");
@@ -22645,7 +22631,7 @@ function SendMenu() {
22645
22631
  },
22646
22632
  []
22647
22633
  );
22648
- useEffect42(() => {
22634
+ useEffect41(() => {
22649
22635
  const shouldSetNativeAsset = assets.length > 0 && !selectedAsset;
22650
22636
  if (!shouldSetNativeAsset) return;
22651
22637
  const native = assets.find((a) => a.type === "native");
@@ -22671,7 +22657,7 @@ function SendMenu() {
22671
22657
  enabled: isSecurity && !!effectiveAddress && !!complianceAmount,
22672
22658
  chainId: activeChainId
22673
22659
  });
22674
- useEffect42(() => {
22660
+ useEffect41(() => {
22675
22661
  const updateMenuTitle = useFlowSelectorStore.getState().setMenuTitle;
22676
22662
  switch (true) {
22677
22663
  case txStep === "select-asset":
@@ -22764,7 +22750,7 @@ var init_send = __esm({
22764
22750
 
22765
22751
  // src/internal/components/SendMenu/SendFlowSelector.tsx
22766
22752
  import { ArrowLeft as ArrowLeft19, ArrowRightIcon as ArrowRightIcon2, ArrowRightLeftIcon as ArrowRightLeftIcon2, InfoIcon as InfoIcon5 } from "lucide-react";
22767
- import { useEffect as useEffect43 } from "react";
22753
+ import { useEffect as useEffect42 } from "react";
22768
22754
  import { jsx as jsx108, jsxs as jsxs99 } from "react/jsx-runtime";
22769
22755
  function SelectorFlowButtons() {
22770
22756
  const { t } = useT();
@@ -22827,7 +22813,7 @@ function SendFlowSelector() {
22827
22813
  const error = useFlowSelectorStore((st) => st.error);
22828
22814
  const menuTitle = useFlowSelectorStore((st) => st.menuTitle);
22829
22815
  const selectorFlow = useFlowSelectorStore((st) => st.flow);
22830
- useEffect43(
22816
+ useEffect42(
22831
22817
  () => () => {
22832
22818
  useFlowSelectorStore.getState().setError(null);
22833
22819
  },
@@ -23010,7 +22996,7 @@ var init_constants6 = __esm({
23010
22996
  // src/internal/components/SettingsMenu/SettingsMenu.tsx
23011
22997
  import { useQuery as useQuery22 } from "@tanstack/react-query";
23012
22998
  import { ArrowLeft as ArrowLeft20, HardDrive as HardDrive3 } from "lucide-react";
23013
- import { useEffect as useEffect44 } from "react";
22999
+ import { useEffect as useEffect43 } from "react";
23014
23000
  import { jsx as jsx110, jsxs as jsxs100 } from "react/jsx-runtime";
23015
23001
  function useSettingsButtons() {
23016
23002
  const config = useProviderConfig().config;
@@ -23029,7 +23015,7 @@ function useSettingsButtons() {
23029
23015
  if (proMode) {
23030
23016
  settingsButtons.push({ id: "devices" /* DEVICES */, name: "Guardians", Icon: HardDrive3 });
23031
23017
  }
23032
- useEffect44(() => {
23018
+ useEffect43(() => {
23033
23019
  const cssvEl = document.querySelector(".embarkai-ui-scope");
23034
23020
  if (!cssvEl || !window?.getComputedStyle) {
23035
23021
  return;
@@ -23159,7 +23145,7 @@ import {
23159
23145
  BSC_TESTNET_CHAIN_ID as BSC_TESTNET_CHAIN_ID4,
23160
23146
  LUMIA_MAINNET_CHAIN_ID as LUMIA_MAINNET_CHAIN_ID4,
23161
23147
  LUMIA_TESTNET_CHAIN_ID as LUMIA_TESTNET_CHAIN_ID4,
23162
- SEPOLIA_CHAIN_ID as SEPOLIA_CHAIN_ID2
23148
+ SEPOLIA_CHAIN_ID
23163
23149
  } from "@embarkai/core/read";
23164
23150
  function isTransactionHistorySupported(chainId) {
23165
23151
  return !UNSUPPORTED_HISTORY_CHAINS.has(chainId);
@@ -23229,7 +23215,7 @@ var init_txUrls = __esm({
23229
23215
  };
23230
23216
  CHAIN_SPECIFIC_API_URLS = {};
23231
23217
  ETHERSCAN_CHAINS = /* @__PURE__ */ new Set([
23232
- SEPOLIA_CHAIN_ID2,
23218
+ SEPOLIA_CHAIN_ID,
23233
23219
  ARBITRUM_SEPOLIA_CHAIN_ID2,
23234
23220
  BASE_SEPOLIA_CHAIN_ID2
23235
23221
  ]);
@@ -24037,7 +24023,7 @@ var init_TransactionsGroup = __esm({
24037
24023
  // src/internal/components/TransactionsMenu/TransactionsMenu.tsx
24038
24024
  import { useQuery as useQuery23, useQueryClient as useQueryClient25 } from "@tanstack/react-query";
24039
24025
  import { ArrowLeft as ArrowLeft22, Loader as Loader32, RefreshCw as RefreshCw3, XCircle } from "lucide-react";
24040
- import { useCallback as useCallback28, useState as useState31 } from "react";
24026
+ import { useCallback as useCallback29, useState as useState31 } from "react";
24041
24027
  import { jsx as jsx114, jsxs as jsxs104 } from "react/jsx-runtime";
24042
24028
  function TransactionsMenu() {
24043
24029
  const qc = useQueryClient25();
@@ -24059,7 +24045,7 @@ function TransactionsMenu() {
24059
24045
  queryKey: [TRANSACTIONS_HISTORY_QUERY_KEY, chainConfig.id, address],
24060
24046
  queryFn: () => getTransactionsListQuery({ address, chainConfig })
24061
24047
  });
24062
- const refreshTxHistory = useCallback28(
24048
+ const refreshTxHistory = useCallback29(
24063
24049
  () => qc.invalidateQueries({ queryKey: [TRANSACTIONS_HISTORY_QUERY_KEY, chainConfig.id, address] }),
24064
24050
  [qc, chainConfig.id, address]
24065
24051
  );
@@ -24298,7 +24284,7 @@ var init_PageMap = __esm({
24298
24284
  });
24299
24285
 
24300
24286
  // src/internal/hooks/usePageMapper.tsx
24301
- import { useCallback as useCallback29, useEffect as useEffect45 } from "react";
24287
+ import { useCallback as useCallback30, useEffect as useEffect44 } from "react";
24302
24288
  import { jsx as jsx115 } from "react/jsx-runtime";
24303
24289
  function usePageMapper() {
24304
24290
  const page = useLayoutDataStore((st) => st.page);
@@ -24310,7 +24296,7 @@ function usePageMapper() {
24310
24296
  setIsDialogOpen,
24311
24297
  setIsDialogClosing
24312
24298
  } = useLayoutStore();
24313
- const closeDialog = useCallback29(() => {
24299
+ const closeDialog = useCallback30(() => {
24314
24300
  setIsDialogClosing(true);
24315
24301
  setTimeout(() => {
24316
24302
  setDialogContent(null);
@@ -24321,7 +24307,7 @@ function usePageMapper() {
24321
24307
  setIsDialogOpen(false);
24322
24308
  }, CLEAR_DIALOG_TIMEOUT);
24323
24309
  }, [setDialogContent, setDialogDescription, setDialogTitle, setIsDialogForced, setIsDialogOpen, setIsDialogClosing]);
24324
- const openDialog = useCallback29(
24310
+ const openDialog = useCallback30(
24325
24311
  (pageItem) => {
24326
24312
  const PageContentComponent = pageItem.component;
24327
24313
  setDialogTitle(pageItem.title);
@@ -24331,7 +24317,7 @@ function usePageMapper() {
24331
24317
  },
24332
24318
  [setDialogContent, setDialogDescription, setDialogTitle, setIsDialogOpen]
24333
24319
  );
24334
- useEffect45(() => {
24320
+ useEffect44(() => {
24335
24321
  if (page === null) return closeDialog();
24336
24322
  const pageItem = PAGE_MAP[page];
24337
24323
  if (!pageItem) {
@@ -24355,7 +24341,7 @@ var init_usePageMapper = __esm({
24355
24341
 
24356
24342
  // src/internal/hooks/useSettingsNotifications.ts
24357
24343
  import { useQuery as useQuery24 } from "@tanstack/react-query";
24358
- import { useEffect as useEffect46 } from "react";
24344
+ import { useEffect as useEffect45 } from "react";
24359
24345
  function useSettingsNotifications() {
24360
24346
  const address = useSession((st) => st.address);
24361
24347
  const setSettingsNotifications = useLayoutDataStore((st) => st.setSettingsNotifications);
@@ -24367,14 +24353,14 @@ function useSettingsNotifications() {
24367
24353
  queryKey: [QUERY_KEYS.userProfile, address],
24368
24354
  queryFn: getUserProfile
24369
24355
  });
24370
- useEffect46(() => {
24356
+ useEffect45(() => {
24371
24357
  const isKYCVerified = userProfile?.kycDetails?.kycStatus === "verified";
24372
24358
  setSettingsNotifications({
24373
24359
  ...COMPLETE_KYC_PROGRESS,
24374
24360
  status: isKYCVerified ? "resolved" : "active"
24375
24361
  });
24376
24362
  }, [userProfile, setSettingsNotifications]);
24377
- useEffect46(() => {
24363
+ useEffect45(() => {
24378
24364
  setSettingsNotifications({
24379
24365
  ...EMAIL_NOT_CONNECTED_NOTIFICATION,
24380
24366
  status: hasEmail ? "resolved" : "active"
@@ -24407,7 +24393,7 @@ var init_package = __esm({
24407
24393
  "package.json"() {
24408
24394
  package_default = {
24409
24395
  name: "@embarkai/ui-kit",
24410
- version: "0.4.46",
24396
+ version: "0.4.48",
24411
24397
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
24412
24398
  type: "module",
24413
24399
  main: "./dist/index.cjs",
@@ -24507,19 +24493,31 @@ var init_package = __esm({
24507
24493
  // src/internal/components/Footer/Footer.tsx
24508
24494
  import { useMutation as useMutation20, useQueryClient as useQueryClient26 } from "@tanstack/react-query";
24509
24495
  import { Loader as Loader33, LogOut } from "lucide-react";
24496
+ import { useDisconnect as useDisconnect3 } from "wagmi";
24510
24497
  import { jsx as jsx116, jsxs as jsxs105 } from "react/jsx-runtime";
24511
24498
  function Footer() {
24512
24499
  const qc = useQueryClient26();
24513
24500
  const { callbacksRef } = useProviderConfig();
24514
- const { address, setSession, setAddress, setStatus, setError, setIsLoading } = useSession();
24515
- const chainConfig = useSession((st) => st.chainConfig);
24516
24501
  const { t } = useT();
24517
- const setPage = useLayoutDataStore((st) => st.setPage);
24518
- const setIsDialogForced = useLayoutStore((st) => st.setIsDialogForced);
24502
+ const address = useSession((st) => st.address);
24503
+ const chainConfig = useSession((st) => st.chainConfig);
24504
+ const { disconnect: wagmiDisconnect } = useDisconnect3({
24505
+ mutation: {
24506
+ onSuccess: () => {
24507
+ useExternalWalletStore.getState().clearExternalWallet();
24508
+ useExternalWalletStore.getState().setExternalChainId(null);
24509
+ console.log("[ExternalWalletStore] Disconnected from external wallet");
24510
+ },
24511
+ onError: (err) => {
24512
+ console.error("[ExternalWalletStore] Error disconnecting from external wallet:", err);
24513
+ }
24514
+ }
24515
+ });
24519
24516
  const { mutate: disconnect, isPending: isDisconnecting } = useMutation20({
24520
24517
  mutationFn: async (disconnectAddress) => {
24521
24518
  if (!disconnectAddress) throw new Error("No address to disconnect");
24522
- setIsDialogForced(true);
24519
+ const { setError, setStatus, setIsLoading } = useSession.getState();
24520
+ useLayoutStore.getState().setIsDialogForced(true);
24523
24521
  setError(null);
24524
24522
  setStatus("disconnecting");
24525
24523
  setIsLoading(true);
@@ -24530,6 +24528,8 @@ function Footer() {
24530
24528
  },
24531
24529
  onSuccess: async ({ disconnectAddress, disconnectedUserId }) => {
24532
24530
  await qc.resetQueries({ queryKey: [CHECK_BACKUP_QUERY_KEY] });
24531
+ if (!!useExternalWalletStore.getState().externalAddress) wagmiDisconnect();
24532
+ const { setError, setStatus, setIsLoading, setSession, setAddress } = useSession.getState();
24533
24533
  setSession(null);
24534
24534
  setAddress(null);
24535
24535
  setError(null);
@@ -24537,15 +24537,16 @@ function Footer() {
24537
24537
  setIsLoading(false);
24538
24538
  callbacksRef.current?.onDisconnect?.({ address: disconnectAddress, userId: disconnectedUserId });
24539
24539
  setTimeout(() => {
24540
- setPage("auth" /* AUTH */);
24541
- setIsDialogForced(false);
24540
+ useLayoutDataStore.getState().setPage("auth" /* AUTH */);
24541
+ useLayoutStore.getState().setIsDialogForced(false);
24542
24542
  }, 200);
24543
24543
  },
24544
24544
  onError: (err) => {
24545
+ const { setError, setStatus, setIsLoading } = useSession.getState();
24545
24546
  setError(err.message || "An unknown error occurred during sign out");
24546
24547
  setStatus("idle");
24547
24548
  setIsLoading(false);
24548
- setIsDialogForced(false);
24549
+ useLayoutStore.getState().setIsDialogForced(false);
24549
24550
  }
24550
24551
  });
24551
24552
  const ChainIcon = NETWORK_OPTIONS.find((net) => net.chainId === chainConfig.id)?.Icon || (() => /* @__PURE__ */ jsx116("div", { className: "flex-none w-4 h-4 rounded-full flex items-center justify-center bg-[var(--ui-kit-primary)]", children: /* @__PURE__ */ jsx116("span", { className: "text-[var(--ui-kit-fg-inverted)] text-xs font-bold", children: chainConfig.name.charAt(0) }) }));
@@ -24601,7 +24602,7 @@ function Footer() {
24601
24602
  var init_Footer = __esm({
24602
24603
  "src/internal/components/Footer/Footer.tsx"() {
24603
24604
  init_package();
24604
- init_networks3();
24605
+ init_networks4();
24605
24606
  init_ProviderContext();
24606
24607
  init_SessionContext();
24607
24608
  init_i18n();
@@ -24610,6 +24611,7 @@ var init_Footer = __esm({
24610
24611
  init_useLayoutDataStore();
24611
24612
  init_useLayoutStore();
24612
24613
  init_utils2();
24614
+ init_useExternalWalletStore();
24613
24615
  init_constants4();
24614
24616
  init_button();
24615
24617
  }
@@ -24625,7 +24627,7 @@ var init_Footer2 = __esm({
24625
24627
  // src/internal/components/Header/Header.tsx
24626
24628
  import { useQuery as useQuery25 } from "@tanstack/react-query";
24627
24629
  import { Copy as Copy5, Loader as Loader34 } from "lucide-react";
24628
- import { useCallback as useCallback30, useRef as useRef20, useState as useState32 } from "react";
24630
+ import { useCallback as useCallback31, useRef as useRef19, useState as useState32 } from "react";
24629
24631
  import { Fragment as Fragment44, jsx as jsx117, jsxs as jsxs106 } from "react/jsx-runtime";
24630
24632
  function formatAddress2(addr) {
24631
24633
  if (!addr) return "";
@@ -24639,9 +24641,9 @@ function Header() {
24639
24641
  const proMode = useProMode();
24640
24642
  const [proToast, setProToast] = useState32(false);
24641
24643
  const [copied, setCopied] = useState32(false);
24642
- const clickCountRef = useRef20(0);
24643
- const clickTimerRef = useRef20(null);
24644
- const handleAvatarClick = useCallback30(() => {
24644
+ const clickCountRef = useRef19(0);
24645
+ const clickTimerRef = useRef19(null);
24646
+ const handleAvatarClick = useCallback31(() => {
24645
24647
  clickCountRef.current += 1;
24646
24648
  if (clickTimerRef.current) {
24647
24649
  clearTimeout(clickTimerRef.current);
@@ -24744,7 +24746,7 @@ function Header() {
24744
24746
  var init_Header = __esm({
24745
24747
  "src/internal/components/Header/Header.tsx"() {
24746
24748
  init_LumiaIcon3();
24747
- init_networks3();
24749
+ init_networks4();
24748
24750
  init_ProviderContext();
24749
24751
  init_SessionContext();
24750
24752
  init_useT();
@@ -24943,7 +24945,7 @@ var init_visually_hidden = __esm({
24943
24945
 
24944
24946
  // src/internal/components/Dialog/Dialog.tsx
24945
24947
  import { AnimatePresence, motion } from "framer-motion";
24946
- import { useEffect as useEffect47 } from "react";
24948
+ import { useEffect as useEffect46 } from "react";
24947
24949
  import { jsx as jsx120, jsxs as jsxs108 } from "react/jsx-runtime";
24948
24950
  function Dialog2() {
24949
24951
  const config = useProviderConfig().config;
@@ -24955,7 +24957,7 @@ function Dialog2() {
24955
24957
  const isWalletLinking = useLayoutDataStore((st) => st.isWalletLinking);
24956
24958
  const setPage = useLayoutDataStore((st) => st.setPage);
24957
24959
  const { colorMode, isDialogOpen, dialogTitle, dialogDescription, dialogContent, isDialogForced, setIsSettings } = useLayoutStore();
24958
- useEffect47(() => setIsSettings(!!session), [session, setIsSettings]);
24960
+ useEffect46(() => setIsSettings(!!session), [session, setIsSettings]);
24959
24961
  usePageMapper();
24960
24962
  useAutoConnect();
24961
24963
  useBackupStatusChanges();
@@ -25021,7 +25023,7 @@ var init_Dialog2 = __esm({
25021
25023
  });
25022
25024
 
25023
25025
  // src/internal/components/TssManager.tsx
25024
- import React8, { useCallback as useCallback31 } from "react";
25026
+ import React8, { useCallback as useCallback32 } from "react";
25025
25027
  var TssManagerWithRef;
25026
25028
  var init_TssManager = __esm({
25027
25029
  "src/internal/components/TssManager.tsx"() {
@@ -25036,7 +25038,7 @@ var init_TssManager = __esm({
25036
25038
  const setStatus = useSession((st) => st.setStatus);
25037
25039
  const setSession = useSession((st) => st.setSession);
25038
25040
  const setAddress = useSession((st) => st.setAddress);
25039
- const onSessionCreated = useCallback31(
25041
+ const onSessionCreated = useCallback32(
25040
25042
  (session, address) => {
25041
25043
  setSession(session);
25042
25044
  setAddress(address);
@@ -25077,15 +25079,15 @@ var init_TssManager = __esm({
25077
25079
  // src/internal/components/WalletConnectHandler.tsx
25078
25080
  import { useConnectModal as useConnectModal2 } from "@rainbow-me/rainbowkit";
25079
25081
  import { useMutation as useMutation21, useQueryClient as useQueryClient27 } from "@tanstack/react-query";
25080
- import React9, { useCallback as useCallback32, useEffect as useEffect48 } from "react";
25081
- import { useAccount, useDisconnect as useDisconnect2, useSignMessage as useSignMessage2 } from "wagmi";
25082
+ import React9, { useCallback as useCallback33, useEffect as useEffect47 } from "react";
25083
+ import { useAccount, useDisconnect as useDisconnect4, useSignMessage as useSignMessage2 } from "wagmi";
25082
25084
  function WalletConnectHandler() {
25083
25085
  const qc = useQueryClient27();
25084
25086
  const { callbacksRef } = useProviderConfig();
25085
25087
  const passportWalletAddress = useSession((st) => st.address);
25086
25088
  const { address: walletAddress, isConnected, chain, connector } = useAccount();
25087
25089
  const { openConnectModal, connectModalOpen } = useConnectModal2();
25088
- const { disconnect } = useDisconnect2();
25090
+ const { disconnect } = useDisconnect4();
25089
25091
  const { signMessageAsync } = useSignMessage2();
25090
25092
  const isWalletLinking = useLayoutDataStore((st) => st.isWalletLinking);
25091
25093
  const setPage = useLayoutDataStore((st) => st.setPage);
@@ -25100,7 +25102,7 @@ function WalletConnectHandler() {
25100
25102
  const projectId = providerConfig?.projectId;
25101
25103
  const setExternalWallet = useExternalWalletStore((st) => st.setExternalWallet);
25102
25104
  const setPendingWalletLogin = useLayoutDataStore((st) => st.setPendingWalletLogin);
25103
- const onLinkingComplete = useCallback32(
25105
+ const onLinkingComplete = useCallback33(
25104
25106
  async (success) => {
25105
25107
  setIsWalletLinking(false);
25106
25108
  if (!success && !passportWalletAddress) {
@@ -25132,7 +25134,7 @@ function WalletConnectHandler() {
25132
25134
  const [hasStartedLinking, setHasStartedLinking] = React9.useState(false);
25133
25135
  const [modalWasOpened, setModalWasOpened] = React9.useState(false);
25134
25136
  const [pendingModalOpen, setPendingModalOpen] = React9.useState(false);
25135
- useEffect48(() => {
25137
+ useEffect47(() => {
25136
25138
  if (isWalletLinking && !hasStartedLinking) {
25137
25139
  console.log("[WalletConnectHandler] Starting wallet link flow:", {
25138
25140
  isConnected,
@@ -25170,18 +25172,18 @@ function WalletConnectHandler() {
25170
25172
  setProviderType,
25171
25173
  walletMode
25172
25174
  ]);
25173
- useEffect48(() => {
25175
+ useEffect47(() => {
25174
25176
  if (pendingModalOpen && !isConnected && openConnectModal) {
25175
25177
  setPendingModalOpen(false);
25176
25178
  openConnectModal();
25177
25179
  }
25178
25180
  }, [pendingModalOpen, isConnected, openConnectModal]);
25179
- useEffect48(() => {
25181
+ useEffect47(() => {
25180
25182
  if (connectModalOpen && hasStartedLinking) {
25181
25183
  setModalWasOpened(true);
25182
25184
  }
25183
25185
  }, [connectModalOpen, hasStartedLinking]);
25184
- useEffect48(() => {
25186
+ useEffect47(() => {
25185
25187
  if (modalWasOpened && !connectModalOpen && !isConnected && isWalletLinking) {
25186
25188
  console.log("[WalletConnectHandler] Modal closed without connecting");
25187
25189
  onLinkingComplete(false);
@@ -25189,7 +25191,7 @@ function WalletConnectHandler() {
25189
25191
  setModalWasOpened(false);
25190
25192
  }
25191
25193
  }, [connectModalOpen, modalWasOpened, isConnected, isWalletLinking]);
25192
- useEffect48(() => {
25194
+ useEffect47(() => {
25193
25195
  if (isWalletLinking) {
25194
25196
  const timeout = setTimeout(() => {
25195
25197
  console.warn("[WalletConnectHandler] Wallet linking timed out, resetting state");
@@ -25309,7 +25311,7 @@ function WalletConnectHandler() {
25309
25311
  setPage(passportWalletAddress ? "manage-wallet" /* MANAGE_WALLET */ : "auth" /* AUTH */);
25310
25312
  }
25311
25313
  });
25312
- useEffect48(() => {
25314
+ useEffect47(() => {
25313
25315
  if (!!chain?.id && isConnected && walletAddress && isWalletLinking && hasStartedLinking && modalWasOpened && !pendingModalOpen) {
25314
25316
  console.log("[WalletConnectHandler] handleWalletSign triggered");
25315
25317
  if (!passportWalletAddress) {
@@ -25319,7 +25321,7 @@ function WalletConnectHandler() {
25319
25321
  handleWalletSign({ chainId: chain.id, signingWalletAddress: walletAddress });
25320
25322
  }
25321
25323
  }, [chain, isConnected, walletAddress, isWalletLinking, hasStartedLinking, modalWasOpened, pendingModalOpen]);
25322
- useEffect48(() => {
25324
+ useEffect47(() => {
25323
25325
  if (isConnected && !chain?.id && isWalletLinking && hasStartedLinking && !connectModalOpen && !isWalletSigning) {
25324
25326
  const timeout = setTimeout(() => {
25325
25327
  console.warn("[WalletConnectHandler] Wallet connected but chain info missing, resetting");
@@ -25355,7 +25357,7 @@ var init_WalletConnectHandler = __esm({
25355
25357
  });
25356
25358
 
25357
25359
  // src/internal/components/DirectWalletHandler.tsx
25358
- import { useEffect as useEffect49 } from "react";
25360
+ import { useEffect as useEffect48 } from "react";
25359
25361
  import { useAccount as useAccount2 } from "wagmi";
25360
25362
  function DirectWalletHandler() {
25361
25363
  const walletMode = useProviderConfig().config.current?.wallet?.mode || "linked";
@@ -25367,13 +25369,13 @@ function DirectWalletHandler() {
25367
25369
  const setExternalChainId = useExternalWalletStore((st) => st.setExternalChainId);
25368
25370
  const setConfigMode = useExternalWalletStore((st) => st.setConfigMode);
25369
25371
  const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
25370
- useEffect49(() => {
25372
+ useEffect48(() => {
25371
25373
  setConfigMode(walletMode);
25372
25374
  if (walletMode !== "both") {
25373
25375
  setActiveMode(walletMode);
25374
25376
  }
25375
25377
  }, [walletMode, setConfigMode, setActiveMode]);
25376
- useEffect49(() => {
25378
+ useEffect48(() => {
25377
25379
  if (isConnected && address && !isExternalConnected && connector && chain?.id) {
25378
25380
  setExternalWallet({
25379
25381
  address,
@@ -25382,17 +25384,17 @@ function DirectWalletHandler() {
25382
25384
  });
25383
25385
  }
25384
25386
  }, [isConnected, address, isExternalConnected, connector, chain?.id, setExternalWallet]);
25385
- useEffect49(() => {
25387
+ useEffect48(() => {
25386
25388
  if (isExternalConnected && !isConnected) {
25387
25389
  clearExternalWallet();
25388
25390
  }
25389
25391
  }, [isConnected, isExternalConnected, clearExternalWallet]);
25390
- useEffect49(() => {
25392
+ useEffect48(() => {
25391
25393
  if (isExternalConnected && isConnected && chain?.id) {
25392
25394
  setExternalChainId(chain.id);
25393
25395
  }
25394
25396
  }, [chain?.id, isConnected, isExternalConnected, setExternalChainId]);
25395
- useEffect49(() => {
25397
+ useEffect48(() => {
25396
25398
  if (isExternalConnected && isConnected && address && address !== externalAddress && connector && chain?.id) {
25397
25399
  setExternalWallet({
25398
25400
  address,
@@ -28219,11 +28221,11 @@ import { initSdkErrorTracking } from "@embarkai/core/internal/error-tracking";
28219
28221
  import { merge as merge3 } from "lodash-es";
28220
28222
  import {
28221
28223
  createContext,
28222
- useCallback as useCallback33,
28224
+ useCallback as useCallback34,
28223
28225
  useContext,
28224
- useEffect as useEffect50,
28226
+ useEffect as useEffect49,
28225
28227
  useMemo as useMemo16,
28226
- useRef as useRef21
28228
+ useRef as useRef20
28227
28229
  } from "react";
28228
28230
  import { jsx as jsx124 } from "react/jsx-runtime";
28229
28231
  function clearLegacyWagmiStorage() {
@@ -28243,10 +28245,10 @@ function clearLegacyWagmiStorage() {
28243
28245
  }
28244
28246
  function Provider(props) {
28245
28247
  const { children, projectId, initialConfig = {}, callbacks } = props;
28246
- const callbacksRef = useRef21(callbacks);
28247
- useEffect50(() => notifyNoProjetctId(projectId), [projectId]);
28248
- const config = useRef21(merge3({}, DEFAULT_PROVIDER_CONFIG, { projectId }, initialConfig));
28249
- const updateConfig = useCallback33((updates) => {
28248
+ const callbacksRef = useRef20(callbacks);
28249
+ useEffect49(() => notifyNoProjetctId(projectId), [projectId]);
28250
+ const config = useRef20(merge3({}, DEFAULT_PROVIDER_CONFIG, { projectId }, initialConfig));
28251
+ const updateConfig = useCallback34((updates) => {
28250
28252
  const prev = config.current;
28251
28253
  const next = { ...prev };
28252
28254
  if (updates.projectId !== void 0) next.projectId = updates.projectId;
@@ -28280,12 +28282,12 @@ function Provider(props) {
28280
28282
  if (updates.translations) next.translations = { ...next.translations, ...updates.translations };
28281
28283
  config.current = next;
28282
28284
  }, []);
28283
- const updateCallbacks = useCallback33((updates) => {
28285
+ const updateCallbacks = useCallback34((updates) => {
28284
28286
  const prev = callbacksRef.current;
28285
28287
  const next = updates ? { ...prev, ...updates } : void 0;
28286
28288
  callbacksRef.current = next;
28287
28289
  }, []);
28288
- useEffect50(() => {
28290
+ useEffect49(() => {
28289
28291
  if (typeof window === "undefined" || !projectId) return;
28290
28292
  const mergedConfig = merge3(DEFAULT_PROVIDER_CONFIG, initialConfig);
28291
28293
  updateConfig(mergedConfig);
@@ -28305,7 +28307,7 @@ function Provider(props) {
28305
28307
  useSession.getState().setActiveChainId(mergedConfig.network.chainId);
28306
28308
  }
28307
28309
  }, [projectId, initialConfig]);
28308
- useEffect50(() => {
28310
+ useEffect49(() => {
28309
28311
  if (typeof window === "undefined" || !projectId) return;
28310
28312
  try {
28311
28313
  initSdkErrorTracking();
@@ -28487,7 +28489,7 @@ init_pro_mode();
28487
28489
  init_utils2();
28488
28490
  import { useQuery as useQuery26 } from "@tanstack/react-query";
28489
28491
  import { Cloud as Cloud4, Laptop as Laptop2, Loader as Loader35, Shield as Shield3 } from "lucide-react";
28490
- import { useEffect as useEffect51, useMemo as useMemo17 } from "react";
28492
+ import { useEffect as useEffect50, useMemo as useMemo17 } from "react";
28491
28493
  import { Fragment as Fragment47, jsx as jsx126, jsxs as jsxs111 } from "react/jsx-runtime";
28492
28494
  function getFormattedStatus(label, status, showStatus) {
28493
28495
  const isStatus = showStatus && status && status !== "idle" && status !== "ready";
@@ -28507,7 +28509,7 @@ function ConnectWalletButton(props) {
28507
28509
  const colorMode = useLayoutStore((st) => st.colorMode);
28508
28510
  const { session, address, hasServerVault, isLoading, isIframeReady, status, setUsePaymaster } = useSession();
28509
28511
  const connectButtonLabel = getFormattedStatus(label || "Connect", status, isIframeReady);
28510
- useEffect51(() => setUsePaymaster(usePaymaster), [setUsePaymaster, usePaymaster]);
28512
+ useEffect50(() => setUsePaymaster(usePaymaster), [setUsePaymaster, usePaymaster]);
28511
28513
  const { data: profile, isLoading: isProfileLoading } = useQuery26({
28512
28514
  retry: false,
28513
28515
  enabled: !!address,
@@ -28702,13 +28704,13 @@ var useHydrated = () => useSession((st) => st.hasHydrated);
28702
28704
  // src/hooks/useOpenPage.ts
28703
28705
  init_SessionContext();
28704
28706
  init_useLayoutDataStore();
28705
- import { useCallback as useCallback34 } from "react";
28707
+ import { useCallback as useCallback35 } from "react";
28706
28708
  function useOpenPage() {
28707
28709
  const page = useLayoutDataStore((st) => st.page);
28708
28710
  const setPage = useLayoutDataStore((st) => st.setPage);
28709
28711
  const setPageParams = useLayoutDataStore((st) => st.setPageParams);
28710
28712
  const address = useSession((st) => st.address);
28711
- const open = useCallback34(
28713
+ const open = useCallback35(
28712
28714
  (passportPage, params) => {
28713
28715
  if (!address) return setPage("auth" /* AUTH */);
28714
28716
  if (!!address && passportPage === "auth" /* AUTH */) return setPage("manage-wallet" /* MANAGE_WALLET */);
@@ -28717,7 +28719,7 @@ function useOpenPage() {
28717
28719
  },
28718
28720
  [setPage, setPageParams, address]
28719
28721
  );
28720
- const close = useCallback34(() => setPage(null), [setPage]);
28722
+ const close = useCallback35(() => setPage(null), [setPage]);
28721
28723
  return { open, close, isOpen: page !== null };
28722
28724
  }
28723
28725
 
@@ -29179,13 +29181,13 @@ var Hash = ({
29179
29181
 
29180
29182
  // src/internal/components/TransactionsMenu/TransactionsList.tsx
29181
29183
  init_base();
29182
- import { useEffect as useEffect53, useState as useState36 } from "react";
29184
+ import { useEffect as useEffect52, useState as useState36 } from "react";
29183
29185
  import { jsx as jsx132, jsxs as jsxs115 } from "react/jsx-runtime";
29184
29186
  var TransactionsList = ({ address, itemsCount = 10 }) => {
29185
29187
  const [transactions, setTransactions] = useState36([]);
29186
29188
  const [loading, setLoading] = useState36(true);
29187
29189
  const [error, setError] = useState36(null);
29188
- useEffect53(() => {
29190
+ useEffect52(() => {
29189
29191
  const fetchTransactions2 = async () => {
29190
29192
  try {
29191
29193
  setLoading(true);
@@ -29477,12 +29479,12 @@ init_useErc3643Compliance();
29477
29479
 
29478
29480
  // src/hooks/useWalletMode.ts
29479
29481
  init_useExternalWalletStore();
29480
- import { useCallback as useCallback37 } from "react";
29482
+ import { useCallback as useCallback38 } from "react";
29481
29483
  function useWalletMode() {
29482
29484
  const configMode = useExternalWalletStore((st) => st.configMode);
29483
29485
  const activeMode = useExternalWalletStore((st) => st.activeMode);
29484
29486
  const setActiveMode = useExternalWalletStore((st) => st.setActiveMode);
29485
- const switchMode = useCallback37(
29487
+ const switchMode = useCallback38(
29486
29488
  (mode) => {
29487
29489
  if (configMode !== "both") return;
29488
29490
  setActiveMode(mode);
@@ -29500,25 +29502,25 @@ function useWalletMode() {
29500
29502
  // src/hooks/useDirectWallet.ts
29501
29503
  init_useExternalWalletStore();
29502
29504
  init_useLayoutDataStore();
29503
- import { useCallback as useCallback38 } from "react";
29505
+ import { useCallback as useCallback39 } from "react";
29504
29506
  import { useConnectModal as useConnectModal3 } from "@rainbow-me/rainbowkit";
29505
- import { useDisconnect as useDisconnect3 } from "wagmi";
29507
+ import { useDisconnect as useDisconnect5 } from "wagmi";
29506
29508
  function useDirectWallet() {
29507
29509
  const address = useExternalWalletStore((st) => st.externalAddress);
29508
29510
  const chainId = useExternalWalletStore((st) => st.externalChainId);
29509
29511
  const isConnected = useExternalWalletStore((st) => st.isExternalConnected);
29510
29512
  const connectorName = useExternalWalletStore((st) => st.connectorName);
29511
29513
  const clearExternalWallet = useExternalWalletStore((st) => st.clearExternalWallet);
29512
- const { disconnect: wagmiDisconnect } = useDisconnect3();
29514
+ const { disconnect: wagmiDisconnect } = useDisconnect5();
29513
29515
  const { openConnectModal } = useConnectModal3();
29514
29516
  const setIsWalletLinking = useLayoutDataStore((st) => st.setIsWalletLinking);
29515
- const connect = useCallback38(() => {
29517
+ const connect = useCallback39(() => {
29516
29518
  setIsWalletLinking(true);
29517
29519
  }, [setIsWalletLinking]);
29518
- const reconnect = useCallback38(() => {
29520
+ const reconnect = useCallback39(() => {
29519
29521
  if (openConnectModal) openConnectModal();
29520
29522
  }, [openConnectModal]);
29521
- const disconnect = useCallback38(() => {
29523
+ const disconnect = useCallback39(() => {
29522
29524
  wagmiDisconnect();
29523
29525
  clearExternalWallet();
29524
29526
  }, [wagmiDisconnect, clearExternalWallet]);
@@ -29535,7 +29537,7 @@ function useDirectWallet() {
29535
29537
 
29536
29538
  // src/hooks/useSendDirectTransaction.ts
29537
29539
  init_useExternalWalletStore();
29538
- import { useCallback as useCallback39, useState as useState38 } from "react";
29540
+ import { useCallback as useCallback40, useState as useState38 } from "react";
29539
29541
  import { isAddress as isAddress3, parseEther as parseEther3 } from "viem";
29540
29542
  import { useSendTransaction as useWagmiSendTransaction, useSwitchChain as useSwitchChain3 } from "wagmi";
29541
29543
  function useSendDirectTransaction() {
@@ -29546,7 +29548,7 @@ function useSendDirectTransaction() {
29546
29548
  const [isPending, setIsPending] = useState38(false);
29547
29549
  const [error, setError] = useState38(null);
29548
29550
  const [txHash, setTxHash] = useState38(null);
29549
- const sendTransaction = useCallback39(
29551
+ const sendTransaction = useCallback40(
29550
29552
  async (params) => {
29551
29553
  if (!isConnected) {
29552
29554
  setError("No external wallet connected");
@@ -29580,7 +29582,7 @@ function useSendDirectTransaction() {
29580
29582
  },
29581
29583
  [isConnected, externalChainId, sendTransactionAsync, switchChainAsync]
29582
29584
  );
29583
- const reset = useCallback39(() => {
29585
+ const reset = useCallback40(() => {
29584
29586
  setError(null);
29585
29587
  setTxHash(null);
29586
29588
  setIsPending(false);
@@ -29592,7 +29594,7 @@ function useSendDirectTransaction() {
29592
29594
  init_SessionContext();
29593
29595
  init_account2();
29594
29596
  init_linkedProfiles();
29595
- import { useCallback as useCallback40, useMemo as useMemo18, useState as useState39 } from "react";
29597
+ import { useCallback as useCallback41, useMemo as useMemo18, useState as useState39 } from "react";
29596
29598
  import { encodeFunctionData as encodeFunctionData3, isAddress as isAddress4, parseEther as parseEther4, parseUnits as parseUnits3 } from "viem";
29597
29599
  var ERC20_TRANSFER_ABI2 = [
29598
29600
  {
@@ -29615,7 +29617,7 @@ function useTransferToLinkedWallet() {
29615
29617
  () => (profiles || []).filter((p) => p.provider === "wallet" && p.externalId).map((p) => p.externalId),
29616
29618
  [profiles]
29617
29619
  );
29618
- const transfer = useCallback40(
29620
+ const transfer = useCallback41(
29619
29621
  async (params) => {
29620
29622
  if (!session) {
29621
29623
  setError("No active session");
@@ -29666,7 +29668,7 @@ function useTransferToLinkedWallet() {
29666
29668
  },
29667
29669
  [session, linkedWallets]
29668
29670
  );
29669
- const reset = useCallback40(() => {
29671
+ const reset = useCallback41(() => {
29670
29672
  setError(null);
29671
29673
  setUserOpHash(null);
29672
29674
  setIsPending(false);
@@ -29691,12 +29693,27 @@ function useNativeWalletSignature() {
29691
29693
  // src/hooks/useLogout.ts
29692
29694
  init_ProviderContext();
29693
29695
  init_SessionContext();
29696
+ init_useExternalWalletStore();
29694
29697
  import { logout as coreLogout, jwtTokenManager as jwtTokenManager3 } from "@embarkai/core/auth";
29695
- import { useCallback as useCallback41 } from "react";
29698
+ import { useCallback as useCallback42 } from "react";
29699
+ import { useDisconnect as useDisconnect6 } from "wagmi";
29696
29700
  function useLogout() {
29697
- const { setSession, setIsLoading, setAddress, setStatus, setError, address } = useSession();
29698
29701
  const { callbacksRef } = useProviderConfig();
29699
- const logout2 = useCallback41(async () => {
29702
+ const address = useSession((st) => st.address);
29703
+ const { disconnect: wagmiDisconnect } = useDisconnect6({
29704
+ mutation: {
29705
+ onSuccess: () => {
29706
+ useExternalWalletStore.getState().clearExternalWallet();
29707
+ useExternalWalletStore.getState().setExternalChainId(null);
29708
+ console.log("[ExternalWalletStore] Disconnected from external wallet");
29709
+ },
29710
+ onError: (err) => {
29711
+ console.error("[ExternalWalletStore] Error disconnecting from external wallet:", err);
29712
+ }
29713
+ }
29714
+ });
29715
+ const logout2 = useCallback42(async () => {
29716
+ const { setSession, setIsLoading, setAddress, setStatus, setError } = useSession.getState();
29700
29717
  const prevAddress = address;
29701
29718
  let userId = null;
29702
29719
  setIsLoading(true);
@@ -29710,6 +29727,7 @@ function useLogout() {
29710
29727
  } catch (error) {
29711
29728
  console.warn("[useLogout] Core logout failed:", error);
29712
29729
  }
29730
+ if (!!useExternalWalletStore.getState().externalAddress) wagmiDisconnect();
29713
29731
  setSession(null);
29714
29732
  setAddress(null);
29715
29733
  setStatus("idle");
@@ -29723,7 +29741,7 @@ function useLogout() {
29723
29741
  } catch (error) {
29724
29742
  console.warn("[useLogout] Callback error:", error);
29725
29743
  }
29726
- }, [address, setAddress, setError, setSession, setStatus]);
29744
+ }, [address]);
29727
29745
  return { logout: logout2 };
29728
29746
  }
29729
29747