diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2017-01-04 03:41:34 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2017-01-04 03:41:34 +0800 |
commit | 1a1605785706a82f89b624d925f55979941df627 (patch) | |
tree | 8942ce51e814ed02129353843b3f893c58e0bd83 | |
parent | 3363a38bfc3317e41ae1540cc630dcf7f11729e0 (diff) | |
parent | 74cccb4f1de288b68f053a75514cf7fd6268388f (diff) | |
download | tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.tar tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.tar.gz tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.tar.bz2 tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.tar.lz tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.tar.xz tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.tar.zst tangerine-wallet-browser-1a1605785706a82f89b624d925f55979941df627.zip |
Merge branch 'dev' of github.com:MetaMask/metamask-plugin into dev
-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)) + }) + } +} |