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

Lint project #33

Merged
merged 2 commits into from
Nov 26, 2024
Merged
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
25 changes: 14 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import importPlugin from 'eslint-plugin-import';
import prettierPlugin from 'eslint-plugin-prettier';
import jestPlugin from 'eslint-plugin-jest';

/** @type {import('eslint').Linter.Config[]} */
export default [
{
files: ['**/*.{js,mjs,cjs,ts,tsx}'],
files: ['**/*.{js,mjs,cjs,ts,tsx}', '**/*.{test,spec}.{js,ts,tsx}'],
languageOptions: {
globals: {
...globals.browser,
...globals.node
...globals.node,
...globals.jest
},
parser: tseslint.parser,
parserOptions: {
Expand All @@ -26,6 +28,7 @@ export default [
plugins: {
import: importPlugin,
prettier: prettierPlugin,
jest: jestPlugin,
'@typescript-eslint': tseslint.plugin
},
settings: {
Expand All @@ -43,6 +46,7 @@ export default [
}
},
rules: {
...jestPlugin.configs.recommended.rules,
...pluginJs.configs.recommended.rules,
...tseslint.configs.recommended.rules,
'import/order': [
Expand Down Expand Up @@ -74,21 +78,20 @@ export default [
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' }
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_'
}
],
'no-unused-vars': ['off'],
'no-prototype-builtins': 'off',
'jest/no-mocks-import': 'off',
'no-async-promise-executor': 'off',
'object-curly-newline': 'off',
'arrow-body-style': 'off',
'implicit-arrow-linebreak': 'off',
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"build-esbuild": "rimraf out && node esbuild.js",
"build": "yarn build-esbuild && yarn compile",
"test": "jest",
"lint": "eslint --fix src",
"compile-next": "rimraf out && tsc --p tsconfig.next.json && tsc-alias --project tsconfig.next.json"
},
"publishConfig": {
Expand Down Expand Up @@ -81,6 +82,7 @@
"eslint-config-standard": "17.1.0",
"eslint-import-resolver-typescript": "3.6.3",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.9.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-promise": "7.1.0",
Expand Down
2 changes: 0 additions & 2 deletions src/__mocks__/utils/mockWindowHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ export const mockWindowHistory = () => {

const history = window.history;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.history;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.history = Object.defineProperties(
{},
Expand Down
2 changes: 0 additions & 2 deletions src/__mocks__/utils/mockWindowLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ export const mockWindowLocation = () => {

const location = window.location;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.location;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window.location = Object.defineProperties(
{},
Expand Down
2 changes: 1 addition & 1 deletion src/apiCalls/account/getAccountFromApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getAccountFromApi = async (address?: string) => {
try {
const { data } = await accountFetcher(address);
return data as AccountType;
} catch (err) {
} catch (_err) {
console.error('error fetching configuration for ', address);
}

Expand Down
2 changes: 1 addition & 1 deletion src/apiCalls/configuration/getNetworkConfigFromApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getNetworkConfigFromApi() {
if (data != null) {
return data?.data?.config;
}
} catch (err) {
} catch (_err) {
console.error('error fetching configuration for ', configUrl);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/apiCalls/configuration/getServerConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function getServerConfiguration(apiAddress: string) {
try {
const { data } = await axios.get<NetworkType>(configUrl);
return data;
} catch (err) {
} catch (_err) {
console.error('error fetching configuration for ', configUrl);
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/apiCalls/transactions/getTransactionByHash.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import { TRANSACTIONS_ENDPOINT } from 'apiCalls/endpoints';
import { getState } from 'store/store';
import { networkSelector } from 'store/selectors';
import { getState } from 'store/store';
import { ServerTransactionType } from 'types/serverTransactions.types';

export const getTransactionByHash = (hash: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/apiCalls/transactions/getTransactionsByHashes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from 'axios';
import { TRANSACTIONS_ENDPOINT } from 'apiCalls/endpoints';

import { getState } from 'store/store';
import { networkSelector } from 'store/selectors';
import { getState } from 'store/store';
import {
GetTransactionsByHashesReturnType,
PendingTransactionsType
Expand Down
4 changes: 2 additions & 2 deletions src/apiCalls/utils/getScamAddressData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from 'axios';
import { ScamInfoType } from 'types/account.types';
import { ACCOUNTS_ENDPOINT } from '../endpoints';
import { networkSelector } from 'store/selectors';
import { getState } from 'store/store';
import { ScamInfoType } from 'types/account.types';
import { ACCOUNTS_ENDPOINT } from '../endpoints';

export async function getScamAddressData(addressToVerify: string) {
const { apiAddress, apiTimeout } = networkSelector(getState());
Expand Down
12 changes: 6 additions & 6 deletions src/core/methods/initApp/initApp.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { initStore } from 'store/store';
import { defaultStorageCallback } from 'store/storage';
import { setNativeAuthConfig } from 'store/actions/config/configActions';
import { initializeNetwork } from 'store/actions';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { restoreProvider } from 'core/providers/helpers/restoreProvider';
import { getDefaultNativeAuthConfig } from 'services/nativeAuth/methods/getDefaultNativeAuthConfig';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { initializeNetwork } from 'store/actions';
import { setNativeAuthConfig } from 'store/actions/config/configActions';
import { defaultStorageCallback } from 'store/storage';
import { initStore } from 'store/store';
import { InitAppType } from './initApp.types';
import { getIsLoggedIn } from '../account/getIsLoggedIn';
import { restoreProvider } from 'core/providers/helpers/restoreProvider';
import { registerWebsocketListener } from './websocket/registerWebsocket';
import { trackTransactions } from '../trackTransactions/trackTransactions';

Expand Down
4 changes: 2 additions & 2 deletions src/core/methods/initApp/initApp.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { StorageCallback } from 'store/storage';
import { CustomNetworkType } from 'types/network.types';
import { EnvironmentsEnum } from 'types/enums.types';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { CustomNetworkType } from 'types/network.types';

type BaseDappConfigType = {
/**
Expand Down
23 changes: 13 additions & 10 deletions src/core/methods/initApp/websocket/initializeWebsocketConnection.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { io } from 'socket.io-client';
import { retryMultipleTimes } from 'utils/retryMultipleTimes';
import {
BatchTransactionsWSResponseType,
websocketConnection,
WebsocketConnectionStatusEnum
} from './websocket.constants';
import { getWebsocketUrl } from 'apiCalls/websocket';
import { getStore } from 'store/store';
import { getAccount } from 'core/methods/account/getAccount';
import { networkSelector } from 'store/selectors';
import {
setWebsocketBatchEvent,
setWebsocketEvent
} from 'store/actions/account/accountActions';
import { networkSelector } from 'store/selectors';
import { getStore } from 'store/store';
import { retryMultipleTimes } from 'utils/retryMultipleTimes';
import {
BatchTransactionsWSResponseType,
websocketConnection,
WebsocketConnectionStatusEnum
} from './websocket.constants';

const TIMEOUT = 3000;
const RECONNECTION_ATTEMPTS = 3;
Expand All @@ -22,12 +22,15 @@ const BATCH_UPDATED_EVENT = 'batchUpdated';
const CONNECT = 'connect';
const DISCONNECT = 'disconnect';

// eslint-disable-next-line no-undef
type TimeoutType = NodeJS.Timeout | null;

export async function initializeWebsocketConnection() {
const { address } = getAccount();
const { apiAddress } = networkSelector(getStore().getState());

let messageTimeout: NodeJS.Timeout | null = null;
let batchTimeout: NodeJS.Timeout | null = null;
let messageTimeout: TimeoutType = null;
let batchTimeout: TimeoutType = null;

const handleMessageReceived = (message: string) => {
if (messageTimeout) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/methods/initApp/websocket/registerWebsocket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { initializeWebsocketConnection } from './initializeWebsocketConnection';
import { getStore } from 'store/store';
import { getAccount } from 'core/methods/account/getAccount';
import { getStore } from 'store/store';
import { initializeWebsocketConnection } from './initializeWebsocketConnection';

let localAddress = '';
let closeConnectionRef: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/core/methods/sendTransactions/sendTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Transaction } from '@multiversx/sdk-core/out';
import { AxiosError } from 'axios';
import { sendSignedTransactions } from './helpers/sendSignedTransactions';
import { createTransactionsSession } from 'store/actions/transactions/transactionsActions';
import { sendSignedTransactions } from './helpers/sendSignedTransactions';

export async function sendTransactions(
transactions: Transaction[] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import { getTransactionsByHashes } from 'apiCalls/transactions/getTransactionsByHashes';
import {
updateSignedTransactionStatus,
updateTransactionsSession
} from 'store/actions/transactions/transactionsActions';
import { getIsTransactionFailed } from 'store/actions/transactions/transactionStateByStatus';
import {
TransactionBatchStatusesEnum,
TransactionServerStatusesEnum
} from 'types/enums.types';
import { ServerTransactionType } from 'types/serverTransactions.types';
import {
GetTransactionsByHashesReturnType,
SignedTransactionType
} from 'types/transactions.types';
import { refreshAccount } from 'utils/account';

import { getPendingTransactions } from './getPendingTransactions';
import { manageFailedTransactions } from './manageFailedTransactions';
import { TransactionsTrackerType } from '../../trackTransactions.types';
import {
GetTransactionsByHashesReturnType,
SignedTransactionType
} from 'types/transactions.types';
import {
BatchTransactionStatus,
ServerTransactionType
} from 'types/serverTransactions.types';
import {
updateSignedTransactionStatus,
updateTransactionsSession
} from 'store/actions/transactions/transactionsActions';
import {
getIsTransactionFailed,
getIsTransactionSuccessful
} from 'store/actions/transactions/transactionStateByStatus';
import { getTransactionsByHashes } from 'apiCalls/transactions/getTransactionsByHashes';

export interface TransactionStatusTrackerPropsType
extends TransactionsTrackerType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { refreshAccount } from 'utils/account';
import { checkBatch } from './checkBatch';
import { getPendingStoreTransactions } from '../getPendingStoreTransactions';
import { TransactionsTrackerType } from '../../trackTransactions.types';
import { getPendingStoreTransactions } from '../getPendingStoreTransactions';

export async function checkTransactionStatus(
props: TransactionsTrackerType & {
Expand Down
9 changes: 5 additions & 4 deletions src/core/methods/trackTransactions/trackTransactions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getTransactionsByHashes as defaultGetTxByHash } from 'apiCalls/transactions/getTransactionsByHashes';
import { TransactionsTrackerType } from './trackTransactions.types';
import { getPollingInterval } from './helpers/getPollingInterval';
import { websocketEventSelector } from 'store/selectors/accountSelectors';
import { getStore } from 'store/store';
import { checkTransactionStatus } from './helpers/checkTransactionStatus';
import { getPollingInterval } from './helpers/getPollingInterval';
import { TransactionsTrackerType } from './trackTransactions.types';
import {
websocketConnection,
WebsocketConnectionStatusEnum
} from '../initApp/websocket/websocket.constants';
import { getStore } from 'store/store';
import { websocketEventSelector } from 'store/selectors/accountSelectors';

/**
* Tracks transactions using websocket or polling
Expand All @@ -17,6 +17,7 @@ import { websocketEventSelector } from 'store/selectors/accountSelectors';
export async function trackTransactions(props?: TransactionsTrackerType) {
const store = getStore();
const pollingInterval = getPollingInterval();
// eslint-disable-next-line no-undef
let pollingIntervalTimer: NodeJS.Timeout | null = null;
let timestamp = websocketEventSelector(store.getState())?.timestamp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { setAccount } from 'store/actions/account';
import { setLoginToken } from 'store/actions/loginInfo/loginInfoActions';
import { getLatestNonce } from 'core/methods/account/getLatestNonce';
import { IProvider } from 'core/providers/types/providerFactory.types';
import { loginAction } from 'store/actions';
import { setAccount } from 'store/actions/account';
import { setLoginToken } from 'store/actions/loginInfo/loginInfoActions';
import { AccountType } from 'types/account.types';
import { getAccountFromToken } from './getAccountFromToken';
import { getLatestNonce } from 'core/methods/account/getLatestNonce';

interface IExtractAccountFromTokenProps {
loginToken: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Address, Message } from '@multiversx/sdk-core';
import { getAccount } from 'core/methods/account/getAccount';
import { nativeAuth } from 'services/nativeAuth';
import { buildNativeAuthConfig } from 'services/nativeAuth/methods';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { setTokenLogin } from 'store/actions/loginInfo/loginInfoActions';
import { networkSelector, tokenLoginSelector } from 'store/selectors';
import { getState } from 'store/store';
import { OnProviderLoginType } from 'types/login.types';
import { setTokenLogin } from 'store/actions/loginInfo/loginInfoActions';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { getAccount } from 'core/methods/account/getAccount';

const getApiAddress = (
apiAddress: string,
Expand Down
10 changes: 5 additions & 5 deletions src/core/providers/DappProvider/helpers/login/login.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { registerWebsocketListener } from 'core/methods/initApp/websocket/registerWebsocket';
import { IProvider } from 'core/providers/types/providerFactory.types';
import { nativeAuth } from 'services/nativeAuth';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { logoutAction } from 'store/actions';
import { setAddress } from 'store/actions/account';
import { setTokenLogin } from 'store/actions/loginInfo/loginInfoActions';
import { IProvider } from 'core/providers/types/providerFactory.types';
import { nativeAuthConfigSelector } from 'store/selectors';
import { getState } from 'store/store';
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types';
import { logoutAction } from 'store/actions';
import { extractAccountFromToken } from './helpers/extractAccountFromToken';
import { registerWebsocketListener } from 'core/methods/initApp/websocket/registerWebsocket';

async function loginWithoutNativeToken(provider: IProvider) {
await provider.login();
Expand Down Expand Up @@ -36,7 +36,7 @@ async function loginWithNativeToken(
noCache: true
});

const { address, signature, ...loginResult } = await provider.login?.({
const { address, signature, ...loginResult } = await provider.login({
token: loginToken
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Transaction } from '@multiversx/sdk-core';
import { getAreAllTransactionsSignedByGuardian } from './getAreAllTransactionsSignedByGuardian';
import { getAccount } from 'core/methods/account/getAccount';
import { createCrossWindowProvider } from 'core/providers/helpers/crossWindow/createCrossWindowProvider';
import { getAreAllTransactionsSignedByGuardian } from './getAreAllTransactionsSignedByGuardian';

export async function getGuardedTransactions({
transactions
Expand Down
Loading
Loading