1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge branch 'dev' into i963-BalancesNotUpdating

This commit is contained in:
Kevin Serrano 2017-01-03 12:07:38 -08:00 committed by GitHub
commit 0a6d8af171

View File

@ -153,7 +153,7 @@ var actions = {
SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN', SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN',
showNewKeychain: showNewKeychain, showNewKeychain: showNewKeychain,
callBackgroundThenUpdate,
} }
module.exports = actions module.exports = actions
@ -226,14 +226,7 @@ function createNewVaultAndRestore (password, seed) {
} }
function createNewVaultAndKeychain (password) { function createNewVaultAndKeychain (password) {
return (dispatch) => { return callBackgroundThenUpdate(background.createNewVaultAndKeychain, password)
background.createNewVaultAndKeychain(password, (err, newState) => {
if (err) {
return dispatch(actions.showWarning(err.message))
}
dispatch(actions.updateMetamaskState(newState))
})
}
} }
function revealSeedConfirmation () { function revealSeedConfirmation () {
@ -255,29 +248,12 @@ function requestRevealSeed (password) {
} }
} }
function addNewKeyring (type, opts) { function addNewKeyring (type, opts) {
return (dispatch) => { return callBackgroundThenUpdate(background.addNewKeyring, type, opts)
dispatch(actions.showLoadingIndication())
background.addNewKeyring(type, opts, (err) => {
dispatch(this.hideLoadingIndication())
if (err) {
return dispatch(actions.showWarning(err))
}
})
}
} }
function addNewAccount (ringNumber = 0) { function addNewAccount (ringNumber = 0) {
return (dispatch) => { return callBackgroundThenUpdate(background.addNewAccount, ringNumber)
dispatch(actions.showLoadingIndication())
background.addNewAccount(ringNumber, (err) => {
dispatch(this.hideLoadingIndication())
if (err) {
return dispatch(actions.showWarning(err))
}
})
}
} }
function showInfoPage () { function showInfoPage () {
@ -475,15 +451,7 @@ function updateMetamaskState (newState) {
} }
function lockMetamask () { function lockMetamask () {
return (dispatch) => { return callBackgroundThenUpdate(background.setLocked)
background.setLocked((err, newState) => {
dispatch(actions.hideLoadingIndication())
if (err) {
return dispatch(actions.displayWarning(err.message))
}
dispatch(actions.updateMetamaskState(newState))
})
}
} }
function showAccountDetail (address) { function showAccountDetail (address) {
@ -565,7 +533,7 @@ function markNoticeRead (notice) {
background.markNoticeRead(notice, (err, notice) => { background.markNoticeRead(notice, (err, notice) => {
dispatch(this.hideLoadingIndication()) dispatch(this.hideLoadingIndication())
if (err) { if (err) {
return dispatch(actions.showWarning(err)) return dispatch(actions.displayWarning(err))
} }
if (notice) { if (notice) {
return dispatch(actions.showNotice(notice)) return dispatch(actions.showNotice(notice))
@ -593,14 +561,7 @@ function clearNotices () {
} }
function markAccountsFound() { function markAccountsFound() {
return (dispatch) => { return callBackgroundThenUpdate(background.markAccountsFound)
dispatch(this.showLoadingIndication())
background.markAccountsFound((err, newState) => {
dispatch(this.hideLoadingIndication())
if (err) return dispatch(this.showWarning(err.message))
dispatch(actions.updateMetamaskState(newState))
})
}
} }
// //
@ -857,3 +818,24 @@ function shapeShiftRequest (query, options, cb) {
return shapShiftReq.send() 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))
})
}
}