diff --git a/src/extension/apps/main/Root.tsx b/src/extension/apps/main/Root.tsx index 140ae6e1..249296a2 100644 --- a/src/extension/apps/main/Root.tsx +++ b/src/extension/apps/main/Root.tsx @@ -64,9 +64,8 @@ import WhatsNewModal from '@extension/modals/WhatsNewModal'; import { useSelectAccounts, useSelectNotificationsShowingConfetti, - useSelectSettings, useSelectSettingsSelectedNetwork, - useSelectSystemInfo, + useSelectSystemWhatsNewInfo, } from '@extension/selectors'; // types @@ -78,8 +77,7 @@ const Root: FC = () => { const accounts = useSelectAccounts(); const network = useSelectSettingsSelectedNetwork(); const showingConfetti = useSelectNotificationsShowingConfetti(); - const { general } = useSelectSettings(); - const systemInfo = useSelectSystemInfo(); + const whatsNewInfo = useSelectSystemWhatsNewInfo(); // handlers const handleAddAssetsModalClose = () => dispatch(resetAddAsset()); const handleConfirmClose = () => dispatch(setConfirmModal(null)); @@ -125,17 +123,16 @@ const Root: FC = () => { dispatch(updateTransactionParamsForSelectedNetworkThunk()); } }, [network]); - // if the saved what's new version is null or less than the current version (and the update message is not disabled in the settings), display the modal + // if the saved what's new version is null or less than the current version (and the update message is not disabled), display the modal useEffect(() => { if ( - systemInfo && - !general.disableWhatsNewModalOnUpdate && - (!systemInfo.whatsNewVersion || - systemInfo.whatsNewVersion !== __VERSION__) + whatsNewInfo && + !whatsNewInfo.disableOnUpdate && + (!whatsNewInfo.version || whatsNewInfo.version !== __VERSION__) ) { dispatch(setWhatsNewModal(true)); } - }, [systemInfo]); + }, [whatsNewInfo]); useOnDebugLogging(); useOnNewAssets(); // handle new assets added useNotifications(); // handle notifications diff --git a/src/extension/features/system/enums/ThunkEnum.ts b/src/extension/features/system/enums/ThunkEnum.ts index bc6b901e..a13afb07 100644 --- a/src/extension/features/system/enums/ThunkEnum.ts +++ b/src/extension/features/system/enums/ThunkEnum.ts @@ -1,5 +1,6 @@ enum ThunkEnum { FetchFromStorage = 'system/fetchFromStorage', + SaveDisableWhatsNewOnUpdate = 'system/saveDisableWhatsNewOnUpdate', SaveWhatsNewVersion = 'system/saveWhatsNewVersion', StartPollingForNetworkConnectivity = 'networks/startPollingForNetworkConnectivity', StopPollingForNetworkConnectivity = 'networks/stopPollingForNetworkConnectivity', diff --git a/src/extension/features/system/slice.ts b/src/extension/features/system/slice.ts index 3283169d..b5138a50 100644 --- a/src/extension/features/system/slice.ts +++ b/src/extension/features/system/slice.ts @@ -6,6 +6,7 @@ import { StoreNameEnum } from '@extension/enums'; // thunks import { fetchFromStorageThunk, + saveDisableWhatsNewOnUpdateThunk, saveWhatsNewVersionThunk, startPollingForNetworkConnectivityThunk, stopPollingForTransactionsParamsThunk, @@ -29,6 +30,21 @@ const slice = createSlice({ state.info = action.payload; } ); + /** save disable what's on update **/ + builder.addCase( + saveDisableWhatsNewOnUpdateThunk.fulfilled, + (state: IState, action: PayloadAction) => { + if (state.info) { + state.info = { + ...state.info, + whatsNewInfo: { + ...state.info.whatsNewInfo, + disableOnUpdate: action.payload, + }, + }; + } + } + ); /** save what's new version **/ builder.addCase( saveWhatsNewVersionThunk.fulfilled, @@ -36,7 +52,10 @@ const slice = createSlice({ if (state.info) { state.info = { ...state.info, - whatsNewVersion: action.payload, + whatsNewInfo: { + ...state.info.whatsNewInfo, + version: action.payload, + }, }; } } diff --git a/src/extension/features/system/thunks/index.ts b/src/extension/features/system/thunks/index.ts index f70b63a3..2a58675f 100644 --- a/src/extension/features/system/thunks/index.ts +++ b/src/extension/features/system/thunks/index.ts @@ -1,4 +1,5 @@ export { default as fetchFromStorageThunk } from './fetchFromStorageThunk'; +export { default as saveDisableWhatsNewOnUpdateThunk } from './saveDisableWhatsNewOnUpdateThunk'; export { default as saveWhatsNewVersionThunk } from './saveWhatsNewVersionThunk'; export { default as startPollingForNetworkConnectivityThunk } from './startPollingForNetworkConnectivityThunk'; export { default as stopPollingForTransactionsParamsThunk } from './stopPollingForTransactionsParamsThunk'; diff --git a/src/extension/features/system/thunks/saveDisableWhatsNewOnUpdateThunk.ts b/src/extension/features/system/thunks/saveDisableWhatsNewOnUpdateThunk.ts new file mode 100644 index 00000000..0cc52ee6 --- /dev/null +++ b/src/extension/features/system/thunks/saveDisableWhatsNewOnUpdateThunk.ts @@ -0,0 +1,46 @@ +import { AsyncThunk, createAsyncThunk } from '@reduxjs/toolkit'; + +// enums +import { ThunkEnum } from '../enums'; + +// services +import SystemService from '@extension/services/SystemService'; + +// types +import type { IBaseAsyncThunkConfig, IMainRootState } from '@extension/types'; +import { MalformedDataError } from '@extension/errors'; + +const saveDisableWhatsNewOnUpdateThunk: AsyncThunk< + boolean, // return + boolean, // args + IBaseAsyncThunkConfig +> = createAsyncThunk>( + ThunkEnum.SaveDisableWhatsNewOnUpdate, + async (value, { getState, rejectWithValue }) => { + const logger = getState().system.logger; + const systemInfo = getState().system.info; + let _error: string; + + if (!systemInfo) { + _error = 'system info not found'; + + logger.debug(`${ThunkEnum.SaveDisableWhatsNewOnUpdate}: ${_error}`); + + return rejectWithValue(new MalformedDataError(_error)); + } + + const { whatsNewInfo } = await new SystemService({ + logger, + }).saveToStorage({ + ...systemInfo, + whatsNewInfo: { + ...systemInfo.whatsNewInfo, + disableOnUpdate: value, + }, + }); + + return whatsNewInfo.disableOnUpdate; + } +); + +export default saveDisableWhatsNewOnUpdateThunk; diff --git a/src/extension/features/system/thunks/saveWhatsNewVersionThunk.ts b/src/extension/features/system/thunks/saveWhatsNewVersionThunk.ts index cb1af969..71c57df8 100644 --- a/src/extension/features/system/thunks/saveWhatsNewVersionThunk.ts +++ b/src/extension/features/system/thunks/saveWhatsNewVersionThunk.ts @@ -33,14 +33,17 @@ const saveWhatsNewVersionThunk: AsyncThunk< return rejectWithValue(new MalformedDataError(_error)); } - const { whatsNewVersion } = await new SystemService({ + const { whatsNewInfo } = await new SystemService({ logger, }).saveToStorage({ ...systemInfo, - whatsNewVersion: version, + whatsNewInfo: { + ...systemInfo.whatsNewInfo, + version, + }, }); - return whatsNewVersion; + return whatsNewInfo.version; } ); diff --git a/src/extension/modals/WhatsNewModal/WhatsNewModal.tsx b/src/extension/modals/WhatsNewModal/WhatsNewModal.tsx index 79f0f7fc..60c293f2 100644 --- a/src/extension/modals/WhatsNewModal/WhatsNewModal.tsx +++ b/src/extension/modals/WhatsNewModal/WhatsNewModal.tsx @@ -24,8 +24,10 @@ import Link from '@extension/components/Link'; import { BODY_BACKGROUND_COLOR, DEFAULT_GAP } from '@extension/constants'; // features -import { saveToStorageThunk as saveSettingsToStorageThunk } from '@extension/features/settings'; -import { saveWhatsNewVersionThunk } from '@extension/features/system'; +import { + saveDisableWhatsNewOnUpdateThunk, + saveWhatsNewVersionThunk, +} from '@extension/features/system'; // hooks import useDefaultTextColor from '@extension/hooks/useDefaultTextColor'; @@ -35,8 +37,8 @@ import useSubTextColor from '@extension/hooks/useSubTextColor'; // selectors import { - useSelectSettings, useSelectWhatsNewModal, + useSelectSystemWhatsNewInfo, } from '@extension/selectors'; // theme @@ -54,8 +56,8 @@ const WhatsNewModal: FC = ({ onClose }) => { const dispatch = useDispatch>(); const initialRef = createRef(); // selectors - const settings = useSelectSettings(); const whatsNewModalOpen = useSelectWhatsNewModal(); + const whatsNewInfo = useSelectSystemWhatsNewInfo(); // hooks const defaultTextColor = useDefaultTextColor(); const primaryColor = usePrimaryColor(); @@ -70,16 +72,13 @@ const WhatsNewModal: FC = ({ onClose }) => { }; const handleOnDisableOnUpdateChange = ( event: ChangeEvent - ) => - dispatch( - saveSettingsToStorageThunk({ - ...settings, - general: { - ...settings.general, - disableWhatsNewModalOnUpdate: event.target.checked, - }, - }) - ); + ) => { + if (!whatsNewInfo) { + return; + } + + dispatch(saveDisableWhatsNewOnUpdateThunk(!whatsNewInfo.disableOnUpdate)); + }; return ( = ({ onClose }) => { > - {`What's New In Kibisis v2.0.0`} + {`What's New In Kibisis v${__VERSION__}`} @@ -138,7 +137,7 @@ const WhatsNewModal: FC = ({ onClose }) => { > 12th September 2024 {' '} - which means Voi has officially launched on MainNet! + which means Voi has officially launched its MainNet! = ({ onClose }) => { textAlign="left" w="full" > - This truly has been a community effort, from the builders, the + This truly has been a community effort; from the builders, the node runners to the questers. Voi's TestNet has been a monumental success and Voi has a solid foundation that makes it an ecosystem - that is run by you, the Voiagers. + that is run by you: the Voiagers. = ({ onClose }) => { textAlign="left" w="full" > - MainNet Rollout: Staking Program + Voi MainNet Rollout: Staking Program = ({ onClose }) => { textAlign="left" w="full" > - With the Voi's MainNet rollout, there is a new incentive for early + With Voi's MainNet rollout, there is a new incentive for early participation: the Staking Program. @@ -373,20 +372,22 @@ const WhatsNewModal: FC = ({ onClose }) => { - - - {t('captions.disableWhatsNewMessageOnUpdate')} - - + + {t('captions.disableWhatsNewMessageOnUpdate')} + + + )} {/*ok*/}