Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devDeps: update @metamask/eslint-config* from 10 to 12 #195

Merged
merged 12 commits into from
Feb 27, 2024
Merged
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ module.exports = {
{
files: ['*.ts'],
extends: ['@metamask/eslint-config-typescript'],
rules: {
'@typescript-eslint/naming-convention': 0,
mcmire marked this conversation as resolved.
Show resolved Hide resolved
'@typescript-eslint/no-floating-promises': 1,
'@typescript-eslint/prefer-enum-initializers': 0,
'@typescript-eslint/restrict-template-expressions': 1,
'no-restricted-syntax': 0,
},
},

{
files: ['*.js'],
parserOptions: {
Expand All @@ -19,6 +25,10 @@ module.exports = {

{
files: ['*.test.ts', '*.test.js'],
parserOptions: {
project: ['./tsconfig.test.json'],
tsconfigRootDir: __dirname,
},
extends: ['@metamask/eslint-config-jest'],
},
],
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,32 @@
"devDependencies": {
"@lavamoat/allow-scripts": "^2.3.1",
"@metamask/auto-changelog": "^3.1.0",
"@metamask/eslint-config": "^10.0.0",
"@metamask/eslint-config-jest": "^10.0.0",
"@metamask/eslint-config-nodejs": "^10.0.0",
"@metamask/eslint-config-typescript": "^10.0.0",
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@types/jest": "^26.0.24",
"@types/lodash": "^4.14.194",
"@types/node": "^16.18.31",
"@types/sinon": "^9.0.10",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint": "^8.21.0",
"eslint": "^8.48.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^26.8.2",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.2.9",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"isomorphic-fetch": "^3.0.0",
"jest": "^26.4.2",
"nock": "^13.3.1",
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.4.3",
"sinon": "^9.2.4",
"ts-jest": "^26.5.6",
"typescript": "~4.4.4"
"typescript": "~4.8.4"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
25 changes: 11 additions & 14 deletions src/SmartTransactionsController.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { convertHexToDecimal } from '@metamask/controller-utils';
import type { NetworkState } from '@metamask/network-controller';
import nock from 'nock';
import * as sinon from 'sinon';
import { NetworkState } from '@metamask/network-controller';
import { convertHexToDecimal } from '@metamask/controller-utils';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import packageJson from '../package.json';

import { API_BASE_URL, CHAIN_IDS } from './constants';
import SmartTransactionsController, {
DEFAULT_INTERVAL,
} from './SmartTransactionsController';
import { API_BASE_URL, CHAIN_IDS } from './constants';
import {
SmartTransaction,
SmartTransactionStatuses,
UnsignedTransaction,
} from './types';
import * as utils from './utils';
import { flushPromises, advanceTime } from './test-helpers';
import type { SmartTransaction, UnsignedTransaction } from './types';
import { SmartTransactionStatuses } from './types';
import * as utils from './utils';
import packageJson from '../package.json';

jest.mock('@ethersproject/bytes', () => ({
...jest.requireActual('@ethersproject/bytes'),
Expand Down Expand Up @@ -397,7 +394,7 @@
it('calls poll if there is no pending transaction and pending transactions', () => {
const pollSpy = jest
.spyOn(smartTransactionsController, 'poll')
.mockImplementation(() => {
.mockImplementation(async () => {
return new Promise(() => ({}));
});
const { smartTransactionsState } = smartTransactionsController.state;
Expand Down Expand Up @@ -445,7 +442,7 @@
it('calls fetchSmartTransactionsStatus if there are pending transactions', () => {
const fetchSmartTransactionsStatusSpy = jest
.spyOn(smartTransactionsController, 'fetchSmartTransactionsStatus')
.mockImplementation(() => {
.mockImplementation(async () => {
return new Promise(() => ({}));
});
const { smartTransactionsState } = smartTransactionsController.state;
Expand Down Expand Up @@ -527,7 +524,7 @@
approvalTxFees: getFeesApiResponse.txs[0],
tradeTxFees: getFeesApiResponse.txs[1],
});
await smartTransactionsController.clearFees();
smartTransactionsController.clearFees();
expect(
smartTransactionsController.state.smartTransactionsState.fees,
).toStrictEqual({
Expand Down Expand Up @@ -862,13 +859,13 @@

describe('setStatusRefreshInterval', () => {
it('sets refresh interval if different', () => {
smartTransactionsController.setStatusRefreshInterval(100);

Check warning on line 862 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 862 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
expect(smartTransactionsController.config.interval).toBe(100);
});

it('does not set refresh interval if they are the same', () => {
const configureSpy = jest.spyOn(smartTransactionsController, 'configure');
smartTransactionsController.setStatusRefreshInterval(DEFAULT_INTERVAL);

Check warning on line 868 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 868 in src/SmartTransactionsController.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
expect(configureSpy).toHaveBeenCalledTimes(0);
});
});
Expand Down
44 changes: 23 additions & 21 deletions src/SmartTransactionsController.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import EventEmitter from 'events';
import { BaseConfig, BaseState } from '@metamask/base-controller';
// eslint-disable-next-line import/no-nodejs-modules
import { hexlify } from '@ethersproject/bytes';
import type { BaseConfig, BaseState } from '@metamask/base-controller';
import { safelyExecute, query } from '@metamask/controller-utils';
import {
import type { Provider } from '@metamask/eth-query';
import EthQuery from '@metamask/eth-query';
import type {
NetworkState,
NetworkController,
NetworkClientId,
} from '@metamask/network-controller';
import EthQuery, { Provider } from '@metamask/eth-query';
import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';
import { BigNumber } from 'bignumber.js';
import { hexlify } from '@ethersproject/bytes';
// eslint-disable-next-line import/no-nodejs-modules
import { EventEmitter } from 'events';
import cloneDeep from 'lodash/cloneDeep';

import {
APIType,
import { CHAIN_IDS } from './constants';
import type {
SmartTransaction,
SignedTransaction,
SignedCanceledTransaction,
UnsignedTransaction,
SmartTransactionsStatus,
SmartTransactionStatuses,
Fees,
IndividualTxFees,
Hex,
} from './types';
import { APIType, SmartTransactionStatuses } from './types';
import {
getAPIRequestURL,
isSmartTransactionPending,
Expand All @@ -36,7 +39,6 @@
isSmartTransactionCancellable,
incrementNonceInHex,
} from './utils';
import { CHAIN_IDS } from './constants';

const SECOND = 1000;
export const DEFAULT_INTERVAL = SECOND * 5;
Expand Down Expand Up @@ -76,17 +78,17 @@

public timeoutHandle?: NodeJS.Timeout;

private getNonceLock: any;
private readonly getNonceLock: any;

private ethQuery: EthQuery;

public confirmExternalTransaction: any;

private trackMetaMetricsEvent: any;
private readonly trackMetaMetricsEvent: any;

private eventEmitter: EventEmitter;
private readonly eventEmitter: EventEmitter;

private getNetworkClientById: NetworkController['getNetworkClientById'];
private readonly getNetworkClientById: NetworkController['getNetworkClientById'];

/* istanbul ignore next */
private async fetch(request: string, options?: RequestInit) {
Expand Down Expand Up @@ -181,7 +183,7 @@
this.eventEmitter = new EventEmitter();
}

_executePoll(networkClientId: string): Promise<void> {
async _executePoll(networkClientId: string): Promise<void> {
// if this is going to be truly UI driven polling we shouldn't really reach here
// with a networkClientId that is not supported, but for now I'll add a check in case
// wondering if we should add some kind of predicate to the polling controller to check whether
Expand All @@ -200,9 +202,9 @@
isSmartTransactionPending,
);
if (!this.timeoutHandle && pendingTransactions?.length > 0) {
this.poll();

Check warning on line 205 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 205 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else if (this.timeoutHandle && pendingTransactions?.length === 0) {
this.stop();

Check warning on line 207 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 207 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
}

Expand Down Expand Up @@ -230,9 +232,9 @@
if (!supportedChainIds.includes(chainId)) {
return;
}
await safelyExecute(() => this.updateSmartTransactions());
await safelyExecute(async () => this.updateSmartTransactions());
this.timeoutHandle = setInterval(() => {
safelyExecute(() => this.updateSmartTransactions());
safelyExecute(async () => this.updateSmartTransactions());

Check warning on line 237 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 237 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}, this.config.interval);
}

Expand Down Expand Up @@ -388,7 +390,7 @@
...smartTransaction,
};
if (!smartTransaction.skipConfirm) {
this.#confirmSmartTransaction(nextSmartTransaction, {

Check warning on line 393 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 393 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
chainId,
ethQuery,
});
Expand Down Expand Up @@ -426,7 +428,7 @@
.map((smartTransaction) => smartTransaction.uuid);

if (transactionsToUpdate.length > 0) {
this.fetchSmartTransactionsStatus(transactionsToUpdate, {

Check warning on line 431 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

Check warning on line 431 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
networkClientId,
});
}
Expand Down Expand Up @@ -517,12 +519,12 @@
{ chainId, ethQuery },
);
}
} catch (e) {
} catch (error) {
this.trackMetaMetricsEvent({
event: 'STX Confirmation Failed',
category: 'swaps',
});
console.error('confirm error', e);
console.error('confirm error', error);
}
}

Expand Down Expand Up @@ -575,7 +577,7 @@
nonceLock.releaseLock();
return {
...transaction,
nonce: `0x${nonce.toString(16)}`,

Check warning on line 580 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Invalid type "any" of template literal expression

Check warning on line 580 in src/SmartTransactionsController.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Invalid type "any" of template literal expression
};
}

Expand Down Expand Up @@ -692,8 +694,8 @@
txParams?.from,
]);
preTxBalance = new BigNumber(preTxBalanceBN).toString(16);
} catch (e) {
console.error('provider error', e);
} catch (error) {
console.error('provider error', error);
}

const requiresNonce = !txParams.nonce;
Expand Down Expand Up @@ -780,7 +782,7 @@
getAPIRequestURL(APIType.LIVENESS, chainId),
);
liveness = Boolean(response.lastBlock);
} catch (e) {
} catch (error) {
console.log('"fetchLiveness" API call failed');
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SmartTransactionsController from './SmartTransactionsController';
import DefaultExport from '.';
import SmartTransactionsController from './SmartTransactionsController';

describe('default export', () => {
it('exports SmartTransactionsController', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This method is used for async tests that use fake timers.
* See https://stackoverflow.com/a/58716087 and https://jestjs.io/docs/timer-mocks.
*/
export const flushPromises = () => {
export const flushPromises = async () => {
return new Promise(jest.requireActual('timers').setImmediate);
};

Expand Down
7 changes: 3 additions & 4 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import packageJson from '../package.json';

import * as utils from './utils';
import { API_BASE_URL, CHAIN_IDS } from './constants';
import {
SmartTransactionMinedTx,
APIType,
SmartTransactionStatuses,
SmartTransactionCancellationReason,
} from './types';
import { API_BASE_URL, CHAIN_IDS } from './constants';
import * as utils from './utils';
import packageJson from '../package.json';

describe('src/utils.js', () => {
describe('isSmartTransactionPending', () => {
Expand Down
15 changes: 7 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { hexlify } from '@ethersproject/bytes';
import { BigNumber } from 'bignumber.js';
import jsonDiffer from 'fast-json-patch';
import _ from 'lodash';
import { BigNumber } from 'bignumber.js';
import { hexlify } from '@ethersproject/bytes';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import packageJson from '../package.json';

import { API_BASE_URL } from './constants';
import type { SmartTransaction, SmartTransactionsStatus } from './types';
import {
APIType,
SmartTransaction,
SmartTransactionsStatus,
SmartTransactionStatuses,
SmartTransactionCancellationReason,
SmartTransactionMinedTx,
cancellationReasonToStatusMap,
} from './types';
import { API_BASE_URL } from './constants';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import packageJson from '../package.json';

export function isSmartTransactionPending(smartTransaction: SmartTransaction) {
return smartTransaction.status === SmartTransactionStatuses.PENDING;
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["./src/**/*.test.ts"],
"exclude": []
}
Loading
Loading