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

Broke the close notification window logic out into it's own action. (#6864)

This commit is contained in:
Terry Smith 2019-07-16 05:55:52 -03:00 committed by Dan J Miller
parent 721215973a
commit 5cc4a5c6b7

View File

@ -26,6 +26,9 @@ var actions = {
MODAL_CLOSE: 'UI_MODAL_CLOSE',
showModal: showModal,
hideModal: hideModal,
// notification state
CLOSE_NOTIFICATION_WINDOW: 'CLOSE_NOTIFICATION_WINDOW',
closeNotifacationWindow: closeNotifacationWindow,
// sidebar state
SIDEBAR_OPEN: 'UI_SIDEBAR_OPEN',
SIDEBAR_CLOSE: 'UI_SIDEBAR_CLOSE',
@ -913,7 +916,7 @@ function setCurrentCurrency (currencyCode) {
function signMsg (msgData) {
log.debug('action - signMsg')
return (dispatch, getState) => {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
@ -931,11 +934,7 @@ function signMsg (msgData) {
}
dispatch(actions.completedTx(msgData.metamaskId))
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return resolve(msgData)
})
@ -945,7 +944,7 @@ function signMsg (msgData) {
function signPersonalMsg (msgData) {
log.debug('action - signPersonalMsg')
return (dispatch, getState) => {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
return new Promise((resolve, reject) => {
@ -962,11 +961,7 @@ function signPersonalMsg (msgData) {
}
dispatch(actions.completedTx(msgData.metamaskId))
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return resolve(msgData)
})
@ -976,7 +971,7 @@ function signPersonalMsg (msgData) {
function signTypedMsg (msgData) {
log.debug('action - signTypedMsg')
return (dispatch, getState) => {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
return new Promise((resolve, reject) => {
@ -993,11 +988,7 @@ function signTypedMsg (msgData) {
}
dispatch(actions.completedTx(msgData.metamaskId))
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return resolve(msgData)
})
@ -1255,7 +1246,7 @@ function updateTransaction (txData) {
function updateAndApproveTx (txData) {
log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
return (dispatch, getState) => {
return (dispatch) => {
log.debug(`actions calling background.updateAndApproveTx`)
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
@ -1280,11 +1271,7 @@ function updateAndApproveTx (txData) {
dispatch(actions.clearSend())
dispatch(actions.completedTx(txData.id))
dispatch(actions.hideLoadingIndication())
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return txData
})
@ -1318,7 +1305,7 @@ function txError (err) {
}
function cancelMsg (msgData) {
return (dispatch, getState) => {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
return new Promise((resolve, reject) => {
@ -1332,11 +1319,7 @@ function cancelMsg (msgData) {
}
dispatch(actions.completedTx(msgData.id))
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return resolve(msgData)
})
@ -1345,7 +1328,7 @@ function cancelMsg (msgData) {
}
function cancelPersonalMsg (msgData) {
return (dispatch, getState) => {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
return new Promise((resolve, reject) => {
@ -1359,11 +1342,7 @@ function cancelPersonalMsg (msgData) {
}
dispatch(actions.completedTx(id))
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return resolve(msgData)
})
@ -1372,7 +1351,7 @@ function cancelPersonalMsg (msgData) {
}
function cancelTypedMsg (msgData) {
return (dispatch, getState) => {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
return new Promise((resolve, reject) => {
@ -1386,11 +1365,7 @@ function cancelTypedMsg (msgData) {
}
dispatch(actions.completedTx(id))
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return resolve(msgData)
})
@ -1399,7 +1374,7 @@ function cancelTypedMsg (msgData) {
}
function cancelTx (txData) {
return (dispatch, getState) => {
return (dispatch) => {
log.debug(`background.cancelTransaction`)
dispatch(actions.showLoadingIndication())
window.onbeforeunload = null
@ -1418,11 +1393,7 @@ function cancelTx (txData) {
dispatch(actions.clearSend())
dispatch(actions.completedTx(txData.id))
dispatch(actions.hideLoadingIndication())
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
return global.platform.closeCurrentWindow()
}
dispatch(closeCurrentNotificationWindow())
return txData
})
@ -2097,6 +2068,23 @@ function hideModal (payload) {
}
}
function closeCurrentNotificationWindow () {
return (dispatch, getState) => {
if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState())) {
global.platform.closeCurrentWindow()
dispatch(closeNotifacationWindow())
}
}
}
function closeNotifacationWindow () {
return {
type: actions.CLOSE_NOTIFICATION_WINDOW,
}
}
function showSidebar ({ transitionName, type, props }) {
return {
type: actions.SIDEBAR_OPEN,