Skip to content

Commit 68f0198

Browse files
committed
fix: fix polling on new api and fix e2e
1 parent 079bdfa commit 68f0198

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

app/components/UI/TokenDetails/hooks/useTokenSecurityData.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
TokenSecurityData,
66
} from '@metamask/assets-controllers';
77

8-
const REFRESH_INTERVAL_MS = 60_000;
9-
108
interface 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

2521
export 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
};

tests/api-mocking/mock-responses/defaults/token-apis.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ import { TOKEN_API_TOKENS_RESPONSE } from '../token-api-responses.ts';
99
const tokenListRegex =
1010
/^https:\/\/token\.api\.cx\.metamask\.io\/tokens\/\d+\?.*$/;
1111

12+
const tokenAssetsRegex =
13+
/^https:\/\/token\.api\.cx\.metamask\.io\/assets\?assetIds=.*&includeTokenSecurityData=true$/;
14+
1215
export const TOKEN_API_MOCKS: MockEventsObject = {
1316
GET: [
1417
{
1518
urlEndpoint: tokenListRegex,
1619
responseCode: 200,
1720
response: TOKEN_API_TOKENS_RESPONSE,
1821
},
22+
{
23+
urlEndpoint: tokenAssetsRegex,
24+
responseCode: 200,
25+
response: [],
26+
},
1927
],
2028
};

0 commit comments

Comments
 (0)