Skip to content

Commit a8176d0

Browse files
fix: removed duplicate isPassportValid method
1 parent bd049ef commit a8176d0

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/pages/Home/index.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CopyProxyInfo from '../../components/CopyProxyInfo';
1111
import Footer from '../../components/Footer';
1212
import RegionSelector from '../../components/RegionSelector';
1313
import { useNavigate } from 'react-router-dom';
14-
import { formatMinutesToHHMM } from "../../utils/utils";
14+
import { formatMinutesToHHMM, isPassportValid } from "../../utils/utils";
1515
import { startSilentPass, stopSilentPass } from "../../api";
1616
import PassportInfoPopup from "../../components/PassportInfoPopup";
1717

@@ -161,16 +161,6 @@ const Home = () => {
161161
_getAllRegions()
162162
}, []);
163163

164-
const isPassportValid = (expires: number | undefined) => {
165-
if (!expires) return false
166-
if (expires > 32503690800000) return true;
167-
168-
const now = Math.floor(Date.now());
169-
const expiresDate = new Date(expires * 1000);
170-
171-
return expiresDate.getTime() > now
172-
}
173-
174164
const handleTogglePower = async () => {
175165
setIsConnectionLoading(true)
176166
let error = false;

src/utils/utils.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ export const postToEndpoint = (url: string, post: boolean, jsonData: any) => {
131131
};
132132

133133
export const getRemainingTime = (timestamp: number): string => {
134-
const now = Math.floor(Date.now() / 1000); // Convert current time to seconds
134+
const now = Math.floor(Date.now() / 1000);
135135
const diff = timestamp - now;
136136

137-
if (diff <= 0) return "00:00:00"; // Time has already passed
137+
if (diff <= 0) return "00:00:00";
138138

139-
const days = Math.floor(diff / 86400); // 86400 seconds in a day
139+
const days = Math.floor(diff / 86400);
140140
const hours = Math.floor((diff % 86400) / 3600);
141141
const minutes = Math.floor((diff % 3600) / 60);
142142
const seconds = diff % 60;
@@ -154,14 +154,15 @@ export const getRemainingTime = (timestamp: number): string => {
154154
)}:${String(seconds).padStart(2, "0")}`;
155155
};
156156

157-
export const isPassportValid = (timestamp: number): boolean => {
158-
const now = Math.floor(Date.now() / 1000); // Convert current time to seconds
159-
const diff = timestamp - now;
157+
export const isPassportValid = (expires: number | undefined) => {
158+
if (!expires) return false;
159+
if (expires > 32503690800000) return true;
160160

161-
if (diff <= 0) return false; // Time has already passed
161+
const now = Math.floor(Date.now());
162+
const expiresDate = new Date(expires * 1000);
162163

163-
return true;
164-
};
164+
return expiresDate.getTime() > now
165+
}
165166

166167
export const parseQueryParams = (queryString: string) => {
167168
const params = new Map();

0 commit comments

Comments
 (0)