Skip to content
Draft
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
8 changes: 4 additions & 4 deletions packages/polling-controller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ module.exports = merge(baseConfig, {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 82.35,
functions: 87.5,
lines: 92.13,
statements: 92.55,
branches: 83.33,
functions: 88,
lines: 92.39,
statements: 92.78,
},
},
});
4 changes: 3 additions & 1 deletion packages/polling-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
},
"dependencies": {
"@metamask/base-controller": "^9.1.0",
"@metamask/network-controller": "^35.0.1",
"@metamask/eth-block-tracker": "^15.0.1",
"@metamask/eth-json-rpc-provider": "^6.0.1",
"@metamask/json-rpc-engine": "^10.5.0",
"@metamask/utils": "^11.11.0",
"@types/uuid": "^8.3.0",
"fast-json-stable-stringify": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,85 @@
import { BaseController } from '@metamask/base-controller';
import type {
NetworkClientId,
NetworkClient,
} from '@metamask/network-controller';
import type { Json } from '@metamask/utils';
import type { BlockTracker as BaseBlockTracker } from '@metamask/eth-block-tracker';
import type { InternalProvider } from '@metamask/eth-json-rpc-provider';
import type { MiddlewareContext } from '@metamask/json-rpc-engine/v2';
import type { Json, Hex } from '@metamask/utils';

import {
AbstractPollingControllerBaseMixin,
getKey,
} from './AbstractPollingController.js';
import type { Constructor, PollingTokenSetId } from './types.js';

/**
* The type of network client that can be created.
*/
enum NetworkClientType {
Custom = 'custom',
Infura = 'infura',
}

/**
* A configuration object that can be used to create a client for a network.
*/
type CommonNetworkClientConfiguration = {
chainId: Hex;
failoverRpcUrls?: string[];
ticker: string;
};

/**
* A configuration object that can be used to create a client for a custom
* network.
*/
type CustomNetworkClientConfiguration = CommonNetworkClientConfiguration & {
rpcUrl: string;
type: NetworkClientType.Custom;
};

/**
* A configuration object that can be used to create a client for an Infura
* network.
*/
type InfuraNetworkClientConfiguration = CommonNetworkClientConfiguration & {
network: string;
infuraProjectId: string;
type: NetworkClientType.Infura;
};

/**
* A configuration object that can be used to create a client for a network.
*/
type NetworkClientConfiguration =
| CustomNetworkClientConfiguration
| InfuraNetworkClientConfiguration;

type Provider = InternalProvider<
MiddlewareContext<
{ origin: string; skipCache: boolean } & Record<string, unknown>
>
>;

type BlockTracker = BaseBlockTracker & {
checkForLatestBlock(): Promise<string>;
};

/**
* The pair of provider / block tracker that can be used to interface with the
* network and respond to new activity.
*/
type NetworkClient = {
configuration: NetworkClientConfiguration;
provider: Provider;
blockTracker: BlockTracker;
destroy: () => void;
};

/**
* The minimum input required to start polling for a {@link BlockTrackerPollingController}.
* Implementing classes may provide additional properties.
*/
export type BlockTrackerPollingInput = {
networkClientId: NetworkClientId;
networkClientId: string;
};

/**
Expand All @@ -40,7 +103,7 @@ function BlockTrackerPollingControllerMixin<
#activeListeners: Record<string, (options: Json) => Promise<void>> = {};

abstract _getNetworkClientById(
networkClientId: NetworkClientId,
networkClientId: string,
): NetworkClient | undefined;

_startPolling(input: PollingInput): void {
Expand All @@ -67,7 +130,7 @@ function BlockTrackerPollingControllerMixin<
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {
const { networkClientId } = JSON.parse(key);
const networkClient = this._getNetworkClientById(
networkClientId as NetworkClientId,
networkClientId as string,
);

if (networkClient && this.#activeListeners[key]) {
Expand Down
8 changes: 7 additions & 1 deletion packages/polling-controller/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
"path": "../base-controller/tsconfig.build.json"
},
{
"path": "../network-controller/tsconfig.build.json"
"path": "../eth-block-tracker/tsconfig.build.json"
},
{
"path": "../eth-json-rpc-provider/tsconfig.build.json"
},
{
"path": "../json-rpc-engine/tsconfig.build.json"
},
{
"path": "../messenger/tsconfig.build.json"
Expand Down
8 changes: 7 additions & 1 deletion packages/polling-controller/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
"path": "../base-controller"
},
{
"path": "../network-controller"
"path": "../eth-block-tracker"
},
{
"path": "../eth-json-rpc-provider"
},
{
"path": "../json-rpc-engine"
},
{
"path": "../messenger"
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8518,8 +8518,10 @@ __metadata:
dependencies:
"@metamask/auto-changelog": "npm:^6.1.0"
"@metamask/base-controller": "npm:^9.1.0"
"@metamask/eth-block-tracker": "npm:^15.0.1"
"@metamask/eth-json-rpc-provider": "npm:^6.0.1"
"@metamask/json-rpc-engine": "npm:^10.5.0"
"@metamask/messenger": "npm:^2.0.0"
"@metamask/network-controller": "npm:^35.0.1"
"@metamask/utils": "npm:^11.11.0"
"@ts-bridge/cli": "npm:^0.6.4"
"@types/jest": "npm:^30.0.0"
Expand Down
Loading