aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js211
1 files changed, 132 insertions, 79 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index f5456e0d2..87b02966b 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -5,24 +5,40 @@ var actions = {
goHome: goHome,
// menu state
getNetworkStatus: 'getNetworkStatus',
-
+ // transition state
+ TRANSITION_FORWARD: 'TRANSITION_FORWARD',
+ TRANSITION_BACKWARD: 'TRANSITION_BACKWARD',
+ transitionForward,
+ transitionBackward,
// remote state
UPDATE_METAMASK_STATE: 'UPDATE_METAMASK_STATE',
updateMetamaskState: updateMetamaskState,
+ // notices
+ MARK_NOTICE_READ: 'MARK_NOTICE_READ',
+ markNoticeRead: markNoticeRead,
+ SHOW_NOTICE: 'SHOW_NOTICE',
+ showNotice: showNotice,
+ CLEAR_NOTICES: 'CLEAR_NOTICES',
+ clearNotices: clearNotices,
+ markAccountsFound,
// intialize screen
AGREE_TO_DISCLAIMER: 'AGREE_TO_DISCLAIMER',
agreeToDisclaimer: agreeToDisclaimer,
CREATE_NEW_VAULT_IN_PROGRESS: 'CREATE_NEW_VAULT_IN_PROGRESS',
SHOW_CREATE_VAULT: 'SHOW_CREATE_VAULT',
SHOW_RESTORE_VAULT: 'SHOW_RESTORE_VAULT',
+ FORGOT_PASSWORD: 'FORGOT_PASSWORD',
+ forgotPassword: forgotPassword,
SHOW_INIT_MENU: 'SHOW_INIT_MENU',
SHOW_NEW_VAULT_SEED: 'SHOW_NEW_VAULT_SEED',
SHOW_INFO_PAGE: 'SHOW_INFO_PAGE',
+ SHOW_IMPORT_PAGE: 'SHOW_IMPORT_PAGE',
unlockMetamask: unlockMetamask,
unlockFailed: unlockFailed,
showCreateVault: showCreateVault,
showRestoreVault: showRestoreVault,
showInitializeMenu: showInitializeMenu,
+ showImportPage,
createNewVaultAndKeychain: createNewVaultAndKeychain,
createNewVaultAndRestore: createNewVaultAndRestore,
createNewVaultInProgress: createNewVaultInProgress,
@@ -46,7 +62,6 @@ var actions = {
unlockInProgress: unlockInProgress,
// error handling
displayWarning: displayWarning,
- showWarning: showWarning, // alias
DISPLAY_WARNING: 'DISPLAY_WARNING',
HIDE_WARNING: 'HIDE_WARNING',
hideWarning: hideWarning,
@@ -74,7 +89,7 @@ var actions = {
TRANSACTION_ERROR: 'TRANSACTION_ERROR',
NEXT_TX: 'NEXT_TX',
PREVIOUS_TX: 'PREV_TX',
- setSelectedAddress: setSelectedAddress,
+ setSelectedAccount: setSelectedAccount,
signMsg: signMsg,
cancelMsg: cancelMsg,
sendTx: sendTx,
@@ -142,13 +157,13 @@ var actions = {
SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN',
showNewKeychain: showNewKeychain,
-
+ callBackgroundThenUpdate,
}
module.exports = actions
var background = null
-function _setBackgroundConnection(backgroundConnection) {
+function _setBackgroundConnection (backgroundConnection) {
background = backgroundConnection
}
@@ -169,24 +184,32 @@ function tryUnlockMetamask (password) {
if (err) {
dispatch(actions.unlockFailed(err.message))
} else {
- dispatch(this.updateMetamaskState(newState))
- let selectedAccount
- try {
- selectedAccount = newState.metamask.selectedAccount
- } catch (e) {}
- dispatch(actions.unlockMetamask(selectedAccount))
+ dispatch(actions.transitionForward())
+ dispatch(actions.updateMetamaskState(newState))
}
})
}
}
+function transitionForward () {
+ return {
+ type: this.TRANSITION_FORWARD,
+ }
+}
+
+function transitionBackward () {
+ return {
+ type: this.TRANSITION_BACKWARD,
+ }
+}
+
function confirmSeedWords () {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
background.clearSeedWordCache((err, account) => {
dispatch(actions.hideLoadingIndication())
if (err) {
- return dispatch(actions.showWarning(err.message))
+ return dispatch(actions.displayWarning(err.message))
}
console.log('Seed word cache cleared. ' + account)
@@ -198,25 +221,16 @@ function confirmSeedWords () {
function createNewVaultAndRestore (password, seed) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
- background.createNewVaultAndRestore(password, seed, (err, newState) => {
+ background.createNewVaultAndRestore(password, seed, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) return dispatch(actions.displayWarning(err.message))
- dispatch(this.updateMetamaskState(newState))
+ dispatch(actions.showAccountsPage())
})
}
}
-function createNewVaultAndKeychain (password, entropy) {
- return (dispatch) => {
- background.createNewVaultAndKeychain(password, entropy, (err, newState) => {
- if (err) {
- return dispatch(actions.showWarning(err.message))
- }
-
- dispatch(this.updateMetamaskState(newState))
- dispatch(this.showNewVaultSeed())
- })
- }
+function createNewVaultAndKeychain (password) {
+ return callBackgroundThenUpdate(background.createNewVaultAndKeychain, password)
}
function revealSeedConfirmation () {
@@ -228,28 +242,18 @@ function revealSeedConfirmation () {
function requestRevealSeed (password) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
- background.submitPassword(password, (err, newState) => {
- dispatch(actions.hideLoadingIndication())
+ background.submitPassword(password, (err) => {
if (err) return dispatch(actions.displayWarning(err.message))
- background.placeSeedWords()
- dispatch(actions.showNewVaultSeed())
+ background.placeSeedWords((err) => {
+ if (err) return dispatch(actions.displayWarning(err.message))
+ dispatch(actions.hideLoadingIndication())
+ })
})
}
}
-
function addNewKeyring (type, opts) {
- return (dispatch) => {
- dispatch(actions.showLoadingIndication())
- background.addNewKeyring(type, opts, (err, newState) => {
- dispatch(this.hideLoadingIndication())
- if (err) {
- return dispatch(actions.showWarning(err))
- }
- dispatch(this.updateMetamaskState(newState))
- dispatch(this.showAccountsPage())
- })
- }
+ return callBackgroundThenUpdate(background.addNewKeyring, type, opts)
}
function navigateToNewAccountScreen() {
@@ -259,16 +263,7 @@ function navigateToNewAccountScreen() {
}
function addNewAccount (ringNumber = 0) {
- return (dispatch) => {
- dispatch(actions.showLoadingIndication())
- background.addNewAccount(ringNumber, (err, newState) => {
- dispatch(this.hideLoadingIndication())
- if (err) {
- return dispatch(actions.showWarning(err))
- }
- dispatch(this.updateMetamaskState(newState))
- })
- }
+ return callBackgroundThenUpdate(background.addNewAccount, ringNumber)
}
function showInfoPage () {
@@ -277,10 +272,8 @@ function showInfoPage () {
}
}
-function setSelectedAddress (address) {
- return (dispatch) => {
- background.setSelectedAddress(address)
- }
+function setSelectedAccount (address) {
+ return callBackgroundThenUpdate(background.setSelectedAccount, address)
}
function setCurrentFiat (fiat) {
@@ -381,18 +374,30 @@ function showRestoreVault () {
}
}
+function forgotPassword () {
+ return {
+ type: actions.FORGOT_PASSWORD,
+ }
+}
+
function showInitializeMenu () {
return {
type: actions.SHOW_INIT_MENU,
}
}
+function showImportPage () {
+ return {
+ type: actions.SHOW_IMPORT_PAGE,
+ }
+}
+
function agreeToDisclaimer () {
return (dispatch) => {
dispatch(this.showLoadingIndication())
background.agreeToDisclaimer((err) => {
if (err) {
- return dispatch(actions.showWarning(err.message))
+ return dispatch(actions.displayWarning(err.message))
}
dispatch(this.hideLoadingIndication())
@@ -460,32 +465,22 @@ function updateMetamaskState (newState) {
}
function lockMetamask () {
- return (dispatch) => {
- background.setLocked((err) => {
- dispatch(actions.hideLoadingIndication())
- if (err) {
- return dispatch(actions.showWarning(err.message))
- }
-
- dispatch({
- type: actions.LOCK_METAMASK,
- })
- })
- }
+ return callBackgroundThenUpdate(background.setLocked)
}
function showAccountDetail (address) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
- background.setSelectedAddress(address, (err, address) => {
+ background.setSelectedAccount(address, (err, newState) => {
dispatch(actions.hideLoadingIndication())
if (err) {
- return dispatch(actions.showWarning(err.message))
+ return dispatch(actions.displayWarning(err.message))
}
+ dispatch(actions.updateMetamaskState(newState))
dispatch({
type: actions.SHOW_ACCOUNT_DETAIL,
- value: address,
+ value: newState.selectedAccount,
})
})
}
@@ -544,6 +539,47 @@ function goBackToInitView () {
}
//
+// notice
+//
+
+function markNoticeRead (notice) {
+ return (dispatch) => {
+ dispatch(this.showLoadingIndication())
+ background.markNoticeRead(notice, (err, notice) => {
+ dispatch(this.hideLoadingIndication())
+ if (err) {
+ return dispatch(actions.displayWarning(err))
+ }
+ if (notice) {
+ return dispatch(actions.showNotice(notice))
+ } else {
+ dispatch(this.clearNotices())
+ return {
+ type: actions.SHOW_ACCOUNTS_PAGE,
+ }
+ }
+ })
+ }
+}
+
+function showNotice (notice) {
+ return {
+ type: actions.SHOW_NOTICE,
+ value: notice,
+ }
+}
+
+function clearNotices () {
+ return {
+ type: actions.CLEAR_NOTICES,
+ }
+}
+
+function markAccountsFound() {
+ return callBackgroundThenUpdate(background.markAccountsFound)
+}
+
+//
// config
//
@@ -594,10 +630,6 @@ function hideSubLoadingIndication () {
}
}
-function showWarning (text) {
- return this.displayWarning(text)
-}
-
function displayWarning (text) {
return {
type: actions.DISPLAY_WARNING,
@@ -649,7 +681,7 @@ function saveAccountLabel (account, label) {
background.saveAccountLabel(account, label, (err) => {
dispatch(actions.hideLoadingIndication())
if (err) {
- return dispatch(actions.showWarning(err.message))
+ return dispatch(actions.displayWarning(err.message))
}
dispatch({
type: actions.SAVE_ACCOUNT_LABEL,
@@ -725,7 +757,7 @@ function shapeShiftSubview (network) {
shapeShiftRequest('marketinfo', {pair}, (mktResponse) => {
shapeShiftRequest('getcoins', {}, (response) => {
dispatch(actions.hideSubLoadingIndication())
- if (mktResponse.error) return dispatch(actions.showWarning(mktResponse.error))
+ if (mktResponse.error) return dispatch(actions.displayWarning(mktResponse.error))
dispatch({
type: actions.SHAPESHIFT_SUBVIEW,
value: {
@@ -742,7 +774,7 @@ function coinShiftRquest (data, marketData) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
shapeShiftRequest('shift', { method: 'POST', data}, (response) => {
- if (response.error) return dispatch(actions.showWarning(response.error))
+ if (response.error) return dispatch(actions.displayWarning(response.error))
var message = `
Deposit your ${response.depositType} to the address bellow:`
background.createShapeShiftTx(response.deposit, response.depositType)
@@ -764,7 +796,7 @@ function reshowQrCode (data, coin) {
return (dispatch) => {
dispatch(actions.showLoadingIndication())
shapeShiftRequest('marketinfo', {pair: `${coin.toLowerCase()}_eth`}, (mktResponse) => {
- if (mktResponse.error) return dispatch(actions.showWarning(mktResponse.error))
+ if (mktResponse.error) return dispatch(actions.displayWarning(mktResponse.error))
var message = [
`Deposit your ${coin} to the address bellow:`,
@@ -801,3 +833,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))
+ })
+ }
+}