Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notification fix attempt #2687

Merged
merged 6 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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