From f2291ddc9d0c8e26dda47ac6fe8e2260ad3d8fa2 Mon Sep 17 00:00:00 2001 From: Philipp Walter Date: Wed, 26 Feb 2025 12:43:37 +0100 Subject: [PATCH] refactor(onboarding): move default widgets to initial state --- src/screens/Wallets/MainOnboarding.tsx | 8 -------- src/screens/Wallets/index.tsx | 5 +---- src/store/reselect/widgets.ts | 4 ---- src/store/slices/widgets.ts | 7 ++++++- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/screens/Wallets/MainOnboarding.tsx b/src/screens/Wallets/MainOnboarding.tsx index ddcd95c15..ec6a94826 100644 --- a/src/screens/Wallets/MainOnboarding.tsx +++ b/src/screens/Wallets/MainOnboarding.tsx @@ -5,9 +5,7 @@ import { StyleProp, ViewStyle } from 'react-native'; import WalletOnboarding from '../../components/WalletOnboarding'; import { useAppDispatch } from '../../hooks/redux'; import { updateSettings } from '../../store/slices/settings'; -import { saveWidget } from '../../store/slices/widgets'; import { Display } from '../../styles/text'; -import { getDefaultOptions } from '../../utils/widgets'; const MainOnboarding = ({ style, @@ -16,14 +14,8 @@ const MainOnboarding = ({ }): ReactElement => { const dispatch = useAppDispatch(); const { t } = useTranslation('onboarding'); - const priceOptions = getDefaultOptions('price'); - const newsOptions = getDefaultOptions('news'); - const blocksOptions = getDefaultOptions('blocks'); const onHideOnboarding = (): void => { - dispatch(saveWidget({ id: 'price', options: priceOptions })); - dispatch(saveWidget({ id: 'news', options: newsOptions })); - dispatch(saveWidget({ id: 'blocks', options: blocksOptions })); dispatch(updateSettings({ hideOnboardingMessage: true })); }; diff --git a/src/screens/Wallets/index.tsx b/src/screens/Wallets/index.tsx index 20457310b..002e5b329 100644 --- a/src/screens/Wallets/index.tsx +++ b/src/screens/Wallets/index.tsx @@ -26,7 +26,6 @@ import { ignoresHideBalanceToastSelector, scanAllAddressesTimestampSelector, } from '../../store/reselect/user'; -import { hasWidgetsSelector } from '../../store/reselect/widgets'; import { updateSettings } from '../../store/slices/settings'; import { ignoreHideBalanceToast, updateUser } from '../../store/slices/user'; import { View as ThemedView } from '../../styles/components'; @@ -57,7 +56,6 @@ const Wallets = ({ onFocus }: Props): ReactElement => { scanAllAddressesTimestampSelector, ); const hideOnboardingSetting = useAppSelector(hideOnboardingMessageSelector); - const hasWidgets = useAppSelector(hasWidgetsSelector); const showWidgets = useAppSelector(showWidgetsSelector); const insets = useSafeAreaInsets(); const { t } = useTranslation('wallet'); @@ -94,8 +92,7 @@ const Wallets = ({ onFocus }: Props): ReactElement => { setRefreshing(false); }; - const hideOnboarding = - hideOnboardingSetting || totalBalance > 0 || hasWidgets; + const hideOnboarding = hideOnboardingSetting || totalBalance > 0; return ( diff --git a/src/store/reselect/widgets.ts b/src/store/reselect/widgets.ts index 3ec741eba..9e89da15f 100644 --- a/src/store/reselect/widgets.ts +++ b/src/store/reselect/widgets.ts @@ -23,10 +23,6 @@ export const widgetsOrderSelector = createSelector( (widgets) => widgets.sortOrder, ); -export const hasWidgetsSelector = (state: RootState): boolean => { - return Object.keys(state.widgets.widgets).length > 0; -}; - export const onboardedWidgetsSelector = (state: RootState): boolean => { return state.widgets.onboardedWidgets; }; diff --git a/src/store/slices/widgets.ts b/src/store/slices/widgets.ts index abd9153d1..87303793f 100644 --- a/src/store/slices/widgets.ts +++ b/src/store/slices/widgets.ts @@ -1,4 +1,5 @@ import { PayloadAction, createSlice } from '@reduxjs/toolkit'; +import { getDefaultOptions } from '../../utils/widgets'; import { TWidgets } from '../types/widgets'; export type TWidgetsState = { @@ -8,7 +9,11 @@ export type TWidgetsState = { }; export const initialWidgetsState: TWidgetsState = { - widgets: {}, + widgets: { + price: getDefaultOptions('price'), + news: getDefaultOptions('news'), + blocks: getDefaultOptions('blocks'), + }, onboardedWidgets: false, sortOrder: [], };