Skip to content

Commit

Permalink
fix(restore): backup intro screens seen (#2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr authored Jan 11, 2025
1 parent 41f33e8 commit ed3ad40
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 79 deletions.
2 changes: 1 addition & 1 deletion __tests__/todos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Todos selector', () => {

it('should not return backupSeedPhraseTodo if backup is verified', () => {
const state = cloneDeep(s);
state.user.backupVerified = true;
state.settings.backupVerified = true;

expect(todosFullSelector(state)).not.toEqual(
expect.arrayContaining([backupSeedPhraseTodo]),
Expand Down
4 changes: 2 additions & 2 deletions src/components/Suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import SuggestionCard from './SuggestionCard';
import { ITodo, TTodoType } from '../store/types/todos';
import { channelsNotificationsShown, hideTodo } from '../store/slices/todos';
import { showBottomSheet } from '../store/utils/ui';
import { pinSelector } from '../store/reselect/settings';
import {
pinSelector,
quickpayIntroSeenSelector,
transferIntroSeenSelector,
} from '../store/reselect/user';
} from '../store/reselect/settings';
import {
newChannelsNotificationsSelector,
todosFullSelector,
Expand Down
10 changes: 5 additions & 5 deletions src/navigation/bottom-sheet/QuickPayPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
useSnapPoints,
} from '../../hooks/bottomSheet';
import { closeSheet } from '../../store/slices/ui';
import { updateUser } from '../../store/slices/user';
import { updateSettings } from '../../store/slices/settings';
import { showBottomSheet } from '../../store/utils/ui';
import { viewControllersSelector } from '../../store/reselect/ui';
import { quickpayIntroSeenSelector } from '../../store/reselect/user';
import { quickpayIntroSeenSelector } from '../../store/reselect/settings';
import { RootNavigationProp } from '../types';

const imageSrc = require('../../assets/illustrations/fast-forward.png');
Expand Down Expand Up @@ -72,12 +72,12 @@ const QuickPayPrompt = ({ enabled }: { enabled: boolean }): ReactElement => {

const onMore = (): void => {
navigation.navigate('Settings', { screen: 'QuickpaySettings' });
dispatch(updateUser({ quickpayIntroSeen: true }));
dispatch(updateSettings({ quickpayIntroSeen: true }));
dispatch(closeSheet('quickPay'));
};

const onDismiss = (): void => {
dispatch(updateUser({ quickpayIntroSeen: true }));
dispatch(updateSettings({ quickpayIntroSeen: true }));
dispatch(closeSheet('quickPay'));
};

Expand All @@ -86,7 +86,7 @@ const QuickPayPrompt = ({ enabled }: { enabled: boolean }): ReactElement => {
view="quickPay"
snapPoints={snapPoints}
onClose={(): void => {
dispatch(updateUser({ quickpayIntroSeen: true }));
dispatch(updateSettings({ quickpayIntroSeen: true }));
}}>
<BottomSheetScreen
navTitle={t('quickpay.nav_title')}
Expand Down
6 changes: 2 additions & 4 deletions src/screens/Activity/ActivitySavings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import ActivityList from './ActivityList';
import { useBalance } from '../../hooks/wallet';
import { useAppSelector } from '../../hooks/redux';
import { EActivityType } from '../../store/types/activity';
import {
isGeoBlockedSelector,
spendingIntroSeenSelector,
} from '../../store/reselect/user';
import { isGeoBlockedSelector } from '../../store/reselect/user';
import { spendingIntroSeenSelector } from '../../store/reselect/settings';
import { activityItemsSelector } from '../../store/reselect/activity';
import { WalletScreenProps } from '../../navigation/types';

Expand Down
2 changes: 1 addition & 1 deletion src/screens/Activity/ActivitySpending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useBalance } from '../../hooks/wallet';
import { useAppSelector } from '../../hooks/redux';
import { EActivityType } from '../../store/types/activity';
import { spendingOnboardingSelector } from '../../store/reselect/aggregations';
import { savingsIntroSeenSelector } from '../../store/reselect/user';
import { savingsIntroSeenSelector } from '../../store/reselect/settings';
import { WalletScreenProps } from '../../navigation/types';

const imageSrc = require('../../assets/illustrations/coin-stack-x-2.png');
Expand Down
5 changes: 3 additions & 2 deletions src/screens/Onboarding/RestoreFromSeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TextInput,
View as ThemedView,
} from '../../styles/components';
import { BodyM, BodyS, Display } from '../../styles/text';
import NavigationHeader from '../../components/NavigationHeader';
import SafeAreaInset from '../../components/SafeAreaInset';
import SeedInput from '../../components/SeedInput';
Expand All @@ -31,8 +32,8 @@ import VerticalShadow from '../../components/VerticalShadow';
import Button from '../../components/buttons/Button';
import { useAppDispatch } from '../../hooks/redux';
import { OnboardingStackScreenProps } from '../../navigation/types';
import { updateUser, verifyBackup } from '../../store/slices/user';
import { BodyM, BodyS, Display } from '../../styles/text';
import { updateUser } from '../../store/slices/user';
import { verifyBackup } from '../../store/slices/settings';
import { validateMnemonic } from '../../utils/wallet';

const RestoreFromSeed = ({
Expand Down
16 changes: 7 additions & 9 deletions src/screens/Settings/Backup/BackupPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import { __E2E__ } from '../../../constants/env';
import { Display } from '../../../styles/text';
import BottomSheetWrapper from '../../../components/BottomSheetWrapper';
import BottomSheetScreen from '../../../components/BottomSheetScreen';
import { closeSheet } from '../../../store/slices/ui';
import { ignoreBackup } from '../../../store/slices/user';
import { showBottomSheet } from '../../../store/utils/ui';
import { useBalance } from '../../../hooks/wallet';
import { useAppDispatch, useAppSelector } from '../../../hooks/redux';
import { objectKeys } from '../../../utils/objectKeys';
import { viewControllersSelector } from '../../../store/reselect/ui';
import {
useBottomSheetBackPress,
useSnapPoints,
} from '../../../hooks/bottomSheet';
import {
backupVerifiedSelector,
ignoreBackupTimestampSelector,
} from '../../../store/reselect/user';
import { closeSheet } from '../../../store/slices/ui';
import { ignoreBackup } from '../../../store/slices/user';
import { showBottomSheet } from '../../../store/utils/ui';
import { objectKeys } from '../../../utils/objectKeys';
import { viewControllersSelector } from '../../../store/reselect/ui';
import { ignoreBackupTimestampSelector } from '../../../store/reselect/user';
import { backupVerifiedSelector } from '../../../store/reselect/settings';

const imageSrc = require('../../../assets/illustrations/safe.png');

Expand Down
2 changes: 1 addition & 1 deletion src/screens/Settings/Backup/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SafeAreaInset from '../../../components/SafeAreaInset';
import GradientView from '../../../components/GradientView';
import Button from '../../../components/buttons/Button';
import { useAppDispatch } from '../../../hooks/redux';
import { verifyBackup } from '../../../store/slices/user';
import { verifyBackup } from '../../../store/slices/settings';
import { BackupScreenProps } from '../../../navigation/types';

const imageSrc = require('../../../assets/illustrations/check.png');
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Settings/General/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAppSelector } from '../../../hooks/redux';
import type { SettingsScreenProps } from '../../../navigation/types';
import { EUnit } from '../../../store/types/wallet';
import { lastUsedTagsSelector } from '../../../store/reselect/metadata';
import { quickpayIntroSeenSelector } from '../../../store/reselect/user';
import { quickpayIntroSeenSelector } from '../../../store/reselect/settings';
import {
unitSelector,
selectedCurrencySelector,
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Settings/Quickpay/QuickpayIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Display } from '../../../styles/text';
import OnboardingScreen from '../../../components/OnboardingScreen';
import { useAppDispatch } from '../../../hooks/redux';
import { updateUser } from '../../../store/slices/user';
import { updateSettings } from '../../../store/slices/settings';
import type { SettingsScreenProps } from '../../../navigation/types';

const imageSrc = require('../../../assets/illustrations/fast-forward.png');
Expand All @@ -31,7 +31,7 @@ const QuickpayIntro = ({
buttonText={t('continue')}
testID="QuickpayIntro"
onButtonPress={(): void => {
dispatch(updateUser({ quickpayIntroSeen: true }));
dispatch(updateSettings({ quickpayIntroSeen: true }));
navigation.navigate('QuickpaySettings');
}}
/>
Expand Down
6 changes: 2 additions & 4 deletions src/screens/Transfer/Funding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import RectangleButton from '../../components/buttons/RectangleButton';
import SafeAreaInset from '../../components/SafeAreaInset';
import NavigationHeader from '../../components/NavigationHeader';
import { useBalance } from '../../hooks/wallet';
import {
isGeoBlockedSelector,
spendingIntroSeenSelector,
} from '../../store/reselect/user';
import { isGeoBlockedSelector } from '../../store/reselect/user';
import { spendingIntroSeenSelector } from '../../store/reselect/settings';
import { TRANSACTION_DEFAULTS } from '../../utils/wallet/constants';
import { showBottomSheet } from '../../store/utils/ui';
import type { TransferScreenProps } from '../../navigation/types';
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Transfer/SavingsIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Display } from '../../styles/text';
import OnboardingScreen from '../../components/OnboardingScreen';
import { useAppDispatch } from '../../hooks/redux';
import { updateUser } from '../../store/slices/user';
import { updateSettings } from '../../store/slices/settings';
import type { TransferScreenProps } from '../../navigation/types';

const imageSrc = require('../../assets/illustrations/piggybank.png');
Expand All @@ -17,7 +17,7 @@ const SavingsIntro = ({

const onContinue = (): void => {
navigation.navigate('Availability');
dispatch(updateUser({ savingsIntroSeen: true }));
dispatch(updateSettings({ savingsIntroSeen: true }));
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Transfer/SpendingIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Display } from '../../styles/text';
import OnboardingScreen from '../../components/OnboardingScreen';
import { useAppDispatch } from '../../hooks/redux';
import { updateUser } from '../../store/slices/user';
import { updateSettings } from '../../store/slices/settings';
import type { TransferScreenProps } from '../../navigation/types';

const imageSrc = require('../../assets/illustrations/coin-stack-x.png');
Expand All @@ -17,7 +17,7 @@ const SpendingIntro = ({

const onContinue = (): void => {
navigation.navigate('SpendingAmount');
dispatch(updateUser({ spendingIntroSeen: true }));
dispatch(updateSettings({ spendingIntroSeen: true }));
};

return (
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Transfer/TransferIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Display } from '../../styles/text';
import OnboardingScreen from '../../components/OnboardingScreen';
import { useAppDispatch } from '../../hooks/redux';
import { updateUser } from '../../store/slices/user';
import { updateSettings } from '../../store/slices/settings';
import type { TransferScreenProps } from '../../navigation/types';

const imageSrc = require('../../assets/illustrations/lightning.png');
Expand All @@ -17,7 +17,7 @@ const TransferIntro = ({

const onContinue = (): void => {
navigation.navigate('Funding');
dispatch(updateUser({ transferIntroSeen: true }));
dispatch(updateSettings({ transferIntroSeen: true }));
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const persistConfig = {
key: 'root',
storage: reduxStorage,
// increase version after store shape changes
version: 49,
version: 50,
stateReconciler: autoMergeLevel2,
blacklist: ['receive', 'ui'],
migrate: createMigrate(migrations, { debug: __ENABLE_MIGRATION_DEBUG__ }),
Expand Down
13 changes: 13 additions & 0 deletions src/store/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ const migrations = {

return state;
},
50: (state): PersistedState => {
return {
...state,
settings: {
...state.settings,
backupVerified: state.user.backupVerified,
quickpayIntroSeen: state.user.quickpayIntroSeen,
transferIntroSeen: state.user.transferIntroSeen,
spendingIntroSeen: state.user.spendingIntroSeen,
savingsIntroSeen: state.user.savingsIntroSeen,
},
};
},
};

export default migrations;
16 changes: 16 additions & 0 deletions src/store/reselect/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import {
} from '../types/settings';

export const settingsSelector = (state: RootState): TSettings => state.settings;

const customElectrumPeersState = (state: RootState): TCustomElectrumPeers => {
return state.settings.customElectrumPeers;
};

export const backupVerifiedSelector = (state: RootState): boolean => {
return state.settings.backupVerified;
};
export const selectedCurrencySelector = (state: RootState): string => {
return state.settings.selectedCurrency;
};
Expand Down Expand Up @@ -118,6 +122,18 @@ export const denominationSelector = (state: RootState): EDenomination => {
export const webRelaySelector = (state: RootState): string => {
return state.settings.webRelay;
};
export const quickpayIntroSeenSelector = (state: RootState): boolean => {
return state.settings.quickpayIntroSeen;
};
export const transferIntroSeenSelector = (state: RootState): boolean => {
return state.settings.transferIntroSeen;
};
export const spendingIntroSeenSelector = (state: RootState): boolean => {
return state.settings.spendingIntroSeen;
};
export const savingsIntroSeenSelector = (state: RootState): boolean => {
return state.settings.savingsIntroSeen;
};

/**
* Returns custom Electrum peers for a given network.
Expand Down
7 changes: 2 additions & 5 deletions src/store/reselect/todos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ import {
btFailedTodo,
inviteTodo,
} from '../shapes/todos';
import {
backupVerifiedSelector,
startCoopCloseTimestampSelector,
} from './user';
import { pinSelector } from './settings';
import { startCoopCloseTimestampSelector } from './user';
import { backupVerifiedSelector, pinSelector } from './settings';
import { onboardingProfileStepSelector } from './slashtags';
import { closedChannelsSelector, openChannelsSelector } from './lightning';
import { blocktankPaidOrdersFullSelector } from './blocktank';
Expand Down
21 changes: 0 additions & 21 deletions src/store/reselect/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ export const isGeoBlockedSelector = createSelector(
(user): boolean => user.isGeoBlocked ?? false,
);

export const backupVerifiedSelector = createSelector(
[userState],
(user): boolean => user.backupVerified,
);

export const ignoreBackupTimestampSelector = createSelector(
[userState],
(user): number => user.ignoreBackupTimestamp,
Expand All @@ -24,10 +19,6 @@ export const lightningSettingUpStepSelector = createSelector(
(user): number => user.lightningSettingUpStep,
);

export const quickpayIntroSeenSelector = (state: RootState): boolean => {
return state.user.quickpayIntroSeen;
};

export const requiresRemoteRestoreSelector = createSelector(
[userState],
(user): boolean => user.requiresRemoteRestore,
Expand Down Expand Up @@ -67,15 +58,3 @@ export const scanAllAddressesTimestampSelector = createSelector(
[userState],
(user): number => user.scanAllAddressesTimestamp,
);

export const transferIntroSeenSelector = (state: RootState): boolean => {
return state.user.transferIntroSeen;
};

export const spendingIntroSeenSelector = (state: RootState): boolean => {
return state.user.spendingIntroSeen;
};

export const savingsIntroSeenSelector = (state: RootState): boolean => {
return state.user.savingsIntroSeen;
};
5 changes: 5 additions & 0 deletions src/store/shapes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const defaultReceivePreference = [
];

export const initialSettingsState: TSettings = {
backupVerified: false,
enableAutoReadClipboard: false,
enableSendAmountWarning: false,
enableSwipeToHideBalance: true,
Expand Down Expand Up @@ -107,6 +108,10 @@ export const initialSettingsState: TSettings = {
treasureChests: [],
orangeTickets: [],
webRelay: __WEB_RELAY__,
quickpayIntroSeen: false,
transferIntroSeen: false,
spendingIntroSeen: false,
savingsIntroSeen: false,
};

export const getDefaultSettingsShape = (): TSettings => {
Expand Down
Loading

0 comments on commit ed3ad40

Please sign in to comment.