Skip to content

Commit 8253d1a

Browse files
committed
Fix constants formatting
1 parent 117968a commit 8253d1a

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

pages/constants.vue

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,29 @@ const constantsToPercentage = [
9393
const constantsToFormat = [...constantsToMb, ...constantsToDays, ...constantsToTia, ...constantsToPercentage]
9494
9595
const formatConstant = (key, value) => {
96-
if (key === "allow_messages")
97-
return JSON.parse(value)
98-
.map((v) => v.split(".").slice(-1)[0])
99-
.join(", ")
100-
101-
if (constantsToMb.includes(key)) return formatBytes(value)
102-
if (constantsToDays.includes(key)) {
103-
const dur = Duration.fromMillis(value / 1_000_000)
104-
105-
if (dur.toFormat("s") >= 86_400) {
106-
return `${dur.toFormat("d")} day${dur.toFormat("d") > 1 ? "s" : ""}`
107-
} else {
108-
return `${dur.toFormat("s")} seconds`
96+
try {
97+
if (key === "allow_messages")
98+
return JSON.parse(value)
99+
.map((v) => v.split(".").slice(-1)[0])
100+
.join(", ")
101+
102+
if (constantsToMb.includes(key)) return formatBytes(value)
103+
if (constantsToDays.includes(key)) {
104+
const dur = Duration.fromMillis(value / 1_000_000)
105+
106+
if (dur.toFormat("s") >= 86_400) {
107+
return `${dur.toFormat("d")} day${dur.toFormat("d") > 1 ? "s" : ""}`
108+
} else {
109+
return `${dur.toFormat("s")} seconds`
110+
}
109111
}
110-
}
111-
if (constantsToTia.includes(key)) return `${comma(value.replace("utia", "") / 1_000_000, ",", 8)} TIA`
112-
if (constantsToPercentage.includes(key)) return `${round(value * 100, 6)}%`
112+
if (constantsToTia.includes(key)) return `${comma(value.replace("utia", "") / 1_000_000, ",", 8)} TIA`
113+
if (constantsToPercentage.includes(key)) return `${round(value * 100, 6)}%`
113114
114-
return value
115+
return value
116+
} catch {
117+
return ""
118+
}
115119
}
116120
117121
const DescriptionMap = {

0 commit comments

Comments
 (0)