From 296b2785926ffce7f65b86b12d7733111a43d30e Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 16:46:56 -0800 Subject: actions - dont expect background to provide newState, manually update --- ui/app/actions.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'ui') diff --git a/ui/app/actions.js b/ui/app/actions.js index fa1e0deb5..a27ab2c14 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,13 @@ function tryUnlockMetamask (password) { return (dispatch) => { dispatch(actions.showLoadingIndication()) dispatch(actions.unlockInProgress()) - background.submitPassword(password, (err, newState) => { + background.submitPassword(password, (err) => { dispatch(actions.hideLoadingIndication()) if (err) { dispatch(actions.unlockFailed(err.message)) } else { dispatch(actions.transitionForward()) - dispatch(actions.updateMetamaskState(newState)) + forceUpdateMetamaskState(dispatch) } }) } @@ -232,16 +233,16 @@ function createNewVaultAndRestore (password, seed) { function createNewVaultAndKeychain (password) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - background.createNewVaultAndKeychain(password, (err, newState) => { + background.createNewVaultAndKeychain(password, (err) => { if (err) { return dispatch(actions.displayWarning(err.message)) } - background.placeSeedWords((err, newState) => { + background.placeSeedWords((err) => { if (err) { return dispatch(actions.displayWarning(err.message)) } dispatch(actions.hideLoadingIndication()) - dispatch(actions.updateMetamaskState(newState)) + forceUpdateMetamaskState(dispatch) }) }) } @@ -280,13 +281,18 @@ 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) => { + 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, + 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, + }) }) }) } @@ -876,12 +882,21 @@ 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){ + background.getState((err, newState) => { + if (err) { + return dispatch(actions.displayWarning(err.message)) + } + dispatch(actions.updateMetamaskState(newState)) + }) +} \ No newline at end of file -- cgit From 99fa9ab13aaf69cb8602612816a4df49209fa8a6 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 20:20:13 -0800 Subject: migration 7 - break off TransactionManager substate --- ui/app/actions.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'ui') diff --git a/ui/app/actions.js b/ui/app/actions.js index a27ab2c14..228adcf18 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -180,6 +180,7 @@ function tryUnlockMetamask (password) { return (dispatch) => { dispatch(actions.showLoadingIndication()) dispatch(actions.unlockInProgress()) + if (global.METAMASK_DEBUG) console.log(`background.submitPassword`) background.submitPassword(password, (err) => { dispatch(actions.hideLoadingIndication()) if (err) { @@ -207,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) { @@ -222,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)) @@ -233,10 +236,12 @@ function createNewVaultAndRestore (password, seed) { function createNewVaultAndKeychain (password) { return (dispatch) => { dispatch(actions.showLoadingIndication()) + if (global.METAMASK_DEBUG) console.log(`background.createNewVaultAndKeychain`) background.createNewVaultAndKeychain(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)) @@ -257,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()) @@ -270,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)) @@ -281,9 +289,11 @@ function addNewKeyring (type, opts) { function importNewAccount (strategy, args) { return (dispatch) => { dispatch(actions.showLoadingIndication('This may take a while, be patient.')) + if (global.METAMASK_DEBUG) console.log(`background.importAccountWithStrategy`) background.importAccountWithStrategy(strategy, args, (err) => { dispatch(actions.hideLoadingIndication()) if (err) return dispatch(actions.displayWarning(err.message)) + if (global.METAMASK_DEBUG) console.log(`background.getState`) background.getState((err, newState) => { if (err) { return dispatch(actions.displayWarning(err.message)) @@ -305,6 +315,7 @@ function navigateToNewAccountScreen() { } function addNewAccount () { + if (global.METAMASK_DEBUG) console.log(`background.addNewAccount`) return callBackgroundThenUpdate(background.addNewAccount) } @@ -317,6 +328,7 @@ function showInfoPage () { function setCurrentFiat (fiat) { return (dispatch) => { dispatch(this.showLoadingIndication()) + if (global.METAMASK_DEBUG) console.log(`background.setCurrentFiat`) background.setCurrentFiat(fiat, (data, err) => { dispatch(this.hideLoadingIndication()) dispatch({ @@ -335,6 +347,7 @@ function signMsg (msgData) { return (dispatch) => { dispatch(actions.showLoadingIndication()) + if (global.METAMASK_DEBUG) console.log(`background.signMessage`) background.signMessage(msgData, (err) => { dispatch(actions.hideLoadingIndication()) @@ -346,6 +359,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) => { @@ -361,6 +375,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) @@ -387,11 +402,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) } @@ -433,6 +450,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)) @@ -503,12 +521,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) { @@ -581,6 +601,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) { @@ -612,6 +633,7 @@ function clearNotices () { } function markAccountsFound() { + if (global.METAMASK_DEBUG) console.log(`background.markAccountsFound`) return callBackgroundThenUpdate(background.markAccountsFound) } @@ -620,6 +642,7 @@ function markAccountsFound() { // function setRpcTarget (newRpc) { + if (global.METAMASK_DEBUG) console.log(`background.setRpcTarget`) background.setRpcTarget(newRpc) return { type: actions.SET_RPC_TARGET, @@ -628,6 +651,7 @@ function setRpcTarget (newRpc) { } function setProviderType (type) { + if (global.METAMASK_DEBUG) console.log(`background.setProviderType`) background.setProviderType(type) return { type: actions.SET_PROVIDER_TYPE, @@ -636,6 +660,7 @@ function setProviderType (type) { } function useEtherscanProvider () { + if (global.METAMASK_DEBUG) console.log(`background.useEtherscanProvider`) background.useEtherscanProvider() return { type: actions.USE_ETHERSCAN_PROVIDER, @@ -692,6 +717,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()) @@ -715,6 +741,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) { @@ -736,6 +763,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, @@ -814,6 +842,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))) }) @@ -893,6 +922,7 @@ function callBackgroundThenUpdate (method, ...args) { } function forceUpdateMetamaskState(dispatch){ + if (global.METAMASK_DEBUG) console.log(`background.getState`) background.getState((err, newState) => { if (err) { return dispatch(actions.displayWarning(err.message)) -- cgit From 9e4ef45b6ac460e6539e0f79ad5c78959fa1c4cb Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 2 Feb 2017 23:32:24 -0800 Subject: migration #9 - break out CurrencyController substate --- ui/app/actions.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/app/actions.js b/ui/app/actions.js index 228adcf18..c153a55a6 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -325,12 +325,16 @@ function showInfoPage () { } } -function setCurrentFiat (fiat) { +function setCurrentFiat (currencyCode) { return (dispatch) => { dispatch(this.showLoadingIndication()) if (global.METAMASK_DEBUG) console.log(`background.setCurrentFiat`) - background.setCurrentFiat(fiat, (data, err) => { + 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: { -- cgit