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

chore: add curly eslint rule #273

Merged
merged 1 commit into from
Nov 22, 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
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default [
},

rules: {
curly: 'error',
'no-console': 'off',
'unicorn/no-negated-condition': 'off',
'unicorn/no-null': 'off',
Expand Down
4 changes: 3 additions & 1 deletion src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const onBlock = async (
subscribedAddresses: SubscribedAddress[] | undefined,
) => {
// client has no subscription
if (!activeSubscriptions) return;
if (!activeSubscriptions) {
return;
}

// block subscription
const activeBlockSub = activeSubscriptions?.find(index => index.type === 'block');
Expand Down
4 changes: 3 additions & 1 deletion src/methods/get-balance-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ export const getAccountBalanceHistory = async (
)
// eslint-disable-next-line unicorn/no-await-expression-member
.filter(tx => {
if (typeof from !== 'number' || typeof to !== 'number') return true;
if (typeof from !== 'number' || typeof to !== 'number') {
return true;
}
return tx.txData.block_time >= from && tx.txData.block_time <= to;
})
// txs are sorted from newest to oldest, we need exact opposite
Expand Down
4 changes: 3 additions & 1 deletion src/methods/push-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export default async (
);

return message;
} else throw error;
} else {
throw error;
}
}
};
12 changes: 9 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,13 @@ wss.on('connection', async (ws: Server.Ws) => {
);

// Subscribe to new address...
if (subscriptionIndex === -1) addressesSubscribed[clientId].push({ address, cbor });
if (subscriptionIndex === -1) {
addressesSubscribed[clientId].push({ address, cbor });
}
// ... or update the cbor option
else addressesSubscribed[clientId][subscriptionIndex].cbor ||= cbor;
else {
addressesSubscribed[clientId][subscriptionIndex].cbor ||= cbor;
}
}

const activeAddressSubIndex = activeSubscriptions[clientId].findIndex(
Expand Down Expand Up @@ -362,7 +366,9 @@ wss.on('connection', async (ws: Server.Ws) => {
};

const handleError = (id: MessageId, error: unknown) => {
if (!(error instanceof MessageError)) logger.error(error);
if (!(error instanceof MessageError)) {
logger.error(error);
}

const response = prepareErrorMessage(id, clientId, error);

Expand Down
4 changes: 3 additions & 1 deletion src/utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const getTxidsFromAccountAddresses = async (addresses: Address[], account
address: string;
} & Responses['address_transactions_content'][number])[] = [];

if (accountEmpty) return [];
if (accountEmpty) {
return [];
}

const transactionsPerAddressList = await addressesToTxIds(addresses);

Expand Down
18 changes: 13 additions & 5 deletions src/utils/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ export const addressesToUtxos = async (

const assets = new Set<string>();

for (const addressUtxos of allUtxos)
for (const utxo of addressUtxos)
for (const addressUtxos of allUtxos) {
for (const utxo of addressUtxos) {
for (const a of utxo.amount) {
if (a.unit !== 'lovelace') {
assets.add(a.unit);
}
}
}
}

const tokenMetadata = await Promise.all(
[...assets].map(a => assetMetadataLimiter.add(() => getAssetData(a), { throwOnTimeout: true })),
Expand All @@ -160,7 +162,9 @@ export const utxosWithBlocks = async (
const promisesBundle: Promise<Addresses.UtxosWithBlockResponse>[] = [];

for (const utxo of utxos) {
if (utxo.data === 'empty') continue;
if (utxo.data === 'empty') {
continue;
}

for (const utxoData of utxo.data) {
const promise = limiter(() =>
Expand Down Expand Up @@ -190,7 +194,9 @@ export const addressesToTxIds = async (
}>[] = [];

for (const item of addresses) {
if (item.data === 'empty') continue;
if (item.data === 'empty') {
continue;
}

const promise = limiter(() =>
// 1 page (100 txs) per address at a time should be more efficient default value
Expand Down Expand Up @@ -257,7 +263,9 @@ export const getAddressesData = async (
return addresses.map(addr => {
const response = responses.find(r => r.address === addr.address);

if (!response) throw new Error('Failed getAddressData');
if (!response) {
throw new Error('Failed getAddressData');
}

return {
address: addr.address,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { logger } from './logger.js';

export const getAssetData = memoizee(
async (hex: string) => {
if (hex === 'lovelace') return;
if (hex === 'lovelace') {
return;
}
logger.debug(`Fetching asset metadata for ${hex}`);
try {
const response = await blockfrostAPI.assetsById(hex);
Expand Down
4 changes: 3 additions & 1 deletion src/utils/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export const validators = Object.fromEntries(
return [
title,
(data: unknown) => {
if (!validator(data)) throw new MessageError(JSON.stringify(validator.errors));
if (!validator(data)) {
throw new MessageError(JSON.stringify(validator.errors));
}
},
];
}),
Expand Down
16 changes: 13 additions & 3 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export const txIdsToTransactions = async (
txIds: string[];
}[],
): Promise<Types.TxIdsToTransactionsResponse[]> => {
if (txIdsPerAddress.length === 0) return [];
if (txIdsPerAddress.length === 0) {
return [];
}

const promises: Promise<Types.TxIdsToTransactionsResponse | undefined>[] = [];

Expand Down Expand Up @@ -115,8 +117,16 @@ export const transformTransactionUtxo = async (
): Promise<Types.TransformedTransactionUtxo> => {
const assets = new Set<string>();

for (const input of utxo.inputs) for (const a of input.amount) assets.add(a.unit);
for (const output of utxo.outputs) for (const a of output.amount) assets.add(a.unit);
for (const input of utxo.inputs) {
for (const a of input.amount) {
assets.add(a.unit);
}
}
for (const output of utxo.outputs) {
for (const a of output.amount) {
assets.add(a.unit);
}
}

const assetsMetadata = await Promise.all(
[...assets]
Expand Down
Loading