Skip to content

Commit

Permalink
Merge branch 'main' into resolve-constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Oct 24, 2024
2 parents e751798 + 81546f1 commit 1a0bafd
Show file tree
Hide file tree
Showing 43 changed files with 265 additions and 108 deletions.
2 changes: 1 addition & 1 deletion examples/example-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/controller-utils": "^11.3.0",
"@metamask/controller-utils": "^11.4.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/core-monorepo",
"version": "225.0.0",
"version": "228.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/address-book-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/controller-utils": "^11.3.0",
"@metamask/controller-utils": "^11.4.0",
"@metamask/utils": "^9.1.0"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/assets-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** Bump `@metamask/network-controller` peer dependency from `^21.0.0` to `^22.0.0` ([#4841](https://github.com/MetaMask/core/pull/4841))

## [39.0.0]

### Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@metamask/abi-utils": "^2.0.3",
"@metamask/base-controller": "^7.0.1",
"@metamask/contract-metadata": "^2.4.0",
"@metamask/controller-utils": "^11.3.0",
"@metamask/controller-utils": "^11.4.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/polling-controller": "^11.0.0",
Expand All @@ -79,7 +79,7 @@
"@metamask/ethjs-provider-http": "^0.3.0",
"@metamask/keyring-api": "^8.1.3",
"@metamask/keyring-controller": "^17.3.0",
"@metamask/network-controller": "^21.1.0",
"@metamask/network-controller": "^22.0.0",
"@metamask/preferences-controller": "^13.1.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
Expand All @@ -98,7 +98,7 @@
"@metamask/accounts-controller": "^18.0.0",
"@metamask/approval-controller": "^7.0.0",
"@metamask/keyring-controller": "^17.0.0",
"@metamask/network-controller": "^21.0.0",
"@metamask/network-controller": "^22.0.0",
"@metamask/preferences-controller": "^13.0.0"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('CurrencyRateController', () => {
messenger,
});

controller.startPolling({ networkClientId: 'mainnet' });
controller.startPolling({ nativeCurrency: 'ETH' });
await advanceTime({ clock, duration: 0 });
expect(fetchExchangeRateStub).toHaveBeenCalledTimes(1);
expect(controller.state.currencyRates).toStrictEqual({
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('CurrencyRateController', () => {
messenger,
});

controller.startPolling({ networkClientId: 'sepolia' });
controller.startPolling({ nativeCurrency: 'ETH' });

await advanceTime({ clock, duration: 0 });

Expand All @@ -217,15 +217,15 @@ describe('CurrencyRateController', () => {
fetchExchangeRate: fetchExchangeRateStub,
messenger,
});
controller.startPolling({ networkClientId: 'sepolia' });
controller.startPolling({ nativeCurrency: 'ETH' });
await advanceTime({ clock, duration: 0 });

controller.stopAllPolling();

// called once upon initial start
expect(fetchExchangeRateStub).toHaveBeenCalledTimes(1);

controller.startPolling({ networkClientId: 'sepolia' });
controller.startPolling({ nativeCurrency: 'ETH' });
await advanceTime({ clock, duration: 0 });

expect(fetchExchangeRateStub).toHaveBeenCalledTimes(2);
Expand Down
17 changes: 5 additions & 12 deletions packages/assets-controllers/src/CurrencyRateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
TESTNET_TICKER_SYMBOLS,
FALL_BACK_VS_CURRENCY,
} from '@metamask/controller-utils';
import type {
NetworkClientId,
NetworkControllerGetNetworkClientByIdAction,
} from '@metamask/network-controller';
import type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';
import { StaticIntervalPollingController } from '@metamask/polling-controller';
import { Mutex } from 'async-mutex';

Expand Down Expand Up @@ -80,7 +77,7 @@ const defaultState = {

/** The input to start polling for the {@link CurrencyRateController} */
type CurrencyRatePollingInput = {
networkClientId: NetworkClientId;
nativeCurrency: string;
};

/**
Expand Down Expand Up @@ -243,16 +240,12 @@ export class CurrencyRateController extends StaticIntervalPollingController<Curr
* Updates exchange rate for the current currency.
*
* @param input - The input for the poll.
* @param input.networkClientId - The network client ID used to get a ticker value.
* @param input.nativeCurrency - The native currency symbol to poll prices for.
*/
async _executePoll({
networkClientId,
nativeCurrency,
}: CurrencyRatePollingInput): Promise<void> {
const networkClient = this.messagingSystem.call(
'NetworkController:getNetworkClientById',
networkClientId,
);
await this.updateExchangeRate(networkClient.configuration.ticker);
await this.updateExchangeRate(nativeCurrency);
}
}

Expand Down
78 changes: 70 additions & 8 deletions packages/assets-controllers/src/TokenRatesController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ describe('TokenRatesController', () => {
);
});

it('should update exchange rates when chain ID changes', async () => {
it('should not update exchange rates when chain ID changes', async () => {
await withController(
{
options: {
Expand Down Expand Up @@ -722,12 +722,18 @@ describe('TokenRatesController', () => {
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

expect(controller.state.marketData).toStrictEqual({});
expect(controller.state.marketData).toStrictEqual({
'0x1': {
'0x0000000000000000000000000000000000000000': {
currency: 'ETH',
},
},
});
},
);
});

it('should clear marketData state when chain ID changes', async () => {
it('should not clear marketData state when chain ID changes', async () => {
await withController(
{
options: {
Expand Down Expand Up @@ -776,7 +782,13 @@ describe('TokenRatesController', () => {
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

expect(controller.state.marketData).toStrictEqual({});
expect(controller.state.marketData).toStrictEqual({
'0x1': {
'0x0000000000000000000000000000000000000000': {
currency: 'ETH',
},
},
});
},
);
});
Expand Down Expand Up @@ -865,7 +877,7 @@ describe('TokenRatesController', () => {
);
});

it('should clear marketData state when ticker changes', async () => {
it('should not clear marketData state when ticker changes', async () => {
await withController(
{
options: {
Expand Down Expand Up @@ -913,12 +925,37 @@ describe('TokenRatesController', () => {
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

expect(controller.state.marketData).toStrictEqual({});
expect(controller.state.marketData).toStrictEqual({
'0x1': {
'0x02': {
currency: 'ETH',
priceChange1d: 0,
pricePercentChange1d: 0,
tokenAddress: '0x02',
allTimeHigh: 4000,
allTimeLow: 900,
circulatingSupply: 2000,
dilutedMarketCap: 100,
high1d: 200,
low1d: 100,
marketCap: 1000,
marketCapPercentChange1d: 100,
price: 0.001,
pricePercentChange14d: 100,
pricePercentChange1h: 1,
pricePercentChange1y: 200,
pricePercentChange200d: 300,
pricePercentChange30d: 200,
pricePercentChange7d: 100,
totalVolume: 100,
},
},
});
},
);
});

it('should clear marketData state when chain ID changes', async () => {
it('should not clear marketData state when chain ID changes', async () => {
await withController(
{
options: {
Expand Down Expand Up @@ -966,7 +1003,32 @@ describe('TokenRatesController', () => {
selectedNetworkClientId: 'AAAA-BBBB-CCCC-DDDD',
});

expect(controller.state.marketData).toStrictEqual({});
expect(controller.state.marketData).toStrictEqual({
'0x1': {
'0x02': {
currency: 'ETH',
priceChange1d: 0,
pricePercentChange1d: 0,
tokenAddress: '0x02',
allTimeHigh: 4000,
allTimeLow: 900,
circulatingSupply: 2000,
dilutedMarketCap: 100,
high1d: 200,
low1d: 100,
marketCap: 1000,
marketCapPercentChange1d: 100,
price: 0.001,
pricePercentChange14d: 100,
pricePercentChange1h: 1,
pricePercentChange1y: 200,
pricePercentChange200d: 300,
pricePercentChange30d: 200,
pricePercentChange7d: 100,
totalVolume: 100,
},
},
});
},
);
});
Expand Down
8 changes: 4 additions & 4 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,6 @@ export class TokenRatesController extends StaticIntervalPollingController<TokenR
);

if (this.#chainId !== chainId || this.#ticker !== ticker) {
this.update((state) => {
state.marketData = {};
});
this.#chainId = chainId;
this.#ticker = ticker;
if (this.#pollState === PollState.Active) {
Expand Down Expand Up @@ -531,7 +528,10 @@ export class TokenRatesController extends StaticIntervalPollingController<TokenR
};

this.update((state) => {
state.marketData = marketData;
state.marketData = {
...state.marketData,
...marketData,
};
});
updateSucceeded();
} catch (error: unknown) {
Expand Down
9 changes: 8 additions & 1 deletion packages/controller-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [11.4.0]

### Added

- Add `isEqualCaseInsensitive` function for case-insensitive string comparison ([#4811](https://github.com/MetaMask/core/pull/4811))

## [11.3.0]

### Added
Expand Down Expand Up @@ -400,7 +406,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

All changes listed after this point were applied to this package following the monorepo conversion.

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.3.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.4.0...HEAD
[11.4.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.3.0...@metamask/controller-utils@11.4.0
[11.3.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.2.0...@metamask/controller-utils@11.3.0
[11.2.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.1.0...@metamask/controller-utils@11.2.0
[11.1.0]: https://github.com/MetaMask/core/compare/@metamask/controller-utils@11.0.2...@metamask/controller-utils@11.1.0
Expand Down
2 changes: 1 addition & 1 deletion packages/controller-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/controller-utils",
"version": "11.3.0",
"version": "11.4.0",
"description": "Data and convenience functions shared by multiple packages",
"keywords": [
"MetaMask",
Expand Down
4 changes: 4 additions & 0 deletions packages/ens-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** Bump `@metamask/network-controller` peer dependency from `^21.0.0` to `^22.0.0` ([#4841](https://github.com/MetaMask/core/pull/4841))

## [14.0.1]

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions packages/ens-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
"dependencies": {
"@ethersproject/providers": "^5.7.0",
"@metamask/base-controller": "^7.0.1",
"@metamask/controller-utils": "^11.3.0",
"@metamask/controller-utils": "^11.4.0",
"@metamask/utils": "^9.1.0",
"punycode": "^2.1.1"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/network-controller": "^21.1.0",
"@metamask/network-controller": "^22.0.0",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
Expand All @@ -65,7 +65,7 @@
"typescript": "~5.2.2"
},
"peerDependencies": {
"@metamask/network-controller": "^21.0.0"
"@metamask/network-controller": "^22.0.0"
},
"engines": {
"node": "^18.18 || >=20"
Expand Down
4 changes: 4 additions & 0 deletions packages/gas-fee-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **BREAKING:** Bump `@metamask/network-controller` peer dependency from `^21.0.0` to `^22.0.0` ([#4841](https://github.com/MetaMask/core/pull/4841))

## [21.0.0]

### Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/gas-fee-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/controller-utils": "^11.3.0",
"@metamask/controller-utils": "^11.4.0",
"@metamask/eth-query": "^4.0.0",
"@metamask/ethjs-unit": "^0.3.0",
"@metamask/polling-controller": "^11.0.0",
Expand All @@ -60,7 +60,7 @@
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@metamask/network-controller": "^21.1.0",
"@metamask/network-controller": "^22.0.0",
"@types/jest": "^27.4.1",
"@types/jest-when": "^2.7.3",
"deepmerge": "^4.2.2",
Expand All @@ -74,7 +74,7 @@
"typescript": "~5.2.2"
},
"peerDependencies": {
"@metamask/network-controller": "^21.0.0"
"@metamask/network-controller": "^22.0.0"
},
"engines": {
"node": "^18.18 || >=20"
Expand Down
Loading

0 comments on commit 1a0bafd

Please sign in to comment.