mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-04-25 00:36:32 +02:00
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:
parent
38faf59d1e
commit
262a91b558
2 changed files with 11 additions and 7 deletions
|
|
@ -47,10 +47,12 @@ function getNotificationTitle(notification: NotificationHistoryEntry): string {
|
|||
}
|
||||
}
|
||||
|
||||
function formatPrice(price: number | null, currency: string | null): string {
|
||||
if (price === null) return '';
|
||||
function formatPrice(price: number | string | null, currency: string | null): string {
|
||||
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' : '$';
|
||||
return `${symbol}${price.toFixed(2)}`;
|
||||
return `${symbol}${numPrice.toFixed(2)}`;
|
||||
}
|
||||
|
||||
export default function NotificationBell() {
|
||||
|
|
|
|||
|
|
@ -40,10 +40,12 @@ function getNotificationTypeLabel(type: NotificationType): string {
|
|||
}
|
||||
}
|
||||
|
||||
function formatPrice(price: number | null, currency: string | null): string {
|
||||
if (price === null) return '-';
|
||||
function formatPrice(price: number | string | null, currency: string | null): string {
|
||||
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 ' : '$';
|
||||
return `${symbol}${price.toFixed(2)}`;
|
||||
return `${symbol}${numPrice.toFixed(2)}`;
|
||||
}
|
||||
|
||||
function getChannelIcon(channel: string): string {
|
||||
|
|
@ -429,7 +431,7 @@ export default function NotificationHistory() {
|
|||
<div>
|
||||
{notification.price_change_percent && (
|
||||
<span className="notification-price-change">
|
||||
-{Math.abs(notification.price_change_percent).toFixed(1)}%
|
||||
-{Math.abs(parseFloat(String(notification.price_change_percent))).toFixed(1)}%
|
||||
</span>
|
||||
)}
|
||||
{notification.target_price && (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue