@embarkai/ui-kit 0.3.2 → 0.3.4

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.cjs CHANGED
@@ -15573,7 +15573,7 @@ var init_package = __esm({
15573
15573
  "package.json"() {
15574
15574
  package_default = {
15575
15575
  name: "@embarkai/ui-kit",
15576
- version: "0.3.2",
15576
+ version: "0.3.4",
15577
15577
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
15578
15578
  type: "module",
15579
15579
  main: "./dist/index.cjs",
@@ -16392,6 +16392,7 @@ function WalletConnectHandler() {
16392
16392
  const setPage = useLayoutDataStore((st) => st.setPage);
16393
16393
  const setIsWalletLinking = useLayoutDataStore((st) => st.setIsWalletLinking);
16394
16394
  const setAuthError = useAuthStore((st) => st.setAlert);
16395
+ const setAuthStep = useAuthStore((st) => st.setStep);
16395
16396
  const setManageWalletLinkError = useManageWalletStore((st) => st.setLinkError);
16396
16397
  const setLinkIsLoading = useManageWalletStore((st) => st.setLinkIsLoading);
16397
16398
  const setProviderType = useManageWalletStore((st) => st.setProviderType);
@@ -16431,6 +16432,7 @@ function WalletConnectHandler() {
16431
16432
  );
16432
16433
  const [hasStartedLinking, setHasStartedLinking] = import_react63.default.useState(false);
16433
16434
  const [modalWasOpened, setModalWasOpened] = import_react63.default.useState(false);
16435
+ const [pendingModalOpen, setPendingModalOpen] = import_react63.default.useState(false);
16434
16436
  (0, import_react63.useEffect)(() => {
16435
16437
  if (isWalletLinking && !hasStartedLinking) {
16436
16438
  console.log("[WalletConnectHandler] Starting wallet link flow:", {
@@ -16440,21 +16442,22 @@ function WalletConnectHandler() {
16440
16442
  });
16441
16443
  setHasStartedLinking(true);
16442
16444
  setProviderType(null);
16443
- disconnect();
16444
- setTimeout(() => {
16445
- setPage(null);
16446
- if (openConnectModal) {
16447
- openConnectModal();
16448
- } else {
16449
- console.error("[WalletConnectHandler] openConnectModal is undefined!");
16450
- setIsWalletLinking(false);
16451
- setHasStartedLinking(false);
16452
- }
16453
- }, 500);
16445
+ setPage(null);
16446
+ if (isConnected) {
16447
+ disconnect();
16448
+ setPendingModalOpen(true);
16449
+ } else if (openConnectModal) {
16450
+ openConnectModal();
16451
+ } else {
16452
+ console.error("[WalletConnectHandler] openConnectModal is undefined!");
16453
+ setIsWalletLinking(false);
16454
+ setHasStartedLinking(false);
16455
+ }
16454
16456
  }
16455
16457
  if (!isWalletLinking && hasStartedLinking) {
16456
16458
  setHasStartedLinking(false);
16457
16459
  setModalWasOpened(false);
16460
+ setPendingModalOpen(false);
16458
16461
  const shouldKeepConnected = walletMode === "direct" || walletMode === "both";
16459
16462
  if (isConnected && !shouldKeepConnected) disconnect();
16460
16463
  }
@@ -16468,6 +16471,12 @@ function WalletConnectHandler() {
16468
16471
  setProviderType,
16469
16472
  walletMode
16470
16473
  ]);
16474
+ (0, import_react63.useEffect)(() => {
16475
+ if (pendingModalOpen && !isConnected && openConnectModal) {
16476
+ setPendingModalOpen(false);
16477
+ openConnectModal();
16478
+ }
16479
+ }, [pendingModalOpen, isConnected, openConnectModal]);
16471
16480
  (0, import_react63.useEffect)(() => {
16472
16481
  if (connectModalOpen && hasStartedLinking) {
16473
16482
  setModalWasOpened(true);
@@ -16495,7 +16504,7 @@ function WalletConnectHandler() {
16495
16504
  setAuthError({ title: "Connection timed out", message: "Wallet did not respond. Please try again." });
16496
16505
  setPage("auth" /* AUTH */);
16497
16506
  }
16498
- }, 12e4);
16507
+ }, 3e5);
16499
16508
  return () => clearTimeout(timeout);
16500
16509
  }
16501
16510
  }, [isWalletLinking, setIsWalletLinking, disconnect]);
@@ -16522,7 +16531,7 @@ function WalletConnectHandler() {
16522
16531
  const signature = await Promise.race([
16523
16532
  signMessageAsync({ message, account: signingWalletAddress }),
16524
16533
  new Promise(
16525
- (_, reject) => setTimeout(() => reject(new Error("Signature request timed out. Please try again.")), 6e4)
16534
+ (_, reject) => setTimeout(() => reject(new Error("Signature request timed out. Please try again.")), 12e4)
16526
16535
  )
16527
16536
  ]);
16528
16537
  if (!signature) {
@@ -16577,6 +16586,7 @@ function WalletConnectHandler() {
16577
16586
  onLinkingComplete(false);
16578
16587
  setHasStartedLinking(false);
16579
16588
  setLinkIsLoading(false);
16589
+ setAuthStep("signin");
16580
16590
  const errorMsg = err?.message || (isAuthFlow ? "Wallet login failed" : "Failed to link wallet");
16581
16591
  if (errorMsg.includes("User rejected") || errorMsg.includes("User denied")) {
16582
16592
  if (passportWalletAddress) {
@@ -16601,11 +16611,15 @@ function WalletConnectHandler() {
16601
16611
  }
16602
16612
  });
16603
16613
  (0, import_react63.useEffect)(() => {
16604
- if (!!chain?.id && isConnected && walletAddress && isWalletLinking && hasStartedLinking) {
16614
+ if (!!chain?.id && isConnected && walletAddress && isWalletLinking && hasStartedLinking && modalWasOpened && !pendingModalOpen) {
16605
16615
  console.log("[WalletConnectHandler] handleWalletSign triggered");
16616
+ if (!passportWalletAddress) {
16617
+ setPage("auth" /* AUTH */);
16618
+ setAuthStep("loading");
16619
+ }
16606
16620
  handleWalletSign({ chainId: chain.id, signingWalletAddress: walletAddress });
16607
16621
  }
16608
- }, [chain, isConnected, walletAddress, isWalletLinking, hasStartedLinking]);
16622
+ }, [chain, isConnected, walletAddress, isWalletLinking, hasStartedLinking, modalWasOpened, pendingModalOpen]);
16609
16623
  (0, import_react63.useEffect)(() => {
16610
16624
  if (isConnected && !chain?.id && isWalletLinking && hasStartedLinking && !connectModalOpen && !isWalletSigning) {
16611
16625
  const timeout = setTimeout(() => {
@@ -19536,7 +19550,7 @@ function Provider(props) {
19536
19550
  [config, updateConfig, callbacks, updateCallbacks]
19537
19551
  );
19538
19552
  if (!!initialConfig?.wallet?.enabled)
19539
- return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(WagmiProvider2, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(UIContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(RainbowKitProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(SessionProvider, { children }) }) }) });
19553
+ return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(UIContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(RainbowKitProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(SessionProvider, { children }) }) });
19540
19554
  return /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(WagmiProvider2, { children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(UIContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime96.jsx)(SessionProvider, { children }) }) });
19541
19555
  }
19542
19556
  var import_error_tracking4, import_lodash_es6, import_react67, import_jsx_runtime96, UIContext, useProviderConfig;