Skip to content

Commit

Permalink
feat: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jimcase committed May 6, 2024
1 parent e3f138a commit 6ade5d0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 32 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"env": {
"browser": true,
"es2021": true,
"jest": true
"jest": true,
"node": true
},
"globals": {
"__dirname": true,
"NodeJS": true
"NodeJS": true,
"process": "readonly"
},
"extends": [
"eslint:recommended",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
}
]
},
"lockmodal": {
"lockpage": {
"title": "Welcome back",
"description": "Please enter your passcode to login",
"error": "Incorrect passcode",
Expand Down
10 changes: 4 additions & 6 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import React, { useEffect, useState } from "react";
import React, { useEffect } from "react";
import { IonReactRouter } from "@ionic/react-router";
import { IonRouterOutlet, IonSpinner } from "@ionic/react";
import { Redirect, Route, useLocation } from "react-router-dom";
import { IonRouterOutlet } from "@ionic/react";
import { Redirect, Route } from "react-router-dom";
import { Onboarding } from "../ui/pages/Onboarding";
import { GenerateSeedPhrase } from "../ui/pages/GenerateSeedPhrase";
import { SetPasscode } from "../ui/pages/SetPasscode";
import { VerifySeedPhrase } from "../ui/pages/VerifySeedPhrase";
import { CreatePassword } from "../ui/pages/CreatePassword";
import { useAppDispatch, useAppSelector } from "../store/hooks";
import {
getAuthentication,
getRoutes,
getStateCache,
setCurrentRoute,
} from "../store/reducers/stateCache";
import { getNextRoute } from "./nextRoute";
import { TabsMenu, tabsRoutes } from "../ui/components/navigation/TabsMenu";
import { PublicRoutes, RoutePath } from "./paths";
import { RoutePath } from "./paths";
import { IdentifierDetails } from "../ui/pages/IdentifierDetails";
import { CredentialDetails } from "../ui/pages/CredentialDetails";
import { ConnectionDetails } from "../ui/pages/ConnectionDetails";
import { LockModal } from "../ui/components/LockModal";

const Routes = () => {
const stateCache = useAppSelector(getStateCache);
Expand Down
1 change: 0 additions & 1 deletion src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { SetUserName } from "./components/SetUserName";
import { TabsRoutePath } from "../routes/paths";
import { MobileHeaderPreview } from "./components/MobileHeaderPreview";
import { CustomToast } from "./components/CustomToast/CustomToast";
import { LockModal } from "./components/LockModal";
import { LockPage } from "./pages/LockPage/LockPage";

setupIonicReact();
Expand Down
7 changes: 5 additions & 2 deletions src/ui/components/AppWrapper/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ const acdcChangeHandler = async (
}
};

let ACTIVITY_TIMEOUT = 60000; // 1min
if (process.env.NODE_ENV === "development") {
ACTIVITY_TIMEOUT = 3600000; // 1h
}

const AppWrapper = (props: { children: ReactNode }) => {
const dispatch = useAppDispatch();
const authentication = useAppSelector(getAuthentication);
const [agentInitErr, setAgentInitErr] = useState(false);

const ACTIVITY_TIMEOUT = 60000;
let timer: NodeJS.Timeout;

useEffect(() => {
const handleActivity = () => {
clearTimeout(timer);
Expand Down
20 changes: 9 additions & 11 deletions src/ui/pages/LockPage/LockPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ const LockPage = ({ didEnter }: LockPageProps) => {
const [passcode, setPasscode] = useState("");
const seedPhrase = authentication.seedPhraseIsSet;
const [alertIsOpen, setAlertIsOpen] = useState(false);
const [showModalAfterRender, setShowModalAfterRender] = useState(false);
const [passcodeIncorrect, setPasscodeIncorrect] = useState(false);
const headerText = seedPhrase
? i18n.t("lockmodal.alert.text.verify")
: i18n.t("lockmodal.alert.text.restart");
? i18n.t("lockpage.alert.text.verify")
: i18n.t("lockpage.alert.text.restart");
const confirmButtonText = seedPhrase
? i18n.t("lockmodal.alert.button.verify")
: i18n.t("lockmodal.alert.button.restart");
const cancelButtonText = i18n.t("lockmodal.alert.button.cancel");
? i18n.t("lockpage.alert.button.verify")
: i18n.t("lockpage.alert.button.restart");
const cancelButtonText = i18n.t("lockpage.alert.button.cancel");

useEffect(() => {
didEnter && didEnter();
setShowModalAfterRender(true);
}, []);

const handleClearState = () => {
Expand Down Expand Up @@ -127,20 +125,20 @@ const LockPage = ({ didEnter }: LockPageProps) => {
className={`${pageId}-title`}
data-testid={`${pageId}-title`}
>
{i18n.t("lockmodal.title")}
{i18n.t("lockpage.title")}
</h2>
<p
className={`${pageId}-description small-hide`}
data-testid={`${pageId}-description`}
>
{i18n.t("lockmodal.description")}
{i18n.t("lockpage.description")}
</p>
<PasscodeModule
error={
<ErrorMessage
message={
passcode.length === 6 && passcodeIncorrect
? `${i18n.t("lockmodal.error")}`
? `${i18n.t("lockpage.error")}`
: undefined
}
timeout={true}
Expand All @@ -152,7 +150,7 @@ const LockPage = ({ didEnter }: LockPageProps) => {
/>
<PageFooter
pageId={pageId}
secondaryButtonText={`${i18n.t("lockmodal.forgotten.button")}`}
secondaryButtonText={`${i18n.t("lockpage.forgotten.button")}`}
secondaryButtonAction={() => setAlertIsOpen(true)}
/>
<Alert
Expand Down
14 changes: 6 additions & 8 deletions src/ui/pages/LockPage/LockPagel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ describe("Lock Page", () => {
<LockPage />
</Provider>
);
expect(getByText(EN_TRANSLATIONS.lockmodal.title)).toBeInTheDocument();
expect(
getByText(EN_TRANSLATIONS.lockmodal.description)
).toBeInTheDocument();
expect(getByText(EN_TRANSLATIONS.lockpage.title)).toBeInTheDocument();
expect(getByText(EN_TRANSLATIONS.lockpage.description)).toBeInTheDocument();
});

test("The user can add and remove digits from the passcode", () => {
Expand Down Expand Up @@ -115,12 +113,12 @@ describe("Lock Page", () => {
fireEvent.click(getByText(/4/));
fireEvent.click(getByText(/5/));
fireEvent.click(getByText(/6/));
expect(await findByText(EN_TRANSLATIONS.lockmodal.error)).toBeVisible();
fireEvent.click(getByText(EN_TRANSLATIONS.lockmodal.forgotten.button));
expect(await findByText(EN_TRANSLATIONS.lockpage.error)).toBeVisible();
fireEvent.click(getByText(EN_TRANSLATIONS.lockpage.forgotten.button));
expect(
await findByText(EN_TRANSLATIONS.lockmodal.alert.text.restart)
await findByText(EN_TRANSLATIONS.lockpage.alert.text.restart)
).toBeVisible();
fireEvent.click(getByText(EN_TRANSLATIONS.lockmodal.alert.button.restart));
fireEvent.click(getByText(EN_TRANSLATIONS.lockpage.alert.button.restart));
expect(
await findByText(EN_TRANSLATIONS.setpasscode.enterpasscode.title)
).toBeVisible();
Expand Down
3 changes: 2 additions & 1 deletion webpack/webpack.common.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const config = {
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(require("../package.json").version),
"process.env": JSON.stringify(process.env),
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env": JSON.stringify(process.env)
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
Expand Down

0 comments on commit 6ade5d0

Please sign in to comment.