Skip to content

Bug: TxHistory formatTimestamp doesn't handle seconds vs milliseconds — shows 1970 dates #375

@gboigwe

Description

@gboigwe

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

  1. Timestamps from the Stellar blockchain are in seconds (Unix epoch), but Date.now() returns milliseconds
  2. If timestamp is in seconds (e.g., 1711670400), new Date(1711670400) creates a date in January 1970 (interprets as milliseconds)
  3. The diff would be massive, always falling through to toLocaleDateString(), showing "1/20/1970"
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfrontendNextjs frontend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions