Skip to content

Commit b606d54

Browse files
Fix bugs
1 parent b8e7302 commit b606d54

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/components/nodesColumns/columns.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ export function getSendThroughputColumn<T extends {SendThroughput?: string}>():
454454
header: NODES_COLUMNS_TITLES.SendThroughput,
455455
render: ({row}) =>
456456
isNumeric(row.SendThroughput)
457-
? bytesToSpeed(row.SendThroughput)
457+
? bytesToSpeed(row.SendThroughput, 1)
458458
: EMPTY_DATA_PLACEHOLDER,
459459
align: DataTable.RIGHT,
460460
width: 110,
@@ -466,7 +466,7 @@ export function getReceiveThroughputColumn<T extends {ReceiveThroughput?: string
466466
header: NODES_COLUMNS_TITLES.ReceiveThroughput,
467467
render: ({row}) =>
468468
isNumeric(row.ReceiveThroughput)
469-
? bytesToSpeed(row.ReceiveThroughput)
469+
? bytesToSpeed(row.ReceiveThroughput, 1)
470470
: EMPTY_DATA_PLACEHOLDER,
471471
align: DataTable.RIGHT,
472472
width: 110,
@@ -564,7 +564,7 @@ export function getPeerSkewColumn<T extends {ClockSkewUs?: string | number}>():
564564
resizeMinWidth: 90,
565565
render: ({row}) =>
566566
isNumeric(row.ClockSkewUs)
567-
? formatToMs(parseUsToMs(row.ClockSkewUs, 2))
567+
? formatToMs(parseUsToMs(row.ClockSkewUs, 1))
568568
: EMPTY_DATA_PLACEHOLDER,
569569
};
570570
}
@@ -578,7 +578,7 @@ export function getPeerPingColumn<T extends {PingTimeUs?: string | number}>(): C
578578
resizeMinWidth: 90,
579579
render: ({row}) =>
580580
isNumeric(row.PingTimeUs)
581-
? formatToMs(parseUsToMs(row.PingTimeUs, 2))
581+
? formatToMs(parseUsToMs(row.PingTimeUs))
582582
: EMPTY_DATA_PLACEHOLDER,
583583
};
584584
}

src/containers/Node/NodeNetwork/columns.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function getPeerSentBytesColumn<T extends {BytesSend?: string | number}>(): Colu
4343
width: 140,
4444
resizeMinWidth: 120,
4545
render: ({row}) =>
46-
isNumeric(row.BytesSend) ? bytesToMB(row.BytesSend) : EMPTY_DATA_PLACEHOLDER,
46+
isNumeric(row.BytesSend) ? bytesToMB(row.BytesSend, 0) : EMPTY_DATA_PLACEHOLDER,
4747
};
4848
}
4949

@@ -55,7 +55,7 @@ function getPeerReceivedBytesColumn<T extends {BytesReceived?: string | number}>
5555
width: 160,
5656
resizeMinWidth: 130,
5757
render: ({row}) =>
58-
isNumeric(row.BytesReceived) ? bytesToMB(row.BytesReceived) : EMPTY_DATA_PLACEHOLDER,
58+
isNumeric(row.BytesReceived) ? bytesToMB(row.BytesReceived, 0) : EMPTY_DATA_PLACEHOLDER,
5959
};
6060
}
6161

src/utils/utils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,20 @@ export function bytesToSize(bytes: number) {
3131
return val.toPrecision(3) + sizes[i];
3232
}
3333

34-
export function bytesToMB(bytes?: number | string) {
34+
export function bytesToMB(bytes?: number | string, fractionDigits?: number) {
3535
const bytesNumber = Number(bytes);
3636
if (isNaN(bytesNumber)) {
3737
return '';
3838
}
39+
3940
const val = bytesNumber / base ** 2;
41+
42+
if (isNumeric(fractionDigits)) {
43+
const rounded = Number(val.toFixed(fractionDigits));
44+
45+
return String(rounded) + sizes[2];
46+
}
47+
4048
if (val < 10) {
4149
return val.toFixed(2) + sizes[2];
4250
} else if (val < 100) {
@@ -46,8 +54,8 @@ export function bytesToMB(bytes?: number | string) {
4654
}
4755
}
4856

49-
export function bytesToSpeed(bytes?: number | string) {
50-
const speed = bytesToMB(bytes);
57+
export function bytesToSpeed(bytes?: number | string, fractionDigits?: number) {
58+
const speed = bytesToMB(bytes, fractionDigits);
5159
return `${speed}${speed ? 'ps' : ''}`;
5260
}
5361

0 commit comments

Comments
 (0)