Skip to content
Open
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
21 changes: 21 additions & 0 deletions app/core/AppStateEventListener.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('AppStateEventListener', () => {
appStateManager.setCurrentDeeplink(
'metamask://connect?attributionId=test123',
);
mockAppStateListener('background');
mockAppStateListener('active');
jest.advanceTimersByTime(2000);

Expand All @@ -121,6 +122,7 @@ describe('AppStateEventListener', () => {
.mockReturnValue({} as unknown as ReduxStore);
(processAttribution as jest.Mock).mockReturnValue(undefined);

mockAppStateListener('background');
mockAppStateListener('active');
jest.advanceTimersByTime(2000);

Expand Down Expand Up @@ -168,6 +170,7 @@ describe('AppStateEventListener', () => {
throw testError;
});

mockAppStateListener('background');
mockAppStateListener('active');
jest.advanceTimersByTime(2000);

Expand Down Expand Up @@ -206,10 +209,27 @@ describe('AppStateEventListener', () => {
.mockReturnValue({} as unknown as ReduxStore);
(processAttribution as jest.Mock).mockReturnValue(undefined);

mockAppStateListener('background');
mockAppStateListener('active');
jest.advanceTimersByTime(2000);
mockAnalytics.trackEvent.mockClear();

// Sending 'active' again without going through 'background' should not re-fire
mockAppStateListener('active');
jest.advanceTimersByTime(2000);

expect(mockAnalytics.trackEvent).not.toHaveBeenCalled();
});

it('does not fire APP_OPENED when transitioning from inactive to active (e.g. system permission dialog dismissed)', () => {
jest.clearAllMocks();
jest
.spyOn(ReduxService, 'store', 'get')
.mockReturnValue({} as unknown as ReduxStore);
(processAttribution as jest.Mock).mockReturnValue(undefined);

// Simulate iOS system permission dialog: active → inactive → active
mockAppStateListener('inactive');
mockAppStateListener('active');
jest.advanceTimersByTime(2000);

Expand All @@ -225,6 +245,7 @@ describe('AppStateEventListener', () => {
realProcessAttribution,
);

mockAppStateListener('background');
mockAppStateListener('active');
jest.advanceTimersByTime(2000);

Expand Down
5 changes: 4 additions & 1 deletion app/core/AppStateEventListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export class AppStateEventListener {
}

private handleAppStateChange = (nextAppState: AppStateStatus) => {
if (nextAppState === 'active' && this.lastAppState !== nextAppState) {
// Only fire APP_OPENED when transitioning from background to active.
// Transitioning from inactive (e.g. system permission dialogs, incoming calls)
// back to active should NOT count as the user opening the app.
if (nextAppState === 'active' && this.lastAppState === 'background') {
// delay to allow time for the deeplink to be set
setTimeout(() => {
this.processAppStateChange();
Expand Down
Loading