Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/DTIS-728-agen…
Browse files Browse the repository at this point in the history
…t-services-re-work
  • Loading branch information
iFergal committed Apr 30, 2024
2 parents c903e87 + 2d261bc commit 4ec34a0
Show file tree
Hide file tree
Showing 22 changed files with 558 additions and 724 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"jest": true
},
"globals": {
"__dirname": true
"__dirname": true,
"NodeJS": true
},
"extends": [
"eslint:recommended",
Expand Down
5 changes: 3 additions & 2 deletions src/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
}
]
},
"passcodelogin": {
"lockmodal": {
"title": "Welcome back",
"description": "Please enter your passcode to login",
"error": "Incorrect passcode",
Expand Down Expand Up @@ -856,7 +856,8 @@
"connections": "Connections",
"p2p": "P2P",
"identity": "Identity",
"credentials": "Credentials"
"credentials": "Credentials",
"lock": "Lock"
}
}
},
Expand Down
61 changes: 1 addition & 60 deletions src/routes/backRoute/backRoute.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { RootState } from "../../store";
import { DataProps } from "../nextRoute/nextRoute.types";
import {
calcPreviousRoute,
getBackRoute,
getPreviousRoute,
updateStoreAfterPasscodeLoginRoute,
} from "./backRoute";
import { RoutePath } from "../index";
import { calcPreviousRoute, getBackRoute, getPreviousRoute } from "./backRoute";
import { setAuthentication } from "../../store/reducers/stateCache";
import { FIFTEEN_WORDS_BIT_LENGTH } from "../../ui/globals/constants";
import { OperationType } from "../../ui/globals/types";
Expand Down Expand Up @@ -109,51 +103,6 @@ describe("getBackRoute", () => {
expect(result.backPath).toEqual({ pathname: "/route2" });
expect(result.updateRedux).toHaveLength(2);
});

test("should update store correctly after /passcodelogin route", () => {
storeMock = {
stateCache: {
initialized: true,
routes: [],
authentication: {
loggedIn: false,
userName: "",
time: 0,
passcodeIsSet: true,
seedPhraseIsSet: false,
passwordIsSet: false,
passwordIsSkipped: true,
},
currentOperation: OperationType.IDLE,
queueIncomingRequest: {
isProcessing: false,
queues: [],
isPaused: false,
},
},
seedPhraseCache: {
seedPhrase160: "",
seedPhrase256: "",
selected: FIFTEEN_WORDS_BIT_LENGTH,
},
identifiersCache: { identifiers: [], favourites: [] },
credsCache: { creds: [], favourites: [] },
connectionsCache: {
connections: [],
},
};
const expectedAuthentication = {
...storeMock.stateCache.authentication,
loggedIn: true,
time: expect.any(Number),
};
const result = updateStoreAfterPasscodeLoginRoute({
store: storeMock,
state,
});

expect(result).toEqual(setAuthentication(expectedAuthentication));
});
});

describe("calcPreviousRoute", () => {
Expand All @@ -169,14 +118,6 @@ describe("calcPreviousRoute", () => {

expect(result).toEqual({ path: "/generateseedphrase", payload: {} });
});

test("should return undefined if not available routes", () => {
const routes = [{ path: RoutePath.PASSCODE_LOGIN, payload: {} }];

const result = calcPreviousRoute(routes);

expect(result).toBeUndefined();
});
});

