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

Refresh security settings on screen focus #2554

Merged
Merged
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
14 changes: 14 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import isEqual from 'lodash/isEqual';
import BackendUtils from '../utils/BackendUtils';
import { localeString } from '../utils/LocaleUtils';
import { doTorRequest, RequestMethod } from '../utils/TorUtils';
import { getSupportedBiometryType } from '../utils/BiometricUtils';

// lndhub
import LoginRequest from './../models/LoginRequest';
Expand Down Expand Up @@ -1821,6 +1822,19 @@ export default class SettingsStore {
this.settings.pin ||
this.isBiometryConfigured());

public checkBiometricsStatus = async () => {
const biometryType = await getSupportedBiometryType();
if (this.settings.supportedBiometryType !== biometryType) {
this.updateSettings({
supportedBiometryType: biometryType
});
}
return {
supportedBiometryType: biometryType,
isBiometryEnabled: this.settings.isBiometryEnabled
};
};

public isBiometryConfigured = () =>
this.settings != null &&
this.settings.isBiometryEnabled &&
Expand Down
22 changes: 16 additions & 6 deletions views/Settings/Security.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,26 @@ export default class Security extends React.Component<
isBiometryEnabled: undefined
};

async componentDidMount() {
componentDidMount() {
this.checkSettings();
this.props.navigation.addListener('focus', this.checkSettings);
}

componentWillUnmount() {
this.props.navigation.removeListener &&
this.props.navigation.removeListener('focus', this.checkSettings);
}

checkSettings = async () => {
const { SettingsStore } = this.props;
const { getSettings } = SettingsStore;
const settings = await getSettings();
const biometricsStatus = await SettingsStore.checkBiometricsStatus();
const settings = await SettingsStore.getSettings();

this.setState({
scramblePin: settings.scramblePin ?? true,
loginBackground: settings.loginBackground ?? false,
isBiometryEnabled: settings.isBiometryEnabled,
supportedBiometryType: settings.supportedBiometryType
isBiometryEnabled: biometricsStatus.isBiometryEnabled,
supportedBiometryType: biometricsStatus.supportedBiometryType
});

if (settings.pin) {
Expand Down Expand Up @@ -135,7 +145,7 @@ export default class Security extends React.Component<
displaySecurityItems: minPinItems
});
}
}
};

async handleBiometricsSwitchChange(value: boolean): Promise<void> {
const isVerified = await verifyBiometry(
Expand Down
Loading