fix: address review findings for snatch notifications (#151)

- Extract relativeTime and formatTokenAmount to helper.ts, eliminating
  duplicated logic between CollapseHistory and NotificationBell
- Use formatUnits (via formatTokenAmount) instead of Number(BigInt)/1e18
  to avoid precision loss on large token amounts
- Fix allRecentSnatches emptying after mark-seen: now runs two parallel
  queries — one filtered by lastSeen timestamp (unseen badge count) and
  one unfiltered (panel history), so history is preserved after opening
- Remove dead no-op watch block from useSnatchNotifications

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-02-24 09:18:28 +00:00
parent 60d0859eb3
commit 2fffd2a567
4 changed files with 78 additions and 92 deletions

View file

@ -46,6 +46,28 @@ export function InsertCommaNumber(number: number) {
return formattedWithOptions;
}
export function relativeTime(timestamp: string | number): string {
try {
const sec = typeof timestamp === 'string' ? Number(timestamp) : timestamp;
const nowSec = Math.floor(Date.now() / 1000);
const diff = nowSec - sec;
if (diff < 60) return 'just now';
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
return `${Math.floor(diff / 86400)}d ago`;
} catch {
return '';
}
}
export function formatTokenAmount(raw: string, decimals: number = 18, digits: number = 4): string {
try {
return Number(formatUnits(BigInt(raw), decimals)).toFixed(digits);
} catch {
return '?';
}
}
export function formatBigIntDivision(nominator: bigint, denominator: bigint, _digits: number = 2) {
if (!nominator) {
return 0;