Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ulan committed Sep 2, 2024
1 parent 7282def commit 4c2d658
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
</script>

<main>
<h1>ICP Pricing Calculator</h1>
<h1>ICP Pricing Calculator<sup>(beta)</sup></h1>

<aside class="l-stack">
<form class="l-stack">
Expand Down
32 changes: 16 additions & 16 deletions src/lib/utils/calc.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {
calculators,
Direction,
Duration,
Mode,
type Direction,
type Duration,
type Mode,
type Bytes,
type Cycles,
type Instructions,
type USD,
} from "@dfinity/icp-calculator";
import { Amount } from "./cost";
import { type Amount } from "./cost";

let calcUSD = calculators().calculatorUSD;
let calcCycles = calculators().calculatorCycles;
const calcUSD = calculators().calculatorUSD;
const calcCycles = calculators().calculatorCycles;

export function canister(count: number): Amount {
let usd = (calcUSD.canisterCreation() * count) as USD;
let cycles = (calcCycles.canisterCreation() * count) as Cycles;
const usd = (calcUSD.canisterCreation() * count) as USD;
const cycles = (calcCycles.canisterCreation() * count) as Cycles;
return { usd, cycles };
}

Expand All @@ -24,8 +24,8 @@ export function execution(
instructions: Instructions,
count: number,
): Amount {
let usd = (calcUSD.execution(mode, instructions) * count) as USD;
let cycles = (calcCycles.execution(mode, instructions) * count) as Cycles;
const usd = (calcUSD.execution(mode, instructions) * count) as USD;
const cycles = (calcCycles.execution(mode, instructions) * count) as Cycles;
return { usd, cycles };
}

Expand All @@ -34,8 +34,8 @@ export function storage(
duration: Duration,
count: number,
): Amount {
let usd = (calcUSD.storage(size, duration) * count) as USD;
let cycles = (calcCycles.storage(size, duration) * count) as Cycles;
const usd = (calcUSD.storage(size, duration) * count) as USD;
const cycles = (calcCycles.storage(size, duration) * count) as Cycles;
return { usd, cycles };
}

Expand All @@ -45,8 +45,8 @@ export function message(
bytes: Bytes,
count: number,
): Amount {
let usd = (calcUSD.message(mode, direction, bytes) * count) as USD;
let cycles = (calcCycles.message(mode, direction, bytes) * count) as Cycles;
const usd = (calcUSD.message(mode, direction, bytes) * count) as USD;
const cycles = (calcCycles.message(mode, direction, bytes) * count) as Cycles;
return { usd, cycles };
}

Expand All @@ -55,7 +55,7 @@ export function httpOutcall(
response: Bytes,
count: number,
): Amount {
let usd = (calcUSD.httpOutcall(request, response) * count) as USD;
let cycles = (calcCycles.httpOutcall(request, response) * count) as Cycles;
const usd = (calcUSD.httpOutcall(request, response) * count) as USD;
const cycles = (calcCycles.httpOutcall(request, response) * count) as Cycles;
return { usd, cycles };
}
22 changes: 11 additions & 11 deletions src/lib/utils/cost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Cost {
}

public addIfSameKind(other: Cost): boolean {
if (this.kind == other.kind) {
if (this.kind === other.kind) {
this.amount.usd = (this.amount.usd + other.amount.usd) as USD;
this.amount.cycles = (this.amount.cycles + other.amount.cycles) as Cycles;
return true;
Expand All @@ -53,7 +53,7 @@ export class Cost {
}

public addIfSameCategoryAndKind(other: Cost): boolean {
if (this.category == other.category) {
if (this.category === other.category) {
return this.addIfSameKind(other);
}
return false;
Expand Down Expand Up @@ -97,10 +97,10 @@ export class Cost {
}
}

type TotalCost = {
interface TotalCost {
oneTime: Cost;
perDay: Cost;
};
}

export class Breakdown {
items: Cost[];
Expand All @@ -109,24 +109,24 @@ export class Breakdown {
this.items = [];
}

public add(cost: Cost) {
for (let item of this.items) {
public add(cost: Cost): void {
for (const item of this.items) {
if (item.addIfSameCategoryAndKind(cost)) {
return;
}
}
this.items.push(cost);
}

public merge(other: Breakdown) {
public merge(other: Breakdown): void {
for (const item of other.items) {
this.add(item);
}
}

public sort() {
public sort(): void {
this.items.sort((a, b) => {
if (a.category != b.category) {
if (a.category !== b.category) {
return a.category.valueOf() - b.category.valueOf();
}
return a.kind.valueOf() - b.kind.valueOf();
Expand All @@ -138,12 +138,12 @@ export class Breakdown {
}

public total(): TotalCost {
let oneTime = new Cost(Kind.OneTime, Category.Total, Amount.zero());
const oneTime = new Cost(Kind.OneTime, Category.Total, Amount.zero());
for (const item of this.items) {
oneTime.addIfSameKind(item);
}

let perDay = new Cost(Kind.PerDay, Category.Total, Amount.zero());
const perDay = new Cost(Kind.PerDay, Category.Total, Amount.zero());
for (const item of this.items) {
perDay.addIfSameKind(item);
}
Expand Down
Loading

0 comments on commit 4c2d658

Please sign in to comment.