1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fix #17385 - Provide autohide callback for ActionMessage (#17392)

* Fix #17385 - Provide autohide callback for ActionMessage

* Add autohide to the removeal message
This commit is contained in:
David Walsh 2023-01-27 08:31:43 -06:00 committed by GitHub
parent 30520a3352
commit b21e0df4fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -31,6 +31,7 @@ export default function ActionableMessage({
roundedButtons, roundedButtons,
dataTestId, dataTestId,
autoHideTime = 0, autoHideTime = 0,
onAutoHide,
}) { }) {
const [shouldDisplay, setShouldDisplay] = useState(true); const [shouldDisplay, setShouldDisplay] = useState(true);
useEffect( useEffect(
@ -40,6 +41,7 @@ export default function ActionableMessage({
} }
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
onAutoHide?.();
setShouldDisplay(false); setShouldDisplay(false);
}, autoHideTime); }, autoHideTime);
@ -190,4 +192,8 @@ ActionableMessage.propTypes = {
* Whether the actionable message should auto-hide itself after a given amount of time * Whether the actionable message should auto-hide itself after a given amount of time
*/ */
autoHideTime: PropTypes.number, autoHideTime: PropTypes.number,
/**
* Callback when autoHide time expires
*/
onAutoHide: PropTypes.func,
}; };

View File

@ -274,6 +274,10 @@ export default class Home extends PureComponent {
clearNewCustomNetworkAdded, clearNewCustomNetworkAdded,
setRpcTarget, setRpcTarget,
} = this.props; } = this.props;
const onAutoHide = () => setNewCollectibleAddedMessage('');
const autoHideDelay = 5 * SECOND;
return ( return (
<MultipleNotifications> <MultipleNotifications>
{ {
@ -317,7 +321,8 @@ export default class Home extends PureComponent {
<ActionableMessage <ActionableMessage
type="success" type="success"
className="home__new-network-notification" className="home__new-network-notification"
autoHideTime={5 * SECOND} autoHideTime={autoHideDelay}
onAutoHide={onAutoHide}
message={ message={
<Box display={DISPLAY.INLINE_FLEX}> <Box display={DISPLAY.INLINE_FLEX}>
<i className="fa fa-check-circle home__new-nft-notification-icon" /> <i className="fa fa-check-circle home__new-nft-notification-icon" />
@ -330,7 +335,7 @@ export default class Home extends PureComponent {
<button <button
className="fas fa-times home__new-nft-notification-close" className="fas fa-times home__new-nft-notification-close"
title={t('close')} title={t('close')}
onClick={() => setNewCollectibleAddedMessage('')} onClick={onAutoHide}
/> />
</Box> </Box>
} }
@ -341,6 +346,8 @@ export default class Home extends PureComponent {
<ActionableMessage <ActionableMessage
type="danger" type="danger"
className="home__new-network-notification" className="home__new-network-notification"
autoHideTime={autoHideDelay}
onAutoHide={onAutoHide}
message={ message={
<Box display={DISPLAY.INLINE_FLEX}> <Box display={DISPLAY.INLINE_FLEX}>
<i className="fa fa-check-circle home__new-nft-notification-icon" /> <i className="fa fa-check-circle home__new-nft-notification-icon" />