aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js77
1 files changed, 63 insertions, 14 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index fa1e0deb5..c153a55a6 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -158,6 +158,7 @@ var actions = {
showNewKeychain: showNewKeychain,
callBackgroundThenUpdate,
+ forceUpdateMetamaskState,
}
module.exports = actions
@@ -179,13 +180,14 @@ function tryUnlockMetamask (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
dispatch(actions.unlockInProgress())
- background.submitPassword(password, (err, newState) => {
+ if (global.METAMASK_DEBUG) console.log(`background.submitPassword`)
+ background.submitPassword(password, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
dispatch(actions.unlockFailed(err.message))
} else {
dispatch(actions.transitionForward())
- dispatch(actions.updateMetamaskState(newState))
+ forceUpdateMetamaskState(dispatch)
}
})
}
@@ -206,6 +208,7 @@ function transitionBackward () {
function confirmSeedWords () {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.clearSeedWordCache`)
background.clearSeedWordCache((err, account) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -221,6 +224,7 @@ function confirmSeedWords () {
function createNewVaultAndRestore (password, seed) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndRestore`)
background.createNewVaultAndRestore(password, seed, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
@@ -232,16 +236,18 @@ function createNewVaultAndRestore (password, seed) {
function createNewVaultAndKeychain (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
- background.createNewVaultAndKeychain(password, (err, newState) => {
+ if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndKeychain`)
+ background.createNewVaultAndKeychain(password, (err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
- background.placeSeedWords((err, newState) => {
+ if (global.METAMASK_DEBUG) console.log(`background.placeSeedWords`)
+ background.placeSeedWords((err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
dispatch(actions.hideLoadingIndication())
- dispatch(actions.updateMetamaskState(newState))
+ forceUpdateMetamaskState(dispatch)
})
})
}
@@ -256,8 +262,10 @@ function revealSeedConfirmation () {
function requestRevealSeed (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.submitPassword`)
background.submitPassword(password, (err) => {
if (err) return dispatch(actions.displayWarning(err.message))
+ if (global.METAMASK_DEBUG) console.log(`background.placeSeedWords`)
background.placeSeedWords((err) => {
if (err) return dispatch(actions.displayWarning(err.message))
dispatch(actions.hideLoadingIndication())
@@ -269,6 +277,7 @@ function requestRevealSeed (password) {
function addNewKeyring (type, opts) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.addNewKeyring`)
background.addNewKeyring(type, opts, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
@@ -280,13 +289,20 @@ function addNewKeyring (type, opts) {
function importNewAccount (strategy, args) {
return (dispatch) => {
dispatch(actions.showLoadingIndication('This may take a while, be patient.'))
- background.importAccountWithStrategy(strategy, args, (err, newState) => {
+ if (global.METAMASK_DEBUG) console.log(`background.importAccountWithStrategy`)
+ background.importAccountWithStrategy(strategy, args, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
- dispatch(actions.updateMetamaskState(newState))
- dispatch({
- type: actions.SHOW_ACCOUNT_DETAIL,
- value: newState.selectedAddress,
+ if (global.METAMASK_DEBUG) console.log(`background.getState`)
+ background.getState((err, newState) => {
+ if (err) {
+ return dispatch(actions.displayWarning(err.message))
+ }
+ dispatch(actions.updateMetamaskState(newState))
+ dispatch({
+ type: actions.SHOW_ACCOUNT_DETAIL,
+ value: newState.selectedAddress,
+ })
})
})
}
@@ -299,6 +315,7 @@ function navigateToNewAccountScreen() {
}
function addNewAccount () {
+ if (global.METAMASK_DEBUG) console.log(`background.addNewAccount`)
return callBackgroundThenUpdate(background.addNewAccount)
}
@@ -308,11 +325,16 @@ function showInfoPage () {
}
}
-function setCurrentFiat (fiat) {
+function setCurrentFiat (currencyCode) {
return (dispatch) => {
dispatch(this.showLoadingIndication())
- background.setCurrentFiat(fiat, (data, err) => {
+ if (global.METAMASK_DEBUG) console.log(`background.setCurrentFiat`)
+ background.setCurrentCurrency(currencyCode, (err, data) => {
dispatch(this.hideLoadingIndication())
+ if (err) {
+ console.error(err.stack)
+ return dispatch(actions.displayWarning(err.message))
+ }
dispatch({
type: this.SET_CURRENT_FIAT,
value: {
@@ -329,6 +351,7 @@ function signMsg (msgData) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.signMessage`)
background.signMessage(msgData, (err) => {
dispatch(actions.hideLoadingIndication())
@@ -340,6 +363,7 @@ function signMsg (msgData) {
function signTx (txData) {
return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.setGasMultiplier`)
background.setGasMultiplier(txData.gasMultiplier, (err) => {
if (err) return dispatch(actions.displayWarning(err.message))
web3.eth.sendTransaction(txData, (err, data) => {
@@ -355,6 +379,7 @@ function signTx (txData) {
function sendTx (txData) {
return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.approveTransaction`)
background.approveTransaction(txData.id, (err) => {
if (err) {
alert(err.message)
@@ -381,11 +406,13 @@ function txError (err) {
}
function cancelMsg (msgData) {
+ if (global.METAMASK_DEBUG) console.log(`background.cancelMessage`)
background.cancelMessage(msgData.id)
return actions.completedTx(msgData.id)
}
function cancelTx (txData) {
+ if (global.METAMASK_DEBUG) console.log(`background.cancelTransaction`)
background.cancelTransaction(txData.id)
return actions.completedTx(txData.id)
}
@@ -427,6 +454,7 @@ function showImportPage () {
function agreeToDisclaimer () {
return (dispatch) => {
dispatch(this.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.agreeToDisclaimer`)
background.agreeToDisclaimer((err) => {
if (err) {
return dispatch(actions.displayWarning(err.message))
@@ -497,12 +525,14 @@ function updateMetamaskState (newState) {
}
function lockMetamask () {
+ if (global.METAMASK_DEBUG) console.log(`background.setLocked`)
return callBackgroundThenUpdate(background.setLocked)
}
function showAccountDetail (address) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.setSelectedAddress`)
background.setSelectedAddress(address, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -575,6 +605,7 @@ function goBackToInitView () {
function markNoticeRead (notice) {
return (dispatch) => {
dispatch(this.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.markNoticeRead`)
background.markNoticeRead(notice, (err, notice) => {
dispatch(this.hideLoadingIndication())
if (err) {
@@ -606,6 +637,7 @@ function clearNotices () {
}
function markAccountsFound() {
+ if (global.METAMASK_DEBUG) console.log(`background.markAccountsFound`)
return callBackgroundThenUpdate(background.markAccountsFound)
}
@@ -614,6 +646,7 @@ function markAccountsFound() {
//
function setRpcTarget (newRpc) {
+ if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`)
background.setRpcTarget(newRpc)
return {
type: actions.SET_RPC_TARGET,
@@ -622,6 +655,7 @@ function setRpcTarget (newRpc) {
}
function setProviderType (type) {
+ if (global.METAMASK_DEBUG) console.log(`background.setProviderType`)
background.setProviderType(type)
return {
type: actions.SET_PROVIDER_TYPE,
@@ -630,6 +664,7 @@ function setProviderType (type) {
}
function useEtherscanProvider () {
+ if (global.METAMASK_DEBUG) console.log(`background.useEtherscanProvider`)
background.useEtherscanProvider()
return {
type: actions.USE_ETHERSCAN_PROVIDER,
@@ -686,6 +721,7 @@ function exportAccount (address) {
return function (dispatch) {
dispatch(self.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.exportAccount`)
background.exportAccount(address, function (err, result) {
dispatch(self.hideLoadingIndication())
@@ -709,6 +745,7 @@ function showPrivateKey (key) {
function saveAccountLabel (account, label) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
+ if (global.METAMASK_DEBUG) console.log(`background.saveAccountLabel`)
background.saveAccountLabel(account, label, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -730,6 +767,7 @@ function showSendPage () {
function buyEth (address, amount) {
return (dispatch) => {
+ if (global.METAMASK_DEBUG) console.log(`background.buyEth`)
background.buyEth(address, amount)
dispatch({
type: actions.BUY_ETH,
@@ -808,6 +846,7 @@ function coinShiftRquest (data, marketData) {
if (response.error) return dispatch(actions.displayWarning(response.error))
var message = `
Deposit your ${response.depositType} to the address bellow:`
+ if (global.METAMASK_DEBUG) console.log(`background.createShapeShiftTx`)
background.createShapeShiftTx(response.deposit, response.depositType)
dispatch(actions.showQrView(response.deposit, [message].concat(marketData)))
})
@@ -876,12 +915,22 @@ function shapeShiftRequest (query, options, cb) {
function callBackgroundThenUpdate (method, ...args) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
- method.call(background, ...args, (err, newState) => {
+ method.call(background, ...args, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
return dispatch(actions.displayWarning(err.message))
}
- dispatch(actions.updateMetamaskState(newState))
+ forceUpdateMetamaskState(dispatch)
})
}
}
+
+function forceUpdateMetamaskState(dispatch){
+ if (global.METAMASK_DEBUG) console.log(`background.getState`)
+ background.getState((err, newState) => {
+ if (err) {
+ return dispatch(actions.displayWarning(err.message))
+ }
+ dispatch(actions.updateMetamaskState(newState))
+ })
+} \ No newline at end of file