Skip to content

Commit

Permalink
fix: merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jimcase committed May 3, 2024
1 parent 8fe19e7 commit 3a83e28
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 106 deletions.
14 changes: 2 additions & 12 deletions src/routes/nextRoute/nextRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,13 @@ import { RoutePath, TabsRoutePath } from "../paths";
import { ToastMsgType } from "../../ui/globals/types";

const getNextRootRoute = (store: StoreState) => {
const isInitialized = store.stateCache.initialized;
const authentication = store.stateCache.authentication;
const routes = store.stateCache.routes;
const initialRoute =
routes.some((route) => route.path === "/") || routes.length === 0;

let path;
if (routes.length === 1 && !isInitialized) {
path = RoutePath.ONBOARDING;
} else if (authentication.passcodeIsSet && authentication.seedPhraseIsSet) {
if (authentication.passcodeIsSet && authentication.seedPhraseIsSet) {
path = RoutePath.TABS_MENU;
} else {
if (initialRoute) {
path = RoutePath.ONBOARDING;
} else {
path = routes[0].path;
}
path = RoutePath.ONBOARDING;
}

return { pathname: path };
Expand Down
26 changes: 15 additions & 11 deletions src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getAuthentication,
getCurrentOperation,
getCurrentRoute,
getStateCache,
getToastMsg,
} from "../store/reducers/stateCache";
import { useAppSelector } from "../store/hooks";
Expand All @@ -32,6 +33,7 @@ import { LockModal } from "./components/LockModal";
setupIonicReact();

const App = () => {
const stateCache = useAppSelector(getStateCache);
const authentication = useAppSelector(getAuthentication);
const currentRoute = useAppSelector(getCurrentRoute);
const [showSetUserName, setShowSetUserName] = useState(false);
Expand Down Expand Up @@ -77,23 +79,25 @@ const App = () => {
}, [authentication.loggedIn, currentRoute]);

useEffect(() => {
ScreenOrientation.lock({ orientation: "portrait" });

const platforms = getPlatforms();
if (!platforms.includes("mobileweb")) {
ScreenOrientation.lock({ orientation: "portrait" });
if (platforms.includes("ios")) {
StatusBar.setStyle({
style: Style.Light,
});
}
const isIosAppPlatform =
platforms.includes("ios") && !platforms.includes("mobileweb");

return () => {
ScreenOrientation.unlock();
};
if (isIosAppPlatform) {
StatusBar.setStyle({
style: Style.Light,
});
}

return () => {
ScreenOrientation.unlock();
};
}, []);

const renderApp = () => {
if (!lockIsRendered) {
if (!lockIsRendered && !stateCache.initialized) {
// We need to include the LockModal in the loading page to track when is rendered
return (
<>
Expand Down
103 changes: 67 additions & 36 deletions src/ui/components/AppWrapper/AppWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { CredentialStatus } from "../../../core/agent/services/credentialService
import { FavouriteIdentifier } from "../../../store/reducers/identifiersCache/identifiersCache.types";
import "./AppWrapper.scss";
import { ConfigurationService } from "../../../core/configuration";
import { PreferencesStorageItem } from "../../../core/storage/preferences/preferencesStorage.type";

const connectionStateChangedHandler = async (
event: ConnectionStateChangedEvent,
Expand Down Expand Up @@ -169,48 +170,80 @@ const AppWrapper = (props: { children: ReactNode }) => {
};

const loadPreferences = async () => {
const getPreferenceSafe = async (key: string) => {
try {
return await PreferencesStorage.get(key);
} catch (e) {
// TODO: handle error
}
};
const userName = await getPreferenceSafe(PreferencesKeys.APP_USER_NAME);

let userName: PreferencesStorageItem = { userName: "" };
const passcodeIsSet = await checkKeyStore(KeyStoreKeys.APP_PASSCODE);
const seedPhraseIsSet = await checkKeyStore(
KeyStoreKeys.IDENTITY_ROOT_XPRV_KEY
);
const passwordIsSet = await checkKeyStore(KeyStoreKeys.APP_OP_PASSWORD);

const updatedAuthentication = {
...authentication,
loggedIn: false,
userName: userName?.userName as string,
passcodeIsSet,
seedPhraseIsSet,
passwordIsSet,
};
try {
const identifiersFavourites = await PreferencesStorage.get(
PreferencesKeys.APP_IDENTIFIERS_FAVOURITES
);
dispatch(
setFavouritesIdentifiersCache(
identifiersFavourites.favourites as FavouriteIdentifier[]
)
);
} catch (e) {
if (
!(e instanceof Error) ||
!(
e instanceof Error &&
e.message ===
`${PreferencesStorage.KEY_NOT_FOUND} ${PreferencesKeys.APP_IDENTIFIERS_FAVOURITES}`
)
) {
throw e;
}
}

dispatch(setAuthentication(updatedAuthentication));
try {
const credsFavourites = await PreferencesStorage.get(
PreferencesKeys.APP_CREDS_FAVOURITES
);
dispatch(
setFavouritesCredsCache(
credsFavourites.favourites as FavouriteIdentifier[]
)
);
} catch (e) {
if (
!(e instanceof Error) ||
!(
e instanceof Error &&
e.message ===
`${PreferencesStorage.KEY_NOT_FOUND} ${PreferencesKeys.APP_CREDS_FAVOURITES}`
)
) {
throw e;
}
}

const identifiersFavourites = await getPreferenceSafe(
PreferencesKeys.APP_IDENTIFIERS_FAVOURITES
);
dispatch(
setFavouritesIdentifiersCache(
identifiersFavourites?.favourites as FavouriteIdentifier[]
)
);
try {
userName = await PreferencesStorage.get(PreferencesKeys.APP_USER_NAME);
} catch (e) {
if (
!(e instanceof Error) ||
!(
e instanceof Error &&
e.message ===
`${PreferencesStorage.KEY_NOT_FOUND} ${PreferencesKeys.APP_USER_NAME}`
)
) {
throw e;
}
}

const credsFavourites = await getPreferenceSafe(
PreferencesKeys.APP_CREDS_FAVOURITES
);
dispatch(
setFavouritesCredsCache(
credsFavourites?.favourites as FavouriteIdentifier[]
)
setAuthentication({
...authentication,
userName: userName.userName as string,
passcodeIsSet,
seedPhraseIsSet,
passwordIsSet,
})
);
};

Expand All @@ -222,7 +255,6 @@ const AppWrapper = (props: { children: ReactNode }) => {
isInitialized = await PreferencesStorage.get(
PreferencesKeys.APP_ALREADY_INIT
);
dispatch(setInitialized(isInitialized?.initialized as boolean));
} catch (e) {
await SecureStorage.delete(KeyStoreKeys.APP_PASSCODE);
await SecureStorage.delete(KeyStoreKeys.IDENTITY_ENTROPY);
Expand All @@ -246,9 +278,8 @@ const AppWrapper = (props: { children: ReactNode }) => {
}
dispatch(setPauseQueueIncomingRequest(true));

await loadDatabase().catch((e) => {
/* TODO: handle error */
});
await loadDatabase();
dispatch(setInitialized(isInitialized?.initialized as boolean));

Agent.agent.connections.onConnectionStateChanged((event) => {
return connectionStateChangedHandler(event, dispatch);
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/LockModal/LockModal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ion-modal.lock-modal {
flex-direction: column;
justify-content: end;
--height: auto;
--width: 100%;

.responsive-page-content {
justify-content: space-evenly;
Expand Down

0 comments on commit 3a83e28

Please sign in to comment.