Skip to content

Commit

Permalink
Added polling-controller (#1703)
Browse files Browse the repository at this point in the history
## Explanation

> Originally was in #1673 but
pulled out to get this in on its own.

Adds an abstract class (currently named `PollingController`. The start
and stop methods are parameterized by `networkClientId`'s and
`pollingToken`'s and polling intervals are stored in class variables by
`chainId` so that multiple `networkClients`/`chainIds` can poll
simultaneously. `executePoll` is an abstract method to be implemented by
the controller itself so that this pattern could be generalized and be
agnostic to what is being executed on the polling interval.


## References
Related to #1673
Related to MetaMask/MetaMask-planning#1314

---------

Co-authored-by: Alex Donesky <adonesky@gmail.com>
  • Loading branch information
shanejonas and adonesky1 authored Sep 26, 2023
1 parent e84aa47 commit 9698b0a
Show file tree
Hide file tree
Showing 12 changed files with 643 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/polling-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/core/
20 changes: 20 additions & 0 deletions packages/polling-controller/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2018 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 changes: 15 additions & 0 deletions packages/polling-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `@metamask/polling-controller`

PollingController is used as the base for all controllers that need to poll for updates based on `networkClientId`.

## Installation

`yarn add @metamask/polling-controller`

or

`npm install @metamask/polling-controller`

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/polling-controller/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 65.31,
functions: 76.59,
lines: 75.83,
statements: 75.91,
},
},
});
58 changes: 58 additions & 0 deletions packages/polling-controller/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@metamask/polling-controller",
"version": "0.0.0",
"description": "Polling Controller is the base for controllers that polling by networkClientId",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/polling-controller#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/"
],
"scripts": {
"build:docs": "typedoc",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/polling-controller",
"publish:preview": "yarn npm publish --tag preview",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/base-controller": "^3.2.1",
"@metamask/controller-utils": "^5.0.0",
"@metamask/network-controller": "^13.0.0",
"@metamask/utils": "^6.2.0",
"@types/uuid": "^8.3.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.1.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typedoc": "^0.23.15",
"typedoc-plugin-missing-exports": "^0.23.0",
"typescript": "~4.6.3"
},
"peerDependencies": {
"@metamask/network-controller": "^13.0.0"
},
"engines": {
"node": ">=16.0.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
Loading

0 comments on commit 9698b0a

Please sign in to comment.