Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cherry-pick #10064 #10107

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading