ESLint standard

This commit is contained in:
Aleksandr Kraiz
2023-02-08 02:15:43 +04:00
parent f5b7b019c8
commit ed33a83570
14 changed files with 354 additions and 72 deletions

View File

@@ -82,9 +82,9 @@ export default class BalanceGuard {
return requirements
.reduce<AggregatedBalanceRequirement[]>((prev, curr) => {
const aggregatedBalanceRequirement = prev.find(
(item) => item.asset.address === curr.asset.address
&& arrayEquals(item.sources, curr.sources)
&& item.spenderAddress === curr.spenderAddress,
(item) => item.asset.address === curr.asset.address &&
arrayEquals(item.sources, curr.sources) &&
item.spenderAddress === curr.spenderAddress,
);
if (aggregatedBalanceRequirement) {
@@ -163,9 +163,9 @@ export default class BalanceGuard {
async check(fixAutofixable?: boolean) {
this.logger?.(`Balance requirements: ${this.requirements
.map((requirement) => `${requirement.amount} ${requirement.asset.name} `
+ `for '${requirement.reason}' `
+ `from [${requirement.sources.join(' + ')}]`)
.map((requirement) => `${requirement.amount} ${requirement.asset.name} ` +
`for '${requirement.reason}' ` +
`from [${requirement.sources.join(' + ')}]`)
.join(', ')}`);
const remainingBalances = clone(this.balances);
@@ -206,9 +206,9 @@ export default class BalanceGuard {
balanceIssues.push({
asset,
sources: ['exchange'],
message: `Not enough ${asset.name} on exchange balance. `
+ `Needed: ${itemsAmountSum.toString()}, available: ${exchangeBalance?.toString()}. `
+ `You need to deposit at least ${lackAmount.toString()} ${asset.name} into exchange contract`,
message: `Not enough ${asset.name} on exchange balance. ` +
`Needed: ${itemsAmountSum.toString()}, available: ${(exchangeBalance ?? '[UNDEFINED]')?.toString()}. ` +
`You need to deposit at least ${lackAmount.toString()} ${asset.name} into exchange contract`,
});
}
});
@@ -260,10 +260,10 @@ export default class BalanceGuard {
const exchangeBalance = this.balances?.[asset.name]?.exchange;
const available = exchangeBalance?.plus(approvedWalletBalance);
const issueMessage = `Not enough ${asset.name} on exchange + wallet balance. `
+ `Needed: ${itemsAmountSum.toString()}, available: ${available?.toString()} `
+ `(exchange: ${exchangeBalance?.toString()}, available (approved): ${approvedWalletBalance.toString()}).`
+ ` ${approveIsHelpful
const issueMessage = `Not enough ${asset.name} on exchange + wallet balance. ` +
`Needed: ${itemsAmountSum.toString()}, available: ${(available ?? '[UNDEFINED]')?.toString()} ` +
`(exchange: ${(exchangeBalance ?? '[UNKNOWN]')?.toString()}, available (approved): ${approvedWalletBalance.toString()}).` +
` ${approveIsHelpful
? `You need approve at least ${lackAmount.toString()} ${asset.name}`
: 'Approve is not helpful'}`;
if (approveIsHelpful) {
@@ -290,11 +290,13 @@ export default class BalanceGuard {
asset,
sources: ['exchange', 'wallet'],
fixes: [
...resetRequired ? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}] : [],
...resetRequired
? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}]
: [],
{
type: 'byApprove',
targetAmount: targetApprove,
@@ -351,8 +353,8 @@ export default class BalanceGuard {
const approveIsHelpful = approveAvailable.gte(lackAmount);
const targetApprove = approvedWalletBalance.plus(lackAmount);
const issueMessage = `Not enough ${asset.name} on wallet balance. `
+ `Needed: ${itemsAmountSum.toString()}, available (approved): ${approvedWalletBalance.toString()}. ${approveIsHelpful
const issueMessage = `Not enough ${asset.name} on wallet balance. ` +
`Needed: ${itemsAmountSum.toString()}, available (approved): ${approvedWalletBalance.toString()}. ${approveIsHelpful
? `You need approve at least ${lackAmount.toString()} ${asset.name}`
: 'Approve is not helpful'}`;
if (approveIsHelpful) {
@@ -379,11 +381,13 @@ export default class BalanceGuard {
asset,
sources: ['wallet'],
fixes: [
...resetRequired ? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}] : [],
...resetRequired
? [{
type: 'byApprove' as const,
targetAmount: 0,
spenderAddress,
}]
: [],
{
type: 'byApprove',
targetAmount: targetApprove,
@@ -418,8 +422,8 @@ export default class BalanceGuard {
balanceIssues.push({
asset,
sources: ['wallet'],
message: `Not enough ${asset.name} on wallet balance. `
+ `You need to deposit at least ${lackAmount.toString()} ${asset.name} into wallet contract`,
message: `Not enough ${asset.name} on wallet balance. ` +
`You need to deposit at least ${lackAmount.toString()} ${asset.name} into wallet contract`,
});
}
});
@@ -428,7 +432,10 @@ export default class BalanceGuard {
const unfixed = await this.fixAllAutofixableBalanceIssues(balanceIssues);
if (unfixed.length > 0) throw new Error(`Balance issues: ${unfixed.map((issue, i) => `${i + 1}. ${issue.message}`).join('\n')}`);
} else if (balanceIssues.length > 0) {
throw new Error(`Balance issues (address ${walletAddress}): ${balanceIssues.map((issue, i) => `${i + 1}. ${issue.message}`).join('\n')}`);
throw new Error(
`Balance issues (address ${walletAddress}): ` +
`${balanceIssues.map((issue, i) => `${i + 1}. ${issue.message}`).join('\n')}`
);
}
}
}

View File

@@ -117,9 +117,13 @@ export default class Orion {
if (isValidChainId(networkCodeOrChainId)) {
unit = this.units[networkCodeOrChainId];
} else {
unit = this.unitsArray.find((unit) => unit.networkCode === networkCodeOrChainId);
unit = this.unitsArray.find((u) => u.networkCode === networkCodeOrChainId);
}
if (!unit) {
throw new Error(
`Invalid network code: ${networkCodeOrChainId}. ` +
`Available network codes: ${this.unitsArray.map((u) => u.networkCode).join(', ')}`);
}
if (!unit) throw new Error(`Invalid network code: ${networkCodeOrChainId}. Available network codes: ${this.unitsArray.map((unit) => unit.networkCode).join(', ')}`);
return unit;
}

View File

@@ -85,11 +85,11 @@ export default async function getSwapInfo({
if (options?.poolOnly) {
route = 'pool';
} else if (
swapExchanges !== undefined
&& poolExchangesList.length > 0
&& swapExchanges.length === 1
&& firstSwapExchange
&& poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
swapExchanges !== undefined &&
poolExchangesList.length > 0 &&
swapExchanges.length === 1 &&
firstSwapExchange &&
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
) {
route = 'pool';
} else {

View File

@@ -170,11 +170,11 @@ export default async function swapMarket({
options?.logger?.('Swap is through pool (because "poolOnly" option is true)');
route = 'pool';
} else if (
swapExchanges !== undefined
&& poolExchangesList.length > 0
&& swapExchanges.length === 1
&& firstSwapExchange
&& poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
swapExchanges !== undefined &&
poolExchangesList.length > 0 &&
swapExchanges.length === 1 &&
firstSwapExchange &&
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
) {
options?.logger?.(`Swap is through pool [via ${firstSwapExchange}] (detected by "exchanges" field)`);
route = 'pool';

View File

@@ -7,9 +7,9 @@ import { INTERNAL_ORION_PRECISION } from '../constants';
import { CFDOrder, SignedCFDOrder, SupportedChainId } from '../types';
import normalizeNumber from '../utils/normalizeNumber';
import getDomainData from './getDomainData';
import signCFDOrderPersonal from "./signCFDOrderPersonal";
import hashCFDOrder from "./hashCFDOrder";
import CFD_ORDER_TYPES from "../constants/cfdOrderTypes";
import signCFDOrderPersonal from './signCFDOrderPersonal';
import hashCFDOrder from './hashCFDOrder';
import CFD_ORDER_TYPES from '../constants/cfdOrderTypes';
const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days

View File

@@ -133,7 +133,7 @@ type BufferLike =
| Uint8Array
| ArrayBuffer
| SharedArrayBuffer
| ReadonlyArray<any>
| ReadonlyArray<unknown>
| ReadonlyArray<number>
| { valueOf(): ArrayBuffer }
| { valueOf(): SharedArrayBuffer }
@@ -142,7 +142,6 @@ type BufferLike =
| { valueOf(): string }
| { [Symbol.toPrimitive](hint: string): string };
const isSubType = (subType: string): subType is keyof Subscription => Object.values(SubscriptionType).some((t) => t === subType);
class OrionAggregatorWS {
private ws: WebSocket | undefined;
@@ -483,7 +482,7 @@ class OrionAggregatorWS {
});
}
break;
case MessageType.CFD_ADDRESS_UPDATE: {
case MessageType.CFD_ADDRESS_UPDATE:
switch (json.k) { // message kind
case 'i': { // initial
const fullOrders = json.o
@@ -522,7 +521,6 @@ class OrionAggregatorWS {
default:
break;
}
}
break;
case MessageType.ADDRESS_UPDATE: {
const balances = json.b

View File

@@ -1,8 +1,8 @@
import { z } from "zod";
import { fullOrderSchema, orderUpdateSchema } from "./addressUpdateSchema";
import baseMessageSchema from "./baseMessageSchema";
import MessageType from "../MessageType";
import cfdBalancesSchema from "./cfdBalancesSchema";
import { z } from 'zod';
import { fullOrderSchema, orderUpdateSchema } from './addressUpdateSchema';
import baseMessageSchema from './baseMessageSchema';
import MessageType from '../MessageType';
import cfdBalancesSchema from './cfdBalancesSchema';
const baseCfdAddressUpdate = baseMessageSchema.extend({
id: z.string(),

View File

@@ -1,5 +1,5 @@
import { z } from 'zod';
import positionStatuses from "../../../../constants/positionStatuses";
import positionStatuses from '../../../../constants/positionStatuses';
const cfdBalanceSchema = z
.object({

View File

@@ -1,4 +1,4 @@
const arrayEquals = (a: unknown[], b: unknown[]) => a.length === b.length
&& a.every((value, index) => value === b[index]);
const arrayEquals = (a: unknown[], b: unknown[]) => a.length === b.length &&
a.every((value, index) => value === b[index]);
export default arrayEquals;

View File

@@ -1,11 +1,11 @@
const httpToWS = (url: string) => {
const parsedUrl = new URL(url);
if (parsedUrl.protocol === 'https:') {
parsedUrl.protocol = 'wss:';
} else if (parsedUrl.protocol === 'http:') {
parsedUrl.protocol = 'ws:';
}
return parsedUrl.toString();
const parsedUrl = new URL(url);
if (parsedUrl.protocol === 'https:') {
parsedUrl.protocol = 'wss:';
} else if (parsedUrl.protocol === 'http:') {
parsedUrl.protocol = 'ws:';
}
return parsedUrl.toString();
};
export default httpToWS;
export default httpToWS;

View File

@@ -9,6 +9,6 @@ export default function isNetworkCodeInEnvironment(networkCode: string, env: str
if (envNetworks === undefined) throw new Error('Env networks is undefined (isNetworkCodeInEnvironment)');
return Object.values(chains)
.some((chain) => chain.code.toLowerCase() === networkCode.toLowerCase()
&& chain.chainId in envNetworks);
.some((chain) => chain.code.toLowerCase() === networkCode.toLowerCase() &&
chain.chainId in envNetworks);
}