Skip to content

Commit

Permalink
Merge pull request #2660 from myxmaster/call-getSettingsAndNavigate-l…
Browse files Browse the repository at this point in the history
…ess-often

Call getSettingsAndNavigate less often
  • Loading branch information
kaloudis authored Feb 16, 2025
2 parents d801dd9 + 47a356e commit 532ab1e
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 38 deletions.
11 changes: 11 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,7 @@ export default class SettingsStore {
selectNodeOnStartup: false
};
@observable public posStatus: string = 'unselected';
@observable public posWasEnabled: boolean = false;
@observable public loading = false;
@observable public settingsUpdateInProgress: boolean = false;
@observable btcPayError: string | null;
Expand All @@ -1237,6 +1238,7 @@ export default class SettingsStore {
@observable implementation: Implementations;
@observable certVerification: boolean | undefined;
@observable public loggedIn = false;
@observable public triggerSettingsRefresh: boolean = false;
@observable public connecting = true;
@observable public lurkerExposed = false;
private lurkerTimeout: ReturnType<typeof setTimeout> | null = null;
Expand Down Expand Up @@ -1482,7 +1484,16 @@ export default class SettingsStore {
...newSetting
};

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

await this.setSettings(newSettings);
this.triggerSettingsRefresh = true;

// Update store's node properties from latest settings
this.updateNodeProperties(newSettings);
this.settingsUpdateInProgress = false;
Expand Down
4 changes: 1 addition & 3 deletions views/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ const Intro: React.FC<IntroProps> = (props) => {

updateSettings({ nodes }).then(() => {
setConnectingStatus(true);
navigation.navigate('Wallet', {
refresh: true
});
navigation.navigate('Wallet');
});
} else {
setCreatingWallet(false);
Expand Down
5 changes: 1 addition & 4 deletions views/IntroSplash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ export default class IntroSplash extends React.Component<
() => {
setConnectingStatus(true);
navigation.navigate(
'Wallet',
{
refresh: true
}
'Wallet'
);
}
);
Expand Down
14 changes: 12 additions & 2 deletions views/Lockscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ export default class Lockscreen extends React.Component<
proceed = (targetScreen?: string, navigationParams?: any) => {
const { SettingsStore, navigation } = this.props;
if (targetScreen) {
navigation.popTo(targetScreen, navigationParams);
navigation.popTo(targetScreen, { ...navigationParams });
} else if (
SettingsStore.settings.selectNodeOnStartup &&
SettingsStore.initialStart
) {
navigation.popTo('Wallets');
} else {
// Default login flow
// Resets navigation stack to previous screen
// to prevent back navigation to Lockscreen
SettingsStore.triggerSettingsRefresh = true;
navigation.pop();
}
};
Expand All @@ -119,6 +123,7 @@ export default class Lockscreen extends React.Component<
!deletePin &&
!deleteDuressPin
) {
// If POS is enabled and active, proceed without authentication
SettingsStore.setLoginStatus(true);
this.proceed('Wallet');
return;
Expand Down Expand Up @@ -253,7 +258,12 @@ 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();
const pendingNavigation = route.params?.pendingNavigation;
this.proceed(
Expand Down
10 changes: 5 additions & 5 deletions views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Row } from '../components/layout/Row';
import TransactionsStore from '../stores/TransactionsStore';
import LnurlPayStore from '../stores/LnurlPayStore';
import PaymentsStore from '../stores/PaymentsStore';
import SettingsStore from '../stores/SettingsStore';

import { localeString } from '../utils/LocaleUtils';
import { themeColor } from '../utils/ThemeUtils';
Expand All @@ -38,6 +39,7 @@ interface SendingLightningProps {
TransactionsStore: TransactionsStore;
LnurlPayStore: LnurlPayStore;
PaymentsStore: PaymentsStore;
SettingsStore: SettingsStore;
}

interface SendingLightningState {
Expand Down Expand Up @@ -503,11 +505,9 @@ export default class SendingLightning extends React.Component<
size: 25,
color: themeColor('background')
}}
onPress={() =>
navigation.popTo('Wallet', {
refresh: true
})
}
onPress={() => {
navigation.popTo('Wallet');
}}
buttonStyle={{ height: 40 }}
titleStyle={{
color: themeColor('background')
Expand Down
4 changes: 2 additions & 2 deletions views/Settings/SeedRecovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export default class SeedRecovery extends React.PureComponent<

if (nodes.length === 1) {
setConnectingStatus(true);
navigation.popTo('Wallet', { refresh: true });
navigation.popTo('Wallet');
} else {
navigation.popTo('Wallets', { refresh: true });
navigation.popTo('Wallets');
}
});
};
Expand Down
4 changes: 1 addition & 3 deletions views/Settings/SelectCurrency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ export default class SelectCurrency extends React.Component<
fiat: item.value
}).then(() => {
getSettings();
navigation.popTo('Currency', {
refresh: true
});
navigation.popTo('Currency');
});
}
}}
Expand Down
8 changes: 2 additions & 6 deletions views/Settings/SetDuressPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ export default class SetDuressPassphrase extends React.Component<

