Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ module.exports = {
'off',
{ matchDescription: '^[A-Z`\\d_][\\s\\S]*[.?!`>)}]$' },
],

// Disable rules that the `eslint-config-prettier` tool reports as
// conflicting
'max-statements-per-line': 'off',
'no-tabs': 'off',
},
settings: {
'import/resolver': {
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @type {import('prettier').Options}
*/
module.exports = {
plugins: ['prettier-plugin-packagejson'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears that Prettier no longer autodetects plugins in v3. I couldn't find any mention of this in the release notes, but I found this necessary to add to format package.json correctly.

// All of these are defaults except singleQuote, but we specify them
// for explicitness
quoteProps: 'as-needed',
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@
"babel-jest": "^27.5.1",
"depcheck": "^1.4.7",
"eslint": "^8.44.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-interactive": "^10.8.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.1.1",
"eth-block-tracker": "^8.0.0",
"execa": "^5.0.0",
"isomorphic-fetch": "^3.0.0",
"jest": "^27.5.1",
"jest-silent-reporter": "^0.5.0",
"nock": "^13.3.1",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.4.5",
"prettier": "^3.2.5",
"prettier-plugin-packagejson": "^2.5.0",
"simple-git-hooks": "^2.8.0",
"ts-node": "^10.9.1",
"tsup": "^8.0.2",
Expand Down
67 changes: 36 additions & 31 deletions packages/accounts-controller/src/AccountsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,39 +327,44 @@ export class AccountsController extends BaseController<
const accounts: Record<string, InternalAccount> = [
...normalAccounts,
...snapAccounts,
].reduce((internalAccountMap, internalAccount) => {
const keyringTypeName = keyringTypeToName(
internalAccount.metadata.keyring.type,
);
const keyringAccountIndex = keyringTypes.get(keyringTypeName) ?? 0;
if (keyringAccountIndex) {
keyringTypes.set(keyringTypeName, keyringAccountIndex + 1);
} else {
keyringTypes.set(keyringTypeName, 1);
}

const existingAccount = previousAccounts[internalAccount.id];

internalAccountMap[internalAccount.id] = {
...internalAccount,
].reduce(
(internalAccountMap, internalAccount) => {
const keyringTypeName = keyringTypeToName(
internalAccount.metadata.keyring.type,
);
const keyringAccountIndex = keyringTypes.get(keyringTypeName) ?? 0;
if (keyringAccountIndex) {
keyringTypes.set(keyringTypeName, keyringAccountIndex + 1);
} else {
keyringTypes.set(keyringTypeName, 1);
}

metadata: {
...internalAccount.metadata,
name:
this.#populateExistingMetadata(existingAccount?.id, 'name') ??
`${keyringTypeName} ${keyringAccountIndex + 1}`,
importTime:
this.#populateExistingMetadata(existingAccount?.id, 'importTime') ??
Date.now(),
lastSelected: this.#populateExistingMetadata(
existingAccount?.id,
'lastSelected',
),
},
};
const existingAccount = previousAccounts[internalAccount.id];

internalAccountMap[internalAccount.id] = {
...internalAccount,

metadata: {
...internalAccount.metadata,
name:
this.#populateExistingMetadata(existingAccount?.id, 'name') ??
`${keyringTypeName} ${keyringAccountIndex + 1}`,
importTime:
this.#populateExistingMetadata(
existingAccount?.id,
'importTime',
) ?? Date.now(),
lastSelected: this.#populateExistingMetadata(
existingAccount?.id,
'lastSelected',
),
},
};

return internalAccountMap;
}, {} as Record<string, InternalAccount>);
return internalAccountMap;
},
{} as Record<string, InternalAccount>,
);

this.update((currentState: Draft<AccountsControllerState>) => {
(currentState as AccountsControllerState).internalAccounts.accounts =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function setupAssetContractControllers() {
provider,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any),
}) as any,
});

