Skip to content

Commit

Permalink
Change naming of provider to providerConfig where applicable (#995)
Browse files Browse the repository at this point in the history
fixes #994
  • Loading branch information
BelfordZ authored Dec 1, 2022
1 parent 5f1f69d commit 55c30e2
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 130 deletions.
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/AssetsContractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export class AssetsContractController extends BaseController<
});

onNetworkStateChange((networkState) => {
if (this.config.chainId !== networkState.provider.chainId) {
if (this.config.chainId !== networkState.providerConfig.chainId) {
this.configure({
chainId: networkState.provider.chainId,
chainId: networkState.providerConfig.chainId,
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ export class NftController extends BaseController<NftConfig, NftState> {
},
);

onNetworkStateChange(({ provider }) => {
const { chainId } = provider;
onNetworkStateChange(({ providerConfig }) => {
const { chainId } = providerConfig;
this.configure({ chainId });
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/assets-controllers/src/NftDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ export class NftDetectionController extends BaseController<
}
});

onNetworkStateChange(({ provider }) => {
onNetworkStateChange(({ providerConfig }) => {
this.configure({
networkType: provider.type,
chainId: provider.chainId as NftDetectionConfig['chainId'],
networkType: providerConfig.type,
chainId: providerConfig.chainId as NftDetectionConfig['chainId'],
});
});
this.getOpenSeaApiKey = getOpenSeaApiKey;
Expand Down
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/TokenDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BN } from 'ethereumjs-util';
import {
NetworkController,
NetworkControllerMessenger,
NetworkControllerProviderChangeEvent,
NetworkControllerProviderConfigChangeEvent,
NetworkControllerStateChangeEvent,
} from '@metamask/network-controller';
import { NetworksChainId, MAINNET } from '@metamask/controller-utils';
Expand Down Expand Up @@ -86,7 +86,7 @@ const sampleTokenB: Token = {
type MainControllerMessenger = ControllerMessenger<
GetTokenListState,
| TokenListStateChange
| NetworkControllerProviderChangeEvent
| NetworkControllerProviderConfigChangeEvent
| NetworkControllerStateChangeEvent
>;

Expand All @@ -100,7 +100,7 @@ const setupNetworkController = (
const networkMessenger = controllerMessenger.getRestricted({
name: 'NetworkController',
allowedEvents: [
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
'NetworkController:stateChange',
],
allowedActions: [],
Expand All @@ -122,7 +122,7 @@ const setupTokenListController = (
allowedActions: [],
allowedEvents: [
'TokenListController:stateChange',
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
],
});

Expand Down Expand Up @@ -468,7 +468,7 @@ describe('TokenDetectionController', () => {
tokenDetection.stop();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
provider: { chainId: polygonDecimalChainId },
providerConfig: { chainId: polygonDecimalChainId },
});

expect(getBalancesInSingleCallMock.called).toBe(false);
Expand Down Expand Up @@ -572,7 +572,7 @@ describe('TokenDetectionController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkStateChangeListener!({
provider: { chainId: NetworksChainId.mainnet },
providerConfig: { chainId: NetworksChainId.mainnet },
});

expect(getBalancesInSingleCallMock.called).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/TokenDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class TokenDetectionController extends BaseController<
state?: Partial<BaseState>,
) {
const {
provider: { chainId: defaultChainId },
providerConfig: { chainId: defaultChainId },
} = getNetworkState();
const { useTokenDetection: defaultUseTokenDetection } =
getPreferencesState();
Expand Down Expand Up @@ -159,7 +159,7 @@ export class TokenDetectionController extends BaseController<
}
});

onNetworkStateChange(({ provider: { chainId } }) => {
onNetworkStateChange(({ providerConfig: { chainId } }) => {
const { chainId: currentChainId } = this.config;
const isDetectionEnabledForNetwork =
isTokenDetectionSupportedForNetwork(chainId);
Expand Down
50 changes: 25 additions & 25 deletions packages/assets-controllers/src/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import nock from 'nock';
import { ControllerMessenger } from '@metamask/base-controller';
import {
NetworkController,
NetworkControllerProviderChangeEvent,
NetworkControllerProviderConfigChangeEvent,
} from '@metamask/network-controller';
import { NetworksChainId } from '@metamask/controller-utils';
import {
Expand Down Expand Up @@ -473,7 +473,7 @@ const expiredCacheExistingState: TokenListState = {

type MainControllerMessenger = ControllerMessenger<
GetTokenListState,
TokenListStateChange | NetworkControllerProviderChangeEvent
TokenListStateChange | NetworkControllerProviderConfigChangeEvent
>;

const getControllerMessenger = (): MainControllerMessenger => {
Expand All @@ -485,7 +485,7 @@ const setupNetworkController = (
) => {
const networkMessenger = controllerMessenger.getRestricted({
name: 'NetworkController',
allowedEvents: ['NetworkController:providerChange'],
allowedEvents: ['NetworkController:providerConfigChange'],
allowedActions: [],
});

Expand All @@ -505,7 +505,7 @@ const getRestrictedMessenger = (
allowedActions: [],
allowedEvents: [
'TokenListController:stateChange',
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
],
});

Expand Down Expand Up @@ -536,7 +536,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -586,7 +586,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand All @@ -607,7 +607,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand All @@ -627,7 +627,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand All @@ -645,7 +645,7 @@ describe('TokenListController', () => {
chainId: NetworksChainId.mainnet,
onNetworkStateChange: (callback) =>
controllerMessenger.subscribe(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
callback,
),
preventPollingOnNetworkRestart: false,
Expand All @@ -663,7 +663,7 @@ describe('TokenListController', () => {
expect(controller.state.tokenList).toStrictEqual({});
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -692,7 +692,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -723,7 +723,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -758,7 +758,7 @@ describe('TokenListController', () => {
expect(tokenListMock.calledThrice).toBe(true);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand All @@ -784,7 +784,7 @@ describe('TokenListController', () => {
expect(tokenListMock.called).toBe(true);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -812,7 +812,7 @@ describe('TokenListController', () => {
controller.destroy();
tokenListMock.restore();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -852,7 +852,7 @@ describe('TokenListController', () => {
);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
} finally {
controller.destroy();
Expand Down Expand Up @@ -892,7 +892,7 @@ describe('TokenListController', () => {
);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand All @@ -919,7 +919,7 @@ describe('TokenListController', () => {
);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -966,7 +966,7 @@ describe('TokenListController', () => {
).toStrictEqual(sampleWithDuplicateSymbolsTokensChainsCache);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -994,7 +994,7 @@ describe('TokenListController', () => {
).toStrictEqual(sampleWith3OrMoreOccurrences);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -1026,7 +1026,7 @@ describe('TokenListController', () => {
);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -1061,7 +1061,7 @@ describe('TokenListController', () => {
);
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -1127,7 +1127,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand All @@ -1149,7 +1149,7 @@ describe('TokenListController', () => {

controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
});

Expand Down Expand Up @@ -1206,7 +1206,7 @@ describe('TokenListController', () => {
messenger.clearEventSubscriptions('TokenListController:stateChange');
controller.destroy();
controllerMessenger.clearEventSubscriptions(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
);
resolve();
});
Expand Down
13 changes: 7 additions & 6 deletions packages/assets-controllers/src/TokenListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@metamask/base-controller';
import { safelyExecute } from '@metamask/controller-utils';
import {
NetworkControllerProviderChangeEvent,
NetworkControllerProviderConfigChangeEvent,
NetworkState,
ProviderConfig,
} from '@metamask/network-controller';
Expand Down Expand Up @@ -62,9 +62,10 @@ export type GetTokenListState = {
type TokenListMessenger = RestrictedControllerMessenger<
typeof name,
GetTokenListState,
TokenListStateChange | NetworkControllerProviderChangeEvent,
TokenListStateChange | NetworkControllerProviderConfigChangeEvent,
never,
TokenListStateChange['type'] | NetworkControllerProviderChangeEvent['type']
| TokenListStateChange['type']
| NetworkControllerProviderConfigChangeEvent['type']
>;

const metadata = {
Expand Down Expand Up @@ -146,9 +147,9 @@ export class TokenListController extends BaseControllerV2<
// this check for "provider" is for testing purposes, since in the extension this callback will receive
// an object typed as NetworkState but within repo we can only simulate as if the callback receives an
// object typed as ProviderConfig
if ('provider' in networkStateOrProviderConfig) {
if ('providerConfig' in networkStateOrProviderConfig) {
await this.#onNetworkStateChangeCallback(
networkStateOrProviderConfig.provider,
networkStateOrProviderConfig.providerConfig,
);
} else {
await this.#onNetworkStateChangeCallback(
Expand All @@ -158,7 +159,7 @@ export class TokenListController extends BaseControllerV2<
});
} else {
this.messagingSystem.subscribe(
'NetworkController:providerChange',
'NetworkController:providerConfigChange',
async (providerConfig) => {
await this.#onNetworkStateChangeCallback(providerConfig);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ describe('TokenRatesController', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await networkChangeListener!({
provider: { chainId: '4' },
providerConfig: { chainId: '4' },
});

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
4 changes: 2 additions & 2 deletions packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ export class TokenRatesController extends BaseController<
this.configure({ nativeCurrency: currencyRateState.nativeCurrency });
});

onNetworkStateChange(({ provider }) => {
const { chainId } = provider;
onNetworkStateChange(({ providerConfig }) => {
const { chainId } = providerConfig;
this.update({ contractExchangeRates: {} });
this.configure({ chainId });
});
Expand Down
Loading

0 comments on commit 55c30e2

Please sign in to comment.