-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: assets controllers package upgrade with fix #36808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 47 commits
102687b
c130949
d7a8983
35700fc
f7624cf
bf14880
025f486
49f553d
f631510
791b24c
2012727
c4a696f
8d2e86c
eae81ee
53290e8
a18994c
7e745db
970d100
5302bed
22cb1c7
4d6060c
8013943
cdd10c6
1749a1e
7cea266
c3bca42
9b7192f
2804fe0
ef8aba5
a47e0a9
809974b
e724c58
1d66063
98e4e16
57bab48
77e1769
3d2c66f
7a3305a
20e0309
2df6aa5
9f4bdc5
f54abe9
47dadc2
6047fba
fd8906f
142e9d9
b96ae8e
0392b88
105d8af
3fbd97d
a3868fe
ae0cb15
5002a15
8e07250
28e8f6e
6103c55
394a657
b83e654
a9d29fd
e734416
2f89104
8c5178c
b66d349
29d80bd
9b20aec
60ddebb
8ee380e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,38 @@ | ||
| import { assert } from '@metamask/utils'; | ||
| import { getProviderConfig } from '../../../shared/modules/selectors/networks'; | ||
| import { NETWORK_TYPES } from '../../../shared/constants/network'; | ||
| import AccountTrackerController from '../controllers/account-tracker-controller'; | ||
| import { AccountTrackerController } from '@metamask/assets-controllers'; | ||
| import { NetworkClientId } from '@metamask/network-controller'; | ||
| import { ControllerInitFunction } from './types'; | ||
| import { | ||
| AccountTrackerControllerInitMessenger, | ||
| AccountTrackerControllerMessenger, | ||
| } from './messengers'; | ||
|
|
||
| /** | ||
| * Initialize the account tracker controller. | ||
| * | ||
| * @param request - The request object. | ||
| * @param request.controllerMessenger - The messenger to use for the controller. | ||
| * @param request.initMessenger - The messenger to use for initialization. | ||
| * @returns The initialized controller. | ||
| */ | ||
| export const AccountTrackerControllerInit: ControllerInitFunction< | ||
| AccountTrackerController, | ||
| AccountTrackerControllerMessenger, | ||
| AccountTrackerControllerInitMessenger | ||
| > = ({ controllerMessenger, initMessenger }) => { | ||
| const { provider, blockTracker } = | ||
| initMessenger.call('NetworkController:getSelectedNetworkClient') ?? {}; | ||
|
|
||
| assert( | ||
| provider, | ||
| 'Provider is required to initialize AccountTrackerController.', | ||
| ); | ||
|
|
||
| assert( | ||
| blockTracker, | ||
| 'Block tracker is required to initialize AccountTrackerController.', | ||
| ); | ||
| > = ({ controllerMessenger, initMessenger, persistedState, getController }) => { | ||
| const getAssetsContractController = () => | ||
| getController('AssetsContractController'); | ||
|
|
||
| const controller = new AccountTrackerController({ | ||
| state: { accounts: {} }, | ||
| state: persistedState.AccountTrackerController, | ||
| messenger: controllerMessenger, | ||
| provider, | ||
| blockTracker, | ||
| getNetworkIdentifier: (providerConfig): string => { | ||
| const metamask = initMessenger.call('NetworkController:getState'); | ||
|
|
||
| const config = | ||
| providerConfig ?? | ||
| getProviderConfig({ | ||
| metamask, | ||
| }); | ||
|
|
||
| return config.type === NETWORK_TYPES.RPC && config.rpcUrl | ||
| ? config.rpcUrl | ||
| : config.type; | ||
| getStakedBalanceForChain: ( | ||
| addresses: string[], | ||
| networkClientId?: NetworkClientId, | ||
| ) => { | ||
| const assetsContractController = getAssetsContractController(); | ||
| return assetsContractController.getStakedBalanceForChain( | ||
| addresses, | ||
| networkClientId, | ||
| ); | ||
| }, | ||
| includeStakedAssets: false, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not part of this PR to include staked assets in the assets list. When we want to enable them, we can do so. |
||
| allowExternalServices: () => { | ||
| const { useExternalServices } = initMessenger.call( | ||
| 'PreferencesController:getState', | ||
| ); | ||
| return useExternalServices; | ||
| }, | ||
| accountsApiChainIds: () => { | ||
| const state = initMessenger.call('RemoteFeatureFlagController:getState'); | ||
|
|
@@ -59,16 +41,11 @@ export const AccountTrackerControllerInit: ControllerInitFunction< | |
| state?.remoteFeatureFlags?.assetsAccountApiBalances; | ||
|
|
||
| return Array.isArray(featureFlagForAccountApiBalances) | ||
| ? (featureFlagForAccountApiBalances as string[]) | ||
| ? (featureFlagForAccountApiBalances as `0x${string}`[]) | ||
| : []; | ||
| }, | ||
| }); | ||
|
|
||
| // Ensure `AccountTrackerController` updates balances after network change. | ||
| initMessenger.subscribe('NetworkController:networkDidChange', () => { | ||
| controller.updateAccounts(); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to happen at controller level or not at all. |
||
|
|
||
| return { | ||
| persistedStateKey: null, | ||
| memStateKey: null, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Add migration to remove them from state before merging