diff --git a/common-front/lib/components/MessagesContainer/Messages/MessageView/ProtectionMessageView/ProtectionView/ProtectionView.tsx b/common-front/lib/components/MessagesContainer/Messages/MessageView/ProtectionMessageView/ProtectionView/ProtectionView.tsx index 0a9170e0e..960f2567c 100644 --- a/common-front/lib/components/MessagesContainer/Messages/MessageView/ProtectionMessageView/ProtectionView/ProtectionView.tsx +++ b/common-front/lib/components/MessagesContainer/Messages/MessageView/ProtectionMessageView/ProtectionView/ProtectionView.tsx @@ -7,6 +7,10 @@ type Props = { const DECIMALS = 2; +function safeFixed(val: any, decimals = DECIMALS) { + return typeof val === "number" ? val.toFixed(decimals) : String(val); +} + export const ProtectionView = ({ protection }: Props) => { const ProtectionText = getProtectionText(protection); @@ -20,36 +24,35 @@ function getProtectionText(protection: ProtectionMessage) { <> {" "} - Want: [{protection.payload.data.bounds[0].toFixed( - DECIMALS - )}, {protection.payload.data.bounds[1].toFixed(DECIMALS)}] + Want: [ + {safeFixed(protection.payload.data.bounds?.[0])}, {safeFixed(protection.payload.data.bounds?.[1])}] {" "} - Got: {protection.payload.data.value.toFixed(DECIMALS)} + Got: {safeFixed(protection.payload.data.value)} ); case "UPPER_BOUND": return ( <> - Want: [{protection.name}] {"<"} {protection.payload.data.bound.toFixed(DECIMALS)} + Want: [{protection.name}] {"<"} {safeFixed(protection.payload.data.bound)} {" "} - Got: {protection.payload.data.value.toFixed(DECIMALS)} + Got: {safeFixed(protection.payload.data.value)} ); case "LOWER_BOUND": return ( <> - Want: [{protection.name}] {">"} {protection.payload.data.bound.toFixed(DECIMALS)} + Want: [{protection.name}] {">"} {safeFixed(protection.payload.data.bound)} {" "} - Got: {protection.payload.data.value.toFixed(DECIMALS)} + Got: {safeFixed(protection.payload.data.value)} ); case "EQUALS": return ( <> - Mustn't be {protection.payload.data.value.toFixed(DECIMALS)} + Mustn't be {safeFixed(protection.payload.data.value)} ); @@ -57,16 +60,16 @@ function getProtectionText(protection: ProtectionMessage) { return ( <> - Must be {protection.payload.data.want.toFixed(DECIMALS)} but is{" "} - {protection.payload.data.value.toFixed(DECIMALS)} + Must be {safeFixed(protection.payload.data.want)} but is{" "} + {safeFixed(protection.payload.data.value)} ); case "TIME_ACCUMULATION": return ( - Value was {protection.payload.data.value.toFixed(DECIMALS)} for{" "} - {protection.payload.data.timelimit.toFixed(DECIMALS)} seconds + Value was {safeFixed(protection.payload.data.value)} for{" "} + {safeFixed(protection.payload.data.timelimit)} seconds ); case "ERROR_HANDLER":