Skip to content

Commit

Permalink
Fix more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Spenhouet committed Mar 1, 2024
1 parent 953b26e commit 05c1f36
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/api/resources/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { icons } from "../utils/icons";
import { JsonResources } from "../utils/resources";

function statsToSummary<T extends primitive.Timestamped>(path: string, stats: Stats<T>) {
if (!stats || !stats.min || !stats.max || !stats.median) {
if (!stats.min || !stats.max || !stats.median) {
throw new Error("Stats missing. This should have been checked prior.");
}

Expand Down Expand Up @@ -52,7 +52,7 @@ function yearResource<T extends primitive.Timestamped>(
) {
if (!year || !months.length) return;

if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
$id: `${path}/${year}`,
Expand All @@ -72,7 +72,7 @@ function monthResource<T extends primitive.Timestamped>(
) {
if (!year || !month || !days.length) return;

if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
$id: `${path}/${year}/${month}`,
Expand All @@ -93,7 +93,7 @@ function dayResource<T extends primitive.Timestamped>(
) {
if (!year || !month || !day || !hours.length) return;

if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
$id: `${path}/${year}/${month}/${day}`,
Expand Down Expand Up @@ -221,7 +221,7 @@ export class Asset extends JsonResources {
async collateralizationGraphHour<T extends primitive.Timestamped & bcked.asset.Graph>(
stats: Stats<T> | undefined
) {
if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
...hourBaseResource(`/assets/collateralization-graph`, stats.median.timestamp),
Expand Down Expand Up @@ -427,7 +427,7 @@ export class Asset extends JsonResources {
id: bcked.entity.Id,
stats: Stats<T> | undefined
) {
if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
...hourBaseResource(`/assets/${id}/price`, stats.median.timestamp),
Expand Down Expand Up @@ -517,7 +517,7 @@ export class Asset extends JsonResources {
schema: {},
})
async supplyHour(id: bcked.entity.Id, stats: Stats<bcked.asset.SupplyAmount> | undefined) {
if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

if (!stats.median.amount) return;

Expand Down Expand Up @@ -612,7 +612,7 @@ export class Asset extends JsonResources {
schema: {},
})
async marketCapHour(id: bcked.entity.Id, stats: Stats<bcked.asset.MarketCap> | undefined) {
if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
...hourBaseResource(`/assets/${id}/market-cap`, stats.median.timestamp),
Expand Down Expand Up @@ -717,7 +717,7 @@ export class Asset extends JsonResources {
id: bcked.entity.Id,
stats: Stats<bcked.asset.Relationships> | undefined
) {
if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
...hourBaseResource(`/assets/${id}/underlying-assets`, stats.median.timestamp),
Expand Down Expand Up @@ -836,7 +836,7 @@ export class Asset extends JsonResources {
id: bcked.entity.Id,
stats: Stats<bcked.asset.Collateralization> | undefined
) {
if (!stats || !stats.min || !stats.max || !stats.median) return;
if (!stats?.min || !stats.max || !stats.median) return;

return {
...hourBaseResource(`/assets/${id}/collateralization-ratio`, stats.median.timestamp),
Expand Down
6 changes: 2 additions & 4 deletions src/api/utils/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ export abstract class JsonResources {
if (tag) {
this.extendSpec({ tags: this.tag ? [this.tag] : [] });
}
if (resources) {
this.extend(...resources);
}
this.extend(...resources);
}

register({ path, summary, description, parameters, type, schema }: RegistrationParams) {
// Only register if not already registered
if (this.spec.paths && this.spec.paths[path]) return;
if (this.spec.paths?.[path]) return;

this.extendSpec({
paths: {
Expand Down
2 changes: 1 addition & 1 deletion src/api/workers/precompile_supply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function* computeSupplyFallback(

// Define fallback for supply data
const amount =
supplyEntry.total || supplyEntry.circulating || supplyEntry.issued || supplyEntry.max;
supplyEntry.total ?? supplyEntry.circulating ?? supplyEntry.issued ?? supplyEntry.max;

if (!amount) continue;

Expand Down
1 change: 1 addition & 0 deletions src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export function* cycleIndex(
if (start < lower || start > upper) throw Error(`Start ${start} outside bounds ${bounds}.`);
if (step > upper - lower) throw Error(`Step larger than range of bounds ${bounds}.`);
let index = start;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
while (true) {
yield index;
index += step;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function readHeadersFromStream<T>(
): Promise<[AsyncGenerator<T, void, undefined>, string[]] | [undefined, undefined]> {
// Read the first row to get the header
const [value, _rows] = await getFirstElement(rows);
if (!value || !_rows) return [undefined, undefined];
if (!value) return [undefined, undefined];

const rowFlattened = flatten<object, object>(value);
// Ensure header consistency
Expand Down Expand Up @@ -120,7 +120,7 @@ export async function rewriteCSV<T>(

export async function writeToCsv<T>(pathToFile: string, rows: AsyncIterable<T>, index?: string) {
const [_rows, _header] = await readHeadersFromStream(rows);
if (!_rows || !_header) return;
if (!_rows || !_header.length) return;

// By default, take first key as index
const headerIndex = index ?? _header[0]!;
Expand Down
4 changes: 2 additions & 2 deletions src/watcher/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export async function sendErrorReport(subject: string, error: any) {
logMessage = [
"Error Type: AxiosError",
`Request: ${axiosError.config?.method} ${axiosError.config?.baseURL}${axiosError.config?.url}`,
`Status Code: ${axiosError.response?.status || "Unknown"}`,
`Status Text: ${axiosError.response?.statusText || "Unknown"}`,
`Status Code: ${axiosError.response?.status ?? "Unknown"}`,
`Status Text: ${axiosError.response?.statusText ?? "Unknown"}`,
`Response Data: ${JSON.stringify(
axiosError.response?.data || "No response data",
null,
Expand Down

0 comments on commit 05c1f36

Please sign in to comment.