Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adonesky1 committed Mar 17, 2023
1 parent dfc3acd commit b0f9743
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 Down Expand Up @@ -295,7 +295,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
3 changes: 1 addition & 2 deletions packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
toChecksumHexAddress,
BNToHex,
fetchWithErrorHandling,
MAINNET,
IPFS_DEFAULT_GATEWAY_URL,
ERC721,
ERC1155,
Expand Down Expand Up @@ -911,7 +910,7 @@ export class NftController extends BaseController<NftConfig, NftState> {
) {
super(config, state);
this.defaultConfig = {
networkType: MAINNET,
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 number Diff line number Diff 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 Down Expand 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 Down Expand 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 Down Expand 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 Down Expand Up @@ -660,12 +658,12 @@ describe('NftDetectionController', () => {
});

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

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

Expand Down Expand 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 number Diff line number Diff 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 Down Expand 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 Down Expand 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 number Diff line number Diff 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 Down Expand 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 number Diff line number Diff 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 Down Expand 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 Down Expand 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',
rpcUrl: 'http://localhost:8545',
});
Expand Down Expand Up @@ -1095,7 +1095,7 @@ describe('TokenListController', () => {
});
await controller.start();
controllerMessenger.publish('NetworkController:providerConfigChange', {
type: 'mainnet',
type: NetworkType.mainnet,
chainId: NetworksChainId.mainnet,
});

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

controllerMessenger.publish('NetworkController:providerConfigChange', {
type: 'rpc',
type: NetworkType.rpc,
chainId: '56',
rpcUrl: 'http://localhost:8545',
});
Expand Down
6 changes: 3 additions & 3 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff 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 number Diff line number Diff 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 Down Expand 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
1 change: 0 additions & 1 deletion packages/controller-utils/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NetworkType } from './types';

export const MAINNET = 'mainnet';
export const RPC = 'rpc';
export const FALL_BACK_VS_CURRENCY = 'ETH';
export const IPFS_DEFAULT_GATEWAY_URL = 'https://cloudflare-ipfs.com/ipfs/';
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MetaMaskKeyring as QRKeyring } from '@keystonehq/metamask-airgapped-key
import { CryptoHDKey, ETHSignature } from '@keystonehq/bc-ur-registry-eth';
import * as uuid from 'uuid';
import { PreferencesController } from '@metamask/preferences-controller';
import { MAINNET } from '@metamask/controller-utils';
import { NetworkType } from '@metamask/controller-utils';
import { keyringBuilderFactory } from '@metamask/eth-keyring-controller';
import MockEncryptor from '../tests/mocks/mockEncryptor';
import {
Expand Down Expand Up @@ -991,7 +991,7 @@ describe('KeyringController', () => {
},
{
common: Common.forCustomChain(
MAINNET,
NetworkType.mainnet,
{
name: 'goerli',
chainId: parseInt('5'),
Expand Down
8 changes: 6 additions & 2 deletions packages/transaction-controller/src/TransactionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
safelyExecute,
isSmartContractCode,
query,
MAINNET,
NetworkType,
RPC,
} from '@metamask/controller-utils';
import {
Expand Down Expand Up @@ -603,7 +603,11 @@ export class TransactionController extends BaseController<
networkId: parseInt(networkId, undefined),
};

return Common.forCustomChain(MAINNET, customChainParams, HARDFORK);
return Common.forCustomChain(
NetworkType.mainnet,
customChainParams,
HARDFORK,
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/transaction-controller/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addHexPrefix, isHexString } from 'ethereumjs-util';
import {
MAINNET,
NetworkType,
convertHexToDecimal,
handleFetch,
isValidHexAddress,
Expand Down Expand Up @@ -41,7 +41,7 @@ export function getEtherscanApiUrl(
urlParams: any,
): string {
let etherscanSubdomain = 'api';
if (networkType !== MAINNET) {
if (networkType !== NetworkType.mainnet) {
etherscanSubdomain = `api-${networkType}`;
}
const apiUrl = `https://${etherscanSubdomain}.etherscan.io`;
Expand Down

0 comments on commit b0f9743

Please sign in to comment.