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

Call getSettingsAndNavigate less often #2660

Open
wants to merge 1 commit into
base: master
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
9 changes: 9 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ export default class SettingsStore {
selectNodeOnStartup: false
};
@observable public posStatus: string = 'unselected';
@observable public posWasEnabled: boolean = false;
@observable public loading = false;
@observable btcPayError: string | null;
@observable sponsorsError: string | null;
Expand All @@ -1225,6 +1226,7 @@ export default class SettingsStore {
@observable implementation: Implementations;
@observable certVerification: boolean | undefined;
@observable public loggedIn = false;
@observable public comingFromLockscreen: boolean = false;
@observable public connecting = true;
@observable public lurkerExposed = false;
// LNDHub
Expand Down Expand Up @@ -1661,6 +1663,13 @@ export default class SettingsStore {
...newSetting
};

if (
newSetting.pos?.posEnabled &&
newSetting.pos.posEnabled !== PosEnabled.Disabled
) {
this.posWasEnabled = true;
}

await this.setSettings(JSON.stringify(newSettings));
// ensure we get the enhanced settings set
const settings = await this.getSettings(true);
Expand Down
8 changes: 7 additions & 1 deletion views/Lockscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,14 @@ export default class Lockscreen extends React.Component<
} else if (deleteDuressPin) {
this.deleteDuressPin();
} else {
setPosStatus('inactive');
if (
(SettingsStore.settings?.pos?.posEnabled ||
PosEnabled.Disabled) !== PosEnabled.Disabled
) {
setPosStatus('inactive');
}
this.resetAuthenticationAttempts();
SettingsStore.comingFromLockscreen = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Think I'd rather just pass in a parameter into the proceed call below than add another var to keep track of in the store.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I tried that, but while navigation.navigate() works fine with parameters, navigation.pop() does not (or I don't know how). And we need to keep using pop() to maintain proper navigation stack management (we don't want users to navigate back to Lockscreen).

this.proceed();
}
} else if (
Expand Down
21 changes: 18 additions & 3 deletions views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,18 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
'hardwareBackPress',
this.handleBackButton.bind(this)
);
this.getSettingsAndNavigate();

const { SettingsStore } = this.props;

if (
this.state.initialLoad ||
SettingsStore.posWasEnabled ||
SettingsStore.comingFromLockscreen
) {
this.getSettingsAndNavigate();
SettingsStore.posWasEnabled = false;
SettingsStore.comingFromLockscreen = false;
}
};

private handleBlur = () => this.backPressSubscription?.remove();
Expand Down Expand Up @@ -235,8 +246,12 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
loginBackground
) {
SettingsStore.setLoginStatus(false);
} else if (nextAppState === 'active' && SettingsStore.loginRequired()) {
this.props.navigation.navigate('Lockscreen');
} else if (nextAppState === 'active') {
if (SettingsStore.loginRequired()) {
this.props.navigation.navigate('Lockscreen');
} else {
this.getSettingsAndNavigate();
}
}
};

Expand Down
Loading