Skip to content

Commit 0c2c7ba

Browse files
fix: Resolve ESLint issues to improve code quality [DEV-4792] (#274)
* fix: Resolve ESLint issues to improve code quality First set of fixes are the automatic fixes suggested on `npm run lint:fix` * Ditch unused getRandomGroup * Remove `request` parameter where not required This helps resolve "'request' is defined but never used" linting errors. * Remove error for unused variables for `ctx` and `controller` Need to retain the parameters for structure but suppress linting error. * Remove redundant `insertResult` We can invoke the DB insert directly, since the value of `insertResult` is never used * Better error catching in circulating supplyz * Update worker-types.d.ts Worker Types: Changing Promise<any> to Promise<unknown> maintains compatibility while being more type-safe. The unknown type can hold any value just like any, but requires type checking before use, which is actually safer. * Update node.ts Node Types: The ValidatorRewards type directly models the existing data structure based on how it's used. * Replace `any` with AnalyticsItem * Fix export path type issues * Fix error in db any usage * Remove ExportAnalyticsItem This was breaking the structure of CSV response * Fix type issues in GraphQL * Restore original CSV format * Make export for CSV's consistent * Revert combining * Strong types --------- Co-authored-by: filipdjokic <djokicf@protonmail.com>
1 parent 5f6a5a8 commit 0c2c7ba

25 files changed

Lines changed: 192 additions & 115 deletions

src/api/bigDipperApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ export class BigDipperApi {
1616
constructor(public readonly graphql_client: GraphQLClient) {}
1717

1818
async getTotalSupply(): Promise<number> {
19-
let query = `query TotalSupply {
19+
const query = `query TotalSupply {
2020
supply {
2121
coins
2222
}
2323
}`;
2424

25-
let resp = await this.graphql_client.query<{
25+
const resp = await this.graphql_client.query<{
2626
data: TotalSupplyResponse;
2727
}>(query);
2828

2929
return Number(resp.data.supply[0].coins.find((coin) => coin.denom === 'ncheq')?.amount || '0');
3030
}
3131

3232
getTotalStakedCoins = async (): Promise<string> => {
33-
let query = `query StakingInfo{
33+
const query = `query StakingInfo{
3434
staking_pool {
3535
bonded_tokens
3636
}

src/api/nodeApi.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ export class NodeApi {
44
constructor(public readonly base_rest_api_url: string) {}
55

66
async getAccountInfo(address: string): Promise<Account> {
7-
let resp = await fetch(`${this.base_rest_api_url}/cosmos/auth/v1beta1/accounts/${address}`);
8-
let respJson = (await resp.json()) as { account: Account };
7+
const resp = await fetch(`${this.base_rest_api_url}/cosmos/auth/v1beta1/accounts/${address}`);
8+
const respJson = (await resp.json()) as { account: Account };
99

1010
return respJson.account;
1111
}
1212

1313
async getAvailableBalance(address: string): Promise<Coin[]> {
14-
let resp = await fetch(`${this.base_rest_api_url}/cosmos/bank/v1beta1/balances/${address}`);
15-
let respJson = (await resp.json()) as { balances: Coin[] };
14+
const resp = await fetch(`${this.base_rest_api_url}/cosmos/bank/v1beta1/balances/${address}`);
15+
const respJson = (await resp.json()) as { balances: Coin[] };
1616

1717
return respJson.balances;
1818
}
1919

2020
async distributionGetRewards(address: string): Promise<number> {
21-
let resp = await fetch(`${this.base_rest_api_url}/cosmos/distribution/v1beta1/delegators/${address}/rewards`);
22-
let respJson = (await resp.json()) as RewardsResponse;
21+
const resp = await fetch(`${this.base_rest_api_url}/cosmos/distribution/v1beta1/delegators/${address}/rewards`);
22+
const respJson = (await resp.json()) as RewardsResponse;
2323

2424
return Number(respJson?.total?.[0]?.amount ?? '0');
2525
}

src/database/scripts/initialDataFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ clientConfig.ssl = {
1414
ca: fs.readFileSync('/tmp/do-cert.pem').toString(),
1515
};
1616

17-
let client = new Client(clientConfig);
17+
const client = new Client(clientConfig);
1818

1919
client.connect();
2020
const db = drizzle(client, { logger: false });

src/database/scripts/seed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clientConfig.ssl = {
1212
ca: fs.readFileSync('/tmp/do-cert.pem').toString(),
1313
};
1414

15-
let client = new Client(clientConfig);
15+
const client = new Client(clientConfig);
1616

1717
client.connect();
1818
const db = drizzle(client, { logger: true });

src/handlers/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function parseQueryParams(url: URL): AnalyticsQueryParams {
146146
export async function handler(
147147
request: IRequest,
148148
env: Env,
149-
ctx: ExecutionContext,
149+
_ctx: ExecutionContext,
150150
network: Network,
151151
entityType?: EntityType
152152
): Promise<Response> {

src/handlers/circulatingSupply.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { IRequest } from 'itty-router';
21
import { getCirculatingSupply } from '../helpers/circulating';
32

4-
export async function handler(request: IRequest, env: Env): Promise<Response> {
3+
export async function handler(env: Env): Promise<Response> {
54
try {
65
const circulating_supply = await getCirculatingSupply(env);
76
return new Response(circulating_supply.toString());

src/handlers/liquidBalance.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ export async function handler(request: IRequest, env: Env): Promise<Response> {
1111
throw new Error('No address specified or wrong address format.');
1212
}
1313

14-
let api = new NodeApi(env.REST_API);
14+
const api = new NodeApi(env.REST_API);
1515
const account = await api.getAccountInfo(address);
1616

1717
if (!isVestingAccount(account['@type'])) {
1818
throw new Error(`Only vesting accounts are supported. Accounts type '${account['@type']}'.`);
1919
}
2020

2121
if (isDelayedVestingAccount(account?.['@type'])) {
22-
let balance =
22+
const balance =
2323
account?.base_vesting_account?.base_account?.sequence !== '0'
2424
? Number(
2525
(await (await api.getAvailableBalance(address)).find((b) => b.denom === 'ncheq')?.amount) ?? '0'
2626
)
2727
: 0;
28-
let rewards = Number((await await api.distributionGetRewards(address)) ?? '0');
29-
let delegated = Number(
28+
const rewards = Number((await await api.distributionGetRewards(address)) ?? '0');
29+
const delegated = Number(
3030
account?.base_vesting_account?.delegated_free?.find((d) => d.denom === 'ncheq')?.amount ?? '0'
3131
);
3232

3333
return new Response(convertToMainTokenDenom(balance + rewards + delegated, env.TOKEN_EXPONENT));
3434
}
3535

36-
let vested_coins = Number(calculateVesting(account)?.vested);
37-
let balance = Number(
36+
const vested_coins = Number(calculateVesting(account)?.vested);
37+
const balance = Number(
3838
(await (await api.getAvailableBalance(address)).find((b) => b.denom === 'ncheq')?.amount) ?? '0'
3939
);
40-
let rewards = Number((await api.distributionGetRewards(address)) ?? '0');
41-
let liquid_coins = vested_coins + balance + rewards;
40+
const rewards = Number((await api.distributionGetRewards(address)) ?? '0');
41+
const liquid_coins = vested_coins + balance + rewards;
4242

4343
return new Response(convertToMainTokenDenom(liquid_coins, env.TOKEN_EXPONENT));
4444
}

src/handlers/totalBalance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { fetchAccountBalances } from '../helpers/balance';
33

44
export async function handler(request: IRequest, env: Env): Promise<Response> {
55
const address = request.params?.['address'];
6-
let account_balance_infos = await fetchAccountBalances(address!!, env);
6+
const account_balance_infos = await fetchAccountBalances(address!, env);
77
return new Response(account_balance_infos?.totalBalance.toString());
88
}

src/handlers/totalStakedCoins.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { IRequest } from 'itty-router';
21
import { BigDipperApi } from '../api/bigDipperApi';
32
import { convertToMainTokenDenom } from '../helpers/currency';
43
import { GraphQLClient } from '../helpers/graphql';
54

6-
export async function handler(request: IRequest, env: Env): Promise<Response> {
7-
let gql_client = new GraphQLClient(env.GRAPHQL_API);
8-
let bd_api = new BigDipperApi(gql_client);
5+
export async function handler(env: Env): Promise<Response> {
6+
const gql_client = new GraphQLClient(env.GRAPHQL_API);
7+
const bd_api = new BigDipperApi(gql_client);
98

10-
let total_staked_coins = await bd_api.getTotalStakedCoins();
9+
const total_staked_coins = await bd_api.getTotalStakedCoins();
1110

1211
return new Response(convertToMainTokenDenom(Number(total_staked_coins), env.TOKEN_EXPONENT));
1312
}

src/handlers/totalSupply.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { IRequest } from 'itty-router';
21
import { BigDipperApi } from '../api/bigDipperApi';
32
import { convertToMainTokenDenom } from '../helpers/currency';
43
import { GraphQLClient } from '../helpers/graphql';
54

6-
export async function handler(request: IRequest, env: Env): Promise<Response> {
7-
let gql_client = new GraphQLClient(env.GRAPHQL_API);
8-
let bd_api = new BigDipperApi(gql_client);
5+
export async function handler(env: Env): Promise<Response> {
6+
const gql_client = new GraphQLClient(env.GRAPHQL_API);
7+
const bd_api = new BigDipperApi(gql_client);
98
const total_supply = await bd_api.getTotalSupply();
109
return new Response(convertToMainTokenDenom(total_supply, env.TOKEN_EXPONENT));
1110
}

0 commit comments

Comments
 (0)