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
4 changes: 4 additions & 0 deletions packages/assets-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `AccountsApiDataSource` now treats Accounts API `/v2/supportedNetworks` `partialSupport` as active chains in addition to `fullSupport`, still gated by the Snaps assets migration feature flags ([#10144](https://github.com/MetaMask/core/pull/10144))
- `AccountsApiDataSource` now reads Accounts API `/v2/supportedNetworks` as CAIP-2 `fullSupport` and `partialSupport` string arrays, matching the current API payload

### Fixed

- Fix post-transaction balance refreshes for default-tracked native assets on AccountActivity-active chains ([#10198](https://github.com/MetaMask/core/pull/10198))

## [16.0.0]

### Changed
Expand Down
33 changes: 33 additions & 0 deletions packages/assets-controller/src/AssetsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,39 @@ describe('AssetsController', () => {
});
});

it('force refreshes default-tracked native assets even when the chain is AccountActivity-active', async () => {
await withController(async ({ controller, messenger }) => {
const getAssetsSpy = jest
.spyOn(controller, 'getAssets')
.mockResolvedValue({});

messenger.publish('AccountActivityService:statusChanged', {
chainIds: ['eip155:5042'],
status: 'up',
});

await flushPromises();

messenger.publish('TransactionController:transactionConfirmed', {
chainId: '0x13b2',
txParams: { from: '0x1234567890123456789012345678901234567890' },
});

await flushPromises();

expect(getAssetsSpy).toHaveBeenCalledWith(
[expect.objectContaining({ id: MOCK_ACCOUNT_ID })],
{
chainIds: ['eip155:5042'],
forceUpdate: true,
bypassServerCache: true,
},
);

getAssetsSpy.mockRestore();
});
});

it('publishes balanceChanged event when balance updates', async () => {
await withController(async ({ controller, messenger }) => {
const balanceChangedHandler = jest.fn();
Expand Down
10 changes: 9 additions & 1 deletion packages/assets-controller/src/AssetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import {
DEFAULT_TRACKED_ASSETS_BY_CHAIN,
buildDefaultAssetsInfo,
getDefaultAssetMetadata,
getDefaultTrackedAssetsForChain,
} from './defaults.js';
import { AssetsDataSourceError } from './errors.js';
import { projectLogger, createModuleLogger } from './logger.js';
Expand Down Expand Up @@ -1258,12 +1259,19 @@ export class AssetsController extends BaseController<

const caipChainId = `eip155:${parseInt(hexChainId, 16)}` as ChainId;

const hasDefaultTrackedNativeAsset = getDefaultTrackedAssetsForChain(
caipChainId,
).some((assetId) => assetId.includes('/slip44:'));

// AccountActivity pushes live balance updates for its active chains; a
// force getAssets would be redundant and can race the WebSocket path.
// Default-tracked native assets still need the full fetch pipeline because
// AccountActivity can miss their post-transaction balance updates.
if (
this.#accountActivityDataSource
.getActiveChainsSync()
.includes(caipChainId)
.includes(caipChainId) &&
!hasDefaultTrackedNativeAsset
) {
return;
}
Expand Down