diff --git a/packages/polling-controller/CHANGELOG.md b/packages/polling-controller/CHANGELOG.md index 6c4cad8165..6eddc21673 100644 --- a/packages/polling-controller/CHANGELOG.md +++ b/packages/polling-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `BlockTrackerPollingDataService` and `StaticIntervalPollingDataService` mixins for integrating the polling pattern in data services ([#9352](https://github.com/MetaMask/core/pull/9352)) + ## [16.0.8] ### Changed diff --git a/packages/polling-controller/package.json b/packages/polling-controller/package.json index 0efda7e14f..109045de43 100644 --- a/packages/polling-controller/package.json +++ b/packages/polling-controller/package.json @@ -52,6 +52,7 @@ }, "dependencies": { "@metamask/base-controller": "^9.1.0", + "@metamask/base-data-service": "^0.1.3", "@metamask/network-controller": "^34.0.0", "@metamask/utils": "^11.11.0", "@types/uuid": "^8.3.0", diff --git a/packages/polling-controller/src/BlockTrackerPollingController.ts b/packages/polling-controller/src/BlockTrackerPollingController.ts index c01762a4ed..7a2fc2ad7f 100644 --- a/packages/polling-controller/src/BlockTrackerPollingController.ts +++ b/packages/polling-controller/src/BlockTrackerPollingController.ts @@ -1,4 +1,5 @@ import { BaseController } from '@metamask/base-controller'; +import { BaseDataService } from '@metamask/base-data-service'; import type { NetworkClientId, NetworkClient, @@ -103,3 +104,13 @@ export const BlockTrackerPollingController = < BlockTrackerPollingControllerMixin( BaseController, ); + +export const BlockTrackerPollingDataService = < + PollingInput extends BlockTrackerPollingInput, + // The return type is inferred from the class defined inside the function + // scope, so this can't be easily typed. + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type +>() => + BlockTrackerPollingControllerMixin( + BaseDataService, + ); diff --git a/packages/polling-controller/src/StaticIntervalPollingController.ts b/packages/polling-controller/src/StaticIntervalPollingController.ts index dce38ce919..0b7a8b627b 100644 --- a/packages/polling-controller/src/StaticIntervalPollingController.ts +++ b/packages/polling-controller/src/StaticIntervalPollingController.ts @@ -1,4 +1,5 @@ import { BaseController } from '@metamask/base-controller'; +import { BaseDataService } from '@metamask/base-data-service'; import type { Json } from '@metamask/utils'; import { @@ -96,3 +97,11 @@ export const StaticIntervalPollingController = () => StaticIntervalPollingControllerMixin( BaseController, ); + +// The return type is inferred from the class defined inside the function +// scope, so this can't be easily typed. +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type +export const StaticIntervalPollingDataService = () => + StaticIntervalPollingControllerMixin( + BaseDataService, + ); diff --git a/packages/polling-controller/src/index.ts b/packages/polling-controller/src/index.ts index ba1758c443..36ea68e317 100644 --- a/packages/polling-controller/src/index.ts +++ b/packages/polling-controller/src/index.ts @@ -1,11 +1,13 @@ export { BlockTrackerPollingControllerOnly, BlockTrackerPollingController, + BlockTrackerPollingDataService, } from './BlockTrackerPollingController'; export { StaticIntervalPollingControllerOnly, StaticIntervalPollingController, + StaticIntervalPollingDataService, } from './StaticIntervalPollingController'; export type { IPollingController } from './types'; diff --git a/packages/polling-controller/tsconfig.build.json b/packages/polling-controller/tsconfig.build.json index c55f67af5a..de202b8ef9 100644 --- a/packages/polling-controller/tsconfig.build.json +++ b/packages/polling-controller/tsconfig.build.json @@ -7,6 +7,7 @@ }, "references": [ { "path": "../base-controller/tsconfig.build.json" }, + { "path": "../base-data-service/tsconfig.build.json" }, { "path": "../controller-utils/tsconfig.build.json" }, { "path": "../network-controller/tsconfig.build.json" }, { "path": "../messenger/tsconfig.build.json" } diff --git a/packages/polling-controller/tsconfig.json b/packages/polling-controller/tsconfig.json index ca0d50a83f..859b6a2ad6 100644 --- a/packages/polling-controller/tsconfig.json +++ b/packages/polling-controller/tsconfig.json @@ -6,6 +6,7 @@ }, "references": [ { "path": "../base-controller" }, + { "path": "../base-data-service" }, { "path": "../controller-utils" }, { "path": "../network-controller" }, { "path": "../messenger" } diff --git a/yarn.lock b/yarn.lock index 9a0b0651f0..3e75d5cd0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8029,6 +8029,7 @@ __metadata: dependencies: "@metamask/auto-changelog": "npm:^6.1.0" "@metamask/base-controller": "npm:^9.1.0" + "@metamask/base-data-service": "npm:^0.1.3" "@metamask/messenger": "npm:^1.2.0" "@metamask/network-controller": "npm:^34.0.0" "@metamask/utils": "npm:^11.11.0"