diff options
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 105 |
1 files changed, 99 insertions, 6 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 6d5b1ef3f..eea581d33 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -167,6 +167,7 @@ var actions = { updateTransaction, updateAndApproveTx, cancelTx: cancelTx, + cancelTxs, completedTx: completedTx, txError: txError, nextTx: nextTx, @@ -237,6 +238,7 @@ var actions = { removeSuggestedTokens, UPDATE_TOKENS: 'UPDATE_TOKENS', setRpcTarget: setRpcTarget, + delRpcTarget: delRpcTarget, setProviderType: setProviderType, SET_HARDWARE_WALLET_DEFAULT_HD_PATH: 'SET_HARDWARE_WALLET_DEFAULT_HD_PATH', setHardwareWalletDefaultHdPath, @@ -315,6 +317,8 @@ var actions = { CLEAR_PENDING_TOKENS: 'CLEAR_PENDING_TOKENS', setPendingTokens, clearPendingTokens, + + createCancelTransaction, } module.exports = actions @@ -413,12 +417,18 @@ function createNewVaultAndRestore (password, seed) { log.debug(`background.createNewVaultAndRestore`) return new Promise((resolve, reject) => { - background.createNewVaultAndRestore(password, seed, err => { + background.clearSeedWordCache((err) => { if (err) { return reject(err) } - resolve() + background.createNewVaultAndRestore(password, seed, (err) => { + if (err) { + return reject(err) + } + + resolve() + }) }) }) .then(() => dispatch(actions.unMarkPasswordForgotten())) @@ -908,6 +918,7 @@ function updateGasData ({ selectedToken, to, value, + data, }) { return (dispatch) => { dispatch(actions.gasLoadingStarted()) @@ -928,6 +939,7 @@ function updateGasData ({ to, value, estimateGasPrice, + data, }), ]) }) @@ -1291,6 +1303,47 @@ function cancelTx (txData) { } } +/** + * Cancels all of the given transactions + * @param {Array<object>} txDataList a list of tx data objects + * @return {function(*): Promise<void>} + */ +function cancelTxs (txDataList) { + return async (dispatch, getState) => { + dispatch(actions.showLoadingIndication()) + const txIds = txDataList.map(({id}) => id) + const cancellations = txIds.map((id) => new Promise((resolve, reject) => { + background.cancelTransaction(id, (err) => { + if (err) { + return reject(err) + } + + resolve() + }) + })) + + await Promise.all(cancellations) + const newState = await updateMetamaskStateFromBackground() + dispatch(actions.updateMetamaskState(newState)) + dispatch(actions.clearSend()) + + txIds.forEach((id) => { + dispatch(actions.completedTx(id)) + }) + + dispatch(actions.hideLoadingIndication()) + + if (global.METAMASK_UI_TYPE === ENVIRONMENT_TYPE_NOTIFICATION) { + return global.platform.closeCurrentWindow() + } + } +} + +/** + * @deprecated + * @param {Array<object>} txsData + * @return {Function} + */ function cancelAllTx (txsData) { return (dispatch) => { txsData.forEach((txData, i) => { @@ -1709,7 +1762,7 @@ function markNoticeRead (notice) { background.markNoticeRead(notice, (err, notice) => { dispatch(actions.hideLoadingIndication()) if (err) { - dispatch(actions.displayWarning(err)) + dispatch(actions.displayWarning(err.message)) return reject(err) } @@ -1766,6 +1819,29 @@ function retryTransaction (txId) { } } +function createCancelTransaction (txId, customGasPrice) { + log.debug('background.cancelTransaction') + let newTxId + + return dispatch => { + return new Promise((resolve, reject) => { + background.createCancelTransaction(txId, customGasPrice, (err, newState) => { + if (err) { + dispatch(actions.displayWarning(err.message)) + reject(err) + } + + const { selectedAddressTxList } = newState + const { id } = selectedAddressTxList[selectedAddressTxList.length - 1] + newTxId = id + resolve(newState) + }) + }) + .then(newState => dispatch(actions.updateMetamaskState(newState))) + .then(() => newTxId) + } +} + // // config // @@ -1776,7 +1852,7 @@ function setProviderType (type) { background.setProviderType(type, (err, result) => { if (err) { log.error(err) - return dispatch(self.displayWarning('Had a problem changing networks!')) + return dispatch(actions.displayWarning('Had a problem changing networks!')) } dispatch(actions.updateProviderType(type)) dispatch(actions.setSelectedToken()) @@ -1798,7 +1874,20 @@ function setRpcTarget (newRpc) { background.setCustomRpc(newRpc, (err, result) => { if (err) { log.error(err) - return dispatch(self.displayWarning('Had a problem changing networks!')) + return dispatch(actions.displayWarning('Had a problem changing networks!')) + } + dispatch(actions.setSelectedToken()) + }) + } +} + +function delRpcTarget (oldRpc) { + return (dispatch) => { + log.debug(`background.delRpcTarget: ${oldRpc}`) + background.delCustomRpc(oldRpc, (err, result) => { + if (err) { + log.error(err) + return dispatch(self.displayWarning('Had a problem removing network!')) } dispatch(actions.setSelectedToken()) }) @@ -2220,6 +2309,10 @@ function updateNetworkNonce (address) { return (dispatch) => { return new Promise((resolve, reject) => { global.ethQuery.getTransactionCount(address, (err, data) => { + if (err) { + dispatch(actions.displayWarning(err.message)) + return reject(err) + } dispatch(setNetworkNonce(data)) resolve(data) }) @@ -2307,7 +2400,7 @@ function setUseBlockie (val) { function updateCurrentLocale (key) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - fetchLocale(key) + return fetchLocale(key) .then((localeMessages) => { log.debug(`background.setCurrentLocale`) background.setCurrentLocale(key, (err) => { |