Skip to content

Commit

Permalink
bufix: stuck notification (#2687)
Browse files Browse the repository at this point in the history
* hideCurrentNotification

* thinkisfixed

* removenotvisiblenots

* checkarray
  • Loading branch information
estebanmino authored May 17, 2021
1 parent 9b829f6 commit 20235a5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/actions/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ export function showTransactionNotification({ autodismiss, transaction, status }
status
};
}

export function removeNotVisibleNotifications() {
return {
type: 'REMOVE_NOT_VISIBLE_NOTIFICATIONS'
};
}
21 changes: 18 additions & 3 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ import {
showTransactionNotification,
hideCurrentNotification,
showSimpleNotification,
removeNotificationById
removeNotificationById,
removeNotVisibleNotifications
} from '../../../actions/notification';
import { toggleDappTransactionModal, toggleApproveModal } from '../../../actions/modals';
import AccountApproval from '../../UI/AccountApproval';
Expand Down Expand Up @@ -572,6 +573,15 @@ const Main = props => {
}
});

// Remove all notifications that aren't visible
useEffect(
() => {
props.removeNotVisibleNotifications();
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);

// unapprovedTransaction effect
useEffect(() => {
Engine.context.TransactionController.hub.on('unapprovedTransaction', onUnapprovedTransaction);
Expand Down Expand Up @@ -761,7 +771,11 @@ Main.propTypes = {
/**
* Dispatch infura availability not blocked
*/
setInfuraAvailabilityNotBlocked: PropTypes.func
setInfuraAvailabilityNotBlocked: PropTypes.func,
/**
* Remove not visible notifications from state
*/
removeNotVisibleNotifications: PropTypes.func
};

const mapStateToProps = state => ({
Expand All @@ -787,7 +801,8 @@ const mapDispatchToProps = dispatch => ({
toggleDappTransactionModal: (show = null) => dispatch(toggleDappTransactionModal(show)),
toggleApproveModal: show => dispatch(toggleApproveModal(show)),
setInfuraAvailabilityBlocked: () => dispatch(setInfuraAvailabilityBlocked()),
setInfuraAvailabilityNotBlocked: () => dispatch(setInfuraAvailabilityNotBlocked())
setInfuraAvailabilityNotBlocked: () => dispatch(setInfuraAvailabilityNotBlocked()),
removeNotVisibleNotifications: () => dispatch(removeNotVisibleNotifications())
});

export default connect(
Expand Down
11 changes: 9 additions & 2 deletions app/components/UI/Notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Notification(props) {
removeCurrentNotification
} = props;

const notificationAnimated = useRef(new Animated.Value(100)).current;
const notificationAnimated = useRef(new Animated.Value(200)).current;

const usePrevious = value => {
const ref = useRef();
Expand Down Expand Up @@ -49,7 +49,14 @@ function Notification(props) {
return route?.routeName === BROWSER_ROUTE;
}, [navigation.state]);

useEffect(() => () => removeCurrentNotification(), [removeCurrentNotification]);
useEffect(
() => () => {
animatedTimingStart(notificationAnimated, 200);
hideCurrentNotification();
removeCurrentNotification();
},
[notificationAnimated, animatedTimingStart, hideCurrentNotification, removeCurrentNotification]
);

useEffect(() => {
if (!prevNotificationIsVisible && currentNotificationIsVisible) {
Expand Down
12 changes: 12 additions & 0 deletions app/reducers/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ACTIONS = {
REPLACE_NOTIFICATION_BY_ID: 'REPLACE_NOTIFICATION_BY_ID',
REMOVE_NOTIFICATION_BY_ID: 'REMOVE_NOTIFICATION_BY_ID',
REMOVE_CURRENT_NOTIFICATION: 'REMOVE_CURRENT_NOTIFICATION',
REMOVE_NOT_VISIBLE_NOTIFICATIONS: 'REMOVE_NOT_VISIBLE_NOTIFICATIONS',
SHOW_SIMPLE_NOTIFICATION: 'SHOW_SIMPLE_NOTIFICATION',
SHOW_TRANSACTION_NOTIFICATION: 'SHOW_TRANSACTION_NOTIFICATION'
};
Expand Down Expand Up @@ -172,6 +173,17 @@ const notificationReducer = (state = initialState, action) => {
})
};
}
case ACTIONS.REMOVE_NOT_VISIBLE_NOTIFICATIONS: {
const visibleNotifications =
notifications?.reduce(
(newNotifications, notification) => notification.isVisible && newNotifications.concat(notification),
[]
) || [];
return {
...state,
notifications: visibleNotifications
};
}
default:
return state;
}
Expand Down

0 comments on commit 20235a5

Please sign in to comment.