Skip to content

Commit

Permalink
Changed ControllerPolling to PollingController and moved it to its ow…
Browse files Browse the repository at this point in the history
…n package
  • Loading branch information
shanejonas committed Sep 21, 2023
1 parent b98106d commit f0bd599
Show file tree
Hide file tree
Showing 18 changed files with 223 additions and 20 deletions.
5 changes: 1 addition & 4 deletions packages/controller-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ethereumjs-util": "^7.0.10",
"ethjs-unit": "^0.1.6",
"fast-deep-equal": "^3.1.3",
"uuid": "^8.3.2"
"uuid": "^9.0.1"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.1.0",
Expand All @@ -52,9 +52,6 @@
"typedoc-plugin-missing-exports": "^0.22.6",
"typescript": "~4.6.3"
},
"peerDependencies": {
"@metamask/network-controller": "^12.1.2"
},
"engines": {
"node": ">=16.0.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/controller-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './constants';
export * from './util';
export * from './types';
export * from './siwe';
export { default as ControllerPolling } from './ControllerPolling';
5 changes: 5 additions & 0 deletions packages/gas-fee-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
"@metamask/base-controller": "^3.2.1",
"@metamask/controller-utils": "^4.3.2",
"@metamask/eth-query": "^3.0.1",
<<<<<<< HEAD
"@metamask/network-controller": "^12.2.0",
=======
"@metamask/network-controller": "^12.1.2",
"@metamask/polling-controller": "workspace:^",
>>>>>>> 290ac3b4 (Changed ControllerPolling to PollingController and moved it to its own package)
"@metamask/utils": "^6.2.0",
"@types/uuid": "^8.3.0",
"ethereumjs-util": "^7.0.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/gas-fee-controller/src/GasFeeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import {
convertHexToDecimal,
safelyExecute,
ControllerPolling,
} from '@metamask/controller-utils';
import EthQuery from '@metamask/eth-query';
import type {
Expand All @@ -13,6 +12,7 @@ import type {
NetworkState,
ProviderProxy,
} from '@metamask/network-controller';
import { PollingController } from '@metamask/polling-controller';
import type { Hex } from '@metamask/utils';
import type { Patch } from 'immer';
import { v1 as random } from 'uuid';
Expand Down Expand Up @@ -246,7 +246,7 @@ const defaultState: GasFeeState = {
/**
* Controller that retrieves gas fee estimate data and polls for updated data on a set interval
*/
export class GasFeeController extends ControllerPolling<
export class GasFeeController extends PollingController<
typeof name,
GasFeeState,
GasFeeMessenger
Expand Down
3 changes: 2 additions & 1 deletion packages/gas-fee-controller/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"references": [
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../controller-utils/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" }
{ "path": "../network-controller/tsconfig.build.json" },
{ "path": "../polling-controller/tsconfig.build.json" }
],
"include": ["../../types", "./src"]
}
3 changes: 2 additions & 1 deletion packages/gas-fee-controller/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"references": [
{ "path": "../base-controller" },
{ "path": "../controller-utils" },
{ "path": "../network-controller" }
{ "path": "../network-controller" },
{ "path": "../polling-controller" }
],
"include": ["../../types", "./src"]
}
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/compare/@metamask/gas-fee-controller
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,
},
},
});
66 changes: 66 additions & 0 deletions packages/polling-controller/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"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/gas-fee-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/gas-fee-controller",
"publish:preview": "yarn npm publish --tag preview",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/base-controller": "^3.2.1",
"@metamask/controller-utils": "^4.3.2",
"@metamask/eth-query": "^3.0.1",
"@metamask/network-controller": "^12.1.2",
"@metamask/utils": "^6.2.0",
"@types/uuid": "^8.3.0",
"ethereumjs-util": "^7.0.10",
"ethjs-unit": "^0.1.6",
"immer": "^9.0.6",
"uuid": "^8.3.2"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.1.0",
"@types/jest": "^27.4.1",
"@types/jest-when": "^2.7.3",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"jest-when": "^3.4.2",
"nock": "^13.3.1",
"sinon": "^9.2.4",
"ts-jest": "^27.1.4",
"typedoc": "^0.22.15",
"typedoc-plugin-missing-exports": "^0.22.6",
"typescript": "~4.6.3"
},
"peerDependencies": {
"@metamask/network-controller": "^12.1.2"
},
"engines": {
"node": ">=16.0.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ControllerMessenger } from '@metamask/base-controller';

import type { PollingCompleteType } from './ControllerPolling';
import GasFeeControllerPolling from './ControllerPolling';
import type { PollingCompleteType } from './PollingController';
import GasFeeControllerPolling from './PollingController';

describe('ControllerPolling', () => {
describe('PollingController', () => {
let executePollMock: GasFeeControllerPolling<any, any, any>['executePoll'];

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import { BaseControllerV2 } from '@metamask/base-controller';
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
import type { NetworkClientId } from '@metamask/network-controller';
import type { Json } from '@metamask/utils';
import { v1 as random } from 'uuid';
Expand Down
1 change: 1 addition & 0 deletions packages/polling-controller/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as PollingController } from './PollingController';
14 changes: 14 additions & 0 deletions packages/polling-controller/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.packages.build.json",
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist",
"rootDir": "./src"
},
"references": [
{ "path": "../base-controller/tsconfig.build.json" },
{ "path": "../controller-utils/tsconfig.build.json" },
{ "path": "../network-controller/tsconfig.build.json" }
],
"include": ["../../types", "./src"]
}
12 changes: 12 additions & 0 deletions packages/polling-controller/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"baseUrl": "./"
},
"references": [
{ "path": "../base-controller" },
{ "path": "../controller-utils" },
{ "path": "../network-controller" }
],
"include": ["../../types", "./src"]
}
7 changes: 7 additions & 0 deletions packages/polling-controller/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"entryPoints": ["./src/index.ts"],
"excludePrivate": true,
"hideGenerator": true,
"out": "docs",
"tsconfig": "./tsconfig.build.json"
}
44 changes: 37 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,7 @@ __metadata:
typedoc: ^0.22.15
typedoc-plugin-missing-exports: ^0.22.6
typescript: ~4.6.3
uuid: ^8.3.2
peerDependencies:
"@metamask/network-controller": ^12.1.2
uuid: ^9.0.1
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1815,6 +1813,7 @@ __metadata:
"@metamask/controller-utils": ^4.3.2
"@metamask/eth-query": ^3.0.1
"@metamask/network-controller": ^12.2.0
"@metamask/polling-controller": "workspace:^"
"@metamask/utils": ^6.2.0
"@types/jest": ^27.4.1
"@types/jest-when": ^2.7.3
Expand Down Expand Up @@ -2126,6 +2125,37 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/polling-controller@workspace:^, @metamask/polling-controller@workspace:packages/polling-controller":
version: 0.0.0-use.local
resolution: "@metamask/polling-controller@workspace:packages/polling-controller"
dependencies:
"@metamask/auto-changelog": ^3.1.0
"@metamask/base-controller": ^3.2.1
"@metamask/controller-utils": ^4.3.2
"@metamask/eth-query": ^3.0.1
"@metamask/network-controller": ^12.1.2
"@metamask/utils": ^6.2.0
"@types/jest": ^27.4.1
"@types/jest-when": ^2.7.3
"@types/uuid": ^8.3.0
deepmerge: ^4.2.2
ethereumjs-util: ^7.0.10
ethjs-unit: ^0.1.6
immer: ^9.0.6
jest: ^27.5.1
jest-when: ^3.4.2
nock: ^13.3.1
sinon: ^9.2.4
ts-jest: ^27.1.4
typedoc: ^0.22.15
typedoc-plugin-missing-exports: ^0.22.6
typescript: ~4.6.3
uuid: ^8.3.2
peerDependencies:
"@metamask/network-controller": ^12.1.2
languageName: unknown
linkType: soft

"@metamask/post-message-stream@npm:^6.1.1, @metamask/post-message-stream@npm:^6.1.2":
version: 6.1.2
resolution: "@metamask/post-message-stream@npm:6.1.2"
Expand Down Expand Up @@ -10200,12 +10230,12 @@ __metadata:
languageName: node
linkType: hard

"uuid@npm:^9.0.0":
version: 9.0.0
resolution: "uuid@npm:9.0.0"
"uuid@npm:^9.0.1":
version: 9.0.1
resolution: "uuid@npm:9.0.1"
bin:
uuid: dist/bin/uuid
checksum: 8dd2c83c43ddc7e1c71e36b60aea40030a6505139af6bee0f382ebcd1a56f6cd3028f7f06ffb07f8cf6ced320b76aea275284b224b002b289f89fe89c389b028
checksum: 39931f6da74e307f51c0fb463dc2462807531dc80760a9bff1e35af4316131b4fc3203d16da60ae33f07fdca5b56f3f1dd662da0c99fea9aaeab2004780cc5f4
languageName: node
linkType: hard

Expand Down

0 comments on commit f0bd599

Please sign in to comment.