Skip to content

Commit

Permalink
Make provider config property ticker mandatory
Browse files Browse the repository at this point in the history
The `ticker` property of the provider configuration is mandatory for
custom network configurations, and always set for built-in networks.
The type has been updated to reflect that it should always be set. This
ensures that we don't need to handle the "missing ticker" case
throughout the codebase.

The initial state was missing the `ticker` property, so it's possible
that it will be missing for users. It's possible users have a missing
`ticker` property on `providerConfig` if they added a custom network
prior to us making this mandatory, and haven't switched since. As a
precaution we should set `providerConfig.ticker` to `ETH` in a
migration if it is missing. This should preserve the current behavior
(which is to assume the currency is ETH if it's missing).
  • Loading branch information
Gudahtt committed Jul 13, 2023
1 parent 5a3e28f commit 6cc0536
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 6 deletions.
13 changes: 11 additions & 2 deletions packages/assets-controllers/src/NftController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
toHex,
ApprovalType,
ERC20,
NetworksTicker,
} from '@metamask/controller-utils';
import {
AddApprovalRequest,
Expand Down Expand Up @@ -59,8 +60,16 @@ const DEPRESSIONIST_CLOUDFLARE_IPFS_SUBDOMAIN_PATH = getFormattedIpfsUrl(
true,
);

const SEPOLIA = { chainId: toHex(11155111), type: NetworkType.sepolia };
const GOERLI = { chainId: toHex(5), type: NetworkType.goerli };
const SEPOLIA = {
chainId: toHex(11155111),
type: NetworkType.sepolia,
ticker: NetworksTicker.sepolia,
};
const GOERLI = {
chainId: toHex(5),
type: NetworkType.goerli,
ticker: NetworksTicker.goerli,
};

type ApprovalActions = AddApprovalRequest;
type ApprovalEvents = ApprovalStateChange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
ChainId,
NetworkType,
NetworksTicker,
convertHexToDecimal,
toHex,
} from '@metamask/controller-utils';
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('TokenDetectionController', () => {
const mainnet = {
chainId: ChainId.mainnet,
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
};

beforeEach(async () => {
Expand Down Expand Up @@ -295,6 +297,7 @@ describe('TokenDetectionController', () => {
const auroraMainnet = {
chainId: ChainId.aurora,
type: NetworkType.mainnet,
ticker: 'Aurora ETH',
};
preferences.update({ selectedAddress: '0x1' });
changeNetwork(auroraMainnet);
Expand Down
6 changes: 6 additions & 0 deletions packages/assets-controllers/src/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
ChainId,
NetworkType,
NetworksTicker,
convertHexToDecimal,
toHex,
} from '@metamask/controller-utils';
Expand Down Expand Up @@ -658,6 +659,7 @@ describe('TokenListController', () => {
buildNetworkControllerStateWithProviderConfig({
chainId: ChainId.goerli,
type: NetworkType.goerli,
ticker: NetworksTicker.goerli,
}),
);
await new Promise<void>((resolve) => setTimeout(() => resolve(), 500));
Expand Down Expand Up @@ -1049,6 +1051,7 @@ describe('TokenListController', () => {
buildNetworkControllerStateWithProviderConfig({
type: NetworkType.goerli,
chainId: ChainId.goerli,
ticker: NetworksTicker.goerli,
}),
[],
);
Expand All @@ -1068,6 +1071,7 @@ describe('TokenListController', () => {
type: NetworkType.rpc,
chainId: toHex(56),
rpcUrl: 'http://localhost:8545',
ticker: 'TEST',
}),
[],
);
Expand Down Expand Up @@ -1132,6 +1136,7 @@ describe('TokenListController', () => {
buildNetworkControllerStateWithProviderConfig({
type: NetworkType.mainnet,
chainId: ChainId.mainnet,
ticker: NetworksTicker.mainnet,
}),
[],
);
Expand Down Expand Up @@ -1178,6 +1183,7 @@ describe('TokenListController', () => {
type: NetworkType.rpc,
chainId: toHex(56),
rpcUrl: 'http://localhost:8545',
ticker: 'TEST',
}),
[],
);
Expand Down
13 changes: 11 additions & 2 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ChainId,
ERC20,
NetworkType,
NetworksTicker,
ORIGIN_METAMASK,
convertHexToDecimal,
toHex,
Expand Down Expand Up @@ -40,8 +41,16 @@ const stubCreateEthers = (ctrl: TokensController, res: boolean) => {
});
};

const SEPOLIA = { chainId: toHex(11155111), type: NetworkType.sepolia };
const GOERLI = { chainId: toHex(5), type: NetworkType.goerli };
const SEPOLIA = {
chainId: toHex(11155111),
type: NetworkType.sepolia,
ticker: NetworksTicker.sepolia,
};
const GOERLI = {
chainId: toHex(5),
type: NetworkType.goerli,
ticker: NetworksTicker.goerli,
};

const controllerName = 'TokensController' as const;

Expand Down
11 changes: 11 additions & 0 deletions packages/ens-controller/src/EnsController.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ControllerMessenger } from '@metamask/base-controller';
import {
NetworkType,
NetworksTicker,
toChecksumHexAddress,
toHex,
} from '@metamask/controller-utils';
Expand Down Expand Up @@ -121,6 +122,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand Down Expand Up @@ -446,6 +448,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand All @@ -464,6 +467,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand All @@ -489,6 +493,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand Down Expand Up @@ -516,6 +521,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand All @@ -538,6 +544,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand All @@ -563,6 +570,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand All @@ -588,6 +596,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand Down Expand Up @@ -615,6 +624,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand All @@ -641,6 +651,7 @@ describe('EnsController', () => {
providerConfig: {
chainId: toHex(1),
type: NetworkType.mainnet,
ticker: NetworksTicker.mainnet,
},
});
},
Expand Down
4 changes: 4 additions & 0 deletions packages/gas-fee-controller/src/GasFeeController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ describe('GasFeeController', () => {
type: NetworkType.rpc,
chainId: toHex(1337),
rpcUrl: 'http://some/url',
ticker: 'TEST',
},
},
clientId: '99999',
Expand Down Expand Up @@ -372,6 +373,7 @@ describe('GasFeeController', () => {
type: NetworkType.rpc,
chainId: toHex(1337),
rpcUrl: 'http://some/url',
ticker: 'TEST',
},
},
clientId: '99999',
Expand Down Expand Up @@ -682,6 +684,7 @@ describe('GasFeeController', () => {
type: NetworkType.rpc,
chainId: toHex(1337),
rpcUrl: 'http://some/url',
ticker: 'TEST',
},
},
clientId: '99999',
Expand Down Expand Up @@ -793,6 +796,7 @@ describe('GasFeeController', () => {
type: NetworkType.rpc,
chainId: toHex(1337),
rpcUrl: 'http://some/url',
ticker: 'TEST',
},
},
clientId: '99999',
Expand Down
3 changes: 2 additions & 1 deletion packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type ProviderConfig = {
rpcUrl?: string;
type: NetworkType;
chainId: Hex;
ticker?: string;
ticker: string;
nickname?: string;
rpcPrefs?: { blockExplorerUrl?: string };
id?: NetworkConfigurationId;
Expand Down Expand Up @@ -455,6 +455,7 @@ export const defaultState: NetworkState = {
providerConfig: {
type: NetworkType.mainnet,
chainId: ChainId.mainnet,
ticker: NetworksTicker.mainnet,
},
networkDetails: {
EIPS: {},
Expand Down
Loading

0 comments on commit 6cc0536

Please sign in to comment.