diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2017-01-04 04:07:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-04 04:07:38 +0800 |
commit | 0a6d8af171b86c84bb730bf3feed6eeeddaf5531 (patch) | |
tree | 313904aa4b9f9a729ffeedb8f53819a830c93afb | |
parent | 33b4d213f19c4c8105932b2f8b88421bbbf896d3 (diff) | |
parent | 74cccb4f1de288b68f053a75514cf7fd6268388f (diff) | |
download | tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.tar tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.tar.gz tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.tar.bz2 tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.tar.lz tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.tar.xz tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.tar.zst tangerine-wallet-browser-0a6d8af171b86c84bb730bf3feed6eeeddaf5531.zip |
Merge branch 'dev' into i963-BalancesNotUpdating
-rw-r--r-- | ui/app/actions.js | 74 |
1 files changed, 28 insertions, 46 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 606460314..d63d36f19 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -153,7 +153,7 @@ var actions = { SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN', showNewKeychain: showNewKeychain, - + callBackgroundThenUpdate, } module.exports = actions @@ -226,14 +226,7 @@ function createNewVaultAndRestore (password, seed) { } function createNewVaultAndKeychain (password) { - return (dispatch) => { - background.createNewVaultAndKeychain(password, (err, newState) => { - if (err) { - return dispatch(actions.showWarning(err.message)) - } - dispatch(actions.updateMetamaskState(newState)) - }) - } + return callBackgroundThenUpdate(background.createNewVaultAndKeychain, password) } function revealSeedConfirmation () { @@ -255,29 +248,12 @@ function requestRevealSeed (password) { } } - function addNewKeyring (type, opts) { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - background.addNewKeyring(type, opts, (err) => { - dispatch(this.hideLoadingIndication()) - if (err) { - return dispatch(actions.showWarning(err)) - } - }) - } + return callBackgroundThenUpdate(background.addNewKeyring, type, opts) } function addNewAccount (ringNumber = 0) { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - background.addNewAccount(ringNumber, (err) => { - dispatch(this.hideLoadingIndication()) - if (err) { - return dispatch(actions.showWarning(err)) - } - }) - } + return callBackgroundThenUpdate(background.addNewAccount, ringNumber) } function showInfoPage () { @@ -475,15 +451,7 @@ function updateMetamaskState (newState) { } function lockMetamask () { - return (dispatch) => { - background.setLocked((err, newState) => { - dispatch(actions.hideLoadingIndication()) - if (err) { - return dispatch(actions.displayWarning(err.message)) - } - dispatch(actions.updateMetamaskState(newState)) - }) - } + return callBackgroundThenUpdate(background.setLocked) } function showAccountDetail (address) { @@ -565,7 +533,7 @@ function markNoticeRead (notice) { background.markNoticeRead(notice, (err, notice) => { dispatch(this.hideLoadingIndication()) if (err) { - return dispatch(actions.showWarning(err)) + return dispatch(actions.displayWarning(err)) } if (notice) { return dispatch(actions.showNotice(notice)) @@ -593,14 +561,7 @@ function clearNotices () { } function markAccountsFound() { - return (dispatch) => { - dispatch(this.showLoadingIndication()) - background.markAccountsFound((err, newState) => { - dispatch(this.hideLoadingIndication()) - if (err) return dispatch(this.showWarning(err.message)) - dispatch(actions.updateMetamaskState(newState)) - }) - } + return callBackgroundThenUpdate(background.markAccountsFound) } // @@ -857,3 +818,24 @@ function shapeShiftRequest (query, options, cb) { return shapShiftReq.send() } } + +// Call Background Then Update +// +// A function generator for a common pattern wherein: +// We show loading indication. +// We call a background method. +// We hide loading indication. +// If it errored, we show a warning. +// If it didn't, we update the state. +function callBackgroundThenUpdate (method, ...args) { + return (dispatch) => { + dispatch(actions.showLoadingIndication()) + method.call(background, ...args, (err, newState) => { + dispatch(actions.hideLoadingIndication()) + if (err) { + return dispatch(actions.displayWarning(err.message)) + } + dispatch(actions.updateMetamaskState(newState)) + }) + } +} |