Skip to content

Commit

Permalink
Merge branch 'main' into brian/token-balances-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bergeron authored Oct 24, 2024
2 parents 4394679 + 35b900b commit 5c53457
Show file tree
Hide file tree
Showing 59 changed files with 397 additions and 215 deletions.
4 changes: 2 additions & 2 deletions examples/example-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
},
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/utils": "^9.1.0"
"@metamask/utils": "^10.0.0"
},
"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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -59,7 +59,7 @@
"@metamask/eth-block-tracker": "^11.0.2",
"@metamask/eth-json-rpc-provider": "^4.1.5",
"@metamask/json-rpc-engine": "^10.0.0",
"@metamask/utils": "^9.1.0",
"@metamask/utils": "^10.0.0",
"@ts-bridge/cli": "^0.5.1",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@metamask/keyring-api": "^8.1.3",
"@metamask/snaps-sdk": "^6.5.0",
"@metamask/snaps-utils": "^8.1.1",
"@metamask/utils": "^9.1.0",
"@metamask/utils": "^10.0.0",
"deepmerge": "^4.2.2",
"ethereum-cryptography": "^2.1.2",
"immer": "^9.0.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-controller/src/AccountsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export class AccountsController extends BaseController<
};
// Do not remove this comment - This error is flaky: Comment out or restore the `ts-expect-error` directive below as needed.
// See: https://github.com/MetaMask/utils/issues/168
// // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types
// @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types
currentState.internalAccounts.accounts[accountId] = internalAccount;

if (metadata.name) {
Expand Down
4 changes: 2 additions & 2 deletions packages/address-book-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
},
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/controller-utils": "^11.3.0",
"@metamask/utils": "^9.1.0"
"@metamask/controller-utils": "^11.4.0",
"@metamask/utils": "^10.0.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/approval-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
},
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/rpc-errors": "^7.0.0",
"@metamask/utils": "^9.1.0",
"@metamask/rpc-errors": "^7.0.1",
"@metamask/utils": "^10.0.0",
"nanoid": "^3.1.31"
},
"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
10 changes: 5 additions & 5 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
"@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",
"@metamask/rpc-errors": "^7.0.0",
"@metamask/utils": "^9.1.0",
"@metamask/rpc-errors": "^7.0.1",
"@metamask/utils": "^10.0.0",
"@types/bn.js": "^5.1.5",
"@types/uuid": "^8.3.0",
"async-mutex": "^0.5.0",
Expand All @@ -80,7 +80,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 @@ -99,7 +99,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
2 changes: 1 addition & 1 deletion packages/base-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/utils": "^9.1.0",
"@metamask/utils": "^10.0.0",
"immer": "^9.0.6"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/build-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/utils": "^9.1.0",
"@metamask/utils": "^10.0.0",
"@types/eslint": "^8.44.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@metamask/snaps-controllers": "^9.7.0",
"@metamask/snaps-sdk": "^6.5.0",
"@metamask/snaps-utils": "^8.1.1",
"@metamask/utils": "^9.1.0",
"@metamask/utils": "^10.0.0",
"uuid": "^8.3.2"
},
"devDependencies": {
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
Loading

0 comments on commit 5c53457

Please sign in to comment.