mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 10:27:49 +00:00
fix: double-click guard on link, wall-clock timer, blur cleanup
- Add linkingProvider state to prevent double-click on Link button - Use wall-clock based countdown timer to prevent drift - Clean up onBlur setTimeout ref on unmount
This commit is contained in:
@@ -357,22 +357,26 @@ export default function MergeAccounts() {
|
||||
// If both have subs — null until user picks
|
||||
}, [data, selectedUserId]);
|
||||
|
||||
// Countdown timer
|
||||
// Countdown timer (wall-clock based to avoid drift)
|
||||
useEffect(() => {
|
||||
if (!data) return;
|
||||
setExpiresIn(data.expires_in_seconds);
|
||||
const startTime = Date.now();
|
||||
const totalSeconds = data.expires_in_seconds;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setExpiresIn((prev) => {
|
||||
if (prev <= 1) {
|
||||
clearInterval(interval);
|
||||
setIsExpired(true);
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
const tick = () => {
|
||||
const elapsed = Math.floor((Date.now() - startTime) / 1000);
|
||||
const remaining = totalSeconds - elapsed;
|
||||
if (remaining <= 0) {
|
||||
setExpiresIn(0);
|
||||
setIsExpired(true);
|
||||
clearInterval(interval);
|
||||
} else {
|
||||
setExpiresIn(remaining);
|
||||
}
|
||||
};
|
||||
|
||||
tick();
|
||||
const interval = setInterval(tick, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, [data]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user