Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Add warning if trying to enable biometrics when it's off in phone settings #972

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,11 @@
"security": {
"title": "Security",
"biometry": "Biometric authentication",
"biometricsalert": {
"message": "In order to use biometrics you need to enable this in your settings. Would you like to do this?",
"ok": "Go to settings",
"cancel": "Setup later"
},
"changepin": {
"title": "Change passcode",
"createpasscode": "Create new passcode",
Expand Down
16 changes: 16 additions & 0 deletions src/ui/pages/Menu/components/Settings/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ describe("Settings page", () => {
fireEvent.click(getByTestId("settings-item-0"));
});

await waitFor(() => {
expect(
getByText(
EN_TRANSLATIONS.tabs.menu.tab.settings.sections.security
.biometricsalert.message
)
);
});

fireEvent.click(
getByText(
EN_TRANSLATIONS.tabs.menu.tab.settings.sections.security.biometricsalert
.ok
)
);

await waitFor(() => {
expect(openSettingMock).toBeCalledTimes(1);
});
Expand Down
96 changes: 56 additions & 40 deletions src/ui/pages/Menu/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
import { BiometryErrorType } from "@aparajita/capacitor-biometric-auth";
import { Browser } from "@capacitor/browser";
import { IonCard, IonList, IonToggle } from "@ionic/react";
import {
lockClosedOutline,
AndroidSettings,
IOSSettings,
NativeSettings,
} from "capacitor-native-settings";
import {
checkboxOutline,
fingerPrintOutline,
informationCircleOutline,
keyOutline,
logoDiscord,
libraryOutline,
checkboxOutline,
layersOutline,
fingerPrintOutline,
libraryOutline,
lockClosedOutline,
logoDiscord,
} from "ionicons/icons";
import "./Settings.scss";
import { useRef, useState } from "react";
import { useSelector } from "react-redux";
import { useEffect, useRef, useState } from "react";
import {
NativeSettings,
AndroidSettings,
IOSSettings,
} from "capacitor-native-settings";
import {
BiometryError,
BiometryErrorType,
} from "@aparajita/capacitor-biometric-auth";
import { Browser } from "@capacitor/browser";
import { i18n } from "../../../../../i18n";
import pJson from "../../../../../../package.json";
import { OptionIndex, OptionProps, SettingsProps } from "./Settings.types";
import { Agent } from "../../../../../core/agent/agent";
import { MiscRecordId } from "../../../../../core/agent/agent.types";
import { BasicRecord } from "../../../../../core/agent/records";
import { i18n } from "../../../../../i18n";
import { useAppDispatch } from "../../../../../store/hooks";
import {
getBiometricsCacheCache,
setEnableBiometricsCache,
} from "../../../../../store/reducers/biometricsCache";
import { Agent } from "../../../../../core/agent/agent";
import { useBiometricAuth } from "../../../../hooks/useBiometricsHook";
import { ChangePin } from "./components/ChangePin";
import { SettingsItem } from "./components/SettingsItem";
import { SubMenuKey } from "../../Menu.types";
import { Alert } from "../../../../components/Alert";
import { Verification } from "../../../../components/Verification";
import {
DISCORD_LINK,
DOCUMENTATION_LINK,
} from "../../../../globals/constants";
import { Verification } from "../../../../components/Verification";
import { useBiometricAuth } from "../../../../hooks/useBiometricsHook";
import { showError } from "../../../../utils/error";
import { SubMenuKey } from "../../Menu.types";
import { ChangePin } from "./components/ChangePin";
import { SettingsItem } from "./components/SettingsItem";
import "./Settings.scss";
import { OptionIndex, OptionProps, SettingsProps } from "./Settings.types";
import { usePrivacyScreen } from "../../../../hooks/privacyScreenHook";

const Settings = ({ switchView }: SettingsProps) => {
const dispatch = useAppDispatch();
const biometricsCache = useSelector(getBiometricsCacheCache);
const [option, setOption] = useState<number | null>(null);
const { biometricInfo, handleBiometricAuth } = useBiometricAuth();
const inBiometricSetup = useRef(false);
const [verifyIsOpen, setVerifyIsOpen] = useState(false);
const [changePinIsOpen, setChangePinIsOpen] = useState(false);
const [openBiometricAlert, setOpenBiometricAlert] = useState(false);
const { enablePrivacy, disablePrivacy } = usePrivacyScreen(false);

const securityItems: OptionProps[] = [
{
Expand Down Expand Up @@ -125,8 +125,6 @@ const Settings = ({ switchView }: SettingsProps) => {
};

const handleBiometricUpdate = () => {
inBiometricSetup.current = false;

if (biometricsCache.enabled) {
handleToggleBiometricAuth();
return;
Expand All @@ -136,13 +134,7 @@ const Settings = ({ switchView }: SettingsProps) => {
!biometricInfo?.strongBiometryIsAvailable &&
biometricInfo?.code === BiometryErrorType.biometryNotEnrolled
) {
NativeSettings.open({
optionAndroid: AndroidSettings.Security,
optionIOS: IOSSettings.TouchIdPasscode,
}).then((result) => {
inBiometricSetup.current = result.status;
});

setOpenBiometricAlert(true);
return;
}

Expand All @@ -151,18 +143,21 @@ const Settings = ({ switchView }: SettingsProps) => {

const biometricAuth = async () => {
try {
await disablePrivacy();
const result = await handleBiometricAuth();
await enablePrivacy();
if (result === true) handleToggleBiometricAuth();
} catch (e) {
showError("Unable to enable/disable biometric auth", e, dispatch);
}
};

useEffect(() => {
if (biometricInfo?.strongBiometryIsAvailable && inBiometricSetup.current) {
handleBiometricUpdate();
}
}, [biometricInfo]);
const openSetting = () => {
NativeSettings.open({
optionAndroid: AndroidSettings.Security,
optionIOS: IOSSettings.TouchIdPasscode,
});
};

const handleChangePin = () => {
setVerifyIsOpen(true);
Expand Down Expand Up @@ -220,6 +215,10 @@ const Settings = ({ switchView }: SettingsProps) => {
setOption(null);
};

const closeAlert = () => {
setOpenBiometricAlert(false);
};

return (
<>
<div className="settings-section-title">
Expand Down Expand Up @@ -269,6 +268,23 @@ const Settings = ({ switchView }: SettingsProps) => {
isOpen={changePinIsOpen}
setIsOpen={setChangePinIsOpen}
/>
<Alert
isOpen={openBiometricAlert}
setIsOpen={setOpenBiometricAlert}
dataTestId="biometric-enable-alert"
headerText={i18n.t(
"tabs.menu.tab.settings.sections.security.biometricsalert.message"
)}
confirmButtonText={`${i18n.t(
"tabs.menu.tab.settings.sections.security.biometricsalert.ok"
)}`}
cancelButtonText={`${i18n.t(
"tabs.menu.tab.settings.sections.security.biometricsalert.cancel"
)}`}
actionConfirm={openSetting}
actionCancel={closeAlert}
actionDismiss={closeAlert}
/>
</>
);
};
Expand Down
Loading