Skip to content

Commit 6ce84cf

Browse files
authored
fix:History UI improvments (#116)
* change ENS description position * clear all expired items from history * change to hourglass icon * update expiry info on history when we top up stamp
1 parent 4ab5886 commit 6ce84cf

4 files changed

Lines changed: 185 additions & 23 deletions

File tree

src/app/components/SwapComponent.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
formatExpiryTime,
5555
isExpiringSoon,
5656
getStampUsage,
57+
updateHistoryAfterTopUp,
5758
} from './utils';
5859
import { useTimer } from './TimerUtils';
5960

@@ -915,6 +916,11 @@ const SwapComponent: React.FC = () => {
915916
message: 'Batch Topped Up Successfully',
916917
isSuccess: true,
917918
});
919+
920+
// Update upload history with new expiry date immediately
921+
if (address && topUpBatchId && selectedDays) {
922+
updateHistoryAfterTopUp(topUpBatchId as string, selectedDays, address);
923+
}
918924
// Don't set upload step for top-ups
919925
} else {
920926
try {
@@ -1137,6 +1143,11 @@ const SwapComponent: React.FC = () => {
11371143
message: 'Batch Topped Up Successfully',
11381144
isSuccess: true,
11391145
});
1146+
1147+
// Update upload history with new expiry date immediately
1148+
if (address && selectedDays) {
1149+
updateHistoryAfterTopUp(topUpBatchId, selectedDays, address);
1150+
}
11401151
} else {
11411152
// Calculate the batch ID for new batch creation
11421153
const calculatedBatchId = readBatchId(

src/app/components/UploadHistorySection.tsx

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,41 @@ const UploadHistorySection: React.FC<UploadHistoryProps> = ({ address, setShowUp
870870
}
871871
};
872872

873+
const clearExpiredHistory = () => {
874+
if (!address) return;
875+
876+
const now = Date.now();
877+
const expiredCount = history.filter(record => record.expiryDate < now).length;
878+
879+
if (expiredCount === 0) {
880+
window.alert('No expired items to clear.');
881+
return;
882+
}
883+
884+
const confirmed = window.confirm(
885+
`Are you sure you want to clear ${expiredCount} expired item${expiredCount > 1 ? 's' : ''} from your upload history? This action cannot be undone.`
886+
);
887+
if (confirmed) {
888+
// Filter out expired items
889+
const nonExpiredHistory = history.filter(record => record.expiryDate >= now);
890+
setHistory(nonExpiredHistory);
891+
892+
// Update localStorage
893+
const savedHistory = localStorage.getItem('uploadHistory');
894+
if (savedHistory) {
895+
const allHistory: UploadHistory = JSON.parse(savedHistory);
896+
allHistory[address] = nonExpiredHistory;
897+
localStorage.setItem('uploadHistory', JSON.stringify(allHistory));
898+
}
899+
}
900+
};
901+
902+
// Count expired items for button visibility
903+
const expiredCount = React.useMemo(() => {
904+
const now = Date.now();
905+
return history.filter(record => record.expiryDate < now).length;
906+
}, [history]);
907+
873908
const startEditingFilename = (
874909
index: number,
875910
reference: string,
@@ -1008,8 +1043,12 @@ const UploadHistorySection: React.FC<UploadHistoryProps> = ({ address, setShowUp
10081043
</svg>
10091044
</label>
10101045
)}
1011-
{history.length > 0 && (
1012-
<button className={styles.clearButton} onClick={clearHistory} title="Clear History">
1046+
{expiredCount > 0 && (
1047+
<button
1048+
className={styles.clearExpiredButton}
1049+
onClick={clearExpiredHistory}
1050+
title={`Clear ${expiredCount} Expired Item${expiredCount > 1 ? 's' : ''}`}
1051+
>
10131052
<svg
10141053
width="20"
10151054
height="20"
@@ -1020,15 +1059,15 @@ const UploadHistorySection: React.FC<UploadHistoryProps> = ({ address, setShowUp
10201059
strokeLinecap="round"
10211060
strokeLinejoin="round"
10221061
>
1023-
<polyline points="3,6 5,6 21,6" />
1024-
<path d="m19,6v14a2,2 0 0,1 -2,2H7a2,2 0 0,1 -2,-2V6m3,0V4a2,2 0 0,1 2,-2h4a2,2 0 0,1 2,2v2" />
1025-
<line x1="10" y1="11" x2="10" y2="17" />
1026-
<line x1="14" y1="11" x2="14" y2="17" />
1062+
<path d="M5 22h14" />
1063+
<path d="M5 2h14" />
1064+
<path d="M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22" />
1065+
<path d="M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2" />
10271066
</svg>
10281067
</button>
10291068
)}
1030-
{address && (
1031-
<div className={styles.ensInfo}>
1069+
{history.length > 0 && (
1070+
<button className={styles.clearButton} onClick={clearHistory} title="Clear History">
10321071
<svg
10331072
width="20"
10341073
height="20"
@@ -1039,13 +1078,12 @@ const UploadHistorySection: React.FC<UploadHistoryProps> = ({ address, setShowUp
10391078
strokeLinecap="round"
10401079
strokeLinejoin="round"
10411080
>
1042-
<circle cx="12" cy="12" r="10" />
1043-
<path d="M12 2L2 7v10c0 5.55 3.84 10 9 10s9-4.45 9-10V7L12 2z" />
1081+
<polyline points="3,6 5,6 21,6" />
1082+
<path d="m19,6v14a2,2 0 0,1 -2,2H7a2,2 0 0,1 -2,-2V6m3,0V4a2,2 0 0,1 2,-2h4a2,2 0 0,1 2,2v2" />
1083+
<line x1="10" y1="11" x2="10" y2="17" />
1084+
<line x1="14" y1="11" x2="14" y2="17" />
10441085
</svg>
1045-
<span className={styles.ensTooltip}>
1046-
Click on ENS button to link reference to your ENS domain
1047-
</span>
1048-
</div>
1086+
</button>
10491087
)}
10501088
</div>
10511089
</div>
@@ -1131,6 +1169,27 @@ const UploadHistorySection: React.FC<UploadHistoryProps> = ({ address, setShowUp
11311169
</div>
11321170
)}
11331171

1172+
{/* ENS Note */}
1173+
{address && history.length > 0 && (
1174+
<div className={styles.ensNote}>
1175+
<svg
1176+
width="16"
1177+
height="16"
1178+
viewBox="0 0 24 24"
1179+
fill="none"
1180+
stroke="currentColor"
1181+
strokeWidth="2"
1182+
strokeLinecap="round"
1183+
strokeLinejoin="round"
1184+
>
1185+
<circle cx="12" cy="12" r="10" />
1186+
<line x1="12" y1="16" x2="12" y2="12" />
1187+
<line x1="12" y1="8" x2="12.01" y2="8" />
1188+
</svg>
1189+
<span>Click on ENS button to link reference to your ENS domain</span>
1190+
</div>
1191+
)}
1192+
11341193
{!address ? (
11351194
<div className={styles.emptyState}>Connect wallet to check upload history</div>
11361195
) : history.length === 0 ? (

src/app/components/css/UploadHistorySection.module.css

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@
5454
color: #dc3545;
5555
}
5656

57+
.clearExpiredButton {
58+
background-color: transparent;
59+
border: 1px solid #30363d;
60+
border-radius: 6px;
61+
color: #8b949e;
62+
cursor: pointer;
63+
padding: 8px;
64+
transition: all 0.2s ease;
65+
display: flex;
66+
align-items: center;
67+
justify-content: center;
68+
}
69+
70+
.clearExpiredButton:hover {
71+
background-color: rgba(245, 158, 11, 0.2);
72+
border-color: #f59e0b;
73+
color: #f59e0b;
74+
}
75+
5776
.hiddenInput {
5877
display: none;
5978
}
@@ -410,23 +429,26 @@
410429
}
411430

412431
/* ENS Integration Styles */
413-
.ensInfo {
432+
.ensNote {
414433
display: flex;
415434
align-items: center;
416-
gap: 6px;
435+
gap: 8px;
436+
padding: 10px 14px;
437+
margin-bottom: 12px;
438+
background-color: rgba(59, 130, 246, 0.1);
439+
border: 1px solid rgba(59, 130, 246, 0.25);
440+
border-radius: 6px;
417441
color: #8b949e;
418-
position: relative;
419-
margin-left: 8px;
442+
font-size: 13px;
420443
}
421444

422-
.ensInfo svg {
445+
.ensNote svg {
423446
color: #3b82f6;
447+
flex-shrink: 0;
424448
}
425449

426-
.ensTooltip {
427-
font-size: 12px;
428-
color: #8b949e;
429-
font-weight: 500;
450+
.ensNote span {
451+
color: #c9d1d9;
430452
}
431453

432454
.ensButton {

src/app/components/utils.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,76 @@ export const fetchStampInfo = async (batchId: string, beeApiUrl: string): Promis
415415
}
416416
};
417417

418+
/**
419+
* Update upload history expiry dates for a specific stamp after top-up
420+
* @param stampId The stamp batch ID that was topped up
421+
* @param additionalDays The number of days added by the top-up
422+
* @param address The wallet address whose history to update
423+
* @returns boolean True if history was updated, false otherwise
424+
*/
425+
export const updateHistoryAfterTopUp = (
426+
stampId: string,
427+
additionalDays: number,
428+
address: string
429+
): boolean => {
430+
try {
431+
console.log(`🔄 Updating upload history for topped-up stamp: ${stampId} (+${additionalDays} days)`);
432+
433+
// Get the upload history from localStorage
434+
const savedHistory = localStorage.getItem('uploadHistory');
435+
if (!savedHistory) {
436+
console.log('No upload history found');
437+
return false;
438+
}
439+
440+
const allHistory = JSON.parse(savedHistory);
441+
const addressHistory = allHistory[address];
442+
443+
if (!addressHistory || addressHistory.length === 0) {
444+
console.log('No upload history found for this address');
445+
return false;
446+
}
447+
448+
// Format stamp ID for comparison (remove 0x prefix if present)
449+
const formattedStampId = stampId.startsWith('0x') ? stampId.slice(2) : stampId;
450+
451+
// Calculate additional milliseconds
452+
const additionalMs = additionalDays * 24 * 60 * 60 * 1000;
453+
454+
// Update all records with this stamp ID
455+
let updatedCount = 0;
456+
const updatedHistory = addressHistory.map((record: any) => {
457+
// Format record's stampId for comparison
458+
const recordStampId = record.stampId?.startsWith('0x')
459+
? record.stampId.slice(2)
460+
: record.stampId;
461+
462+
if (recordStampId?.toLowerCase() === formattedStampId.toLowerCase()) {
463+
updatedCount++;
464+
// Add the additional days to the existing expiry date
465+
const newExpiryDate = record.expiryDate + additionalMs;
466+
console.log(`📅 Updated expiry: ${new Date(newExpiryDate).toLocaleDateString()}`);
467+
return { ...record, expiryDate: newExpiryDate };
468+
}
469+
return record;
470+
});
471+
472+
if (updatedCount > 0) {
473+
// Save updated history
474+
allHistory[address] = updatedHistory;
475+
localStorage.setItem('uploadHistory', JSON.stringify(allHistory));
476+
console.log(`✅ Updated ${updatedCount} history record(s) with new expiry date`);
477+
return true;
478+
} else {
479+
console.log('No matching history records found for this stamp');
480+
return false;
481+
}
482+
} catch (error) {
483+
console.error('Error updating history after top-up:', error);
484+
return false;
485+
}
486+
};
487+
418488
/**
419489
* Format TTL (Time To Live) in seconds to a human-readable string
420490
* Shows hours/minutes for < 1 day, otherwise shows days

0 commit comments

Comments
 (0)