Skip to content

Commit

Permalink
fix: patch multiformats
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri committed Oct 28, 2024
1 parent ae62fc9 commit bc7ce34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
31 changes: 21 additions & 10 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import {
TokenListControllerActions,
TokenListControllerEvents,
TokenBalancesControllerState,
AssetsContractControllerGetERC20BalanceOfAction,
AssetsContractControllerGetERC721AssetNameAction,
AssetsContractControllerGetERC721AssetSymbolAction,
AssetsContractControllerGetERC721TokenURIAction,
AssetsContractControllerGetERC721OwnerOfAction,
AssetsContractControllerGetERC1155BalanceOfAction,
AssetsContractControllerGetERC1155TokenURIAction,
} from '@metamask/assets-controllers';
///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps)
import { AppState } from 'react-native';
Expand Down Expand Up @@ -304,7 +311,14 @@ type GlobalActions =
| TokensControllerActions
| TokenListControllerActions
| SelectedNetworkControllerActions
| SmartTransactionsControllerActions;
| SmartTransactionsControllerActions
| AssetsContractControllerGetERC20BalanceOfAction
| AssetsContractControllerGetERC721AssetNameAction
| AssetsContractControllerGetERC721AssetSymbolAction
| AssetsContractControllerGetERC721TokenURIAction
| AssetsContractControllerGetERC721OwnerOfAction
| AssetsContractControllerGetERC1155BalanceOfAction
| AssetsContractControllerGetERC1155TokenURIAction;

type GlobalEvents =
| AddressBookControllerEvents
Expand Down Expand Up @@ -619,7 +633,7 @@ class Engine {
'AssetsContractController:getERC721TokenURI',
'AssetsContractController:getERC721OwnerOf',
'AssetsContractController:getERC1155BalanceOf',
'AssetsContractController:getERC1155TokenURI ',
'AssetsContractController:getERC1155TokenURI',
],
allowedEvents: [
'PreferencesController:stateChange',
Expand Down Expand Up @@ -1638,13 +1652,14 @@ class Engine {
// controllers. They should be initialized via the constructor instead.
for (const controller of controllers) {
if (
// @ts-expect-error controller.name does not exist in AssetsContractController but this should be fixed in v38.
hasProperty(initialState, controller.name) &&
// Use `in` operator here because the `subscribe` function is one level up the prototype chain
'subscribe' in controller &&
controller.subscribe !== undefined
) {
// The following type error can be addressed by passing initial state into controller constructors instead
// @ts-expect-error No type-level guarantee that the correct state is being applied to the correct controller here.

controller.update(initialState[controller.name]);
}
}
Expand All @@ -1657,6 +1672,7 @@ class Engine {
this.context = controllers.reduce<Partial<typeof this.context>>(
(context, controller) => ({
...context,
// @ts-expect-error controller.name does not exist in AssetsContractController but this should be fixed in v38.
[controller.name]: controller,
}),
{},
Expand Down Expand Up @@ -1763,20 +1779,15 @@ class Engine {
}

configureControllersOnNetworkChange() {
const {
AccountTrackerController,
AssetsContractController,
NetworkController,
SwapsController,
} = this.context;
const { AccountTrackerController, NetworkController, SwapsController } =
this.context;
const { provider } = NetworkController.getProviderAndBlockTracker();

// Skip configuration if this is called before the provider is initialized
if (!provider) {
return;
}
provider.sendAsync = provider.sendAsync.bind(provider);
AssetsContractController.setProvider(provider);

SwapsController.configure({
provider,
Expand Down
12 changes: 12 additions & 0 deletions patches/@metamask+assets-controllers++multiformats+13.3.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/node_modules/@metamask/assets-controllers/node_modules/multiformats/package.json b/node_modules/@metamask/assets-controllers/node_modules/multiformats/package.json
index 79fd9b9..662d4c7 100644
--- a/node_modules/@metamask/assets-controllers/node_modules/multiformats/package.json
+++ b/node_modules/@metamask/assets-controllers/node_modules/multiformats/package.json
@@ -22,6 +22,7 @@
"multiformats"
],
"type": "module",
+ "main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"typesVersions": {
"*": {

0 comments on commit bc7ce34

Please sign in to comment.