aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-01-04 03:41:26 +0800
committerGitHub <noreply@github.com>2017-01-04 03:41:26 +0800
commit74cccb4f1de288b68f053a75514cf7fd6268388f (patch)
tree3ad7399679039b58931c72870c0d05011b794b4b
parentb93cdd428b5013787f78a266bcb5ca84d26b9941 (diff)
parent2c2cdc4475b0ac8a6a52186a470a49c6a085ca08 (diff)
downloadtangerine-wallet-browser-74cccb4f1de288b68f053a75514cf7fd6268388f.tar.gz
tangerine-wallet-browser-74cccb4f1de288b68f053a75514cf7fd6268388f.tar.zst
tangerine-wallet-browser-74cccb4f1de288b68f053a75514cf7fd6268388f.zip
Merge pull request #962 from MetaMask/i961-UpdateUiBug
Fix AddAccount not updating UI
-rw-r--r--ui/app/actions.js74
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))
+ })
+ }
+}