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 3 commits 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 @@ -1217,6 +1217,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 @@ -1232,6 +1233,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 @@ -1475,6 +1477,13 @@ export default class SettingsStore {
...newSetting
};

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

await this.setSettings(newSettings);
// ensure we get the enhanced settings set
const settings = await this.getSettings(true);
Expand Down
6 changes: 3 additions & 3 deletions views/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ const Intro: React.FC<IntroProps> = (props) => {

updateSettings({ nodes }).then(() => {
setConnectingStatus(true);
navigation.navigate('Wallet', {
refresh: true
});
stores.settingsStore.triggerSettingsRefresh =
true;
navigation.navigate('Wallet');
});
} else {
setCreatingWallet(false);
Expand Down
7 changes: 3 additions & 4 deletions views/IntroSplash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,10 @@ export default class IntroSplash extends React.Component<
updateSettings({ nodes }).then(
() => {
setConnectingStatus(true);
SettingsStore.triggerSettingsRefresh =
true;
navigation.navigate(
'Wallet',
{
refresh: true
}
'Wallet'
);
}
);
Expand Down
16 changes: 13 additions & 3 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,8 +123,9 @@ export default class Lockscreen extends React.Component<
!deletePin &&
!deleteDuressPin
) {
// If POS is enabled and active, proceed without authentication
SettingsStore.setLoginStatus(true);
this.proceed('Wallet');
this.proceed('Wallet', undefined);
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
12 changes: 7 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,11 @@ export default class SendingLightning extends React.Component<
size: 25,
color: themeColor('background')
}}
onPress={() =>
navigation.popTo('Wallet', {
refresh: true
})
}
onPress={() => {
this.props.SettingsStore.triggerSettingsRefresh =
true;
navigation.popTo('Wallet');
}}
buttonStyle={{ height: 40 }}
titleStyle={{
color: themeColor('background')
Expand Down
5 changes: 3 additions & 2 deletions views/Settings/SeedRecovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ export default class SeedRecovery extends React.PureComponent<

if (nodes.length === 1) {
setConnectingStatus(true);
navigation.popTo('Wallet', { refresh: true });
SettingsStore.triggerSettingsRefresh = 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 @@ -124,7 +124,7 @@ export default class SetPassphrase extends React.Component<
passphrase: '',
isBiometryEnabled: false
});
navigation.popTo('Security', { refresh: true });
navigation.popTo('Security');
};

render() {
Expand Down
7 changes: 4 additions & 3 deletions views/Settings/WalletConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ export default class WalletConfiguration extends React.Component<
BackendUtils.disconnect();
}
setConnectingStatus(true);
navigation.popTo('Wallet', { refresh: true });
SettingsStore.triggerSettingsRefresh = true;
navigation.popTo('Wallet');
} else {
navigation.goBack();
}
Expand Down Expand Up @@ -601,7 +602,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 @@ -642,7 +643,7 @@ export default class WalletConfiguration extends React.Component<
setConnectingStatus(true);
setInitialStart(false);

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

createNewWallet = async (network: string = 'Mainnet') => {
Expand Down
6 changes: 3 additions & 3 deletions views/Settings/Wallets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ export default class Nodes extends React.Component<NodesProps, NodesState> {
}).then(() => {
setConnectingStatus(true);
setInitialStart(false);
navigation.popTo('Wallet', {
refresh: true
});
SettingsStore.triggerSettingsRefresh =
true;
navigation.popTo('Wallet');
});
}}
>
Expand Down
21 changes: 18 additions & 3 deletions views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,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.triggerSettingsRefresh
) {
this.getSettingsAndNavigate();
SettingsStore.posWasEnabled = false;
SettingsStore.triggerSettingsRefresh = 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