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

Bug fix: locking when going to background #1480

Merged
merged 1 commit into from
Jun 13, 2023
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
4 changes: 2 additions & 2 deletions components/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const protectedNavigation = async (
attemptAdminLogin: true
});
} else {
if (disactivatePOS) await setPosStatus('inactive');
if (disactivatePOS) setPosStatus('inactive');
navigation.navigate(route);
}
};
Expand Down Expand Up @@ -113,7 +113,7 @@ const POSBadge = ({
<TouchableOpacity
onPress={async () => {
getOrders();
await setPosStatus('active');
setPosStatus('active');
}}
>
<POS stroke={themeColor('text')} width="34" height="34" />
Expand Down
9 changes: 5 additions & 4 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,14 +1002,15 @@ export default class SettingsStore {
});
};

public loginRequired = () =>
public loginRequired = () => this.loginMethodConfigured() && !this.loggedIn;

public loginMethodConfigured = () =>
this.settings &&
(this.settings.passphrase ||
this.settings.pin ||
this.isBiometryRequired()) &&
!this.loggedIn;
this.isBiometryConfigured());

public isBiometryRequired = () =>
public isBiometryConfigured = () =>
this.settings != null &&
this.settings.isBiometryEnabled &&
this.settings.supportedBiometryType !== undefined;
Expand Down
6 changes: 3 additions & 3 deletions views/Lockscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export default class Lockscreen extends React.Component<
const posEnabled: boolean =
(settings && settings.pos && settings.pos.squareEnabled) || false;

const isBiometryRequired = SettingsStore.isBiometryRequired();
const isBiometryConfigured = SettingsStore.isBiometryConfigured();

if (
isBiometryRequired &&
isBiometryConfigured &&
!attemptAdminLogin &&
!deletePin &&
!deleteDuressPin &&
Expand Down Expand Up @@ -184,7 +184,7 @@ export default class Lockscreen extends React.Component<
} else if (deleteDuressPin) {
this.deleteDuressPin();
} else {
await setPosStatus('inactive');
setPosStatus('inactive');
this.resetAuthenticationAttempts();
navigation.navigate('Wallet');
}
Expand Down
17 changes: 10 additions & 7 deletions views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
tabNavigatorState.routeNames[tabNavigatorState.index];
const defaultView =
this.props.SettingsStore.settings.display.defaultView;
if (defaultView === currentTabName) {

if (defaultView === currentTabName || currentTabName === 'POS') {
return false;
} else if (defaultView) {
tabNavigator.navigate(defaultView);
Expand Down Expand Up @@ -187,15 +188,17 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
const { settings } = SettingsStore;
const { loginBackground } = settings;

const loginRequired = SettingsStore.loginRequired();

if (nextAppState === 'background' && loginRequired && loginBackground) {
if (
nextAppState === 'background' &&
SettingsStore.loginMethodConfigured() &&
loginBackground
) {
// In case the lock screen is visible and a valid PIN is entered and home button is pressed,
// unauthorized access would be possible because the PIN is not cleared on next launch.
// By calling pop, the lock screen is closed to clear the PIN.
this.props.navigation.pop();
SettingsStore.setLoginStatus(false);
} else if (nextAppState === 'active' && loginRequired) {
} else if (nextAppState === 'active' && SettingsStore.loginRequired()) {
this.props.navigation.navigate('Lockscreen');
}
};
Expand All @@ -219,7 +222,7 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
if (posEnabled && posStatus === 'inactive' && loginRequired) {
navigation.navigate('Lockscreen');
} else if (posEnabled && posStatus === 'unselected') {
await setPosStatus('active');
setPosStatus('active');
if (!this.state.unlocked) {
this.startListeners();
this.setState({ unlocked: true });
Expand Down Expand Up @@ -350,7 +353,7 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
const error = NodeInfoStore.error || SettingsStore.error;
const { implementation, settings, loggedIn, connecting, posStatus } =
SettingsStore;
const loginRequired = SettingsStore.loginRequired();
const loginRequired = !settings || SettingsStore.loginRequired();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why require login if no settings here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents rendering potentially sensitive information when settings are not loaded yet and we don't know if login is required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested the behavior on a fresh install here? feel like this would break something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked it by clearing storage and running Zeus again, configured the node and it worked.


const squareEnabled: boolean =
(settings && settings.pos && settings.pos.squareEnabled) || false;
Expand Down