11import "./index.css" ;
22import { mappedCountryCodes } from "../../utils/regions" ;
3- import { useEffect , useState } from "react" ;
3+ import { useEffect , useRef , useState } from "react" ;
44import { useDaemonContext } from "../../providers/DaemonProvider" ;
55import { getAllRegions } from "../../services/regions" ;
66import BlobWrapper from '../../components/BlobWrapper' ;
@@ -14,16 +14,18 @@ import { useNavigate } from 'react-router-dom';
1414import { formatMinutesToHHMM } from "../../utils/utils" ;
1515import { startSilentPass , stopSilentPass } from "../../api" ;
1616import PassportInfo from "../../components/PassportInfo" ;
17+ import { conetProvider } from "../../utils/constants" ;
1718
1819interface RenderButtonProps {
1920 errorStartingSilentPass : boolean ;
2021 isConnectionLoading : boolean ;
2122 power : boolean ;
2223 profile : any ;
24+ _vpnTimeUsedInMin : number ;
2325 handleTogglePower : ( ) => void ;
2426}
2527
26- const RenderButton = ( { errorStartingSilentPass, handleTogglePower, isConnectionLoading, power, profile } : RenderButtonProps ) => {
28+ const RenderButton = ( { errorStartingSilentPass, handleTogglePower, isConnectionLoading, power, profile, _vpnTimeUsedInMin } : RenderButtonProps ) => {
2729 if ( isConnectionLoading )
2830 return (
2931 < div className = "button-wrapper" >
@@ -53,7 +55,8 @@ const RenderButton = ({ errorStartingSilentPass, handleTogglePower, isConnection
5355
5456 < div className = "current-mined" >
5557 < strong > Total time used</ strong >
56- < p > { formatMinutesToHHMM ( parseInt ( profile ?. vpnTimeUsedInMin ) || 0 ) } </ p >
58+ { /* <p>{formatMinutesToHHMM(parseInt(profile?.vpnTimeUsedInMin) || 0)}</p> */ }
59+ < p > { formatMinutesToHHMM ( _vpnTimeUsedInMin ) } </ p >
5760 </ div >
5861 </ div >
5962 )
@@ -72,7 +75,8 @@ const RenderButton = ({ errorStartingSilentPass, handleTogglePower, isConnection
7275
7376 < div className = "current-mined" >
7477 < strong > Total time used</ strong >
75- < p > { formatMinutesToHHMM ( parseInt ( profile ?. vpnTimeUsedInMin ) || 0 ) } </ p >
78+ { /* <p>{formatMinutesToHHMM(parseInt(profile?.vpnTimeUsedInMin) || 0)}</p> */ }
79+ < p > { formatMinutesToHHMM ( _vpnTimeUsedInMin ) } </ p >
7680 </ div >
7781 </ div >
7882
@@ -81,16 +85,37 @@ const RenderButton = ({ errorStartingSilentPass, handleTogglePower, isConnection
8185 )
8286}
8387
88+
8489const Home = ( ) => {
85- const { profile, sRegion, setSRegion, setAllRegions, allRegions, setIsRandom, getAllNodes, closestRegion } = useDaemonContext ( ) ;
90+ const { profile, sRegion, setSRegion, setAllRegions, allRegions, setIsRandom, getAllNodes, closestRegion, _vpnTimeUsedInMin } = useDaemonContext ( ) ;
8691 const [ power , setPower ] = useState < boolean > ( false ) ;
8792 const [ isInitialLoading , setIsInitialLoading ] = useState < boolean > ( true ) ;
8893 const [ isConnectionLoading , setIsConnectionLoading ] = useState < boolean > ( false )
8994 const [ initPercentage , setInitPercentage ] = useState < number > ( 0 ) ;
9095 const [ errorStartingSilentPass , setErrorStartingSilentPass ] = useState < boolean > ( false ) ;
96+ const vpnTimeTimeout = useRef < NodeJS . Timeout > ( ) ;
9197
9298 const navigate = useNavigate ( ) ;
9399
100+
101+ useEffect ( ( ) => {
102+ const countMinutes = ( ) => {
103+ const timeout = setTimeout ( ( ) => {
104+ _vpnTimeUsedInMin . current = ( _vpnTimeUsedInMin . current ) + 1 ;
105+ localStorage . setItem ( "vpnTimeUsedInMin" , ( _vpnTimeUsedInMin . current ) . toString ( ) ) ;
106+ countMinutes ( ) ;
107+ } , 60000 )
108+
109+ vpnTimeTimeout . current = timeout ;
110+ }
111+
112+ clearInterval ( vpnTimeTimeout . current ) ;
113+
114+ if ( power ) {
115+ countMinutes ( )
116+ }
117+ } , [ power ] ) ;
118+
94119 useEffect ( ( ) => {
95120 const listenGetAllNodes = ( ) => {
96121 const initpercentage = maxNodes ? currentScanNodeNumber * 100 / maxNodes : 0
@@ -250,7 +275,7 @@ const Home = () => {
250275 < img src = "/assets/header-title.svg" > </ img >
251276 </ div >
252277
253- < RenderButton profile = { profile } errorStartingSilentPass = { errorStartingSilentPass } isConnectionLoading = { isConnectionLoading } power = { power } handleTogglePower = { handleTogglePower } />
278+ < RenderButton profile = { profile } errorStartingSilentPass = { errorStartingSilentPass } isConnectionLoading = { isConnectionLoading } power = { power } handleTogglePower = { handleTogglePower } _vpnTimeUsedInMin = { _vpnTimeUsedInMin . current } />
254279
255280 < CopyProxyInfo />
256281
0 commit comments