55 TokenSecurityData ,
66} from '@metamask/assets-controllers' ;
77
8- const REFRESH_INTERVAL_MS = 60_000 ;
9-
108interface UseTokenSecurityDataOpts {
119 /** CAIP-19 asset ID. When null, no fetch is attempted. */
1210 assetId : CaipAssetType | null ;
@@ -18,8 +16,6 @@ interface UseTokenSecurityDataResult {
1816 securityData : TokenSecurityData | null ;
1917 isLoading : boolean ;
2018 error : Error | null ;
21- /** UTC timestamp of when the data was last successfully loaded. */
22- fetchedAt : Date | null ;
2319}
2420
2521export const useTokenSecurityData = ( {
@@ -31,10 +27,6 @@ export const useTokenSecurityData = ({
3127 ) ;
3228 const [ isLoading , setIsLoading ] = useState ( ! prefetchedData && ! ! assetId ) ;
3329 const [ error , setError ] = useState < Error | null > ( null ) ;
34- const [ fetchedAt , setFetchedAt ] = useState < Date | null > (
35- prefetchedData ? new Date ( ) : null ,
36- ) ;
37- const intervalRef = useRef < ReturnType < typeof setInterval > | null > ( null ) ;
3830 const isMountedRef = useRef ( true ) ;
3931
4032 const fetchData = useCallback ( async ( ) => {
@@ -46,7 +38,6 @@ export const useTokenSecurityData = ({
4638 if ( ! isMountedRef . current ) return ;
4739 const asset = assets ?. [ 0 ] ;
4840 setSecurityData ( asset ?. securityData ?? null ) ;
49- setFetchedAt ( new Date ( ) ) ;
5041 setError ( null ) ;
5142 } catch ( err ) {
5243 if ( ! isMountedRef . current ) return ;
@@ -63,7 +54,6 @@ export const useTokenSecurityData = ({
6354
6455 if ( prefetchedData ) {
6556 setSecurityData ( prefetchedData ) ;
66- setFetchedAt ( new Date ( ) ) ;
6757 setIsLoading ( false ) ;
6858 return ;
6959 }
@@ -76,15 +66,10 @@ export const useTokenSecurityData = ({
7666 setIsLoading ( true ) ;
7767 fetchData ( ) ;
7868
79- intervalRef . current = setInterval ( fetchData , REFRESH_INTERVAL_MS ) ;
80-
8169 return ( ) => {
8270 isMountedRef . current = false ;
83- if ( intervalRef . current ) {
84- clearInterval ( intervalRef . current ) ;
85- }
8671 } ;
8772 } , [ assetId , prefetchedData , fetchData ] ) ;
8873
89- return { securityData, isLoading, error, fetchedAt } ;
74+ return { securityData, isLoading, error } ;
9075} ;
0 commit comments