Skip to content

Commit

Permalink
Fingerprint auth fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg committed Dec 30, 2020
1 parent 9d90b65 commit ae6acee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ android {
applicationId MYAPP_APP_ID
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 65
versionCode 66
versionName "0.1-alpha"
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
Expand Down
38 changes: 9 additions & 29 deletions src/hooks/useFingerprintAuth.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { useState, useEffect } from "react";
import { convertBitcoinToFiat, unitToSatoshi, valueBitcoinFromFiat, valueBitcoin, BitcoinUnits } from "../utils/bitcoin-units";
import { useEffect } from "react";
import { useStoreState, useStoreActions } from "../state/store";

import exprEval from "expr-eval";
import { countCharInString } from "../utils";
import { AppStateStatus, AppState } from "react-native";
import { useNavigation } from "@react-navigation/native";

export default function useFingerprintAuth(callback: () => void) {
export default function useFingerprintAuth(callback: () => void, forceEnabled: boolean = false) {
const fingerprintAvailable = useStoreState((store) => store.security.fingerprintAvailable);
const fingerprintEnabled = useStoreState((store) => store.security.fingerprintEnabled);
const fingerprintStartScan = useStoreActions((store) => store.security.fingerprintStartScan);
const fingerprintStopScan = useStoreActions((store) => store.security.fingerprintStopScan);

Expand All @@ -21,29 +16,14 @@ export default function useFingerprintAuth(callback: () => void) {
};

useEffect(() => {
if (fingerprintAvailable) {
// Workaround a bug where leaving foreground would
// cause fingerprint scanning to not respond
// TODO check this code
const handler = (status: AppStateStatus) => {
if (status === "background") {
fingerprintStopScan();
}
else if (status === "active") {
// tslint:disable-next-line: no-floating-promises
startScan();
}
};
AppState.addEventListener("change", handler);
// tslint:disable-next-line: no-floating-promises
if (fingerprintAvailable && (fingerprintEnabled || forceEnabled)) {
startScan();

return () => {
fingerprintStopScan();
AppState.removeEventListener("change", handler);
}
}
}, [fingerprintAvailable]);
return () => {
fingerprintStopScan();
// AppState.removeEventListener("change", handler);
}
}, [fingerprintAvailable, fingerprintEnabled, forceEnabled]);

return () => {
// tslint:disable-next-line: no-floating-promises
Expand Down
4 changes: 2 additions & 2 deletions src/windows/Settings/ChangeFingerprintSettingsAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default function ChangeFingerprintSettingsAuth() {
const setFingerprintEnabled = useStoreActions((store) => store.security.setFingerprintEnabled);
const fingerPrintEnabled = useStoreState((store) => store.security.fingerprintEnabled);
const startScan = useFingerprintAuth(async () => {
await setFingerprintEnabled(!fingerPrintEnabled);
navigation.goBack();
});
await setFingerprintEnabled(!fingerPrintEnabled);
}, true);

return (
<Container>
Expand Down

0 comments on commit ae6acee

Please sign in to comment.