Skip to content

Commit e0053e6

Browse files
authored
fix: correctly check for division by zero when calculating statistics change
1 parent 333fdcf commit e0053e6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/controller/allocators/allocators.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,11 @@ export class AllocatorsController extends FilPlusEditionControllerBase {
558558

559559
const percentageChange: AllocatorsDashboardStatistic['percentageChange'] =
560560
(() => {
561-
if (BigInt(previousValue.value) === 0n) return null;
561+
const dividerIsZero =
562+
previousValue.type === 'bigint'
563+
? BigInt(previousValue.value) === 0n
564+
: previousValue.value === 0;
565+
if (dividerIsZero) return null;
562566

563567
const ratio =
564568
currentValue.type === 'bigint' || previousValue.type === 'bigint'

src/controller/clients/clients.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,11 @@ export class ClientsController extends ControllerBase {
408408

409409
const percentageChange: ClientsDashboardStatistic['percentageChange'] =
410410
(() => {
411-
if (BigInt(previousValue.value) === 0n) return null;
411+
const dividerIsZero =
412+
previousValue.type === 'bigint'
413+
? BigInt(previousValue.value) === 0n
414+
: previousValue.value === 0;
415+
if (dividerIsZero) return null;
412416

413417
const ratio =
414418
currentValue.type === 'bigint' || previousValue.type === 'bigint'

src/controller/storage-providers/storage-providers.controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ export class StorageProvidersController extends ControllerBase {
405405

406406
const percentageChange: StorageProvidersDashboardStatistic['percentageChange'] =
407407
(() => {
408-
if (BigInt(previousValue.value) === 0n) return null;
408+
const dividerIsZero =
409+
previousValue.type === 'bigint'
410+
? BigInt(previousValue.value) === 0n
411+
: previousValue.value === 0;
412+
if (dividerIsZero) return null;
409413

410414
const ratio =
411415
currentValue.type === 'bigint' || previousValue.type === 'bigint'

0 commit comments

Comments
 (0)