Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@metamask/network-controller

Package Overview
Dependencies
Maintainers
10
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/network-controller - npm Package Compare versions

Comparing version 11.0.0 to 12.0.0

22

CHANGELOG.md

@@ -9,2 +9,20 @@ # Changelog

## [12.0.0]
### Added
- Add `NetworksMetadata` type ([#1559](https://github.com/MetaMask/core/pull/1559))
### Changed
- **BREAKING:** Remove `NetworkDetails` type in favor of `NetworkMetadata` ([#1559](https://github.com/MetaMask/core/pull/1559))
- This new type includes `NetworkDetails` plus a `status` property
- **BREAKING:** Add `networksMetadata` to state ([#1559](https://github.com/MetaMask/core/pull/1559))
- Consumers will need to add a migration. The data for this property can be constructed by looping over the values in `InfuraNetworkType` from `@metamask/controller-utils` plus the network configuration IDs in the state property `networkConfigurations` and setting each value to `{ status: "unknown", EIPS: {} }`.
- **BREAKING:** Add `selectedNetworkClientId` to state ([#1548](https://github.com/MetaMask/core/pull/1548))
- Consumers will need to add a migration. This property should be set to either `providerConfig.type` or `providerConfig.id`.
- Update `getEIP1559Compatibility` to return `undefined` when the latest block is unavailable ([#1457](https://github.com/MetaMask/core/pull/1457))
- Replace `eth-query` ^2.1.2 with `@metamask/eth-query` ^3.0.1 ([#1546](https://github.com/MetaMask/core/pull/1546))
### Removed
- **BREAKING:** Remove `networkDetails` from state ([#1559](https://github.com/MetaMask/core/pull/1559))
- The data in this state property has been merged into the new `networksMetadata` state property; each value in this object contains an `EIPS` property.
## [11.0.0]

@@ -18,3 +36,2 @@ ### Changed

## [10.3.1]

@@ -219,3 +236,4 @@ ### Changed

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@11.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@12.0.0...HEAD
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@11.0.0...@metamask/network-controller@12.0.0
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@10.3.1...@metamask/network-controller@11.0.0

@@ -222,0 +240,0 @@ [10.3.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@10.3.0...@metamask/network-controller@10.3.1

export * from './NetworkController';
export * from './constants';
export type { BlockTracker, Provider } from './types';
export type { NetworkClientConfiguration } from './types';
export { NetworkClientType } from './types';
//# sourceMappingURL=index.d.ts.map

@@ -17,4 +17,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.NetworkClientType = void 0;
__exportStar(require("./NetworkController"), exports);
__exportStar(require("./constants"), exports);
var types_1 = require("./types");
Object.defineProperty(exports, "NetworkClientType", { enumerable: true, get: function () { return types_1.NetworkClientType; } });
//# sourceMappingURL=index.js.map

45

dist/NetworkController.d.ts
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import { BaseControllerV2 } from '@metamask/base-controller';
import { InfuraNetworkType, NetworkType } from '@metamask/controller-utils';
import EthQuery from '@metamask/eth-query';
import type { SwappableProxy } from '@metamask/swappable-obj-proxy';
import type { Hex } from '@metamask/utils';
import EthQuery from 'eth-query';
import type { Patch } from 'immer';

@@ -37,6 +37,5 @@ import { NetworkStatus } from './constants';

/**
* Information about the network not held by any other part of state. Currently
* only used to capture whether a network supports EIP-1559.
* Information about a network not held by any other part of state.
*/
export declare type NetworkDetails = {
export declare type NetworkMetadata = {
/**

@@ -48,2 +47,6 @@ * EIPs supported by the network.

};
/**
* Indicates the availability of the network
*/
status: NetworkStatus;
};

@@ -89,2 +92,20 @@ /**

/**
* The string that uniquely identifies an Infura network client.
*/
declare type BuiltInNetworkClientId = InfuraNetworkType;
/**
* The string that uniquely identifies a custom network client.
*/
declare type CustomNetworkClientId = string;
/**
* The string that uniquely identifies a network client.
*/
declare type NetworkClientId = BuiltInNetworkClientId | CustomNetworkClientId;
/**
* Information about networks not held by any other part of state.
*/
export declare type NetworksMetadata = {
[networkClientId: NetworkClientId]: NetworkMetadata;
};
/**
* The network ID of a network.

@@ -103,7 +124,7 @@ */

export declare type NetworkState = {
selectedNetworkClientId: NetworkClientId;
networkId: NetworkId | null;
networkStatus: NetworkStatus;
providerConfig: ProviderConfig;
networkDetails: NetworkDetails;
networkConfigurations: NetworkConfigurations;
networksMetadata: NetworksMetadata;
};

@@ -190,10 +211,2 @@ declare const name = "NetworkController";

/**
* The string that uniquely identifies an Infura network client.
*/
declare type BuiltInNetworkClientId = InfuraNetworkType;
/**
* The string that uniquely identifies a custom network client.
*/
declare type CustomNetworkClientId = string;
/**
* The collection of auto-managed network clients that map to Infura networks.

@@ -265,5 +278,5 @@ */

* @returns A promise that resolves to true if the network supports EIP-1559
* and false otherwise.
* , false otherwise, or `undefined` if unable to determine the compatibility.
*/
getEIP1559Compatibility(): Promise<boolean>;
getEIP1559Compatibility(): Promise<boolean | undefined>;
/**

@@ -270,0 +283,0 @@ * Re-initializes the provider and block tracker for the current network.

@@ -30,6 +30,6 @@ "use strict";

const controller_utils_1 = require("@metamask/controller-utils");
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
const swappable_obj_proxy_1 = require("@metamask/swappable-obj-proxy");
const utils_1 = require("@metamask/utils");
const assert_1 = require("assert");
const eth_query_1 = __importDefault(require("eth-query"));
const eth_rpc_errors_1 = require("eth-rpc-errors");

@@ -213,4 +213,4 @@ const uuid_1 = require("uuid");

exports.defaultState = {
selectedNetworkClientId: controller_utils_1.NetworkType.mainnet,
networkId: null,
networkStatus: constants_1.NetworkStatus.Unknown,
providerConfig: {

@@ -221,5 +221,3 @@ type: controller_utils_1.NetworkType.mainnet,

},
networkDetails: {
EIPS: {},
},
networksMetadata: {},
networkConfigurations: {},

@@ -235,11 +233,11 @@ };

metadata: {
networkId: {
selectedNetworkClientId: {
persist: true,
anonymous: false,
},
networkStatus: {
networkId: {
persist: true,
anonymous: false,
},
networkDetails: {
networksMetadata: {
persist: true,

@@ -388,8 +386,9 @@ anonymous: false,

state.networkId = updatedNetworkId;
state.networkStatus = updatedNetworkStatus;
const meta = state.networksMetadata[state.selectedNetworkClientId];
meta.status = updatedNetworkStatus;
if (updatedIsEIP1559Compatible === undefined) {
delete state.networkDetails.EIPS[1559];
delete meta.EIPS[1559];
}
else {
state.networkDetails.EIPS[1559] = updatedIsEIP1559Compatible;
meta.EIPS[1559] = updatedIsEIP1559Compatible;
}

@@ -471,16 +470,19 @@ });

* @returns A promise that resolves to true if the network supports EIP-1559
* and false otherwise.
* , false otherwise, or `undefined` if unable to determine the compatibility.
*/
getEIP1559Compatibility() {
return __awaiter(this, void 0, void 0, function* () {
const { EIPS } = this.state.networkDetails;
if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
return false;
}
const { EIPS } = this.state.networksMetadata[this.state.selectedNetworkClientId];
if (EIPS[1559] !== undefined) {
return EIPS[1559];
}
if (!__classPrivateFieldGet(this, _NetworkController_ethQuery, "f")) {
return false;
}
const isEIP1559Compatible = yield __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_determineEIP1559Compatibility).call(this);
this.update((state) => {
state.networkDetails.EIPS[1559] = isEIP1559Compatible;
if (isEIP1559Compatible !== undefined) {
state.networksMetadata[state.selectedNetworkClientId].EIPS[1559] =
isEIP1559Compatible;
}
});

@@ -660,6 +662,2 @@ return isEIP1559Compatible;

state.networkId = null;
state.networkStatus = constants_1.NetworkStatus.Unknown;
state.networkDetails = {
EIPS: {},
};
});

@@ -706,3 +704,6 @@ __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_applyNetworkSelection).call(this);

const latestBlock = yield __classPrivateFieldGet(this, _NetworkController_instances, "m", _NetworkController_getLatestBlock).call(this);
return (latestBlock === null || latestBlock === void 0 ? void 0 : latestBlock.baseFeePerGas) !== undefined;
if (!latestBlock) {
return undefined;
}
return latestBlock.baseFeePerGas !== undefined;
});

@@ -787,7 +788,9 @@ }, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated = function _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated() {

let autoManagedNetworkClient;
let networkClientId;
if (isInfuraProviderConfig(providerConfig)) {
const networkClientType = types_1.NetworkClientType.Infura;
const networkClientId = buildInfuraNetworkClientId(providerConfig);
networkClientId = buildInfuraNetworkClientId(providerConfig);
const builtInNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClientRegistry, "f")[networkClientType];
autoManagedNetworkClient = builtInNetworkClientRegistry[networkClientId];
autoManagedNetworkClient =
builtInNetworkClientRegistry[networkClientId];
if (!autoManagedNetworkClient) {

@@ -800,3 +803,3 @@ throw new Error(`Could not find custom network matching ${networkClientId}`);

const networkClientType = types_1.NetworkClientType.Custom;
const networkClientId = buildCustomNetworkClientId(providerConfig, this.state.networkConfigurations);
networkClientId = buildCustomNetworkClientId(providerConfig, this.state.networkConfigurations);
const customNetworkClientRegistry = __classPrivateFieldGet(this, _NetworkController_autoManagedNetworkClientRegistry, "f")[networkClientType];

@@ -811,2 +814,11 @@ autoManagedNetworkClient = customNetworkClientRegistry[networkClientId];

}
this.update((state) => {
state.selectedNetworkClientId = networkClientId;
if (state.networksMetadata[networkClientId] === undefined) {
state.networksMetadata[networkClientId] = {
status: constants_1.NetworkStatus.Unknown,
EIPS: {},
};
}
});
const { provider, blockTracker } = autoManagedNetworkClient;

@@ -813,0 +825,0 @@ if (__classPrivateFieldGet(this, _NetworkController_providerProxy, "f")) {

{
"name": "@metamask/network-controller",
"version": "11.0.0",
"version": "12.0.0",
"description": "Provides an interface to the currently selected network via a MetaMask-compatible provider object",

@@ -33,6 +33,7 @@ "keywords": [

"@metamask/base-controller": "^3.2.0",
"@metamask/controller-utils": "^4.3.0",
"@metamask/controller-utils": "^4.3.1",
"@metamask/eth-json-rpc-infura": "^8.1.1",
"@metamask/eth-json-rpc-middleware": "^11.0.0",
"@metamask/eth-json-rpc-provider": "^1.0.0",
"@metamask/eth-query": "^3.0.1",
"@metamask/swappable-obj-proxy": "^2.1.0",

@@ -42,3 +43,2 @@ "@metamask/utils": "^6.2.0",

"eth-block-tracker": "^7.0.1",
"eth-query": "^2.1.2",
"eth-rpc-errors": "^4.0.2",

@@ -59,3 +59,3 @@ "immer": "^9.0.6",

"lodash": "^4.17.21",
"nock": "^13.0.7",
"nock": "^13.3.1",
"sinon": "^9.2.4",

@@ -62,0 +62,0 @@ "ts-jest": "^27.1.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc