Skip to content

Commit

Permalink
feat: network sync - add main sync logic (#4694)
Browse files Browse the repository at this point in the history
## Explanation

This adds support for the "main-sync" on network syncing feature. This
will get all a users local networks, and saved remote networks; then
will append/update/delete networks synced across their devices.

We will add the controller integration in a following PR.

## References

https://consensyssoftware.atlassian.net/browse/NOTIFY-1040

## Changelog

### `@metamask/profile-sync-controller`

- **CHANGED**: Renamed the `sync.ts` file to `sync-mutations.ts`
- **ADDED**: `utils` to the `UserStorageController` subpath.
- **ADDED**: `findNetworksToUpdate()` function which will perform the
"main-sync" logic for local and remote network configurations.

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
Prithpal-Sooriya authored Sep 13, 2024
1 parent 92e6472 commit 97220b5
Show file tree
Hide file tree
Showing 10 changed files with 721 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NetworkConfiguration } from '@metamask/network-controller';

import type { RemoteNetworkConfiguration } from '../types';
import type {
NetworkConfiguration,
RemoteNetworkConfiguration,
} from '../types';

export const createMockNetworkConfiguration = (
override?: Partial<NetworkConfiguration>,
Expand All @@ -18,7 +19,7 @@ export const createMockNetworkConfiguration = (
};

export const createMockRemoteNetworkConfiguration = (
override?: Partial<NetworkConfiguration>,
override?: Partial<RemoteNetworkConfiguration>,
): RemoteNetworkConfiguration => {
return {
v: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { waitFor } from '../__fixtures__/test-utils';
import type { UserStorageBaseOptions } from '../services';
import { createMockNetworkConfiguration } from './__fixtures__/mockNetwork';
import { startNetworkSyncing } from './controller-integration';
import * as SyncModule from './sync';
import * as SyncModule from './sync-mutations';

jest.mock('loglevel', () => {
const actual = jest.requireActual('loglevel');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import log from 'loglevel';

import type { UserStorageBaseOptions } from '../services';
import type { UserStorageControllerMessenger } from '../UserStorageController';
import { addNetwork, deleteNetwork, updateNetwork } from './sync';
import { addNetwork, deleteNetwork, updateNetwork } from './sync-mutations';

type SetupNetworkSyncingProps = {
messenger: UserStorageControllerMessenger;
Expand Down
Loading

0 comments on commit 97220b5

Please sign in to comment.