return {
Expand Down Expand Up @@ -721,9 +721,8 @@ describe('AssetsContractController', () => {
},
],
});
const symbol = await assetsContract.getERC721AssetSymbol(
ERC721_GODS_ADDRESS,
);
const symbol =
await assetsContract.getERC721AssetSymbol(ERC721_GODS_ADDRESS);
expect(symbol).toBe('GODS');
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
});
Expand Down Expand Up @@ -761,9 +760,8 @@ describe('AssetsContractController', () => {
},
],
});
const decimals = await assetsContract.getERC20TokenDecimals(
ERC20_SAI_ADDRESS,
);
const decimals =
await assetsContract.getERC20TokenDecimals(ERC20_SAI_ADDRESS);
expect(Number(decimals)).toBe(18);
messenger.clearEventSubscriptions('NetworkController:networkDidChange');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ describe('ERC20Standard', () => {
result:
'0x0000000000000000000000000000000000000000000000000000000000000012',
});
const maticDecimals = await erc20Standard.getTokenDecimals(
ERC20_MATIC_ADDRESS,
);
const maticDecimals =
await erc20Standard.getTokenDecimals(ERC20_MATIC_ADDRESS);
expect(maticDecimals.toString()).toBe('18');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ export class ERC721Standard {
*/
getTokenURI = async (address: string, tokenId: string): Promise<string> => {
const contract = new Contract(address, abiERC721, this.provider);
const supportsMetadata = await this.contractSupportsMetadataInterface(
address,
);
const supportsMetadata =
await this.contractSupportsMetadataInterface(address);
if (!supportsMetadata) {
// Do not throw error here, supporting Metadata interface is optional even though majority of ERC721 nfts do support it.
// This change is made because of instances of NFTs that are ERC404( mixed ERC20 / ERC721 implementation).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('TokenDetectionController', () => {
() =>
({
configuration: { chainId: '0x89' },
} as unknown as AutoManagedNetworkClient<CustomNetworkClientConfiguration>),
}) as unknown as AutoManagedNetworkClient<CustomNetworkClientConfiguration>,
);

