aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-01-04 02:39:34 +0800
committerDan Finlay <dan@danfinlay.com>2017-01-04 02:39:34 +0800
commit3ebf029c04b15599f571a19524474df9680efa7d (patch)
treed0667727566ec6a96ecb71379b7221916c33ee15 /ui/app/actions.js
parentb93cdd428b5013787f78a266bcb5ca84d26b9941 (diff)
downloadtangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.tar
tangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.tar.gz
tangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.tar.bz2
tangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.tar.lz
tangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.tar.xz
tangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.tar.zst
tangerine-wallet-browser-3ebf029c04b15599f571a19524474df9680efa7d.zip
Update account list after adding account
Fixed by finally making a function generator for a pattern we use frequently, communicating to the background process. Fixes #961
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js34
1 files changed, 24 insertions, 10 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 606460314..018baff73 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
@@ -269,15 +269,7 @@ function 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 () {
@@ -476,6 +468,7 @@ function updateMetamaskState (newState) {
function lockMetamask () {
return (dispatch) => {
+ dispatch(actions.showLoadingIndication())
background.setLocked((err, newState) => {
dispatch(actions.hideLoadingIndication())
if (err) {
@@ -857,3 +850,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))
+ })
+ }
+}