Skip to content

Commit

Permalink
fix: Always mark the STX Opt In modal as seen (#10064)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan437 authored and metamaskbot committed Jun 25, 2024
1 parent 9c5df8c commit 2e914f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(<SmartTransactionsOptInModal />, {
state: initialState,
});
Expand All @@ -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', () => {
Expand Down

0 comments on commit 2e914f7

Please sign in to comment.