diff options
Merge branch 'dev' into i831-AddRopsten-Dev
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 203 |
1 files changed, 93 insertions, 110 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index 3d9588083..e69b743e9 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -1,4 +1,6 @@ var actions = { + _setBackgroundConnection: _setBackgroundConnection, + GO_HOME: 'GO_HOME', goHome: goHome, // menu state @@ -16,17 +18,16 @@ var actions = { SHOW_INIT_MENU: 'SHOW_INIT_MENU', SHOW_NEW_VAULT_SEED: 'SHOW_NEW_VAULT_SEED', SHOW_INFO_PAGE: 'SHOW_INFO_PAGE', - RECOVER_FROM_SEED: 'RECOVER_FROM_SEED', - CLEAR_SEED_WORD_CACHE: 'CLEAR_SEED_WORD_CACHE', - clearSeedWordCache: clearSeedWordCache, - recoverFromSeed: recoverFromSeed, unlockMetamask: unlockMetamask, unlockFailed: unlockFailed, showCreateVault: showCreateVault, showRestoreVault: showRestoreVault, showInitializeMenu: showInitializeMenu, - createNewVault: createNewVault, + createNewVaultAndKeychain: createNewVaultAndKeychain, + createNewVaultAndRestore: createNewVaultAndRestore, createNewVaultInProgress: createNewVaultInProgress, + addNewKeyring, + addNewAccount, showNewVaultSeed: showNewVaultSeed, showInfoPage: showInfoPage, // seed recovery actions @@ -52,8 +53,6 @@ var actions = { SHOW_ACCOUNTS_PAGE: 'SHOW_ACCOUNTS_PAGE', SHOW_CONF_TX_PAGE: 'SHOW_CONF_TX_PAGE', SHOW_CONF_MSG_PAGE: 'SHOW_CONF_MSG_PAGE', - REVEAL_ACCOUNT: 'REVEAL_ACCOUNT', - revealAccount: revealAccount, SET_CURRENT_FIAT: 'SET_CURRENT_FIAT', setCurrentFiat: setCurrentFiat, // account detail screen @@ -67,10 +66,6 @@ var actions = { showPrivateKey: showPrivateKey, SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL', saveAccountLabel: saveAccountLabel, - AGREE_TO_ETH_WARNING: 'AGREE_TO_ETH_WARNING', - agreeToEthWarning: agreeToEthWarning, - SHOW_ETH_WARNING: 'SHOW_ETH_WARNING', - showEthWarning: showEthWarning, // tx conf screen COMPLETED_TX: 'COMPLETED_TX', TRANSACTION_ERROR: 'TRANSACTION_ERROR', @@ -89,12 +84,12 @@ var actions = { viewPendingTx: viewPendingTx, VIEW_PENDING_TX: 'VIEW_PENDING_TX', // app messages + confirmSeedWords: confirmSeedWords, showAccountDetail: showAccountDetail, BACK_TO_ACCOUNT_DETAIL: 'BACK_TO_ACCOUNT_DETAIL', backToAccountDetail: backToAccountDetail, showAccountsPage: showAccountsPage, showConfTxPage: showConfTxPage, - confirmSeedWords: confirmSeedWords, // config screen SHOW_CONFIG_PAGE: 'SHOW_CONFIG_PAGE', SET_RPC_TARGET: 'SET_RPC_TARGET', @@ -104,8 +99,6 @@ var actions = { showConfigPage: showConfigPage, setRpcTarget: setRpcTarget, setProviderType: setProviderType, - // hacky - need a way to get a reference to account manager - _setAccountManager: _setAccountManager, // loading overlay SHOW_LOADING: 'SHOW_LOADING_INDICATION', HIDE_LOADING: 'HIDE_LOADING_INDICATION', @@ -142,13 +135,18 @@ var actions = { RECOVERY_IN_PROGRESS: 'RECOVERY_IN_PROGRESS', BACK_TO_UNLOCK_VIEW: 'BACK_TO_UNLOCK_VIEW', backToUnlockView: backToUnlockView, + // SHOWING KEYCHAIN + SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN', + showNewKeychain: showNewKeychain, + + } module.exports = actions -var _accountManager = null -function _setAccountManager (accountManager) { - _accountManager = accountManager +var background = null +function _setBackgroundConnection (backgroundConnection) { + background = backgroundConnection } function goHome () { @@ -163,25 +161,52 @@ function tryUnlockMetamask (password) { return (dispatch) => { dispatch(actions.showLoadingIndication()) dispatch(actions.unlockInProgress()) - _accountManager.submitPassword(password, (err, selectedAccount) => { + background.submitPassword(password, (err, newState) => { dispatch(actions.hideLoadingIndication()) if (err) { - dispatch(actions.unlockFailed()) + dispatch(actions.unlockFailed(err.message)) } else { + let selectedAccount + try { + selectedAccount = newState.metamask.selectedAccount + } catch (e) {} dispatch(actions.unlockMetamask(selectedAccount)) } }) } } -function createNewVault (password, entropy) { +function confirmSeedWords () { return (dispatch) => { - dispatch(actions.createNewVaultInProgress()) - _accountManager.createNewVault(password, entropy, (err, result) => { + dispatch(actions.showLoadingIndication()) + background.clearSeedWordCache((err, account) => { + dispatch(actions.hideLoadingIndication()) if (err) { return dispatch(actions.displayWarning(err.message)) } - dispatch(actions.showNewVaultSeed(result)) + + console.log('Seed word cache cleared. ' + account) + dispatch(actions.showAccountDetail(account)) + }) + } +} + +function createNewVaultAndRestore (password, seed) { + return (dispatch) => { + dispatch(actions.showLoadingIndication()) + background.createNewVaultAndRestore(password, seed, (err) => { + dispatch(actions.hideLoadingIndication()) + if (err) return dispatch(actions.displayWarning(err.message)) + }) + } +} + +function createNewVaultAndKeychain (password, entropy) { + return (dispatch) => { + background.createNewVaultAndKeychain(password, entropy, (err) => { + if (err) { + return dispatch(actions.showWarning(err.message)) + } }) } } @@ -195,27 +220,35 @@ function revealSeedConfirmation () { function requestRevealSeed (password) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - _accountManager.tryPassword(password, (err, seed) => { + background.submitPassword(password, (err) => { dispatch(actions.hideLoadingIndication()) if (err) return dispatch(actions.displayWarning(err.message)) - _accountManager.recoverSeed((err, seed) => { - if (err) return dispatch(actions.displayWarning(err.message)) - dispatch(actions.showNewVaultSeed(seed)) - }) + background.placeSeedWords() }) } } -function recoverFromSeed (password, seed) { + +function addNewKeyring (type, opts) { return (dispatch) => { - // dispatch(actions.createNewVaultInProgress()) dispatch(actions.showLoadingIndication()) - _accountManager.recoverFromSeed(password, seed, (err, metamaskState) => { - dispatch(actions.hideLoadingIndication()) - if (err) return dispatch(actions.displayWarning(err.message)) + background.addNewKeyring(type, opts, (err) => { + dispatch(this.hideLoadingIndication()) + if (err) { + return dispatch(actions.showWarning(err)) + } + }) + } +} - var account = Object.keys(metamaskState.identities)[0] - dispatch(actions.unlockMetamask(account)) +function addNewAccount (ringNumber = 0) { + return (dispatch) => { + dispatch(actions.showLoadingIndication()) + background.addNewAccount(ringNumber, (err) => { + dispatch(this.hideLoadingIndication()) + if (err) { + return dispatch(actions.showWarning(err)) + } }) } } @@ -228,27 +261,14 @@ function showInfoPage () { function setSelectedAddress (address) { return (dispatch) => { - _accountManager.setSelectedAddress(address) - } -} - -function revealAccount () { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - _accountManager.revealAccount((err) => { - dispatch(actions.hideLoadingIndication()) - if (err) return dispatch(actions.displayWarning(err.message)) - dispatch({ - type: actions.REVEAL_ACCOUNT, - }) - }) + background.setSelectedAddress(address) } } function setCurrentFiat (fiat) { return (dispatch) => { dispatch(this.showLoadingIndication()) - _accountManager.setCurrentFiat(fiat, (data, err) => { + background.setCurrentFiat(fiat, (data, err) => { dispatch(this.hideLoadingIndication()) dispatch({ type: this.SET_CURRENT_FIAT, @@ -266,7 +286,7 @@ function signMsg (msgData) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - _accountManager.signMessage(msgData, (err) => { + background.signMessage(msgData, (err) => { dispatch(actions.hideLoadingIndication()) if (err) return dispatch(actions.displayWarning(err.message)) @@ -277,7 +297,7 @@ function signMsg (msgData) { function signTx (txData) { return (dispatch) => { - _accountManager.setGasMultiplier(txData.gasMultiplier, (err) => { + background.setGasMultiplier(txData.gasMultiplier, (err) => { if (err) return dispatch(actions.displayWarning(err.message)) web3.eth.sendTransaction(txData, (err, data) => { dispatch(actions.hideLoadingIndication()) @@ -292,7 +312,7 @@ function signTx (txData) { function sendTx (txData) { return (dispatch) => { - _accountManager.approveTransaction(txData.id, (err) => { + background.approveTransaction(txData.id, (err) => { if (err) { alert(err.message) dispatch(actions.txError(err)) @@ -318,12 +338,12 @@ function txError (err) { } function cancelMsg (msgData) { - _accountManager.cancelMessage(msgData.id) + background.cancelMessage(msgData.id) return actions.completedTx(msgData.id) } function cancelTx (txData) { - _accountManager.cancelTransaction(txData.id) + background.cancelTransaction(txData.id) return actions.completedTx(txData.id) } @@ -352,7 +372,7 @@ function showInitializeMenu () { function agreeToDisclaimer () { return (dispatch) => { dispatch(this.showLoadingIndication()) - _accountManager.agreeToDisclaimer((err) => { + background.agreeToDisclaimer((err) => { if (err) { return dispatch(actions.displayWarning(err.message)) } @@ -384,6 +404,12 @@ function backToUnlockView () { } } +function showNewKeychain () { + return { + type: actions.SHOW_NEW_KEYCHAIN, + } +} + // // unlock screen // @@ -394,9 +420,10 @@ function unlockInProgress () { } } -function unlockFailed () { +function unlockFailed (message) { return { type: actions.UNLOCK_FAILED, + value: message, } } @@ -416,15 +443,11 @@ function updateMetamaskState (newState) { function lockMetamask () { return (dispatch) => { - _accountManager.setLocked((err) => { + background.setLocked((err) => { dispatch(actions.hideLoadingIndication()) if (err) { return dispatch(actions.displayWarning(err.message)) } - - dispatch({ - type: actions.LOCK_METAMASK, - }) }) } } @@ -432,7 +455,7 @@ function lockMetamask () { function showAccountDetail (address) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - _accountManager.setSelectedAddress(address, (err, address) => { + background.setSelectedAddress(address, (err, address) => { dispatch(actions.hideLoadingIndication()) if (err) { return dispatch(actions.displayWarning(err.message)) @@ -452,27 +475,6 @@ function backToAccountDetail (address) { value: address, } } -function clearSeedWordCache (account) { - return { - type: actions.CLEAR_SEED_WORD_CACHE, - value: account, - } -} - -function confirmSeedWords () { - return (dispatch) => { - dispatch(actions.showLoadingIndication()) - _accountManager.clearSeedWordCache((err, account) => { - dispatch(actions.hideLoadingIndication()) - if (err) { - return dispatch(actions.displayWarning(err.message)) - } - - console.log('Seed word cache cleared. ' + account) - dispatch(actions.showAccountDetail(account)) - }) - } -} function showAccountsPage () { return { @@ -524,7 +526,7 @@ function goBackToInitView () { // function setRpcTarget (newRpc) { - _accountManager.setRpcTarget(newRpc) + background.setRpcTarget(newRpc) return { type: actions.SET_RPC_TARGET, value: newRpc, @@ -532,7 +534,7 @@ function setRpcTarget (newRpc) { } function setProviderType (type) { - _accountManager.setProviderType(type) + background.setProviderType(type) return { type: actions.SET_PROVIDER_TYPE, value: type, @@ -540,7 +542,7 @@ function setProviderType (type) { } function useEtherscanProvider () { - _accountManager.useEtherscanProvider() + background.useEtherscanProvider() return { type: actions.USE_ETHERSCAN_PROVIDER, } @@ -595,7 +597,7 @@ function exportAccount (address) { return function (dispatch) { dispatch(self.showLoadingIndication()) - _accountManager.exportAccount(address, function (err, result) { + background.exportAccount(address, function (err, result) { dispatch(self.hideLoadingIndication()) if (err) { @@ -618,7 +620,7 @@ function showPrivateKey (key) { function saveAccountLabel (account, label) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - _accountManager.saveAccountLabel(account, label, (err) => { + background.saveAccountLabel(account, label, (err) => { dispatch(actions.hideLoadingIndication()) if (err) { return dispatch(actions.displayWarning(err.message)) @@ -637,28 +639,9 @@ function showSendPage () { } } -function agreeToEthWarning () { - return (dispatch) => { - _accountManager.agreeToEthWarning((err) => { - if (err) { - return dispatch(actions.showEthWarning(err.message)) - } - dispatch({ - type: actions.AGREE_TO_ETH_WARNING, - }) - }) - } -} - -function showEthWarning () { - return { - type: actions.SHOW_ETH_WARNING, - } -} - function buyEth (address, amount) { return (dispatch) => { - _accountManager.buyEth(address, amount) + background.buyEth(address, amount) dispatch({ type: actions.BUY_ETH, }) @@ -736,7 +719,7 @@ function coinShiftRquest (data, marketData) { if (response.error) return dispatch(actions.displayWarning(response.error)) var message = ` Deposit your ${response.depositType} to the address bellow:` - _accountManager.createShapeShiftTx(response.deposit, response.depositType) + background.createShapeShiftTx(response.deposit, response.depositType) dispatch(actions.showQrView(response.deposit, [message].concat(marketData))) }) } |