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

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`.
This commit is contained in:
Mark Stacey 2020-04-28 09:49:10 -03:00 committed by GitHub
parent b58c0d7810
commit 580a90d543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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`)
background.signMessage(msgData, (err, newState) => { let newState
log.debug('signMessage called back') try {
newState = await promisifiedBackground.signMessage(msgData)
} catch (error) {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
log.error(error)
if (err) { dispatch(displayWarning(error.message))
log.error(err) throw error
dispatch(displayWarning(err.message))
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') let newState
try {
newState = await promisifiedBackground.signPersonalMessage(msgData)
} catch (error) {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
log.error(error)
if (err) { dispatch(displayWarning(error.message))
log.error(err) throw error
dispatch(displayWarning(err.message))
return reject(err)
} }
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 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') let newState
try {
newState = await promisifiedBackground.decryptMessage(decryptedMsgData)
} catch (error) {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
log.error(error)
if (err) { dispatch(displayWarning(error.message))
log.error(err) throw error
dispatch(displayWarning(err.message))
return reject(err)
} }
dispatch(hideLoadingIndication())
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
dispatch(completedTx(decryptedMsgData.metamaskId)) dispatch(completedTx(decryptedMsgData.metamaskId))
dispatch(closeCurrentNotificationWindow()) dispatch(closeCurrentNotificationWindow())
console.log(decryptedMsgData) return decryptedMsgData
return resolve(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') let newState
try {
newState = await promisifiedBackground.encryptionPublicKey(msgData)
} catch (error) {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
log.error(error)
if (err) { dispatch(displayWarning(error.message))
log.error(err) throw error
dispatch(displayWarning(err.message))
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 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') let newState
try {
newState = await promisifiedBackground.signTypedMessage(msgData)
} catch (error) {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
log.error(error)
if (err) { dispatch(displayWarning(error.message))
log.error(err) throw error
dispatch(displayWarning(err.message))
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)
})
})
} }
} }
@ -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) => { let newState
try {
newState = await promisifiedBackground.cancelMessage(msgData.id)
} finally {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
if (err) {
return reject(err)
} }
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
dispatch(completedTx(msgData.id)) dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow()) dispatch(closeCurrentNotificationWindow())
return msgData
return resolve(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 let newState
background.cancelPersonalMessage(id, (err, newState) => { try {
newState = await promisifiedBackground.cancelPersonalMessage(msgData.id)
} finally {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
if (err) {
return reject(err)
} }
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
dispatch(completedTx(id)) dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow()) dispatch(closeCurrentNotificationWindow())
return msgData
return resolve(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 let newState
background.cancelDecryptMessage(id, (err, newState) => { try {
newState = await promisifiedBackground.cancelDecryptMessage(msgData.id)
} finally {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
if (err) {
return reject(err)
} }
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
dispatch(completedTx(id)) dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow()) dispatch(closeCurrentNotificationWindow())
return msgData
return resolve(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 let newState
background.cancelEncryptionPublicKey(id, (err, newState) => { try {
newState = await promisifiedBackground.cancelEncryptionPublicKey(msgData.id)
} finally {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
if (err) {
return reject(err)
} }
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
dispatch(completedTx(id)) dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow()) dispatch(closeCurrentNotificationWindow())
return msgData
return resolve(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 let newState
background.cancelTypedMessage(id, (err, newState) => { try {
newState = await promisifiedBackground.cancelTypedMessage(msgData.id)
} finally {
dispatch(hideLoadingIndication()) dispatch(hideLoadingIndication())
if (err) {
return reject(err)
} }
dispatch(updateMetamaskState(newState)) dispatch(updateMetamaskState(newState))
dispatch(completedTx(id)) dispatch(completedTx(msgData.id))
dispatch(closeCurrentNotificationWindow()) dispatch(closeCurrentNotificationWindow())
return msgData
return resolve(msgData)
})
})
} }
} }