mockTokenListGetState({
Expand Down
11 changes: 7 additions & 4 deletions packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,13 @@ export class TokensController extends BaseControllerV1<
const { tokens, detectedTokens, ignoredTokens } = this.state;
const importedTokensMap: { [key: string]: true } = {};
// Used later to dedupe imported tokens
const newTokensMap = tokens.reduce((output, current) => {
output[current.address] = current;
return output;
}, {} as { [address: string]: Token });
const newTokensMap = tokens.reduce(
(output, current) => {
output[current.address] = current;
return output;
},
{} as { [address: string]: Token },
);
try {
tokensToImport.forEach((tokenToAdd) => {
const { address, symbol, decimals, image, aggregators, name } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ export class RestrictedControllerMessenger<
/* istanbul ignore if */ // Branch unreachable with valid types
if (!this.#isInCurrentNamespace(action)) {
throw new Error(
`Only allowed registering action handlers prefixed by '${
this.#controllerName
}:'`,
`Only allowed registering action handlers prefixed by '${this.#controllerName}:'`,
);
}
this.#controllerMessenger.registerActionHandler(action, handler);
Expand All @@ -126,9 +124,7 @@ export class RestrictedControllerMessenger<
/* istanbul ignore if */ // Branch unreachable with valid types
if (!this.#isInCurrentNamespace(action)) {
throw new Error(
`Only allowed unregistering action handlers prefixed by '${
this.#controllerName
}:'`,
`Only allowed unregistering action handlers prefixed by '${this.#controllerName}:'`,
);
}
this.#controllerMessenger.unregisterActionHandler(action);
Expand Down
65 changes: 26 additions & 39 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,10 @@ describe('KeyringController', () => {
it('should not add a new account if called twice with the same accountCount param', async () => {
await withController(async ({ controller, initialState }) => {
const accountCount = initialState.keyrings[0].accounts.length;
const firstAccountAdded = await controller.addNewAccount(
accountCount,
);
const secondAccountAdded = await controller.addNewAccount(
accountCount,
);
const firstAccountAdded =
await controller.addNewAccount(accountCount);
const secondAccountAdded =
await controller.addNewAccount(accountCount);
expect(firstAccountAdded).toBe(secondAccountAdded);
expect(controller.state.keyrings[0].accounts).toHaveLength(
accountCount + 1,
Expand Down Expand Up @@ -193,13 +191,11 @@ describe('KeyringController', () => {

const accountCount = initialState.keyrings[0].accounts.length;
// We add a new account for "index 1" (not existing yet)
const firstAccountAdded = await controller.addNewAccount(
accountCount,
);
const firstAccountAdded =
await controller.addNewAccount(accountCount);
// Adding an account for an existing index will return the existing account's address
const secondAccountAdded = await controller.addNewAccount(
accountCount,
);
const secondAccountAdded =
await controller.addNewAccount(accountCount);
expect(firstAccountAdded).toBe(secondAccountAdded);
expect(controller.state.keyrings[0].accounts).toHaveLength(
accountCount + 1,
Expand Down Expand Up @@ -231,9 +227,8 @@ describe('KeyringController', () => {
const [primaryKeyring] = controller.getKeyringsByType(
KeyringTypes.hd,
) as Keyring<Json>[];
const addedAccountAddress = await controller.addNewAccountForKeyring(
primaryKeyring,
);
const addedAccountAddress =
await controller.addNewAccountForKeyring(primaryKeyring);
expect(initialState.keyrings).toHaveLength(1);
expect(initialState.keyrings[0].accounts).not.toStrictEqual(
controller.state.keyrings[0].accounts,
Expand Down Expand Up @@ -279,9 +274,8 @@ describe('KeyringController', () => {
const [primaryKeyring] = controller.getKeyringsByType(
KeyringTypes.hd,
) as Keyring<Json>[];
const addedAccountAddress = await controller.addNewAccountForKeyring(
primaryKeyring,
);
const addedAccountAddress =
await controller.addNewAccountForKeyring(primaryKeyring);
expect(initialState.keyrings).toHaveLength(1);
expect(initialState.keyrings[0].accounts).not.toStrictEqual(
controller.state.keyrings[0].accounts,
Expand Down Expand Up @@ -406,9 +400,8 @@ describe('KeyringController', () => {
await withController(
{ cacheEncryptionKey },
async ({ controller, initialState }) => {
const currentSeedWord = await controller.exportSeedPhrase(
password,
);
const currentSeedWord =
await controller.exportSeedPhrase(password);

await controller.createNewVaultAndRestore(
password,
Expand Down Expand Up @@ -475,9 +468,8 @@ describe('KeyringController', () => {
cacheEncryptionKey,
encryptor,
});
const initialSeedWord = await controller.exportSeedPhrase(
password,
);
const initialSeedWord =
await controller.exportSeedPhrase(password);
await cleanKeyringController.createNewVaultAndKeychain(
password,
);
Expand Down Expand Up @@ -541,14 +533,12 @@ describe('KeyringController', () => {
await withController(
{ cacheEncryptionKey },
async ({ controller, initialState }) => {
const initialSeedWord = await controller.exportSeedPhrase(
password,
);
const initialSeedWord =
await controller.exportSeedPhrase(password);
const initialVault = controller.state.vault;
await controller.createNewVaultAndKeychain(password);
const currentSeedWord = await controller.exportSeedPhrase(
password,
);
const currentSeedWord =
await controller.exportSeedPhrase(password);
expect(initialSeedWord).toBeDefined();
expect(initialState).toStrictEqual(controller.state);
expect(currentSeedWord).toBeDefined();
Expand Down Expand Up @@ -2441,21 +2431,18 @@ describe('KeyringController', () => {
),
);

const firstPage = await signProcessKeyringController.connectQRHardware(
0,
);
const firstPage =
await signProcessKeyringController.connectQRHardware(0);
expect(firstPage).toHaveLength(5);
expect(firstPage[0].index).toBe(0);

const secondPage = await signProcessKeyringController.connectQRHardware(
1,
);
const secondPage =
await signProcessKeyringController.connectQRHardware(1);
expect(secondPage).toHaveLength(5);
expect(secondPage[0].index).toBe(5);

const goBackPage = await signProcessKeyringController.connectQRHardware(
-1,
);
const goBackPage =
await signProcessKeyringController.connectQRHardware(-1);
expect(goBackPage).toStrictEqual(firstPage);

await signProcessKeyringController.unlockQRHardwareWalletAccount(0);
Expand Down
9 changes: 3 additions & 6 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,8 @@ export class NetworkController extends BaseController<
let updatedIsEIP1559Compatible: boolean | undefined;

try {
updatedIsEIP1559Compatible = await this.#determineEIP1559Compatibility(
networkClientId,
);
updatedIsEIP1559Compatible =
await this.#determineEIP1559Compatibility(networkClientId);
updatedNetworkStatus = NetworkStatus.Available;
} catch (error) {
if (isErrorWithCode(error)) {
Expand Down Expand Up @@ -1169,9 +1168,7 @@ export class NetworkController extends BaseController<
networkClientId: NetworkClientId,
): NetworkConfiguration | undefined {
if (isInfuraNetworkType(networkClientId)) {
const rpcUrl = `https://${networkClientId}.infura.io/v3/${
this.#infuraProjectId
}`;
const rpcUrl = `https://${networkClientId}.infura.io/v3/${this.#infuraProjectId}`;
return {
rpcUrl,
...BUILT_IN_NETWORKS[networkClientId],
Expand Down
Loading