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

feat(NOTIFY-1096): add account syncing #11190

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
631dbe9
feat(NOTIFY-1096): add account syncing
mathieuartu Sep 13, 2024
04780e0
fix: import path
mathieuartu Sep 13, 2024
771ad50
fix: useEffect
mathieuartu Sep 13, 2024
2f20cdb
fix: temporarily remove keyring-controller patch
mathieuartu Sep 13, 2024
249a1ba
fix: yarn.lock
mathieuartu Sep 13, 2024
6e2b5b5
fix: remove Gemfile.lock
mathieuartu Sep 13, 2024
888f01d
fix: add @ts-expect-error for controller version mismatch
mathieuartu Sep 13, 2024
b9bb37a
fix: remove unused import
mathieuartu Sep 13, 2024
6c9b2ce
feat: group profile-sync effects under a layout effect + AppState cha…
mathieuartu Sep 13, 2024
80af81c
add layouteffect deps
mathieuartu Sep 13, 2024
ab17435
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 13, 2024
95563d9
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 16, 2024
c8e8e91
chore: remove preview packages and use latest deps
mathieuartu Sep 16, 2024
c3a3cb6
fix: yarn.lock
mathieuartu Sep 16, 2024
c0be57e
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 16, 2024
9aca646
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 17, 2024
8efc079
fix: update package.json & yarn.lock
mathieuartu Sep 17, 2024
8836b0f
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 17, 2024
970f65e
fix: update yarn.lock
mathieuartu Sep 18, 2024
63708ef
feat: add analytics
mathieuartu Sep 18, 2024
b6d891e
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 18, 2024
c821134
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 19, 2024
5d17b5d
fix: yarn.lock
mathieuartu Sep 19, 2024
b7af253
fix: bump snaps packages
mathieuartu Sep 19, 2024
91fa607
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 19, 2024
01d2304
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 19, 2024
a3fc2cc
fix: remove unused ts-error statements
mathieuartu Sep 19, 2024
a971856
fix: snaps imports
mathieuartu Sep 20, 2024
fd5615d
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 20, 2024
cdca605
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 20, 2024
92d9839
fix: yarn.lock
mathieuartu Sep 20, 2024
40e8294
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 23, 2024
c157056
fix: yarn.lock
mathieuartu Sep 23, 2024
5d708da
fix: yarn.lock
mathieuartu Sep 23, 2024
77c9c31
Merge branch 'main' into feat/add_account_syncing
mathieuartu Sep 25, 2024
0210192
fix: yarn.lock
mathieuartu Sep 25, 2024
2be206f
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 3, 2024
f5a2aa9
fix: bump profile-sync-controller version
mathieuartu Oct 3, 2024
1050e86
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 7, 2024
66aff4c
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 8, 2024
22cfc1a
fix: update analytics events names
mathieuartu Oct 9, 2024
bcfd1bb
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 9, 2024
307b449
Merge branch 'feat/add_account_syncing' of github.com:MetaMask/metama…
mathieuartu Oct 9, 2024
7a4dc64
fix: update yarn.lock
mathieuartu Oct 9, 2024
b03fd6a
fix: build issues
mathieuartu Oct 9, 2024
ddf4c9e
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 15, 2024
2fee02f
fix: update yarn.lock
mathieuartu Oct 15, 2024
0fa03b7
fix: yarn dedupe
mathieuartu Oct 15, 2024
730fb38
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 15, 2024
c953e4f
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 16, 2024
1ba5618
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 16, 2024
5752f14
fix: add missing semi-colon
mathieuartu Oct 16, 2024
d859175
fix: move account syncing to its own hook file
mathieuartu Oct 16, 2024
250f1e9
fix: add tests
mathieuartu Oct 17, 2024
b0786f6
Merge branch 'main' into feat/add_account_syncing
mathieuartu Oct 17, 2024
3885490
feat: use new event builder
mathieuartu Oct 17, 2024
9ca93ba
fix: formatting
mathieuartu Oct 17, 2024
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
43 changes: 42 additions & 1 deletion app/components/Views/Wallet/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React from 'react';
import Wallet from './';
import { renderScreen } from '../../../util/test/renderWithProvider';
import { screen } from '@testing-library/react-native';
import { act, screen } from '@testing-library/react-native';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import Routes from '../../../constants/navigation/Routes';
import { backgroundState } from '../../../util/test/initial-root-state';
import { createMockAccountsControllerState } from '../../../util/test/accountsControllerTestUtils';
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors';
import { CommonSelectorsIDs } from '../../../../e2e/selectors/Common.selectors';
import { useAccountSyncing } from '../../../util/notifications/hooks/useAccountSyncing';
import { AppState } from 'react-native';

