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);
|
||||
|
||||
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 };
|
||||
|
Loading…
Reference in New Issue
Block a user