await updateSettings({ duressPassphrase }).then(() => {
getSettings();
navigation.popTo('Settings', {
refresh: true
});
navigation.popTo('Settings');
});
};

Expand All @@ -109,9 +107,7 @@ export default class SetDuressPassphrase extends React.Component<
const { updateSettings } = SettingsStore;

await updateSettings({ duressPassphrase: '' }).then(() => {
navigation.popTo('Settings', {
refresh: true
});
navigation.popTo('Settings');
});
};

Expand Down
4 changes: 1 addition & 3 deletions views/Settings/SetDuressPin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ export default class SetDuressPin extends React.Component<

await updateSettings({ duressPin }).then(() => {
getSettings();
navigation.popTo('Settings', {
refresh: true
});
navigation.popTo('Settings');
});
};

Expand Down
2 changes: 1 addition & 1 deletion views/Settings/SetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default class SetPassphrase extends React.Component<
passphrase: '',
isBiometryEnabled: false
});
navigation.popTo('Security', { refresh: true });
navigation.popTo('Security');
};

render() {
Expand Down
6 changes: 3 additions & 3 deletions views/Settings/WalletConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ export default class WalletConfiguration extends React.Component<
BackendUtils.disconnect();
}
setConnectingStatus(true);
navigation.popTo('Wallet', { refresh: true });
navigation.popTo('Wallet');
} else {
navigation.goBack();
}
Expand Down Expand Up @@ -640,7 +640,7 @@ export default class WalletConfiguration extends React.Component<
if (newNodes.length === 0) {
navigation.navigate('IntroSplash');
} else {
navigation.popTo('Wallets', { refresh: true });
navigation.popTo('Wallets');
}
});
};
Expand Down Expand Up @@ -681,7 +681,7 @@ export default class WalletConfiguration extends React.Component<
setConnectingStatus(true);
setInitialStart(false);

navigation.popTo('Wallet', { refresh: true });
navigation.popTo('Wallet');
};

createNewWallet = async (network: string = 'Mainnet') => {
Expand Down
4 changes: 1 addition & 3 deletions views/Settings/Wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ export default class Nodes extends React.Component<NodesProps, NodesState> {
}).then(() => {
setConnectingStatus(true);
setInitialStart(false);
navigation.popTo('Wallet', {
refresh: true
});
navigation.popTo('Wallet');
});
}}
>
Expand Down
25 changes: 22 additions & 3 deletions views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,22 @@ 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.triggerSettingsRefresh
) {
// Trigger getSettingsAndNavigate() in three scenarios:
// 1. On initial wallet load to ensure proper initialization
// 2. When exiting POS to handle potential lockscreen navigation
// 3. When any settings are updated to refresh the UI state
this.getSettingsAndNavigate();
SettingsStore.posWasEnabled = false;
SettingsStore.triggerSettingsRefresh = false;
}
};

private handleBlur = () => this.backPressSubscription?.remove();
Expand Down Expand Up @@ -238,8 +253,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

0 comments on commit 532ab1e

Please sign in to comment.