Use `async/await` in message manager action creators (#8434)

These action creators for the "message manager" controller
interactions have been updated to use `async/await`. There should be
almost no changes in behavior. The only things removed were a few debug
log statements, and a single `console.log`.
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent b58c0d7810
commit 580a90d543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 337
      ui/app/store/actions.js

@ -434,153 +434,134 @@ export function setCurrentCurrency (currencyCode) {
export function signMsg (msgData) { export function signMsg (msgData) {
log.debug('action - signMsg') log.debug('action - signMsg')
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => { log.debug(`actions calling background.signMessage`)
log.debug(`actions calling background.signMessage`) let newState
background.signMessage(msgData, (err, newState) => { try {
log.debug('signMessage called back') newState = await promisifiedBackground.signMessage(msgData)
dispatch(hideLoadingIndication()) } catch (error) {
dispatch(hideLoadingIndication())
if (err) { log.error(error)
log.error(err) dispatch(displayWarning(error.message))
dispatch(displayWarning(err.message)) throw error
return reject(err) }
} dispatch(hideLoadingIndication())
dispatch(updateMetamaskState(newState))
dispatch(updateMetamaskState(newState)) dispatch(completedTx(msgData.metamaskId))
dispatch(completedTx(msgData.metamaskId)) dispatch(closeCurrentNotificationWindow())
dispatch(closeCurrentNotificationWindow()) return msgData
return resolve(msgData)
})
})
} }
} }
export function signPersonalMsg (msgData) { export function signPersonalMsg (msgData) {
log.debug('action - signPersonalMsg') log.debug('action - signPersonalMsg')
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => { log.debug(`actions calling background.signPersonalMessage`)
log.debug(`actions calling background.signPersonalMessage`)
background.signPersonalMessage(msgData, (err, newState) => {
log.debug('signPersonalMessage called back')
dispatch(hideLoadingIndication())
if (err) { let newState
log.error(err) try {
dispatch(displayWarning(err.message)) newState = await promisifiedBackground.signPersonalMessage(msgData)
return reject(err) } catch (error) {
} dispatch(hideLoadingIndication())
log.error(error)
dispatch(updateMetamaskState(newState)) dispatch(displayWarning(error.message))
dispatch(completedTx(msgData.metamaskId)) throw error
dispatch(closeCurrentNotificationWindow()) }
dispatch(updateMetamaskState(newState))
return resolve(msgData) dispatch(completedTx(msgData.metamaskId))
}) dispatch(closeCurrentNotificationWindow())
}) return msgData
} }
} }
export function decryptMsgInline (decryptedMsgData) { export function decryptMsgInline (decryptedMsgData) {
log.debug('action - decryptMsgInline') log.debug('action - decryptMsgInline')
return (dispatch) => { return async (dispatch) => {
return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessageInline`)
log.debug(`actions calling background.decryptMessageInline`)
background.decryptMessageInline(decryptedMsgData, (err, newState) => {
log.debug('decryptMsgInline called back')
if (err) { let newState
log.error(err) try {
dispatch(displayWarning(err.message)) newState = await promisifiedBackground.decryptMessageInline(decryptedMsgData)
return reject(err) } catch (error) {
} log.error(error)
dispatch(displayWarning(error.message))
throw error
}
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId] decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId]
return resolve(decryptedMsgData) return decryptedMsgData
})
})
} }
} }
export function decryptMsg (decryptedMsgData) { export function decryptMsg (decryptedMsgData) {
log.debug('action - decryptMsg') log.debug('action - decryptMsg')
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => { log.debug(`actions calling background.decryptMessage`)
log.debug(`actions calling background.decryptMessage`)
background.decryptMessage(decryptedMsgData, (err, newState) => {
log.debug('decryptMsg called back')
dispatch(hideLoadingIndication())
if (err) {
log.error(err)
dispatch(displayWarning(err.message))
return reject(err)
}
dispatch(updateMetamaskState(newState)) let newState
dispatch(completedTx(decryptedMsgData.metamaskId)) try {
dispatch(closeCurrentNotificationWindow()) newState = await promisifiedBackground.decryptMessage(decryptedMsgData)
console.log(decryptedMsgData) } catch (error) {
return resolve(decryptedMsgData) dispatch(hideLoadingIndication())
}) log.error(error)
}) dispatch(displayWarning(error.message))
throw error
}
dispatch(hideLoadingIndication())
dispatch(updateMetamaskState(newState))
dispatch(completedTx(decryptedMsgData.metamaskId))
dispatch(closeCurrentNotificationWindow())
return decryptedMsgData
} }
} }
export function encryptionPublicKeyMsg (msgData) { export function encryptionPublicKeyMsg (msgData) {
log.debug('action - encryptionPublicKeyMsg') log.debug('action - encryptionPublicKeyMsg')
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => { log.debug(`actions calling background.encryptionPublicKey`)
log.debug(`actions calling background.encryptionPublicKey`)
background.encryptionPublicKey(msgData, (err, newState) => {
log.debug('encryptionPublicKeyMsg called back')
dispatch(hideLoadingIndication())
if (err) { let newState
log.error(err) try {
dispatch(displayWarning(err.message)) newState = await promisifiedBackground.encryptionPublicKey(msgData)
return reject(err) } catch (error) {
} dispatch(hideLoadingIndication())
log.error(error)
dispatch(updateMetamaskState(newState)) dispatch(displayWarning(error.message))
dispatch(completedTx(msgData.metamaskId)) throw error
dispatch(closeCurrentNotificationWindow()) }
dispatch(hideLoadingIndication())
return resolve(msgData) dispatch(updateMetamaskState(newState))
}) dispatch(completedTx(msgData.metamaskId))
}) dispatch(closeCurrentNotificationWindow())
return msgData
} }
} }
export function signTypedMsg (msgData) { export function signTypedMsg (msgData) {
log.debug('action - signTypedMsg') log.debug('action - signTypedMsg')
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => { log.debug(`actions calling background.signTypedMessage`)
log.debug(`actions calling background.signTypedMessage`)
background.signTypedMessage(msgData, (err, newState) => {
log.debug('signTypedMessage called back')
dispatch(hideLoadingIndication())
if (err) { let newState
log.error(err) try {
dispatch(displayWarning(err.message)) newState = await promisifiedBackground.signTypedMessage(msgData)
return reject(err) } catch (error) {
} dispatch(hideLoadingIndication())
log.error(error)
dispatch(updateMetamaskState(newState)) dispatch(displayWarning(error.message))
dispatch(completedTx(msgData.metamaskId)) throw error
dispatch(closeCurrentNotificationWindow()) }
dispatch(hideLoadingIndication())
return resolve(msgData) dispatch(updateMetamaskState(newState))
}) dispatch(completedTx(msgData.metamaskId))
}) dispatch(closeCurrentNotificationWindow())
return msgData
} }
} }
@ -890,111 +871,87 @@ export function txError (err) {
} }
export function cancelMsg (msgData) { export function cancelMsg (msgData) {
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => {
background.cancelMessage(msgData.id, (err, newState) => {
dispatch(hideLoadingIndication())
if (err) {
return reject(err)
}
dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow())
return resolve(msgData) let newState
}) try {
}) newState = await promisifiedBackground.cancelMessage(msgData.id)
} finally {
dispatch(hideLoadingIndication())
}
dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow())
return msgData
} }
} }
export function cancelPersonalMsg (msgData) { export function cancelPersonalMsg (msgData) {
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => {
const id = msgData.id
background.cancelPersonalMessage(id, (err, newState) => {
dispatch(hideLoadingIndication())
if (err) {
return reject(err)
}
dispatch(updateMetamaskState(newState)) let newState
dispatch(completedTx(id)) try {
dispatch(closeCurrentNotificationWindow()) newState = await promisifiedBackground.cancelPersonalMessage(msgData.id)
} finally {
return resolve(msgData) dispatch(hideLoadingIndication())
}) }
}) dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow())
return msgData
} }
} }
export function cancelDecryptMsg (msgData) { export function cancelDecryptMsg (msgData) {
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => {
const id = msgData.id
background.cancelDecryptMessage(id, (err, newState) => {
dispatch(hideLoadingIndication())
if (err) { let newState
return reject(err) try {
} newState = await promisifiedBackground.cancelDecryptMessage(msgData.id)
} finally {
dispatch(updateMetamaskState(newState)) dispatch(hideLoadingIndication())
dispatch(completedTx(id)) }
dispatch(closeCurrentNotificationWindow()) dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id))
return resolve(msgData) dispatch(closeCurrentNotificationWindow())
}) return msgData
})
} }
} }
export function cancelEncryptionPublicKeyMsg (msgData) { export function cancelEncryptionPublicKeyMsg (msgData) {
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => {
const id = msgData.id
background.cancelEncryptionPublicKey(id, (err, newState) => {
dispatch(hideLoadingIndication())
if (err) { let newState
return reject(err) try {
} newState = await promisifiedBackground.cancelEncryptionPublicKey(msgData.id)
} finally {
dispatch(updateMetamaskState(newState)) dispatch(hideLoadingIndication())
dispatch(completedTx(id)) }
dispatch(closeCurrentNotificationWindow()) dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id))
return resolve(msgData) dispatch(closeCurrentNotificationWindow())
}) return msgData
})
} }
} }
export function cancelTypedMsg (msgData) { export function cancelTypedMsg (msgData) {
return (dispatch) => { return async (dispatch) => {
dispatch(showLoadingIndication()) dispatch(showLoadingIndication())
return new Promise((resolve, reject) => {
const id = msgData.id
background.cancelTypedMessage(id, (err, newState) => {
dispatch(hideLoadingIndication())
if (err) { let newState
return reject(err) try {
} newState = await promisifiedBackground.cancelTypedMessage(msgData.id)
} finally {
dispatch(updateMetamaskState(newState)) dispatch(hideLoadingIndication())
dispatch(completedTx(id)) }
dispatch(closeCurrentNotificationWindow()) dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id))
return resolve(msgData) dispatch(closeCurrentNotificationWindow())
}) return msgData
})
} }
} }

Loading…
Cancel
Save