2016-04-14 00:28:44 +02:00
|
|
|
var actions = {
|
2016-04-25 21:20:33 +02:00
|
|
|
GO_HOME: 'GO_HOME',
|
|
|
|
goHome: goHome,
|
2016-05-18 21:30:03 +02:00
|
|
|
// menu state
|
|
|
|
TOGGLE_MENU: 'TOGGLE_MENU',
|
|
|
|
toggleMenu: toggleMenu,
|
2016-05-18 23:36:35 +02:00
|
|
|
SET_MENU_STATE: 'SET_MENU_STATE',
|
|
|
|
closeMenu: closeMenu,
|
2016-06-02 01:30:14 +02:00
|
|
|
getNetworkStatus: 'getNetworkStatus',
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
// remote state
|
|
|
|
UPDATE_METAMASK_STATE: 'UPDATE_METAMASK_STATE',
|
|
|
|
updateMetamaskState: updateMetamaskState,
|
|
|
|
// intialize screen
|
2016-06-17 00:58:45 +02:00
|
|
|
AGREE_TO_DISCLAIMER: 'AGREE_TO_DISCLAIMER',
|
|
|
|
agreeToDisclaimer: agreeToDisclaimer,
|
2016-04-14 00:28:44 +02:00
|
|
|
CREATE_NEW_VAULT_IN_PROGRESS: 'CREATE_NEW_VAULT_IN_PROGRESS',
|
|
|
|
SHOW_CREATE_VAULT: 'SHOW_CREATE_VAULT',
|
|
|
|
SHOW_RESTORE_VAULT: 'SHOW_RESTORE_VAULT',
|
|
|
|
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,
|
|
|
|
createNewVaultInProgress: createNewVaultInProgress,
|
|
|
|
showNewVaultSeed: showNewVaultSeed,
|
|
|
|
showInfoPage: showInfoPage,
|
2016-06-03 01:52:18 +02:00
|
|
|
// seed recovery actions
|
|
|
|
REVEAL_SEED_CONFIRMATION: 'REVEAL_SEED_CONFIRMATION',
|
|
|
|
revealSeedConfirmation: revealSeedConfirmation,
|
|
|
|
requestRevealSeed: requestRevealSeed,
|
2016-04-14 00:28:44 +02:00
|
|
|
// unlock screen
|
|
|
|
UNLOCK_IN_PROGRESS: 'UNLOCK_IN_PROGRESS',
|
|
|
|
UNLOCK_FAILED: 'UNLOCK_FAILED',
|
|
|
|
UNLOCK_METAMASK: 'UNLOCK_METAMASK',
|
|
|
|
LOCK_METAMASK: 'LOCK_METAMASK',
|
|
|
|
tryUnlockMetamask: tryUnlockMetamask,
|
|
|
|
lockMetamask: lockMetamask,
|
|
|
|
unlockInProgress: unlockInProgress,
|
|
|
|
// error handling
|
|
|
|
displayWarning: displayWarning,
|
|
|
|
DISPLAY_WARNING: 'DISPLAY_WARNING',
|
|
|
|
HIDE_WARNING: 'HIDE_WARNING',
|
|
|
|
hideWarning: hideWarning,
|
|
|
|
// accounts screen
|
|
|
|
SET_SELECTED_ACCOUNT: 'SET_SELECTED_ACCOUNT',
|
|
|
|
SHOW_ACCOUNT_DETAIL: 'SHOW_ACCOUNT_DETAIL',
|
|
|
|
SHOW_ACCOUNTS_PAGE: 'SHOW_ACCOUNTS_PAGE',
|
|
|
|
SHOW_CONF_TX_PAGE: 'SHOW_CONF_TX_PAGE',
|
2016-05-03 23:32:22 +02:00
|
|
|
SHOW_CONF_MSG_PAGE: 'SHOW_CONF_MSG_PAGE',
|
2016-05-20 21:40:44 +02:00
|
|
|
REVEAL_ACCOUNT: 'REVEAL_ACCOUNT',
|
|
|
|
revealAccount: revealAccount,
|
2016-04-14 00:28:44 +02:00
|
|
|
// account detail screen
|
|
|
|
SHOW_SEND_PAGE: 'SHOW_SEND_PAGE',
|
|
|
|
showSendPage: showSendPage,
|
|
|
|
REQUEST_ACCOUNT_EXPORT: 'REQUEST_ACCOUNT_EXPORT',
|
|
|
|
requestExportAccount: requestExportAccount,
|
|
|
|
EXPORT_ACCOUNT: 'EXPORT_ACCOUNT',
|
|
|
|
exportAccount: exportAccount,
|
|
|
|
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
|
|
|
|
showPrivateKey: showPrivateKey,
|
2016-05-21 01:18:54 +02:00
|
|
|
SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL',
|
|
|
|
saveAccountLabel: saveAccountLabel,
|
2016-04-14 00:28:44 +02:00
|
|
|
// tx conf screen
|
|
|
|
COMPLETED_TX: 'COMPLETED_TX',
|
|
|
|
TRANSACTION_ERROR: 'TRANSACTION_ERROR',
|
|
|
|
NEXT_TX: 'NEXT_TX',
|
|
|
|
PREVIOUS_TX: 'PREV_TX',
|
|
|
|
setSelectedAddress: setSelectedAddress,
|
2016-05-03 23:32:22 +02:00
|
|
|
signMsg: signMsg,
|
|
|
|
cancelMsg: cancelMsg,
|
2016-04-14 00:28:44 +02:00
|
|
|
sendTx: sendTx,
|
2016-05-06 23:46:04 +02:00
|
|
|
signTx: signTx,
|
2016-04-14 00:28:44 +02:00
|
|
|
cancelTx: cancelTx,
|
|
|
|
completedTx: completedTx,
|
|
|
|
txError: txError,
|
|
|
|
nextTx: nextTx,
|
|
|
|
previousTx: previousTx,
|
2016-05-26 23:32:45 +02:00
|
|
|
viewPendingTx: viewPendingTx,
|
|
|
|
VIEW_PENDING_TX: 'VIEW_PENDING_TX',
|
2016-04-14 00:28:44 +02:00
|
|
|
// app messages
|
|
|
|
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',
|
2016-05-11 00:37:13 +02:00
|
|
|
SET_PROVIDER_TYPE: 'SET_PROVIDER_TYPE',
|
2016-04-14 00:28:44 +02:00
|
|
|
USE_ETHERSCAN_PROVIDER: 'USE_ETHERSCAN_PROVIDER',
|
|
|
|
useEtherscanProvider: useEtherscanProvider,
|
|
|
|
showConfigPage: showConfigPage,
|
|
|
|
setRpcTarget: setRpcTarget,
|
2016-05-11 00:37:13 +02:00
|
|
|
setProviderType: setProviderType,
|
2016-04-14 00:28:44 +02:00
|
|
|
// 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',
|
|
|
|
showLoadingIndication: showLoadingIndication,
|
|
|
|
hideLoadingIndication: hideLoadingIndication,
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = actions
|
|
|
|
|
|
|
|
var _accountManager = null
|
2016-06-21 22:18:32 +02:00
|
|
|
function _setAccountManager (accountManager) {
|
2016-04-14 00:28:44 +02:00
|
|
|
_accountManager = accountManager
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function goHome () {
|
2016-04-25 21:20:33 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.GO_HOME,
|
2016-04-25 21:20:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-18 21:30:03 +02:00
|
|
|
// menu state
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function toggleMenu () {
|
2016-05-18 21:30:03 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.TOGGLE_MENU,
|
2016-05-18 21:30:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function closeMenu () {
|
2016-05-18 23:36:35 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SET_MENU_STATE,
|
2016-05-18 23:36:35 +02:00
|
|
|
value: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
// async actions
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function tryUnlockMetamask (password) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.unlockInProgress())
|
2016-04-25 23:14:34 +02:00
|
|
|
_accountManager.submitPassword(password, (err, selectedAccount) => {
|
2016-04-14 00:28:44 +02:00
|
|
|
if (err) {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.unlockFailed())
|
2016-04-14 00:28:44 +02:00
|
|
|
} else {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.unlockMetamask(selectedAccount))
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function createNewVault (password, entropy) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.createNewVaultInProgress())
|
2016-04-14 00:28:44 +02:00
|
|
|
_accountManager.createNewVault(password, entropy, (err, result) => {
|
2016-06-21 22:56:04 +02:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.showWarning(err.message))
|
|
|
|
}
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showNewVaultSeed(result))
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function revealSeedConfirmation () {
|
2016-06-03 01:52:18 +02:00
|
|
|
return {
|
|
|
|
type: this.REVEAL_SEED_CONFIRMATION,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function requestRevealSeed (password) {
|
2016-06-03 01:52:18 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
|
|
|
_accountManager.tryPassword(password, (err, seed) => {
|
|
|
|
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))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function recoverFromSeed (password, seed) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
// dispatch(actions.createNewVaultInProgress())
|
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-13 10:13:14 +02:00
|
|
|
_accountManager.recoverFromSeed(password, seed, (err, metamaskState) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2016-05-13 10:13:14 +02:00
|
|
|
var account = Object.keys(metamaskState.identities)[0]
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.unlockMetamask(account))
|
2016-06-21 22:18:32 +02:00
|
|
|
})
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showInfoPage () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_INFO_PAGE,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function setSelectedAddress (address) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
_accountManager.setSelectedAddress(address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function revealAccount () {
|
2016-05-20 21:40:44 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-20 21:40:44 +02:00
|
|
|
_accountManager.revealAccount((err) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2016-05-20 21:40:44 +02:00
|
|
|
dispatch({
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.REVEAL_ACCOUNT,
|
2016-05-20 21:40:44 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function signMsg (msgData) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2016-05-03 23:32:22 +02:00
|
|
|
_accountManager.signMessage(msgData, (err) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2016-05-25 21:39:12 +02:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
|
|
|
dispatch(actions.completedTx(msgData.metamaskId))
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function signTx (txData) {
|
2016-05-06 23:46:04 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-06 23:46:04 +02:00
|
|
|
|
|
|
|
web3.eth.sendTransaction(txData, (err, data) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-05-06 23:46:04 +02:00
|
|
|
|
2016-05-25 21:39:12 +02:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
|
|
|
dispatch(actions.hideWarning())
|
|
|
|
dispatch(actions.goHome())
|
2016-05-06 23:46:04 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function sendTx (txData) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
_accountManager.approveTransaction(txData.id, (err) => {
|
|
|
|
if (err) {
|
|
|
|
alert(err.message)
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.txError(err))
|
2016-04-14 00:28:44 +02:00
|
|
|
return console.error(err.message)
|
|
|
|
}
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.completedTx(txData.id))
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function completedTx (id) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.COMPLETED_TX,
|
2016-04-14 00:28:44 +02:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function txError (err) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.TRANSACTION_ERROR,
|
2016-04-14 00:28:44 +02:00
|
|
|
message: err.message,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function cancelMsg (msgData) {
|
2016-05-03 23:32:22 +02:00
|
|
|
_accountManager.cancelMessage(msgData.id)
|
2016-05-25 21:39:12 +02:00
|
|
|
return actions.completedTx(msgData.id)
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function cancelTx (txData) {
|
2016-04-30 00:53:29 +02:00
|
|
|
_accountManager.cancelTransaction(txData.id)
|
2016-05-25 21:39:12 +02:00
|
|
|
return actions.completedTx(txData.id)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// initialize screen
|
|
|
|
//
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showCreateVault () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_CREATE_VAULT,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showRestoreVault () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_RESTORE_VAULT,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showInitializeMenu () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_INIT_MENU,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function agreeToDisclaimer () {
|
2016-06-17 00:58:45 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(this.showLoadingIndication())
|
2016-06-17 01:40:55 +02:00
|
|
|
_accountManager.agreeToDisclaimer((err) => {
|
2016-06-21 22:56:04 +02:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.showWarning(err.message))
|
|
|
|
}
|
|
|
|
|
2016-06-17 01:40:55 +02:00
|
|
|
dispatch(this.hideLoadingIndication())
|
2016-06-17 00:58:45 +02:00
|
|
|
dispatch({
|
|
|
|
type: this.AGREE_TO_DISCLAIMER,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function createNewVaultInProgress () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.CREATE_NEW_VAULT_IN_PROGRESS,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showNewVaultSeed (seed) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_NEW_VAULT_SEED,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: seed,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// unlock screen
|
|
|
|
//
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function unlockInProgress () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.UNLOCK_IN_PROGRESS,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function unlockFailed () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.UNLOCK_FAILED,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function unlockMetamask (account) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.UNLOCK_METAMASK,
|
2016-05-13 10:13:14 +02:00
|
|
|
value: account,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function updateMetamaskState (newState) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.UPDATE_METAMASK_STATE,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: newState,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function lockMetamask () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
_accountManager.setLocked((err) => {
|
2016-06-21 22:56:04 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.showWarning(err.message))
|
|
|
|
}
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
dispatch({
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.LOCK_METAMASK,
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showAccountDetail (address) {
|
2016-04-25 23:14:34 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-13 10:13:14 +02:00
|
|
|
_accountManager.setSelectedAddress(address, (err, address) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-06-21 22:56:04 +02:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.showWarning(err.message))
|
|
|
|
}
|
|
|
|
|
2016-05-13 10:13:14 +02:00
|
|
|
dispatch({
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_ACCOUNT_DETAIL,
|
2016-05-13 10:13:14 +02:00
|
|
|
value: address,
|
|
|
|
})
|
2016-04-25 23:14:34 +02:00
|
|
|
})
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function backToAccountDetail (address) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.BACK_TO_ACCOUNT_DETAIL,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: address,
|
|
|
|
}
|
|
|
|
}
|
2016-06-21 22:18:32 +02:00
|
|
|
function clearSeedWordCache (account) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.CLEAR_SEED_WORD_CACHE,
|
2016-05-12 07:21:10 +02:00
|
|
|
value: account,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function confirmSeedWords () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-12 07:21:10 +02:00
|
|
|
_accountManager.clearSeedWordCache((err, account) => {
|
2016-06-21 22:56:04 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.showWarning(err.message))
|
|
|
|
}
|
|
|
|
|
2016-05-12 07:21:10 +02:00
|
|
|
console.log('Seed word cache cleared. ' + account)
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showAccountDetail(account))
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showAccountsPage () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_ACCOUNTS_PAGE,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showConfTxPage () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_CONF_TX_PAGE,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function nextTx () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.NEXT_TX,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function viewPendingTx (txId) {
|
2016-05-26 23:32:45 +02:00
|
|
|
return {
|
|
|
|
type: actions.VIEW_PENDING_TX,
|
|
|
|
value: txId,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function previousTx () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.PREVIOUS_TX,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showConfigPage (transitionForward = true) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_CONFIG_PAGE,
|
2016-06-03 01:52:18 +02:00
|
|
|
value: transitionForward,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// config
|
|
|
|
//
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function setRpcTarget (newRpc) {
|
2016-04-14 00:28:44 +02:00
|
|
|
_accountManager.setRpcTarget(newRpc)
|
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SET_RPC_TARGET,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: newRpc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function setProviderType (type) {
|
2016-05-11 00:37:13 +02:00
|
|
|
_accountManager.setProviderType(type)
|
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SET_PROVIDER_TYPE,
|
2016-05-11 00:37:13 +02:00
|
|
|
value: type,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function useEtherscanProvider () {
|
2016-04-14 00:28:44 +02:00
|
|
|
_accountManager.useEtherscanProvider()
|
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.USE_ETHERSCAN_PROVIDER,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showLoadingIndication () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_LOADING,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function hideLoadingIndication () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.HIDE_LOADING,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function displayWarning (text) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.DISPLAY_WARNING,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: text,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function hideWarning () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.HIDE_WARNING,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function requestExportAccount () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.REQUEST_ACCOUNT_EXPORT,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function exportAccount (address) {
|
2016-04-14 00:28:44 +02:00
|
|
|
var self = this
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
return function (dispatch) {
|
2016-04-14 00:28:44 +02:00
|
|
|
dispatch(self.showLoadingIndication())
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
_accountManager.exportAccount(address, function (err, result) {
|
2016-04-14 00:28:44 +02:00
|
|
|
dispatch(self.hideLoadingIndication())
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
return dispatch(self.displayWarning('Had a problem exporting the account.'))
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(self.showPrivateKey(result))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showPrivateKey (key) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_PRIVATE_KEY,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: key,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function saveAccountLabel (account, label) {
|
2016-05-21 01:18:54 +02:00
|
|
|
return (dispatch) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-21 01:18:54 +02:00
|
|
|
_accountManager.saveAccountLabel(account, label, (err) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-05-21 01:18:54 +02:00
|
|
|
if (err) {
|
2016-05-25 21:39:12 +02:00
|
|
|
return dispatch(actions.showWarning(err.message))
|
2016-05-21 01:18:54 +02:00
|
|
|
}
|
|
|
|
dispatch({
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SAVE_ACCOUNT_LABEL,
|
2016-05-21 01:18:54 +02:00
|
|
|
value: { account, label },
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function showSendPage () {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_SEND_PAGE,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|