Skip to content
Merged
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
9 changes: 3 additions & 6 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@
},
"packages/assets-controllers/src/AssetsContractController.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 6
},
"id-length": {
"count": 1
"count": 5
}
},
"packages/assets-controllers/src/CurrencyRateController.test.ts": {
Expand Down Expand Up @@ -213,7 +210,7 @@
},
"packages/assets-controllers/src/MultichainAssetsController/MultichainAssetsController.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 7
"count": 6
},
"@typescript-eslint/no-misused-promises": {
"count": 3
Expand Down Expand Up @@ -362,7 +359,7 @@
},
"packages/assets-controllers/src/TokensController.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 14
"count": 13
},
"@typescript-eslint/no-unused-vars": {
"count": 1
Expand Down
33 changes: 33 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Expose missing public `AssetsContractController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164))
- The following action is now available:
- `AssetsContractController:getStakedBalanceForChain`
- Corresponding action type (`AssetsContractControllerGetStakedBalanceForChainAction`) is available as well.
- Expose missing public `MultichainAssetsRatesController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164))
- The following action is now available:
- `MultichainAssetsRatesController:fetchHistoricalPricesForAsset`
- Corresponding action type (`MultichainAssetsRatesControllerFetchHistoricalPricesForAssetAction`) is available as well.
- Expose missing public `TokenDetectionController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164))
- The following actions are now available:
- `TokenDetectionController:enable`
- `TokenDetectionController:disable`
- `TokenDetectionController:start`
- `TokenDetectionController:stop`
- Corresponding action type (`TokenDetectionControllerEnableAction`) is available as well.
- Expose missing public `TokensController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164))
- The following actions are now available:
- `TokensController:addToken`
- `TokensController:ignoreTokens`
- `TokensController:updateTokenType`
- `TokensController:watchAsset`
- `TokensController:clearIgnoredTokens`
- `TokensController:resetState`
- Corresponding action type (`TokensControllerAddTokenAction`) is available as well.

### Changed

- **BREAKING:** Standardize names of `AccountTrackerController` messenger action types ([#8164](https://github.com/MetaMask/core/pull/8164))
- All existing types for messenger actions have been renamed so they include `Controller` (e.g. `AccountTrackerUpdateNativeBalancesAction` -> `AccountTrackerControllerUpdateNativeBalancesAction`). You will need to update imports appropriately.
- This change only affects the types. The action type strings themselves have not changed, so you do not need to update the list of actions you pass when initializing `AccountTrackerController` messengers.

### Fixed

- Add missing Tron staking lifecycle asset symbols to `TRON_RESOURCE` filter ([#8174](https://github.com/MetaMask/core/pull/8174))
Expand Down
4 changes: 4 additions & 0 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/assets-controllers",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/assets-controllers",
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts \"$@\" && yarn generate-method-action-types:multichain-assets-controller \"$@\" && yarn generate-method-action-types:multichain-assets-rates-controller \"$@\"",
"generate-method-action-types:multichain-assets-controller": "tsx ../../scripts/generate-method-action-types.ts src/MultichainAssetsController",
"generate-method-action-types:multichain-assets-rates-controller": "tsx ../../scripts/generate-method-action-types.ts src/MultichainAssetsRatesController",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
Expand Down Expand Up @@ -110,6 +113,7 @@
"jest-environment-jsdom": "^29.7.0",
"nock": "^13.3.1",
"ts-jest": "^29.2.5",
"tsx": "^4.20.5",
"typedoc": "^0.25.13",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.3.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* This file is auto generated by `scripts/generate-method-action-types.ts`.
* Do not edit manually.
*/

import type { AccountTrackerController } from './AccountTrackerController';

/**
* Updates the balances of multiple native tokens in a single batch operation.
* This is more efficient than calling updateNativeToken multiple times as it
* triggers only one state update.
*
* @param balances - Array of balance updates, each containing address, chainId, and balance.
*/
export type AccountTrackerControllerUpdateNativeBalancesAction = {
type: `AccountTrackerController:updateNativeBalances`;
handler: AccountTrackerController['updateNativeBalances'];
};

/**
* Updates the staked balances of multiple accounts in a single batch operation.
* This is more efficient than updating staked balances individually as it
* triggers only one state update.
*
* @param stakedBalances - Array of staked balance updates, each containing address, chainId, and stakedBalance.
*/
export type AccountTrackerControllerUpdateStakedBalancesAction = {
type: `AccountTrackerController:updateStakedBalances`;
handler: AccountTrackerController['updateStakedBalances'];
};

/**
* Union of all AccountTrackerController action types.
*/
export type AccountTrackerControllerMethodActions =
| AccountTrackerControllerUpdateNativeBalancesAction
| AccountTrackerControllerUpdateStakedBalancesAction;
39 changes: 8 additions & 31 deletions packages/assets-controllers/src/AccountTrackerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type { Hex } from '@metamask/utils';
import { Mutex } from 'async-mutex';
import { cloneDeep, isEqual } from 'lodash';

import type { AccountTrackerControllerMethodActions } from './AccountTrackerController-method-action-types';
import { STAKING_CONTRACT_ADDRESS_BY_CHAINID } from './AssetsContractController';
import type {
AssetsContractController,
Expand Down Expand Up @@ -165,29 +166,12 @@ export type AccountTrackerControllerGetStateAction = ControllerGetStateAction<
AccountTrackerControllerState
>;

/**
* The action that can be performed to update multiple native token balances in batch.
*/
export type AccountTrackerUpdateNativeBalancesAction = {
type: `${typeof controllerName}:updateNativeBalances`;
handler: AccountTrackerController['updateNativeBalances'];
};

/**
* The action that can be performed to update multiple staked balances in batch.
*/
export type AccountTrackerUpdateStakedBalancesAction = {
type: `${typeof controllerName}:updateStakedBalances`;
handler: AccountTrackerController['updateStakedBalances'];
};

/**
* The actions that can be performed using the {@link AccountTrackerController}.
*/
export type AccountTrackerControllerActions =
| AccountTrackerControllerGetStateAction
| AccountTrackerUpdateNativeBalancesAction
| AccountTrackerUpdateStakedBalancesAction;
| AccountTrackerControllerMethodActions;

/**
* The messenger of the {@link AccountTrackerController} for communication.
Expand Down Expand Up @@ -246,6 +230,11 @@ type AccountTrackerPollingInput = {
queryAllAccounts?: boolean;
};

const MESSENGER_EXPOSED_METHODS = [
'updateNativeBalances',
'updateStakedBalances',
] as const;

/**
* Controller that tracks the network balances for all user accounts.
*/
Expand Down Expand Up @@ -426,7 +415,7 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
},
);

this.#registerMessageHandlers();
messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
}

/**
Expand Down Expand Up @@ -1038,18 +1027,6 @@ export class AccountTrackerController extends StaticIntervalPollingController<Ac
});
}
}

#registerMessageHandlers(): void {
this.messenger.registerActionHandler(
`${controllerName}:updateNativeBalances` as const,
this.updateNativeBalances.bind(this),
);

this.messenger.registerActionHandler(
`${controllerName}:updateStakedBalances` as const,
this.updateStakedBalances.bind(this),
);
}
}

export default AccountTrackerController;
Loading
Loading