@embarkai/ui-kit 0.4.11 → 0.4.12

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.
@@ -15,7 +15,7 @@
15
15
  <meta http-equiv="X-Content-Type-Options" content="nosniff" />
16
16
  <meta http-equiv="Referrer-Policy" content="strict-origin-when-cross-origin" />
17
17
 
18
- <title>EmbarkAI Secure Wallet - iframe version 0.4.11</title>
18
+ <title>EmbarkAI Secure Wallet - iframe version 0.4.12</title>
19
19
 
20
20
  <!-- Styles will be injected by build process -->
21
21
  <style>
@@ -6262,7 +6262,7 @@ var SigningManager = class extends TokenRefreshApiClient {
6262
6262
  };
6263
6263
 
6264
6264
  // src/iframe/main.ts
6265
- var IFRAME_VERSION = "0.4.11";
6265
+ var IFRAME_VERSION = "0.4.12";
6266
6266
  var IframeWallet = class {
6267
6267
  constructor() {
6268
6268
  console.log("=".repeat(60));
package/dist/index.cjs CHANGED
@@ -5281,7 +5281,7 @@ var init_OtpIcon = __esm({
5281
5281
  });
5282
5282
 
5283
5283
  // src/internal/components/AuthMenu/VerifyStep/VerificationCodeInput.tsx
5284
- var import_react16, import_jsx_runtime15, VerificationCodeInput;
5284
+ var import_react16, import_jsx_runtime15, getRemainingSeconds, VerificationCodeInput;
5285
5285
  var init_VerificationCodeInput = __esm({
5286
5286
  "src/internal/components/AuthMenu/VerifyStep/VerificationCodeInput.tsx"() {
5287
5287
  init_i18n();
@@ -5290,16 +5290,39 @@ var init_VerificationCodeInput = __esm({
5290
5290
  init_button();
5291
5291
  init_useAuthStore();
5292
5292
  import_jsx_runtime15 = require("react/jsx-runtime");
5293
+ getRemainingSeconds = (expiresAt) => Math.max(0, Math.ceil((expiresAt - Date.now()) / 1e3));
5293
5294
  VerificationCodeInput = (props) => {
5294
5295
  const { onVerifyCode, onResendCode, isLoading, expiresIn } = props;
5295
5296
  const { t } = useT();
5296
5297
  const setAlert = useAuthStore((st) => st.setAlert);
5297
- const [timeLeft, setTimeLeft] = (0, import_react16.useState)(expiresIn);
5298
+ const [expiresAt, setExpiresAt] = (0, import_react16.useState)(() => Date.now() + Math.max(0, expiresIn) * 1e3);
5299
+ const [timeLeft, setTimeLeft] = (0, import_react16.useState)(() => getRemainingSeconds(expiresAt));
5298
5300
  (0, import_react16.useEffect)(() => {
5299
- if (timeLeft <= 0) return;
5300
- const t2 = setTimeout(() => setTimeLeft((s) => s - 1), 1e3);
5301
- return () => clearTimeout(t2);
5302
- }, [timeLeft]);
5301
+ const nextExpiresAt = Date.now() + Math.max(0, expiresIn) * 1e3;
5302
+ setExpiresAt(nextExpiresAt);
5303
+ setTimeLeft(getRemainingSeconds(nextExpiresAt));
5304
+ }, [expiresIn]);
5305
+ (0, import_react16.useEffect)(() => {
5306
+ let intervalId;
5307
+ const syncTimeLeft = () => {
5308
+ const remaining = getRemainingSeconds(expiresAt);
5309
+ setTimeLeft(remaining);
5310
+ if (remaining <= 0 && intervalId) {
5311
+ window.clearInterval(intervalId);
5312
+ intervalId = void 0;
5313
+ }
5314
+ };
5315
+ syncTimeLeft();
5316
+ if (getRemainingSeconds(expiresAt) <= 0) return;
5317
+ intervalId = window.setInterval(syncTimeLeft, 1e3);
5318
+ window.addEventListener("focus", syncTimeLeft);
5319
+ document.addEventListener("visibilitychange", syncTimeLeft);
5320
+ return () => {
5321
+ if (intervalId) window.clearInterval(intervalId);
5322
+ window.removeEventListener("focus", syncTimeLeft);
5323
+ document.removeEventListener("visibilitychange", syncTimeLeft);
5324
+ };
5325
+ }, [expiresAt]);
5303
5326
  const lastSubmittedRef = (0, import_react16.useRef)(null);
5304
5327
  const inputsRef = (0, import_react16.useRef)([]);
5305
5328
  const [digits, setDigits] = (0, import_react16.useState)(["", "", "", "", "", ""]);
@@ -5480,14 +5503,17 @@ function VerifyStep(props) {
5480
5503
  },
5481
5504
  onError: (error) => {
5482
5505
  let errorMessage = "";
5483
- if (error.message?.includes("Invalid") || error.message?.includes("invalid")) {
5506
+ const rawErrorMessage = error.message || "";
5507
+ const normalizedErrorMessage = rawErrorMessage.toLowerCase();
5508
+ if (normalizedErrorMessage.includes("invalid")) {
5484
5509
  errorMessage = "Invalid verification code. Please try again.";
5485
- } else if (error.message?.includes("expired")) {
5510
+ } else if (normalizedErrorMessage.includes("expired")) {
5486
5511
  errorMessage = "Verification code expired. Please request a new one.";
5487
- } else if (error.message?.includes("429") || error.message?.includes("Too many")) {
5512
+ setExpiresIn(0);
5513
+ } else if (normalizedErrorMessage.includes("429") || normalizedErrorMessage.includes("too many")) {
5488
5514
  errorMessage = "Too many attempts. Please try again later.";
5489
5515
  } else {
5490
- errorMessage = error.message || "Verification failed. Please try again.";
5516
+ errorMessage = rawErrorMessage || "Verification failed. Please try again.";
5491
5517
  }
5492
5518
  setAlert({
5493
5519
  title: "Verification failed",
@@ -13716,7 +13742,17 @@ function useVerifyCode() {
13716
13742
  const qc = (0, import_react_query30.useQueryClient)();
13717
13743
  const address = useSession((st) => st.address);
13718
13744
  const setIsLoading = useSession((st) => st.setIsLoading);
13719
- const { email, emailCode, setEmail, setEmailStep, setEmailCode, setProviderType, setLinkIsLoading, setAlert } = useManageWalletStore();
13745
+ const {
13746
+ email,
13747
+ emailCode,
13748
+ setEmail,
13749
+ setEmailStep,
13750
+ setEmailCode,
13751
+ setEmailCodeExpiresIn,
13752
+ setProviderType,
13753
+ setLinkIsLoading,
13754
+ setAlert
13755
+ } = useManageWalletStore();
13720
13756
  return (0, import_react_query30.useMutation)({
13721
13757
  mutationFn: async (codeToVerify) => {
13722
13758
  const code = codeToVerify ?? emailCode;
@@ -13745,7 +13781,11 @@ function useVerifyCode() {
13745
13781
  setLinkIsLoading(false);
13746
13782
  },
13747
13783
  onError: (error) => {
13748
- setAlert({ title: "Error", message: error?.message || "Failed to verify and link email" });
13784
+ const message = error?.message || "Failed to verify and link email";
13785
+ if (message.toLowerCase().includes("expired")) {
13786
+ setEmailCodeExpiresIn(0);
13787
+ }
13788
+ setAlert({ title: "Error", message });
13749
13789
  setIsLoading(false);
13750
13790
  setLinkIsLoading(false);
13751
13791
  }
@@ -19240,7 +19280,7 @@ var init_package = __esm({
19240
19280
  "package.json"() {
19241
19281
  package_default = {
19242
19282
  name: "@embarkai/ui-kit",
19243
- version: "0.4.11",
19283
+ version: "0.4.12",
19244
19284
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
19245
19285
  type: "module",
19246
19286
  main: "./dist/index.cjs",
package/dist/index.js CHANGED
@@ -5262,23 +5262,46 @@ var init_OtpIcon = __esm({
5262
5262
  // src/internal/components/AuthMenu/VerifyStep/VerificationCodeInput.tsx
5263
5263
  import { useEffect as useEffect9, useRef as useRef7, useState as useState3 } from "react";
5264
5264
  import { Fragment as Fragment6, jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
5265
- var VerificationCodeInput;
5265
+ var getRemainingSeconds, VerificationCodeInput;
5266
5266
  var init_VerificationCodeInput = __esm({
5267
5267
  "src/internal/components/AuthMenu/VerifyStep/VerificationCodeInput.tsx"() {
5268
5268
  init_i18n();
5269
5269
  init_utils2();
5270
5270
  init_button();
5271
5271
  init_useAuthStore();
5272
+ getRemainingSeconds = (expiresAt) => Math.max(0, Math.ceil((expiresAt - Date.now()) / 1e3));
5272
5273
  VerificationCodeInput = (props) => {
5273
5274
  const { onVerifyCode, onResendCode, isLoading, expiresIn } = props;
5274
5275
  const { t } = useT();
5275
5276
  const setAlert = useAuthStore((st) => st.setAlert);
5276
- const [timeLeft, setTimeLeft] = useState3(expiresIn);
5277
+ const [expiresAt, setExpiresAt] = useState3(() => Date.now() + Math.max(0, expiresIn) * 1e3);
5278
+ const [timeLeft, setTimeLeft] = useState3(() => getRemainingSeconds(expiresAt));
5277
5279
  useEffect9(() => {
5278
- if (timeLeft <= 0) return;
5279
- const t2 = setTimeout(() => setTimeLeft((s) => s - 1), 1e3);
5280
- return () => clearTimeout(t2);
5281
- }, [timeLeft]);
5280
+ const nextExpiresAt = Date.now() + Math.max(0, expiresIn) * 1e3;
5281
+ setExpiresAt(nextExpiresAt);
5282
+ setTimeLeft(getRemainingSeconds(nextExpiresAt));
5283
+ }, [expiresIn]);
5284
+ useEffect9(() => {
5285
+ let intervalId;
5286
+ const syncTimeLeft = () => {
5287
+ const remaining = getRemainingSeconds(expiresAt);
5288
+ setTimeLeft(remaining);
5289
+ if (remaining <= 0 && intervalId) {
5290
+ window.clearInterval(intervalId);
5291
+ intervalId = void 0;
5292
+ }
5293
+ };
5294
+ syncTimeLeft();
5295
+ if (getRemainingSeconds(expiresAt) <= 0) return;
5296
+ intervalId = window.setInterval(syncTimeLeft, 1e3);
5297
+ window.addEventListener("focus", syncTimeLeft);
5298
+ document.addEventListener("visibilitychange", syncTimeLeft);
5299
+ return () => {
5300
+ if (intervalId) window.clearInterval(intervalId);
5301
+ window.removeEventListener("focus", syncTimeLeft);
5302
+ document.removeEventListener("visibilitychange", syncTimeLeft);
5303
+ };
5304
+ }, [expiresAt]);
5282
5305
  const lastSubmittedRef = useRef7(null);
5283
5306
  const inputsRef = useRef7([]);
5284
5307
  const [digits, setDigits] = useState3(["", "", "", "", "", ""]);
@@ -5463,14 +5486,17 @@ function VerifyStep(props) {
5463
5486
  },
5464
5487
  onError: (error) => {
5465
5488
  let errorMessage = "";
5466
- if (error.message?.includes("Invalid") || error.message?.includes("invalid")) {
5489
+ const rawErrorMessage = error.message || "";
5490
+ const normalizedErrorMessage = rawErrorMessage.toLowerCase();
5491
+ if (normalizedErrorMessage.includes("invalid")) {
5467
5492
  errorMessage = "Invalid verification code. Please try again.";
5468
- } else if (error.message?.includes("expired")) {
5493
+ } else if (normalizedErrorMessage.includes("expired")) {
5469
5494
  errorMessage = "Verification code expired. Please request a new one.";
5470
- } else if (error.message?.includes("429") || error.message?.includes("Too many")) {
5495
+ setExpiresIn(0);
5496
+ } else if (normalizedErrorMessage.includes("429") || normalizedErrorMessage.includes("too many")) {
5471
5497
  errorMessage = "Too many attempts. Please try again later.";
5472
5498
  } else {
5473
- errorMessage = error.message || "Verification failed. Please try again.";
5499
+ errorMessage = rawErrorMessage || "Verification failed. Please try again.";
5474
5500
  }
5475
5501
  setAlert({
5476
5502
  title: "Verification failed",
@@ -13660,7 +13686,17 @@ function useVerifyCode() {
13660
13686
  const qc = useQueryClient14();
13661
13687
  const address = useSession((st) => st.address);
13662
13688
  const setIsLoading = useSession((st) => st.setIsLoading);
13663
- const { email, emailCode, setEmail, setEmailStep, setEmailCode, setProviderType, setLinkIsLoading, setAlert } = useManageWalletStore();
13689
+ const {
13690
+ email,
13691
+ emailCode,
13692
+ setEmail,
13693
+ setEmailStep,
13694
+ setEmailCode,
13695
+ setEmailCodeExpiresIn,
13696
+ setProviderType,
13697
+ setLinkIsLoading,
13698
+ setAlert
13699
+ } = useManageWalletStore();
13664
13700
  return useMutation14({
13665
13701
  mutationFn: async (codeToVerify) => {
13666
13702
  const code = codeToVerify ?? emailCode;
@@ -13689,7 +13725,11 @@ function useVerifyCode() {
13689
13725
  setLinkIsLoading(false);
13690
13726
  },
13691
13727
  onError: (error) => {
13692
- setAlert({ title: "Error", message: error?.message || "Failed to verify and link email" });
13728
+ const message = error?.message || "Failed to verify and link email";
13729
+ if (message.toLowerCase().includes("expired")) {
13730
+ setEmailCodeExpiresIn(0);
13731
+ }
13732
+ setAlert({ title: "Error", message });
13693
13733
  setIsLoading(false);
13694
13734
  setLinkIsLoading(false);
13695
13735
  }
@@ -19158,7 +19198,7 @@ var init_package = __esm({
19158
19198
  "package.json"() {
19159
19199
  package_default = {
19160
19200
  name: "@embarkai/ui-kit",
19161
- version: "0.4.11",
19201
+ version: "0.4.12",
19162
19202
  description: "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
19163
19203
  type: "module",
19164
19204
  main: "./dist/index.cjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embarkai/ui-kit",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "React UI components and hooks for EmbarkAI authentication and Account Abstraction",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",