Description
In frontend/src/components/wallet/TxHistory.tsx (lines 77-91), the formatTimestamp function accepts a timestamp: number but has no validation for the unit (milliseconds vs seconds):
const formatTimestamp = (timestamp: number) => {
const date = new Date(timestamp);
const now = Date.now();
const diff = now - timestamp;
if (diff < 60000) return 'Just now';
if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago`;
if (diff < 86400000) return `${Math.floor(diff / 3600000)}h ago`;
return date.toLocaleDateString();
};
Problem
- Timestamps from the Stellar blockchain are in seconds (Unix epoch), but
Date.now() returns milliseconds
- If
timestamp is in seconds (e.g., 1711670400), new Date(1711670400) creates a date in January 1970 (interprets as milliseconds)
- The
diff would be massive, always falling through to toLocaleDateString(), showing "1/20/1970"
- The
tx-store.ts uses Date.now() (milliseconds) when recording transactions, but if any transaction data comes from the blockchain (seconds), units mismatch
Impact
- Transaction timestamps could show dates from 1970
- "Just now" and relative time formatting breaks for blockchain-sourced timestamps
- Users see incorrect transaction history timing
Suggested Fix
Add unit detection and normalization:
const formatTimestamp = (timestamp: number) => {
// Normalize: if timestamp is in seconds (before year 2100 in ms), convert to ms
const ms = timestamp < 1e12 ? timestamp * 1000 : timestamp;
const date = new Date(ms);
const diff = Date.now() - ms;
if (diff < 60000) return 'Just now';
if (diff < 3600000) return `${Math.floor(diff / 60000)}m ago`;
if (diff < 86400000) return `${Math.floor(diff / 3600000)}h ago`;
return date.toLocaleDateString();
};
File
frontend/src/components/wallet/TxHistory.tsx — Lines 77-91
Description
In
frontend/src/components/wallet/TxHistory.tsx(lines 77-91), theformatTimestampfunction accepts atimestamp: numberbut has no validation for the unit (milliseconds vs seconds):Problem
Date.now()returns millisecondstimestampis in seconds (e.g.,1711670400),new Date(1711670400)creates a date in January 1970 (interprets as milliseconds)diffwould be massive, always falling through totoLocaleDateString(), showing "1/20/1970"tx-store.tsusesDate.now()(milliseconds) when recording transactions, but if any transaction data comes from the blockchain (seconds), units mismatchImpact
Suggested Fix
Add unit detection and normalization:
File
frontend/src/components/wallet/TxHistory.tsx— Lines 77-91