From 25a599c6cd6c1006a5ba0fb6dc3d4dcd4fbc67d2 Mon Sep 17 00:00:00 2001 From: David Walsh Date: Fri, 23 Oct 2020 15:39:26 -0500 Subject: [PATCH] Prevent memory leak from selected account copy tooltip --- .../selected-account/selected-account.component.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/app/components/app/selected-account/selected-account.component.js b/ui/app/components/app/selected-account/selected-account.component.js index ff2dd17c9..c1756b5ee 100644 --- a/ui/app/components/app/selected-account/selected-account.component.js +++ b/ui/app/components/app/selected-account/selected-account.component.js @@ -18,6 +18,17 @@ class SelectedAccount extends Component { selectedIdentity: PropTypes.object.isRequired, } + componentDidMount () { + this.copyTimeout = null + } + + componentWillUnmount () { + if (this.copyTimeout) { + clearTimeout(this.copyTimeout) + this.copyTimeout = null + } + } + render () { const { t } = this.context const { selectedIdentity } = this.props @@ -34,7 +45,7 @@ class SelectedAccount extends Component { className="selected-account__clickable" onClick={() => { this.setState({ copied: true }) - setTimeout(() => this.setState({ copied: false }), 3000) + this.copyTimeout = setTimeout(() => this.setState({ copied: false }), 3000) copyToClipboard(checksummedAddress) }} >