describe("getPreviousRoute", () => {
Expand Down
39 changes: 2 additions & 37 deletions src/routes/backRoute/backRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ const getPreviousRoute = (data: DataProps): { pathname: string } => {

if (routes.length === 0) {
path = RoutePath.ROOT;
} else if (
routes.length === 2 &&
routes[0].path === RoutePath.SET_PASSCODE &&
routes[1].path === RoutePath.PASSCODE_LOGIN
) {
path = RoutePath.PASSCODE_LOGIN;
} else if (prevPath) {
path = prevPath.path;
} else {
Expand All @@ -59,36 +53,11 @@ const getPreviousRoute = (data: DataProps): { pathname: string } => {
return { pathname: path };
};

const updateStoreAfterPasscodeLoginRoute = (data: DataProps) => {
const seedPhraseISet = data.store.stateCache.authentication.seedPhraseIsSet;

if (data.state?.resetPasscode && seedPhraseISet) {
return setAuthentication({
...data.store.stateCache.authentication,
loggedIn: false,
time: 0,
});
} else if (data.state?.resetPasscode) {
return setAuthentication({
...data.store.stateCache.authentication,
loggedIn: false,
time: 0,
});
} else {
return setAuthentication({
...data.store.stateCache.authentication,
loggedIn: true,
time: Date.now(),
});
}
};

const calcPreviousRoute = (
routes: { path: string; payload?: PayloadProps }[]
) => {
return routes
.slice(1)
.find((element) => element.path !== RoutePath.PASSCODE_LOGIN);
if (!routes || routes.length < 2) return undefined;
return routes[1];
};

const backPath = (data: DataProps) => getPreviousRoute(data);
Expand All @@ -113,9 +82,6 @@ const backRoute: Record<string, any> = {
[RoutePath.SET_PASSCODE]: {
updateRedux: [removeCurrentRoute, updateStoreSetCurrentRoute],
},
[RoutePath.PASSCODE_LOGIN]: {
updateRedux: [removeCurrentRoute, updateStoreAfterPasscodeLoginRoute],
},
[RoutePath.CREATE_PASSWORD]: {
updateRedux: [],
},
Expand All @@ -134,7 +100,6 @@ export {
getBackRoute,
calcPreviousRoute,
getPreviousRoute,
updateStoreAfterPasscodeLoginRoute,
updateStoreSetCurrentRoute,
backPath,
};
79 changes: 22 additions & 57 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useEffect, useState } from "react";
import { IonReactRouter } from "@ionic/react-router";
import { IonRouterOutlet } from "@ionic/react";
import { IonRouterOutlet, IonSpinner } from "@ionic/react";
import { Redirect, Route, useLocation } from "react-router-dom";
import { Onboarding } from "../ui/pages/Onboarding";
import { GenerateSeedPhrase } from "../ui/pages/GenerateSeedPhrase";
import { SetPasscode } from "../ui/pages/SetPasscode";
import { PasscodeLogin } from "../ui/pages/PasscodeLogin";
import { VerifySeedPhrase } from "../ui/pages/VerifySeedPhrase";
import { CreatePassword } from "../ui/pages/CreatePassword";
import { useAppDispatch, useAppSelector } from "../store/hooks";
Expand All @@ -17,42 +16,17 @@ import {
} from "../store/reducers/stateCache";
import { getNextRoute } from "./nextRoute";
import { TabsMenu, tabsRoutes } from "../ui/components/navigation/TabsMenu";
import { RoutePath } from "./paths";
import { PublicRoutes, RoutePath } from "./paths";
import { IdentifierDetails } from "../ui/pages/IdentifierDetails";
import { CredentialDetails } from "../ui/pages/CredentialDetails";
import { ConnectionDetails } from "../ui/pages/ConnectionDetails";
import { AuthenticatedRouteProps } from "./routes.types";

const AuthenticatedRoute: React.FC<AuthenticatedRouteProps> = (props) => {
const authentication = useAppSelector(getAuthentication);
const location = useLocation();
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(
authentication.loggedIn
);

useEffect(() => {
setIsAuthenticated(authentication.loggedIn);
}, [authentication.loggedIn]);

return isAuthenticated ? (
<Route
{...props}
component={props.component}
/>
) : (
<Redirect
from={location.pathname}
to={{
pathname: props.nextPathname,
}}
/>
);
};
import { LockModal } from "../ui/components/LockModal";

const Routes = () => {
const stateCache = useAppSelector(getStateCache);
const dispatch = useAppDispatch();
const routes = useAppSelector(getRoutes);

const { nextPath } = getNextRoute(RoutePath.ROOT, {
store: { stateCache },
});
Expand All @@ -64,12 +38,6 @@ const Routes = () => {
return (
<IonReactRouter>
<IonRouterOutlet animated={false}>
<Route
path={RoutePath.PASSCODE_LOGIN}
component={PasscodeLogin}
exact
/>

<Route
path={RoutePath.SET_PASSCODE}
component={SetPasscode}
Expand All @@ -82,39 +50,39 @@ const Routes = () => {
exact
/>

{/* Private Routes */}
<AuthenticatedRoute
<Route
path={RoutePath.GENERATE_SEED_PHRASE}
component={GenerateSeedPhrase}
nextPathname={nextPath.pathname}
exact
/>
<AuthenticatedRoute

<Route
path={RoutePath.VERIFY_SEED_PHRASE}
exact
component={VerifySeedPhrase}
nextPathname={nextPath.pathname}
exact
/>
<AuthenticatedRoute

<Route
path={RoutePath.TABS_MENU}
exact
component={TabsMenu}
nextPathname={nextPath.pathname}
exact
/>
<AuthenticatedRoute

<Route
path={RoutePath.CREATE_PASSWORD}
exact
component={CreatePassword}
nextPathname={nextPath.pathname}
exact
/>
<AuthenticatedRoute

<Route
path={RoutePath.CONNECTION_DETAILS}
exact
component={ConnectionDetails}
nextPathname={nextPath.pathname}
exact
/>

{tabsRoutes.map((tab, index: number) => {
return (
<AuthenticatedRoute
<Route
key={index}
path={tab.path}
exact
Expand All @@ -124,21 +92,18 @@ const Routes = () => {
path={tab.path}
/>
)}
nextPathname={nextPath.pathname}
/>
);
})}
<AuthenticatedRoute
<Route
path="/tabs/identifiers/:id"
component={IdentifierDetails}
exact
nextPathname={nextPath.pathname}
/>
<AuthenticatedRoute
<Route
path="/tabs/creds/:id"
component={CredentialDetails}
exact
nextPathname={nextPath.pathname}
/>
<Redirect
exact
Expand Down
4 changes: 1 addition & 3 deletions src/routes/nextRoute/nextRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const getNextRootRoute = (store: StoreState) => {
routes.some((route) => route.path === "/") || routes.length === 0;

let path;
if (authentication.passcodeIsSet && !authentication.loggedIn) {
path = RoutePath.PASSCODE_LOGIN;
} else if (routes.length === 1 && !isInitialized) {
if (routes.length === 1 && !isInitialized) {
path = RoutePath.ONBOARDING;
} else if (authentication.passcodeIsSet && authentication.seedPhraseIsSet) {
path = RoutePath.TABS_MENU;
Expand Down
9 changes: 7 additions & 2 deletions src/routes/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ enum RoutePath {
ROOT = "/",
ONBOARDING = "/onboarding",
SET_PASSCODE = "/setpasscode",
PASSCODE_LOGIN = "/passcodelogin",
GENERATE_SEED_PHRASE = "/generateseedphrase",
VERIFY_SEED_PHRASE = "/verifyseedphrase",
TABS_MENU = "/tabs",
Expand All @@ -21,4 +20,10 @@ enum TabsRoutePath {
CREDENTIAL_DETAILS = "/tabs/credentials/:id?",
}

export { RoutePath, TabsRoutePath };
const PublicRoutes = [
RoutePath.ROOT,
RoutePath.ONBOARDING,
RoutePath.SET_PASSCODE,
];

export { RoutePath, TabsRoutePath, PublicRoutes };

0 comments on commit 4ec34a0

Please sign in to comment.