Skip to content
Draft
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
8 changes: 8 additions & 0 deletions packages/assets-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `createParallelBalanceMiddleware(sources, options?)` to run balance sources in parallel with chain distribution (same strategy as subscription): each chain is assigned to one source via `getActiveChains`, so there is no overlap. Uses `Promise.allSettled` so failures in one source do not block others. Optional `options.fallbackMiddlewares` run only for remaining chains (no balance after primary run)

### Changed

- **BREAKING:** Require `previousChains` in `handleActiveChainsUpdate(dataSourceId, activeChains, previousChains)` and in the `onActiveChainsUpdated` callback used by data sources; the third parameter is no longer optional. Callers and data sources must pass the previous chain list for correct added/removed chain diff computation ([#7867](https://github.com/MetaMask/core/pull/7867))

### Removed

- **BREAKING:** Remove `initDataSources` and related exports (`InitDataSourcesOptions`, `DataSources`, `DataSourceActions`, `DataSourceEvents`, `DataSourceAllowedActions`, `DataSourceAllowedEvents`, `RootMessenger`). Initialize assets by creating `AssetsController` with `queryApiClient`; the controller instantiates all data sources internally ([#7859](https://github.com/MetaMask/core/pull/7859))
Expand Down
19 changes: 4 additions & 15 deletions packages/assets-controller/src/AssetsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,6 @@ describe('AssetsController', () => {
});
});

describe('registerDataSources', () => {
it('registers data sources in constructor', async () => {
await withController(({ controller }) => {
// The controller registers these data sources in the constructor:
// 'BackendWebsocketDataSource', 'AccountsApiDataSource', 'SnapDataSource', 'RpcDataSource'
// We verify initialization completed without error
expect(controller.state).toBeDefined();
});
});
});

describe('getAssetMetadata', () => {
it('returns metadata for existing asset', async () => {
const initialState: Partial<AssetsControllerState> = {
Expand Down Expand Up @@ -489,7 +478,7 @@ describe('AssetsController', () => {
describe('handleActiveChainsUpdate', () => {
it('updates data source chains', async () => {
await withController(({ controller }) => {
controller.handleActiveChainsUpdate('TestDataSource', ['eip155:1']);
controller.handleActiveChainsUpdate('TestDataSource', ['eip155:1'], []);

// Should not throw
expect(controller.state).toBeDefined();
Expand All @@ -498,7 +487,7 @@ describe('AssetsController', () => {

it('handles empty chains array', async () => {
await withController(({ controller }) => {
controller.handleActiveChainsUpdate('TestDataSource', []);
controller.handleActiveChainsUpdate('TestDataSource', [], []);

expect(controller.state).toBeDefined();
});
Expand All @@ -507,10 +496,10 @@ describe('AssetsController', () => {
it('triggers fetch when chains are added', async () => {
await withController(async ({ controller }) => {
// First set no chains
controller.handleActiveChainsUpdate('TestDataSource', []);
controller.handleActiveChainsUpdate('TestDataSource', [], []);

// Then add chains - this should trigger fetch for added chains
controller.handleActiveChainsUpdate('TestDataSource', ['eip155:1']);
controller.handleActiveChainsUpdate('TestDataSource', ['eip155:1'], []);

// Allow async operations to complete
await new Promise(process.nextTick);
Expand Down
Loading