mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge branch 'dev' of github.com:MetaMask/metamask-plugin into dev
This commit is contained in:
commit
1a16057857
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user