Skip to content

Commit

Permalink
fix(fuel-gauge): clam SoC within 0-100
Browse files Browse the repository at this point in the history
It may report incorrectly values from -2 to 102.
  • Loading branch information
coderbyheart committed Nov 14, 2023
1 parent f12fa1c commit 83818bf
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/FuelGauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export const FuelGauge = ({
{(SoC !== undefined || TTE !== undefined) && (
<ChargingIndicator>
<button type={'button'} onClick={() => onClick?.()}>
{SoC !== undefined && <span class="me-2">{SoC}%</span>}
{SoC !== undefined && (
<span class="me-2">{Math.min(100, Math.max(0, SoC))}%</span>
)}
{TTE !== undefined && (
<>
<span class="me-1">(empty {formatDistance(TTE)})</span>
Expand Down

0 comments on commit 83818bf

Please sign in to comment.