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]); }, [dispatch, isGasLoadingAnimationActive, showLoadingAnimation]);
useEffect(() => { useEffect(() => {
if ( let timer;
isGasLoadingAnimationActive === true &&
showLoadingAnimation === false if (isGasLoadingAnimationActive && !showLoadingAnimation) {
) { timer = setTimeout(() => {
setTimeout(() => {
dispatch(toggleGasLoadingAnimation(false)); dispatch(toggleGasLoadingAnimation(false));
}, 2000); }, 2000);
} }
return () => {
if (timer) {
clearTimeout(timer);
}
};
}, [dispatch, isGasLoadingAnimationActive, showLoadingAnimation]); }, [dispatch, isGasLoadingAnimationActive, showLoadingAnimation]);
} }

View File

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