diff --git a/app/components/Views/SmartTransactionsOptInModal/SmartTranactionsOptInModal.tsx b/app/components/Views/SmartTransactionsOptInModal/SmartTranactionsOptInModal.tsx index 402d75c031c..7eca0b6ed4b 100644 --- a/app/components/Views/SmartTransactionsOptInModal/SmartTranactionsOptInModal.tsx +++ b/app/components/Views/SmartTransactionsOptInModal/SmartTranactionsOptInModal.tsx @@ -149,39 +149,40 @@ const SmartTransactionsOptInModal = () => { modalRef.current?.dismissModal(); }; - const optIn = () => { + const markOptInModalAsSeen = async () => { + const version = await AsyncStorage.getItem(CURRENT_APP_VERSION); + dispatch(updateOptInModalAppVersionSeen(version)); + }; + + const optIn = async () => { Engine.context.PreferencesController.setSmartTransactionsOptInStatus(true); trackEvent(MetaMetricsEvents.SMART_TRANSACTION_OPT_IN, { stx_opt_in: true, location: 'SmartTransactionsOptInModal', }); - hasOptedIn.current = true; + await markOptInModalAsSeen(); dismissModal(); }; - const optOut = () => { + const optOut = async () => { Engine.context.PreferencesController.setSmartTransactionsOptInStatus(false); trackEvent(MetaMetricsEvents.SMART_TRANSACTION_OPT_IN, { stx_opt_in: false, location: 'SmartTransactionsOptInModal', }); - hasOptedIn.current = false; + await markOptInModalAsSeen(); navigation.navigate(Routes.SETTINGS_VIEW, { screen: Routes.SETTINGS.ADVANCED_SETTINGS, }); }; const handleDismiss = async () => { - // Opt out of STX if no prior decision made + // Opt out of STX if no prior decision made. if (hasOptedIn.current === null) { optOut(); } - - // Save the current app version as the last app version seen - const version = await AsyncStorage.getItem(CURRENT_APP_VERSION); - dispatch(updateOptInModalAppVersionSeen(version)); }; const Header = () => ( diff --git a/app/components/Views/SmartTransactionsOptInModal/SmartTransactionsOptInModal.test.tsx b/app/components/Views/SmartTransactionsOptInModal/SmartTransactionsOptInModal.test.tsx index 517c98d3249..50309cc0b0a 100644 --- a/app/components/Views/SmartTransactionsOptInModal/SmartTransactionsOptInModal.test.tsx +++ b/app/components/Views/SmartTransactionsOptInModal/SmartTransactionsOptInModal.test.tsx @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import React from 'react'; -import { fireEvent } from '@testing-library/react-native'; +import { fireEvent, waitFor } from '@testing-library/react-native'; import SmartTransactionsOptInModal from './SmartTranactionsOptInModal'; import renderWithProvider from '../../../util/test/renderWithProvider'; import initialBackgroundState from '../../../util/test/initial-background-state.json'; @@ -96,7 +96,7 @@ describe('SmartTransactionsOptInModal', () => { Engine.context.PreferencesController.setSmartTransactionsOptInStatus, ).toHaveBeenCalledWith(true); }); - it('should opt user out when secondary button is pressed and navigate to Advanced Settings', () => { + it('opts user out when secondary button is pressed and navigate to Advanced Settings', async () => { const { getByText } = renderWithProvider(, { state: initialState, }); @@ -109,8 +109,11 @@ describe('SmartTransactionsOptInModal', () => { expect( Engine.context.PreferencesController.setSmartTransactionsOptInStatus, ).toHaveBeenCalledWith(false); - expect(mockNavigate).toHaveBeenCalledWith(Routes.SETTINGS_VIEW, { - screen: Routes.SETTINGS.ADVANCED_SETTINGS, + expect(updateOptInModalAppVersionSeen).toHaveBeenCalledWith(VERSION); + await waitFor(() => { + expect(mockNavigate).toHaveBeenCalledWith(Routes.SETTINGS_VIEW, { + screen: Routes.SETTINGS.ADVANCED_SETTINGS, + }); }); }); it('should update last app version seen on primary button press', () => {