Skip to content
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
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
import HttpProvider from 'ethjs-provider-http';
import { IPFS_DEFAULT_GATEWAY_URL } from '@metamask/controller-utils';
import {
IPFS_DEFAULT_GATEWAY_URL,
NetworkType,
} from '@metamask/controller-utils';
import { PreferencesController } from '@metamask/preferences-controller';
import {
NetworkController,
Expand DownExpand Up@@ -295,7 +298,7 @@ describe('AssetsContractController', () => {
);
expect(balances[ERC20_DAI_ADDRESS]).not.toBeUndefined();

network.setProviderType('localhost');
network.setProviderType(NetworkType.localhost);

const noBalances = await assetsContract.getBalancesInSingleCall(
ERC20_DAI_ADDRESS,
Expand Down
5 changes: 3 additions & 2 deletions packages/assets-controllers/src/NftController.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ import {
OPENSEA_API_URL,
ERC721,
NetworksChainId,
NetworkType,
} from '@metamask/controller-utils';
import { Network } from '@ethersproject/providers';
import { AssetsContractController } from './AssetsContractController';
Expand DownExpand Up@@ -46,8 +47,8 @@ const DEPRESSIONIST_CLOUDFLARE_IPFS_SUBDOMAIN_PATH = getFormattedIpfsUrl(
true,
);

const SEPOLIA = { chainId: '11155111', type: 'sepolia' as const };
const GOERLI = { chainId: '5', type: 'goerli' as const };
const SEPOLIA = { chainId: '11155111', type: NetworkType.sepolia };
const GOERLI = { chainId: '5', type: NetworkType.goerli };

// Mock out detectNetwork function for cleaner tests, Ethers calls this a bunch of times because the Web3Provider is paranoid.
jest.mock('@ethersproject/providers', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/assets-controllers/src/NftController.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,6 @@ import {
toChecksumHexAddress,
BNToHex,
fetchWithErrorHandling,
MAINNET,
IPFS_DEFAULT_GATEWAY_URL,
ERC721,
ERC1155,
Expand DownExpand Up@@ -911,7 +910,7 @@ export class NftController extends BaseController<NftConfig, NftState> {
) {
super(config, state);
this.defaultConfig = {
networkType: MAINNET,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice! Yeah this is much better.

networkType: NetworkType.mainnet,
selectedAddress: '',
chainId: '',
ipfsGateway: IPFS_DEFAULT_GATEWAY_URL,
Expand Down
38 changes: 18 additions & 20 deletions packages/assets-controllers/src/NftDetectionController.test.ts
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
import * as sinon from 'sinon';
import nock from 'nock';
import { PreferencesController } from '@metamask/preferences-controller';
import { OPENSEA_PROXY_URL } from '@metamask/controller-utils';
import { OPENSEA_PROXY_URL, NetworkType } from '@metamask/controller-utils';
import { NftController } from './NftController';
import { AssetsContractController } from './AssetsContractController';
import { NftDetectionController } from './NftDetectionController';

const DEFAULT_INTERVAL = 180000;
const MAINNET = 'mainnet';
const GOERLI = 'goerli';

describe('NftDetectionController', () => {
let nftDetection: NftDetectionController;
Expand DownExpand Up@@ -236,9 +234,9 @@ describe('NftDetectionController', () => {
});

it('should detect mainnet correctly', () => {
nftDetection.configure({ networkType: MAINNET });
nftDetection.configure({ networkType: NetworkType.mainnet });
expect(nftDetection.isMainnet()).toStrictEqual(true);
nftDetection.configure({ networkType: GOERLI });
nftDetection.configure({ networkType: NetworkType.goerli });
expect(nftDetection.isMainnet()).toStrictEqual(false);
});

Expand All@@ -258,7 +256,7 @@ describe('NftDetectionController', () => {
addNft: nftController.addNft.bind(nftController),
getNftState: () => nftController.state,
},
{ interval: 10, networkType: GOERLI },
{ interval: 10, networkType: NetworkType.goerli },
);
expect(mockNfts.called).toBe(false);
resolve('');
Expand All@@ -269,12 +267,12 @@ describe('NftDetectionController', () => {
const selectedAddress = '0x1';

nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});

nftController.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});
const { chainId } = nftDetection.config;
Expand All@@ -299,7 +297,7 @@ describe('NftDetectionController', () => {
it('should detect, add NFTs and do nor remove not detected NFTs correctly', async () => {
const selectedAddress = '0x1';
nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});
nftController.configure({ selectedAddress });
Expand DownExpand Up@@ -348,7 +346,7 @@ describe('NftDetectionController', () => {
it('should not autodetect NFTs that exist in the ignoreList', async () => {
const selectedAddress = '0x2';
nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress: '0x2',
});
nftController.configure({ selectedAddress });
Expand All@@ -375,7 +373,7 @@ describe('NftDetectionController', () => {
it('should not detect and add NFTs if there is no selectedAddress', async () => {
const selectedAddress = '';
nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});
const { chainId } = nftDetection.config;
Expand All@@ -386,7 +384,7 @@ describe('NftDetectionController', () => {

it('should not detect and add NFTs to the wrong selectedAddress', async () => {
nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress: '0x9',
});
const { chainId } = nftDetection.config;
Expand All@@ -409,7 +407,7 @@ describe('NftDetectionController', () => {
preferences.setUseNftDetection(false);
const selectedAddress = '0x9';
nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});
const { chainId } = nftController.config;
Expand All@@ -423,7 +421,7 @@ describe('NftDetectionController', () => {
preferences.setOpenSeaEnabled(false);
const selectedAddress = '0x9';
nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});
const { chainId } = nftController.config;
Expand DownExpand Up@@ -492,12 +490,12 @@ describe('NftDetectionController', () => {
const selectedAddress = '0x1';
nftDetection.configure({
selectedAddress,
networkType: MAINNET,
networkType: NetworkType.mainnet,
});

nftController.configure({
selectedAddress,
networkType: MAINNET,
networkType: NetworkType.mainnet,
});

const { chainId } = nftDetection.config;
Expand DownExpand Up@@ -660,12 +658,12 @@ describe('NftDetectionController', () => {
});

nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});

nftController.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});

Expand DownExpand Up@@ -698,12 +696,12 @@ describe('NftDetectionController', () => {
.replyWithError(new Error('UNEXPECTED ERROR'));

nftDetection.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});

nftController.configure({
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress,
});

Expand Down
5 changes: 2 additions & 3 deletions packages/assets-controllers/src/NftDetectionController.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,6 @@ import {
import type { NetworkState } from '@metamask/network-controller';
import type { PreferencesState } from '@metamask/preferences-controller';
import {
MAINNET,
OPENSEA_PROXY_URL,
OPENSEA_API_URL,
NetworkType,
Expand DownExpand Up@@ -240,7 +239,7 @@ export class NftDetectionController extends BaseController<
super(config, state);
this.defaultConfig = {
interval: DEFAULT_INTERVAL,
networkType: MAINNET,
networkType: NetworkType.mainnet,
chainId: '1',
selectedAddress: '',
disabled: true,
Expand DownExpand Up@@ -320,7 +319,7 @@ export class NftDetectionController extends BaseController<
*
* @returns Whether current network is mainnet.
*/
isMainnet = (): boolean => this.config.networkType === MAINNET;
isMainnet = (): boolean => this.config.networkType === NetworkType.mainnet;

/**
* Triggers asset ERC721 token auto detection on mainnet. Any newly detected NFTs are
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,11 +8,7 @@ import {
NetworkState,
ProviderConfig,
} from '@metamask/network-controller';
import {
NetworksChainId,
MAINNET,
NetworkType,
} from '@metamask/controller-utils';
import { NetworksChainId, NetworkType } from '@metamask/controller-utils';
import { PreferencesController } from '@metamask/preferences-controller';
import { ControllerMessenger } from '@metamask/base-controller';
import { TokensController } from './TokensController';
Expand DownExpand Up@@ -142,7 +138,7 @@ describe('TokenDetectionController', () => {
};
const mainnet = {
chainId: NetworksChainId.mainnet,
type: MAINNET as NetworkType,
type: NetworkType.mainnet,
};

beforeEach(async () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/assets-controllers/src/TokenListController.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import {
NetworkState,
ProviderConfig,
} from '@metamask/network-controller';
import { NetworksChainId } from '@metamask/controller-utils';
import { NetworksChainId, NetworkType } from '@metamask/controller-utils';
import {
TokenListController,
TokenListStateChange,
Expand DownExpand Up@@ -629,8 +629,8 @@ describe('TokenListController', () => {
sampleSingleChainState.tokenList,
);
onNetworkStateChangeCallback({
chainId: '5',
type: 'rpc',
chainId: NetworksChainId.goerli,
type: NetworkType.goerli,
});
await new Promise<void>((resolve) => setTimeout(() => resolve(), 500));

Expand DownExpand Up@@ -1020,7 +1020,7 @@ describe('TokenListController', () => {
);

controllerMessenger.publish('NetworkController:providerConfigChange', {
type: 'goerli',
type: NetworkType.goerli,
chainId: NetworksChainId.goerli,
});

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

controllerMessenger.publish('NetworkController:providerConfigChange', {
type: 'rpc',
type: NetworkType.rpc,
chainId: '56',
rpcTarget: 'http://localhost:8545',
});
Expand DownExpand Up@@ -1095,7 +1095,7 @@ describe('TokenListController', () => {
});
await controller.start();
controllerMessenger.publish('NetworkController:providerConfigChange', {
type: 'mainnet',
type: NetworkType.mainnet,
chainId: NetworksChainId.mainnet,
});

Expand DownExpand Up@@ -1136,7 +1136,7 @@ describe('TokenListController', () => {
});

controllerMessenger.publish('NetworkController:providerConfigChange', {
type: 'rpc',
type: NetworkType.rpc,
chainId: '56',
rpcTarget: 'http://localhost:8545',
});
Expand Down
6 changes: 3 additions & 3 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@ import * as sinon from 'sinon';
import nock from 'nock';
import contractMaps from '@metamask/contract-metadata';
import { PreferencesController } from '@metamask/preferences-controller';
import { NetworksChainId } from '@metamask/controller-utils';
import { NetworksChainId, NetworkType } from '@metamask/controller-utils';
import {
NetworkState,
ProviderConfig,
Expand All@@ -27,8 +27,8 @@ const stubCreateEthers = (ctrl: TokensController, res: boolean) => {
});
};

const SEPOLIA = { chainId: '11155111', type: 'sepolia' as const };
const GOERLI = { chainId: '5', type: 'goerli' as const };
const SEPOLIA = { chainId: '11155111', type: NetworkType.sepolia };
const GOERLI = { chainId: '5', type: NetworkType.goerli };

describe('TokensController', () => {
let tokensController: TokensController;
Expand Down
3 changes: 1 addition & 2 deletions packages/assets-controllers/src/TokensController.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,6 @@ import type { NetworkState } from '@metamask/network-controller';
import {
NetworkType,
toChecksumHexAddress,
MAINNET,
ERC721_INTERFACE_ID,
} from '@metamask/controller-utils';
import type { Token } from './TokenRatesController';
Expand DownExpand Up@@ -206,7 +205,7 @@ export class TokensController extends BaseController<
super(config, state);

this.defaultConfig = {
networkType: MAINNET,
networkType: NetworkType.mainnet,
selectedAddress: '',
chainId: '',
provider: undefined,
Expand Down
Loading