Skip to content

Commit

Permalink
chore(deps): bump assets controller to v34.0.0 (#25540)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

This PR bumps `@metamask/assets-controllers` to `^34.0.0`.
## **Related issues**

Fixes MetaMask/accounts-planning#481

## **Manual testing steps**

This PR affects all assets related tokens

1. Test added and removing of and tokens
2. Transfer tokens
3. Turn on off token detection and see the detected tokens
4. Check if the token rate values on mainnet

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: MetaMask Bot <[email protected]>
  • Loading branch information
montelaidev and metamaskbot authored Jun 28, 2024
1 parent 58082f5 commit f353f0c
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 188 deletions.
150 changes: 36 additions & 114 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,6 @@ export default class MetamaskController extends EventEmitter {
this.networkController.getProviderAndBlockTracker().blockTracker;
this.deprecatedNetworkVersions = {};

const tokenListMessenger = this.controllerMessenger.getRestricted({
name: 'TokenListController',
allowedEvents: ['NetworkController:stateChange'],
allowedActions: ['NetworkController:getNetworkClientById'],
});

const accountsControllerMessenger = this.controllerMessenger.getRestricted({
name: 'AccountsController',
allowedEvents: [
Expand Down Expand Up @@ -567,6 +561,12 @@ export default class MetamaskController extends EventEmitter {
networkConfigurations: this.networkController.state.networkConfigurations,
});

const tokenListMessenger = this.controllerMessenger.getRestricted({
name: 'TokenListController',
allowedActions: ['NetworkController:getNetworkClientById'],
allowedEvents: ['NetworkController:stateChange'],
});

this.tokenListController = new TokenListController({
chainId: this.networkController.state.providerConfig.chainId,
preventPollingOnNetworkRestart: !this.#isTokenListPollingRequired(
Expand Down Expand Up @@ -604,49 +604,21 @@ export default class MetamaskController extends EventEmitter {
allowedActions: [
'ApprovalController:addRequest',
'NetworkController:getNetworkClientById',
'AccountsController:getSelectedAccount',
'AccountsController:getAccount',
],
allowedEvents: [
'NetworkController:networkDidChange',
'AccountsController:selectedAccountChange',
'AccountsController:selectedEvmAccountChange',
'PreferencesController:stateChange',
'TokenListController:stateChange',
],
});
this.tokensController = new TokensController({
state: initState.TokensController,
provider: this.provider,
messenger: tokensControllerMessenger,
chainId: this.networkController.state.providerConfig.chainId,
// TODO: The tokens controller currently does not support internalAccounts. This is done to match the behavior of the previous tokens controller subscription.
onPreferencesStateChange: (listener) =>
this.controllerMessenger.subscribe(
`AccountsController:selectedAccountChange`,
(newlySelectedInternalAccount) => {
listener({ selectedAddress: newlySelectedInternalAccount.address });
},
),
onNetworkDidChange: (cb) =>
networkControllerMessenger.subscribe(
'NetworkController:networkDidChange',
() => {
const networkState = this.networkController.state;
return cb(networkState);
},
),
onTokenListStateChange: (listener) =>
this.controllerMessenger.subscribe(
`${this.tokenListController.name}:stateChange`,
listener,
),
getNetworkClientById: this.networkController.getNetworkClientById.bind(
this.networkController,
),
config: {
provider: this.provider,
selectedAddress:
initState.AccountsController?.internalAccounts?.accounts[
initState.AccountsController?.internalAccounts?.selectedAccount
]?.address ?? '',
},
state: initState.TokensController,
});

const nftControllerMessenger = this.controllerMessenger.getRestricted({
Expand All @@ -664,15 +636,9 @@ export default class MetamaskController extends EventEmitter {
],
});
this.nftController = new NftController({
state: initState.NftController,
messenger: nftControllerMessenger,
chainId: this.networkController.state.providerConfig.chainId,
onPreferencesStateChange: this.preferencesController.store.subscribe.bind(
this.preferencesController.store,
),
onNetworkStateChange: networkControllerMessenger.subscribe.bind(
networkControllerMessenger,
'NetworkController:stateChange',
),
getERC721AssetName: this.assetsContractController.getERC721AssetName.bind(
this.assetsContractController,
),
Expand Down Expand Up @@ -706,10 +672,6 @@ export default class MetamaskController extends EventEmitter {
source,
},
}),
getNetworkClientById: this.networkController.getNetworkClientById.bind(
this.networkController,
),
state: initState.NftController,
});

this.nftController.setApiKey(process.env.OPENSEA_KEY);
Expand All @@ -718,48 +680,33 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger.getRestricted({
name: 'NftDetectionController',
allowedEvents: [
'PreferencesController:stateChange',
'NetworkController:stateChange',
'PreferencesController:stateChange',
],
allowedActions: [
'ApprovalController:addRequest',
'NetworkController:getState',
'NetworkController:getNetworkClientById',
'PreferencesController:getState',
'AccountsController:getSelectedAccount',
],
});

this.nftDetectionController = new NftDetectionController({
messenger: nftDetectionControllerMessenger,
chainId: this.networkController.state.providerConfig.chainId,
onNftsStateChange: (listener) => this.nftController.subscribe(listener),
onPreferencesStateChange: this.preferencesController.store.subscribe.bind(
this.preferencesController.store,
),
onNetworkStateChange: networkControllerMessenger.subscribe.bind(
networkControllerMessenger,
'NetworkController:stateChange',
),
getOpenSeaApiKey: () => this.nftController.openSeaApiKey,
getBalancesInSingleCall:
this.assetsContractController.getBalancesInSingleCall.bind(
this.assetsContractController,
),
addNft: this.nftController.addNft.bind(this.nftController),
getNftApi: this.nftController.getNftApi.bind(this.nftController),
getNftState: () => this.nftController.state,
// added this to track previous value of useNftDetection, should be true on very first initializing of controller[]
disabled:
this.preferencesController.store.getState().useNftDetection ===
undefined
? false // the detection is enabled by default
: !this.preferencesController.store.getState().useNftDetection,
selectedAddress:
this.preferencesController.store.getState().selectedAddress,
getNetworkClientById: this.networkController.getNetworkClientById.bind(
this.networkController,
),
});

this.metaMetricsController = new MetaMetricsController({
Expand Down Expand Up @@ -953,55 +900,29 @@ export default class MetamaskController extends EventEmitter {
fetchMultiExchangeRate,
});

const tokenRatesControllerMessenger =
this.controllerMessenger.getRestricted({
name: 'TokenRatesController',
allowedEvents: [
'PreferencesController:stateChange',
'TokensController:stateChange',
'NetworkController:stateChange',
],
allowedActions: [
'TokensController:getState',
'NetworkController:getNetworkClientById',
'NetworkController:getState',
'PreferencesController:getState',
],
});
const tokenRatesMessenger = this.controllerMessenger.getRestricted({
name: 'TokenRatesController',
allowedActions: [
'TokensController:getState',
'NetworkController:getNetworkClientById',
'NetworkController:getState',
'AccountsController:getAccount',
'AccountsController:getSelectedAccount',
],
allowedEvents: [
'NetworkController:stateChange',
'AccountsController:selectedEvmAccountChange',
'PreferencesController:stateChange',
'TokensController:stateChange',
],
});

// token exchange rate tracker
this.tokenRatesController = new TokenRatesController(
{
messenger: tokenRatesControllerMessenger,
chainId: this.networkController.state.providerConfig.chainId,
ticker: this.networkController.state.providerConfig.ticker,
selectedAddress: this.accountsController.getSelectedAccount().address,
onTokensStateChange: (listener) =>
this.tokensController.subscribe(listener),
onNetworkStateChange: networkControllerMessenger.subscribe.bind(
networkControllerMessenger,
'NetworkController:stateChange',
),
onPreferencesStateChange: (listener) =>
this.controllerMessenger.subscribe(
`AccountsController:selectedAccountChange`,
(newlySelectedInternalAccount) => {
listener({
selectedAddress: newlySelectedInternalAccount.address,
});
},
),
tokenPricesService: new CodefiTokenPricesServiceV2(),
getNetworkClientById: this.networkController.getNetworkClientById.bind(
this.networkController,
),
},
{
allTokens: this.tokensController.state.allTokens,
allDetectedTokens: this.tokensController.state.allDetectedTokens,
},
initState.TokenRatesController,
);
this.tokenRatesController = new TokenRatesController({
state: initState.TokenRatesController,
messenger: tokenRatesMessenger,
tokenPricesService: new CodefiTokenPricesServiceV2(),
});

this.preferencesController.store.subscribe(
previousValueComparator((prevState, currState) => {
Expand Down Expand Up @@ -1628,6 +1549,7 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger.getRestricted({
name: 'TokenDetectionController',
allowedActions: [
'AccountsController:getAccount',
'AccountsController:getSelectedAccount',
'KeyringController:getState',
'NetworkController:getNetworkClientById',
Expand All @@ -1639,7 +1561,7 @@ export default class MetamaskController extends EventEmitter {
'TokensController:addDetectedTokens',
],
allowedEvents: [
'AccountsController:selectedAccountChange',
'AccountsController:selectedEvmAccountChange',
'KeyringController:lock',
'KeyringController:unlock',
'NetworkController:networkDidChange',
Expand Down
Loading

0 comments on commit f353f0c

Please sign in to comment.