1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

[FLASK] Fix race condition with transaction insights (#16956)

* Fix race condition with transaction insights

* Rename variable
This commit is contained in:
Frederik Bolding 2022-12-14 19:50:23 +01:00 committed by GitHub
parent 0511d6f0b1
commit 13e4d3054b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,12 +28,13 @@ export function useTransactionInsightSnap({
const [error, setError] = useState(undefined); const [error, setError] = useState(undefined);
useEffect(() => { useEffect(() => {
let cancelled = false;
async function fetchInsight() { async function fetchInsight() {
try { try {
setError(undefined); setError(undefined);
setLoading(true); setLoading(true);
const d = await handleSnapRequest({ const newData = await handleSnapRequest({
snapId, snapId,
origin: '', origin: '',
handler: 'onTransaction', handler: 'onTransaction',
@ -43,16 +44,23 @@ export function useTransactionInsightSnap({
params: { transaction, chainId, transactionOrigin }, params: { transaction, chainId, transactionOrigin },
}, },
}); });
setData(d); if (!cancelled) {
setData(newData);
}
} catch (err) { } catch (err) {
if (!cancelled) {
setError(err); setError(err);
}
} finally { } finally {
if (!cancelled) {
setLoading(false); setLoading(false);
} }
} }
}
if (transaction) { if (transaction) {
fetchInsight(); fetchInsight();
} }
return () => (cancelled = true);
}, [snapId, transaction, chainId, transactionOrigin]); }, [snapId, transaction, chainId, transactionOrigin]);
return { data, error, loading }; return { data, error, loading };