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:
parent
0511d6f0b1
commit
13e4d3054b
@ -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 };
|
||||||
|
Loading…
Reference in New Issue
Block a user