Skip to content

Commit deac397

Browse files
committed
Improve sample-controllers to be more useful examples
The controllers and services in `sample-controllers` are not as useful as examples as they could be. They do not follow the best practices that we want others to follow, so we cannot ask teams to copy them, and they do not follow patterns that are standard in the product. This commit makes the following changes: - The `SampleGasPricesService` now makes use of the messenger system. - `SampleGasPricesController` and `SamplePetnamesController` now exposes their methods as actions, which is more typical of a conventional controller. - The `AbstractSampleGasPricesService` has been removed, and `SampleGasPricesService` is now expected to be used via the messaging system. - `SampleGasPricesService` now uses the data services pattern, specifically, `createServicePolicy`. - The tests for `SampleGasPricesController` and `SamplePetnamesController` now use the `withController` pattern. - The tests for `SampleGasPricesController` and `SamplePetnamesController` now set up a "unrestricted" messenger rather than a "root" messenger. - `@metamask/network-controller` types are now used directly instead of being copied (it was already a peer dependency). - `fetchGasPrices` in `SampleGasPricesController` is now called automatically when the globally selected chain changes, and also now takes a chain ID to match. - `getDefaultPetnamesControllerState` is now exported.
1 parent 5b7f673 commit deac397

15 files changed

+958
-407
lines changed

packages/sample-controllers/CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `SampleGasPricesController.updateGasPrices` is now callable via the messaging system ([#6168](https://github.com/MetaMask/core/pull/6168))
13+
- An action type, `SampleGasPricesControllerUpdateGasPricesAction`, is now available for use
14+
- `SamplePetnamesController.assignPetname` is now callable via the messaging system ([#6168](https://github.com/MetaMask/core/pull/6168))
15+
- An action type, `SamplePetnamesControllerAssignPetnameAction`, is now available for use
16+
- Export new types for `SampleGasPricesService` ([#6168](https://github.com/MetaMask/core/pull/6168))
17+
- `SampleGasPricesServiceActions`
18+
- `SampleGasPricesServiceEvents`
19+
- `SampleGasPricesServiceFetchGasPricesAction`
20+
- `SampleGasPricesServiceMessenger`
21+
- Export `getDefaultPetnamesControllerState` ([#6168](https://github.com/MetaMask/core/pull/6168))
22+
1023
### Changed
1124

25+
- **BREAKING:** The messenger for `SampleGasPricesController` now expects `NetworkController:getNetworkClientById` to be allowed, and no longer expects `NetworkController:getState` to be allowed ([#6168](https://github.com/MetaMask/core/pull/6168))
26+
- **BREAKING:** `SampleGasPricesController.updateGasPrices` now takes a required `chainId` option ([#6168](https://github.com/MetaMask/core/pull/6168))
27+
- `SampleGasPricesController` will now automatically update gas prices when the globally selected chain changes ([#6168](https://github.com/MetaMask/core/pull/6168))
1228
- Bump `@metamask/controller-utils` from `^11.10.0` to `^11.11.0` ([#6069](https://github.com/MetaMask/core/pull/6069))
1329
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
1430

31+
### Removed
32+
33+
- **BREAKING:** `SampleGasPricesController` no longer takes a `gasPricesService` option ([#6168](https://github.com/MetaMask/core/pull/6168))
34+
- The controller now expects `SampleGasPricesService` to have been instantiated ahead of time
35+
1536
## [1.0.0]
1637

1738
### Changed

packages/sample-controllers/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"deepmerge": "^4.2.2",
5959
"jest": "^27.5.1",
6060
"nock": "^13.3.1",
61+
"sinon": "^9.2.4",
6162
"ts-jest": "^27.1.4",
6263
"typedoc": "^0.24.8",
6364
"typedoc-plugin-missing-exports": "^2.0.0",

packages/sample-controllers/src/index.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1+
export type {
2+
SampleGasPricesServiceActions,
3+
SampleGasPricesServiceEvents,
4+
SampleGasPricesServiceFetchGasPricesAction,
5+
SampleGasPricesServiceMessenger,
6+
} from './sample-gas-prices-service/sample-gas-prices-service';
7+
export { SampleGasPricesService } from './sample-gas-prices-service/sample-gas-prices-service';
18
export type {
29
SampleGasPricesControllerActions,
310
SampleGasPricesControllerEvents,
411
SampleGasPricesControllerGetStateAction,
512
SampleGasPricesControllerMessenger,
613
SampleGasPricesControllerState,
714
SampleGasPricesControllerStateChangeEvent,
15+
SampleGasPricesControllerUpdateGasPricesAction,
816
} from './sample-gas-prices-controller';
917
export {
10-
getDefaultSampleGasPricesControllerState,
1118
SampleGasPricesController,
19+
getDefaultSampleGasPricesControllerState,
1220
} from './sample-gas-prices-controller';
1321
export type {
1422
SamplePetnamesControllerActions,
23+
SamplePetnamesControllerAssignPetnameAction,
1524
SamplePetnamesControllerEvents,
1625
SamplePetnamesControllerGetStateAction,
1726
SamplePetnamesControllerMessenger,
1827
SamplePetnamesControllerState,
1928
SamplePetnamesControllerStateChangeEvent,
2029
} from './sample-petnames-controller';
21-
export { SamplePetnamesController } from './sample-petnames-controller';
2230
export {
23-
SampleGasPricesService,
24-
type SampleAbstractGasPricesService,
25-
} from './sample-gas-prices-service';
31+
SamplePetnamesController,
32+
getDefaultPetnamesControllerState,
33+
} from './sample-petnames-controller';

packages/sample-controllers/src/network-controller-types.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)