Skip to content

Commit

Permalink
devDeps: update @metamask/eslint-config* from 10 to 12 (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Feb 27, 2024
1 parent fd96ef1 commit c166eb1
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 207 deletions.
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,
'@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 @@ describe('SmartTransactionsController', () => {
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 @@ describe('SmartTransactionsController', () => {
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 @@ describe('SmartTransactionsController', () => {
approvalTxFees: getFeesApiResponse.txs[0],
tradeTxFees: getFeesApiResponse.txs[1],
});
await smartTransactionsController.clearFees();
smartTransactionsController.clearFees();
expect(
smartTransactionsController.state.smartTransactionsState.fees,
).toStrictEqual({
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 @@ import {
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 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo

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 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
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 Down Expand Up @@ -230,9 +232,9 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
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 @@ -517,12 +519,12 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
{ 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 @@ -692,8 +694,8 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
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 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
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

0 comments on commit c166eb1

Please sign in to comment.