Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor services to align with eventual RpcService #5109

Merged
merged 5 commits into from
Jan 24, 2025
Merged
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
2 changes: 1 addition & 1 deletion eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@typescript-eslint/no-unsafe-enum-comparison": 34,
"@typescript-eslint/no-unused-vars": 41,
"@typescript-eslint/prefer-promise-reject-errors": 33,
"@typescript-eslint/prefer-readonly": 147,
"@typescript-eslint/prefer-readonly": 143,
"import-x/namespace": 189,
"import-x/no-named-as-default": 1,
"import-x/no-named-as-default-member": 8,
Expand Down
11 changes: 11 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `onBreak` and `onDegraded` methods to `CodefiTokenPricesServiceV2` ([#5109](https://github.com/MetaMask/core/pull/5109))
- These serve the same purpose as the `onBreak` and `onDegraded` constructor options, but align more closely with the Cockatiel policy API.

### Changed

- Deprecate `ClientConfigApiService` constructor options `onBreak` and `onDegraded` in favor of methods ([#5109](https://github.com/MetaMask/core/pull/5109))
- Add `@metamask/controller-utils@^11.4.5` as a dependency ([#5109](https://github.com/MetaMask/core/pull/5109))
- `cockatiel` should still be in the dependency tree because it's now a dependency of `@metamask/controller-utils`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(comment, can be resolved) IIRC extension assets controller had added patches for cockatiel imports. It would be interesting to see if they are still needed, or if the patch is instead moved to this utils package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting. I wonder if Cockatiel defines a default export in addition to named exports. But to answer your question yes I think these patches may need to be moved to controller-utils.


## [46.0.1]

### Changed
Expand Down
1 change: 0 additions & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"async-mutex": "^0.5.0",
"bitcoin-address-validation": "^2.2.3",
"bn.js": "^5.2.1",
"cockatiel": "^3.1.2",
"immer": "^9.0.6",
"lodash": "^4.17.21",
"multiformats": "^13.1.0",
Expand Down
16 changes: 6 additions & 10 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2093,11 +2093,9 @@ describe('TokenRatesController', () => {
price: 0.002,
},
}),
validateCurrencySupported: jest.fn().mockReturnValue(
false,
// Cast used because this method has an assertion in the return
// value that I don't know how to type properly with Jest's mock.
) as unknown as AbstractTokenPricesService['validateCurrencySupported'],
validateCurrencySupported(_currency: unknown): _currency is string {
return false;
},
});
nock('https://min-api.cryptocompare.com')
.get('/data/price')
Expand Down Expand Up @@ -2288,11 +2286,9 @@ describe('TokenRatesController', () => {
value: 0.002,
},
}),
validateChainIdSupported: jest.fn().mockReturnValue(
false,
// Cast used because this method has an assertion in the return
// value that I don't know how to type properly with Jest's mock.
) as unknown as AbstractTokenPricesService['validateChainIdSupported'],
validateChainIdSupported(_chainId: unknown): _chainId is Hex {
return false;
},
});
await withController(
{
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class TokenRatesController extends StaticIntervalPollingController<TokenR

#pollState = PollState.Inactive;

#tokenPricesService: AbstractTokenPricesService;
readonly #tokenPricesService: AbstractTokenPricesService;

#inProcessExchangeRateUpdates: Record<`${Hex}:${string}`, Promise<void>> = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ServicePolicy } from '@metamask/controller-utils';
import type { Hex } from '@metamask/utils';

/**
Expand Down Expand Up @@ -53,7 +54,7 @@ export type AbstractTokenPricesService<
ChainId extends Hex = Hex,
TokenAddress extends Hex = Hex,
Currency extends string = string,
> = {
> = Partial<Pick<ServicePolicy, 'onBreak' | 'onDegraded'>> & {
/**
* Retrieves prices in the given currency for the tokens identified by the
* given addresses which are expected to live on the given chain.
Expand Down
Loading
Loading