1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Cleanup: clearTimeout on useEffect for gas estimation and prevent state update on unmounted ConfirmTransactionBase (#17804)

This commit is contained in:
Ariella Vu 2023-02-17 22:11:50 +07:00 committed by GitHub
parent 962a861808
commit 7d1dc7f177
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -44,13 +44,18 @@ export function useShouldAnimateGasEstimations() {
}, [dispatch, isGasLoadingAnimationActive, showLoadingAnimation]);
useEffect(() => {
if (
isGasLoadingAnimationActive === true &&
showLoadingAnimation === false
) {
setTimeout(() => {
let timer;
if (isGasLoadingAnimationActive && !showLoadingAnimation) {
timer = setTimeout(() => {
dispatch(toggleGasLoadingAnimation(false));
}, 2000);
}
return () => {
if (timer) {
clearTimeout(timer);
}
};
}, [dispatch, isGasLoadingAnimationActive, showLoadingAnimation]);
}

View File

@ -866,6 +866,10 @@ export default class ConfirmTransactionBase extends Component {
sendTransaction(txData)
.then(() => {
clearConfirmTransaction();
if (!this._isMounted) {
return;
}
this.setState(
{
submitting: false,
@ -877,6 +881,10 @@ export default class ConfirmTransactionBase extends Component {
);
})
.catch((error) => {
if (!this._isMounted) {
return;
}
this.setState({
submitting: false,
submitError: error.message,