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