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

## [Unreleased]

### Added

- Add optional `snapDataSourceConfig.assetEnrichmentEnabled` getter to `AssetsControllerOptions` so clients can enable or disable snap `getAccountAssetInfo` enrichment at runtime (defaults to disabled)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add the PR number and link.

- Add optional snap account-asset enrichment to fungible balances on `SnapDataSource.fetch` so Stellar trustline fields (`accountAssetInfo`) are included when clients call `getAssets`; balance push events (`AccountsController:accountBalancesUpdated`) pass amounts through without enrichment — clients should call `getAssets` after trustline-related snap events (e.g. `AccountsController:accountAssetListUpdated`)

### Changed

- Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))

### Fixed

- Refresh Stellar trustline enrichment for custom assets that drop off `listAccountAssets` after deactivate (e.g. limit 0 tombstones) by including `customAssets` in `SnapDataSource.fetch` balance and enrichment requests
- Fetch balances when switching account groups, enabling RPC-only networks, or after a new account is added to the account tree ([#9388](https://github.com/MetaMask/core/pull/9388))

## [10.0.1]
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/assets-controller",
"version": "10.0.1",
"version": "10.0.1-dev.8",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah nice, didn't know you could do this for testing. Let's clean up

"description": "Tracks assets balances/prices and handles token detection across all digital assets",
"keywords": [
"Ethereum",
Expand Down
34 changes: 34 additions & 0 deletions packages/assets-controller/src/AssetsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,40 @@ describe('AssetsController', () => {
});
});

it('preserves accountAssetInfo enrichment when merge update changes amount', async () => {
const initialState: Partial<AssetsControllerState> = {
assetsBalance: {
[MOCK_ACCOUNT_ID]: {
[MOCK_ASSET_ID]: {
amount: '1',
accountAssetInfo: { limit: '1000', authorized: true },
},
},
},
};

await withController({ state: initialState }, async ({ controller }) => {
await controller.handleAssetsUpdate(
{
updateMode: 'merge',
assetsBalance: {
[MOCK_ACCOUNT_ID]: {
[MOCK_ASSET_ID]: { amount: '2' },
},
},
},
'TestSource',
);

expect(
controller.state.assetsBalance[MOCK_ACCOUNT_ID]?.[MOCK_ASSET_ID],
).toStrictEqual({
amount: '2',
accountAssetInfo: { limit: '1000', authorized: true },
});
});
});

it('preserves existing balances when merge update adds new chain data', async () => {
const polygonNative = 'eip155:137/slip44:966' as Caip19AssetId;
const initialState: Partial<AssetsControllerState> = {
Expand Down
18 changes: 16 additions & 2 deletions packages/assets-controller/src/AssetsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ import type { PriceDataSourceConfig } from './data-sources/PriceDataSource';
import { PriceDataSource } from './data-sources/PriceDataSource';
import type { RpcDataSourceConfig } from './data-sources/RpcDataSource';
import { RpcDataSource } from './data-sources/RpcDataSource';
import type { AccountsControllerAccountBalancesUpdatedEvent } from './data-sources/SnapDataSource';
import type {
AccountsControllerAccountBalancesUpdatedEvent,
SnapDataSourceConfig,
} from './data-sources/SnapDataSource';
import { SnapDataSource } from './data-sources/SnapDataSource';
import type { StakedBalanceDataSourceConfig } from './data-sources/StakedBalanceDataSource';
import { StakedBalanceDataSource } from './data-sources/StakedBalanceDataSource';
Expand Down Expand Up @@ -428,6 +431,8 @@ export type AssetsControllerOptions = {
priceDataSourceConfig?: PriceDataSourceConfig;
/** Optional configuration for StakedBalanceDataSource. */
stakedBalanceDataSourceConfig?: StakedBalanceDataSourceConfig;
/** Optional configuration for SnapDataSource. */
snapDataSourceConfig?: SnapDataSourceConfig;
/**
* Function returning whether onboarding is complete. When false,
* RPC and staked balance data sources skip fetch and subscribe
Expand Down Expand Up @@ -574,7 +579,14 @@ function mergeAccountBalances(
replaceCoveredChains: boolean,
): Record<string, AssetBalance> {
if (!replaceCoveredChains) {
return { ...previousBalances, ...accountBalances };
const next: Record<string, AssetBalance> = { ...previousBalances };
for (const [assetId, balance] of Object.entries(accountBalances)) {
next[assetId] = {
...(previousBalances[assetId] ?? { amount: '0' }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

still have amt 0?

...balance,
};
}
return next;
}

const coveredChains = new Set(
Expand Down Expand Up @@ -848,6 +860,7 @@ export class AssetsController extends BaseController<
accountsApiDataSourceConfig,
priceDataSourceConfig,
stakedBalanceDataSourceConfig,
snapDataSourceConfig,
isOnboarded,
}: AssetsControllerOptions) {
super({
Expand Down Expand Up @@ -900,6 +913,7 @@ export class AssetsController extends BaseController<
this.#snapDataSource = new SnapDataSource({
messenger: this.messenger,
onActiveChainsUpdated: this.#onActiveChainsUpdated,
...snapDataSourceConfig,
});
this.#rpcDataSource = new RpcDataSource({
messenger: this.messenger,
Expand Down
Loading