Skip to content

Commit d1be101

Browse files
authored
refactor(onboarding): move default widgets to initial state (#2494)
1 parent f5a581f commit d1be101

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

src/screens/Wallets/MainOnboarding.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { StyleProp, ViewStyle } from 'react-native';
55
import WalletOnboarding from '../../components/WalletOnboarding';
66
import { useAppDispatch } from '../../hooks/redux';
77
import { updateSettings } from '../../store/slices/settings';
8-
import { saveWidget } from '../../store/slices/widgets';
98
import { Display } from '../../styles/text';
10-
import { getDefaultOptions } from '../../utils/widgets';
119

1210
const MainOnboarding = ({
1311
style,
@@ -16,14 +14,8 @@ const MainOnboarding = ({
1614
}): ReactElement => {
1715
const dispatch = useAppDispatch();
1816
const { t } = useTranslation('onboarding');
19-
const priceOptions = getDefaultOptions('price');
20-
const newsOptions = getDefaultOptions('news');
21-
const blocksOptions = getDefaultOptions('blocks');
2217

2318
const onHideOnboarding = (): void => {
24-
dispatch(saveWidget({ id: 'price', options: priceOptions }));
25-
dispatch(saveWidget({ id: 'news', options: newsOptions }));
26-
dispatch(saveWidget({ id: 'blocks', options: blocksOptions }));
2719
dispatch(updateSettings({ hideOnboardingMessage: true }));
2820
};
2921

src/screens/Wallets/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
ignoresHideBalanceToastSelector,
2727
scanAllAddressesTimestampSelector,
2828
} from '../../store/reselect/user';
29-
import { hasWidgetsSelector } from '../../store/reselect/widgets';
3029
import { updateSettings } from '../../store/slices/settings';
3130
import { ignoreHideBalanceToast, updateUser } from '../../store/slices/user';
3231
import { View as ThemedView } from '../../styles/components';
@@ -57,7 +56,6 @@ const Wallets = ({ onFocus }: Props): ReactElement => {
5756
scanAllAddressesTimestampSelector,
5857
);
5958
const hideOnboardingSetting = useAppSelector(hideOnboardingMessageSelector);
60-
const hasWidgets = useAppSelector(hasWidgetsSelector);
6159
const showWidgets = useAppSelector(showWidgetsSelector);
6260
const insets = useSafeAreaInsets();
6361
const { t } = useTranslation('wallet');
@@ -94,8 +92,7 @@ const Wallets = ({ onFocus }: Props): ReactElement => {
9492
setRefreshing(false);
9593
};
9694

97-
const hideOnboarding =
98-
hideOnboardingSetting || totalBalance > 0 || hasWidgets;
95+
const hideOnboarding = hideOnboardingSetting || totalBalance > 0;
9996

10097
return (
10198
<ThemedView style={styles.root}>

src/store/reselect/widgets.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ export const widgetsOrderSelector = createSelector(
2323
(widgets) => widgets.sortOrder,
2424
);
2525

26-
export const hasWidgetsSelector = (state: RootState): boolean => {
27-
return Object.keys(state.widgets.widgets).length > 0;
28-
};
29-
3026
export const onboardedWidgetsSelector = (state: RootState): boolean => {
3127
return state.widgets.onboardedWidgets;
3228
};

src/store/slices/widgets.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
2+
import { getDefaultOptions } from '../../utils/widgets';
23
import { TWidgets } from '../types/widgets';
34

45
export type TWidgetsState = {
@@ -8,7 +9,11 @@ export type TWidgetsState = {
89
};
910

1011
export const initialWidgetsState: TWidgetsState = {
11-
widgets: {},
12+
widgets: {
13+
price: getDefaultOptions('price'),
14+
news: getDefaultOptions('news'),
15+
blocks: getDefaultOptions('blocks'),
16+
},
1217
onboardedWidgets: false,
1318
sortOrder: [],
1419
};

0 commit comments

Comments
 (0)