Fix notification history crash when prices are strings

PostgreSQL DECIMAL fields are returned as strings by node-postgres.
Convert to numbers before calling toFixed() to prevent TypeError.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-24 03:10:06 -05:00
parent 38faf59d1e
commit 262a91b558
2 changed files with 11 additions and 7 deletions

View file

@ -47,10 +47,12 @@ function getNotificationTitle(notification: NotificationHistoryEntry): string {
} }
} }
function formatPrice(price: number | null, currency: string | null): string { function formatPrice(price: number | string | null, currency: string | null): string {
if (price === null) return ''; if (price === null || price === undefined) return '';
const numPrice = typeof price === 'string' ? parseFloat(price) : price;
if (isNaN(numPrice)) return '';
const symbol = currency === 'EUR' ? '\u20AC' : currency === 'GBP' ? '\u00A3' : '$'; const symbol = currency === 'EUR' ? '\u20AC' : currency === 'GBP' ? '\u00A3' : '$';
return `${symbol}${price.toFixed(2)}`; return `${symbol}${numPrice.toFixed(2)}`;
} }
export default function NotificationBell() { export default function NotificationBell() {

View file

@ -40,10 +40,12 @@ function getNotificationTypeLabel(type: NotificationType): string {
} }
} }
function formatPrice(price: number | null, currency: string | null): string { function formatPrice(price: number | string | null, currency: string | null): string {
if (price === null) return '-'; if (price === null || price === undefined) return '-';
const numPrice = typeof price === 'string' ? parseFloat(price) : price;
if (isNaN(numPrice)) return '-';
const symbol = currency === 'EUR' ? '\u20AC' : currency === 'GBP' ? '\u00A3' : currency === 'CHF' ? 'CHF ' : '$'; const symbol = currency === 'EUR' ? '\u20AC' : currency === 'GBP' ? '\u00A3' : currency === 'CHF' ? 'CHF ' : '$';
return `${symbol}${price.toFixed(2)}`; return `${symbol}${numPrice.toFixed(2)}`;
} }
function getChannelIcon(channel: string): string { function getChannelIcon(channel: string): string {
@ -429,7 +431,7 @@ export default function NotificationHistory() {
<div> <div>
{notification.price_change_percent && ( {notification.price_change_percent && (
<span className="notification-price-change"> <span className="notification-price-change">
-{Math.abs(notification.price_change_percent).toFixed(1)}% -{Math.abs(parseFloat(String(notification.price_change_percent))).toFixed(1)}%
</span> </span>
)} )}
{notification.target_price && ( {notification.target_price && (