const MOCK_ADDRESS = '0xc4955c0d639d99699bfd7ec54d9fafee40e4d272';

Expand Down Expand Up @@ -108,6 +110,13 @@ jest.mock('react-native-scrollable-tab-view', () => {
return ScrollableTabViewMock;
});

jest.mock('../../../util/notifications/hooks/useAccountSyncing', () => ({
useAccountSyncing: jest.fn().mockReturnValue({
dispatchAccountSyncing: jest.fn(),
error: undefined,
}),
}));

const render = (Component: React.ComponentType) =>
renderScreen(
Component,
Expand Down Expand Up @@ -144,4 +153,36 @@ describe('Wallet', () => {
const foxIcon = screen.getByTestId(CommonSelectorsIDs.FOX_ICON);
expect(foxIcon).toBeDefined();
});
it('should dispatch account syncing on mount', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should dispatch account syncing on mount', () => {
it('dispatches account syncing on mount', () => {

jest.clearAllMocks();
//@ts-expect-error we are ignoring the navigation params on purpose because we do not want to mock setOptions to test the navbar
render(Wallet);
expect(useAccountSyncing().dispatchAccountSyncing).toHaveBeenCalledTimes(1);
});
it('should dispatch account syncing when appState switches from inactive|background to active', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('should dispatch account syncing when appState switches from inactive|background to active', () => {
it('dispatches account syncing when appState switches from inactive|background to active', () => {

jest.clearAllMocks();

const addEventListener = jest.spyOn(AppState, 'addEventListener');

//@ts-expect-error we are ignoring the navigation params on purpose because we do not want to mock setOptions to test the navbar
render(Wallet);

expect(addEventListener).toHaveBeenCalledTimes(1);

const handleAppStateChange = addEventListener.mock.calls[0][1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C: Not fond of this as if we add another listener in the code, this will break this test even if the feature works.

Suggested change
const handleAppStateChange = addEventListener.mock.calls[0][1];
expect(addEventListener).toHaveBeenCalledWith('change', expect.any(Function));
const handleAppStateChange = (addEventListener as jest.Mock).mock.calls.find(
([event]) => event === 'change'
)[1];


act(() => {
handleAppStateChange('background');
handleAppStateChange('active');
});

expect(useAccountSyncing().dispatchAccountSyncing).toHaveBeenCalledTimes(2);

act(() => {
handleAppStateChange('inactive');
handleAppStateChange('active');
});

expect(useAccountSyncing().dispatchAccountSyncing).toHaveBeenCalledTimes(3);
});
});
2 changes: 1 addition & 1 deletion app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ const Wallet = ({
useLayoutEffect(() => {
const handleAppStateChange = (nextAppState: AppStateStatus) => {
if (
appState.current.match(/inactive|background/) &&
appState.current?.match(/inactive|background/) &&
nextAppState === 'active'
) {
listNotifications();
Expand Down
25 changes: 16 additions & 9 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ import { HandleSnapRequestArgs } from './Snaps/types';
import { handleSnapRequest } from './Snaps/utils';
///: END:ONLY_INCLUDE_IF
import { trace } from '../util/trace';
import { MetricsEventBuilder } from './Analytics/MetricsEventBuilder';

const NON_EMPTY = 'NON_EMPTY';

Expand Down Expand Up @@ -515,7 +516,7 @@ class Engine {
showApprovalRequest: () => undefined,
typesExcludedFromRateLimiting: [
ApprovalType.Transaction,
ApprovalType.WatchAsset
ApprovalType.WatchAsset,
],
});

Expand Down Expand Up @@ -1220,18 +1221,24 @@ class Engine {
accountSyncing: {
onAccountAdded: (profileId) => {
MetaMetrics.getInstance().trackEvent(
MetaMetricsEvents.ACCOUNTS_SYNC_ADDED,
{
profile_id: profileId,
},
MetricsEventBuilder.createEventBuilder(
MetaMetricsEvents.ACCOUNTS_SYNC_ADDED,
)
.addProperties({
profile_id: profileId,
})
.build(),
);
},
onAccountNameUpdated: (profileId) => {
MetaMetrics.getInstance().trackEvent(
MetaMetricsEvents.ACCOUNTS_SYNC_NAME_UPDATED,
{
profile_id: profileId,
},
MetricsEventBuilder.createEventBuilder(
MetaMetricsEvents.ACCOUNTS_SYNC_NAME_UPDATED,
)
.addProperties({
profile_id: profileId,
})
.build(),
);
},
},
Expand Down
Loading