2017-04-05 03:23:46 +02:00
|
|
|
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
var actions = {
|
2016-10-20 21:07:53 +02:00
|
|
|
_setBackgroundConnection: _setBackgroundConnection,
|
|
|
|
|
2016-04-25 21:20:33 +02:00
|
|
|
GO_HOME: 'GO_HOME',
|
|
|
|
goHome: goHome,
|
2016-05-18 21:30:03 +02:00
|
|
|
// menu state
|
2016-06-02 01:30:14 +02:00
|
|
|
getNetworkStatus: 'getNetworkStatus',
|
2016-12-01 04:34:17 +01:00
|
|
|
// transition state
|
|
|
|
TRANSITION_FORWARD: 'TRANSITION_FORWARD',
|
|
|
|
TRANSITION_BACKWARD: 'TRANSITION_BACKWARD',
|
|
|
|
transitionForward,
|
|
|
|
transitionBackward,
|
2016-04-14 00:28:44 +02:00
|
|
|
// remote state
|
|
|
|
UPDATE_METAMASK_STATE: 'UPDATE_METAMASK_STATE',
|
|
|
|
updateMetamaskState: updateMetamaskState,
|
2016-12-07 23:34:15 +01:00
|
|
|
// notices
|
|
|
|
MARK_NOTICE_READ: 'MARK_NOTICE_READ',
|
|
|
|
markNoticeRead: markNoticeRead,
|
|
|
|
SHOW_NOTICE: 'SHOW_NOTICE',
|
|
|
|
showNotice: showNotice,
|
|
|
|
CLEAR_NOTICES: 'CLEAR_NOTICES',
|
|
|
|
clearNotices: clearNotices,
|
2016-12-20 22:53:14 +01:00
|
|
|
markAccountsFound,
|
2016-04-14 00:28:44 +02:00
|
|
|
// intialize screen
|
|
|
|
CREATE_NEW_VAULT_IN_PROGRESS: 'CREATE_NEW_VAULT_IN_PROGRESS',
|
|
|
|
SHOW_CREATE_VAULT: 'SHOW_CREATE_VAULT',
|
|
|
|
SHOW_RESTORE_VAULT: 'SHOW_RESTORE_VAULT',
|
2016-12-20 00:46:09 +01:00
|
|
|
FORGOT_PASSWORD: 'FORGOT_PASSWORD',
|
|
|
|
forgotPassword: forgotPassword,
|
2016-04-14 00:28:44 +02:00
|
|
|
SHOW_INIT_MENU: 'SHOW_INIT_MENU',
|
|
|
|
SHOW_NEW_VAULT_SEED: 'SHOW_NEW_VAULT_SEED',
|
|
|
|
SHOW_INFO_PAGE: 'SHOW_INFO_PAGE',
|
2017-01-17 22:47:30 +01:00
|
|
|
SHOW_IMPORT_PAGE: 'SHOW_IMPORT_PAGE',
|
2016-04-14 00:28:44 +02:00
|
|
|
unlockMetamask: unlockMetamask,
|
|
|
|
unlockFailed: unlockFailed,
|
|
|
|
showCreateVault: showCreateVault,
|
|
|
|
showRestoreVault: showRestoreVault,
|
|
|
|
showInitializeMenu: showInitializeMenu,
|
2017-01-17 22:47:30 +01:00
|
|
|
showImportPage,
|
2016-11-01 19:25:38 +01:00
|
|
|
createNewVaultAndKeychain: createNewVaultAndKeychain,
|
|
|
|
createNewVaultAndRestore: createNewVaultAndRestore,
|
2016-04-14 00:28:44 +02:00
|
|
|
createNewVaultInProgress: createNewVaultInProgress,
|
2016-10-28 21:10:35 +02:00
|
|
|
addNewKeyring,
|
2017-01-19 00:17:08 +01:00
|
|
|
importNewAccount,
|
2016-10-28 21:10:35 +02:00
|
|
|
addNewAccount,
|
2016-11-04 20:00:56 +01:00
|
|
|
NEW_ACCOUNT_SCREEN: 'NEW_ACCOUNT_SCREEN',
|
|
|
|
navigateToNewAccountScreen,
|
2016-04-14 00:28:44 +02:00
|
|
|
showNewVaultSeed: showNewVaultSeed,
|
|
|
|
showInfoPage: showInfoPage,
|
2016-11-02 06:19:04 +01: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-07-22 19:15:39 +02:00
|
|
|
SET_CURRENT_FIAT: 'SET_CURRENT_FIAT',
|
2017-03-15 01:06:16 +01:00
|
|
|
setCurrentCurrency: setCurrentCurrency,
|
2017-06-14 23:21:50 +02:00
|
|
|
setCurrentAccountTab,
|
2016-04-14 00:28:44 +02:00
|
|
|
// account detail screen
|
|
|
|
SHOW_SEND_PAGE: 'SHOW_SEND_PAGE',
|
|
|
|
showSendPage: showSendPage,
|
2017-03-10 00:10:27 +01:00
|
|
|
ADD_TO_ADDRESS_BOOK: 'ADD_TO_ADDRESS_BOOK',
|
|
|
|
addToAddressBook: addToAddressBook,
|
2016-04-14 00:28:44 +02:00
|
|
|
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',
|
2016-05-03 23:32:22 +02:00
|
|
|
signMsg: signMsg,
|
|
|
|
cancelMsg: cancelMsg,
|
2017-02-23 01:23:13 +01:00
|
|
|
signPersonalMsg,
|
|
|
|
cancelPersonalMsg,
|
2016-04-14 00:28:44 +02:00
|
|
|
sendTx: sendTx,
|
2016-05-06 23:46:04 +02:00
|
|
|
signTx: signTx,
|
2017-02-28 03:26:04 +01:00
|
|
|
updateAndApproveTx,
|
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
|
2016-10-31 19:35:09 +01:00
|
|
|
confirmSeedWords: confirmSeedWords,
|
2016-04-14 00:28:44 +02:00
|
|
|
showAccountDetail: showAccountDetail,
|
|
|
|
BACK_TO_ACCOUNT_DETAIL: 'BACK_TO_ACCOUNT_DETAIL',
|
|
|
|
backToAccountDetail: backToAccountDetail,
|
|
|
|
showAccountsPage: showAccountsPage,
|
|
|
|
showConfTxPage: showConfTxPage,
|
|
|
|
// config screen
|
|
|
|
SHOW_CONFIG_PAGE: 'SHOW_CONFIG_PAGE',
|
|
|
|
SET_RPC_TARGET: 'SET_RPC_TARGET',
|
2017-03-07 19:25:50 +01:00
|
|
|
SET_DEFAULT_RPC_TARGET: 'SET_DEFAULT_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,
|
2017-03-07 19:25:50 +01:00
|
|
|
setDefaultRpcTarget: setDefaultRpcTarget,
|
2016-05-11 00:37:13 +02:00
|
|
|
setProviderType: setProviderType,
|
2016-04-14 00:28:44 +02:00
|
|
|
// loading overlay
|
|
|
|
SHOW_LOADING: 'SHOW_LOADING_INDICATION',
|
|
|
|
HIDE_LOADING: 'HIDE_LOADING_INDICATION',
|
|
|
|
showLoadingIndication: showLoadingIndication,
|
|
|
|
hideLoadingIndication: hideLoadingIndication,
|
2016-08-10 22:43:01 +02:00
|
|
|
// buy Eth with coinbase
|
|
|
|
BUY_ETH: 'BUY_ETH',
|
|
|
|
buyEth: buyEth,
|
2016-08-13 00:41:59 +02:00
|
|
|
buyEthView: buyEthView,
|
|
|
|
BUY_ETH_VIEW: 'BUY_ETH_VIEW',
|
2016-08-10 22:43:01 +02:00
|
|
|
COINBASE_SUBVIEW: 'COINBASE_SUBVIEW',
|
|
|
|
coinBaseSubview: coinBaseSubview,
|
|
|
|
SHAPESHIFT_SUBVIEW: 'SHAPESHIFT_SUBVIEW',
|
|
|
|
shapeShiftSubview: shapeShiftSubview,
|
|
|
|
PAIR_UPDATE: 'PAIR_UPDATE',
|
|
|
|
pairUpdate: pairUpdate,
|
|
|
|
coinShiftRquest: coinShiftRquest,
|
|
|
|
SHOW_SUB_LOADING_INDICATION: 'SHOW_SUB_LOADING_INDICATION',
|
|
|
|
showSubLoadingIndication: showSubLoadingIndication,
|
|
|
|
HIDE_SUB_LOADING_INDICATION: 'HIDE_SUB_LOADING_INDICATION',
|
|
|
|
hideSubLoadingIndication: hideSubLoadingIndication,
|
2016-08-13 00:41:59 +02:00
|
|
|
// QR STUFF:
|
|
|
|
SHOW_QR: 'SHOW_QR',
|
2016-09-13 02:27:14 +02:00
|
|
|
showQrView: showQrView,
|
2016-08-18 19:40:35 +02:00
|
|
|
reshowQrCode: reshowQrCode,
|
|
|
|
SHOW_QR_VIEW: 'SHOW_QR_VIEW',
|
2016-08-24 02:17:08 +02:00
|
|
|
// FORGOT PASSWORD:
|
|
|
|
BACK_TO_INIT_MENU: 'BACK_TO_INIT_MENU',
|
|
|
|
goBackToInitView: goBackToInitView,
|
|
|
|
RECOVERY_IN_PROGRESS: 'RECOVERY_IN_PROGRESS',
|
|
|
|
BACK_TO_UNLOCK_VIEW: 'BACK_TO_UNLOCK_VIEW',
|
|
|
|
backToUnlockView: backToUnlockView,
|
2016-10-15 19:48:12 +02:00
|
|
|
// SHOWING KEYCHAIN
|
|
|
|
SHOW_NEW_KEYCHAIN: 'SHOW_NEW_KEYCHAIN',
|
|
|
|
showNewKeychain: showNewKeychain,
|
|
|
|
|
2017-01-03 19:39:34 +01:00
|
|
|
callBackgroundThenUpdate,
|
2017-02-03 01:46:56 +01:00
|
|
|
forceUpdateMetamaskState,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = actions
|
|
|
|
|
2016-10-20 18:58:33 +02:00
|
|
|
var background = null
|
2016-11-11 19:26:12 +01:00
|
|
|
function _setBackgroundConnection (backgroundConnection) {
|
2016-10-20 18:58:33 +02:00
|
|
|
background = backgroundConnection
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
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-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-09-09 04:53:54 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.unlockInProgress())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.submitPassword`)
|
2017-02-03 01:46:56 +01:00
|
|
|
background.submitPassword(password, (err) => {
|
2016-09-09 04:53:54 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-04-14 00:28:44 +02:00
|
|
|
if (err) {
|
2016-11-02 01:00:17 +01:00
|
|
|
dispatch(actions.unlockFailed(err.message))
|
2016-04-14 00:28:44 +02:00
|
|
|
} else {
|
2016-12-01 04:34:17 +01:00
|
|
|
dispatch(actions.transitionForward())
|
2017-02-03 01:46:56 +01:00
|
|
|
forceUpdateMetamaskState(dispatch)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 23:55:52 +01:00
|
|
|
function transitionForward () {
|
2016-12-01 04:34:17 +01:00
|
|
|
return {
|
|
|
|
type: this.TRANSITION_FORWARD,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 23:55:52 +01:00
|
|
|
function transitionBackward () {
|
2016-12-01 04:34:17 +01:00
|
|
|
return {
|
|
|
|
type: this.TRANSITION_BACKWARD,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 19:35:09 +01:00
|
|
|
function confirmSeedWords () {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.clearSeedWordCache`)
|
2016-10-31 19:35:09 +01:00
|
|
|
background.clearSeedWordCache((err, account) => {
|
2017-03-21 21:38:27 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-10-31 19:35:09 +01:00
|
|
|
if (err) {
|
2016-11-08 01:02:02 +01:00
|
|
|
return dispatch(actions.displayWarning(err.message))
|
2016-10-31 19:35:09 +01:00
|
|
|
}
|
|
|
|
|
2017-06-14 23:21:50 +02:00
|
|
|
log.info('Seed word cache cleared. ' + account)
|
2016-10-31 19:35:09 +01:00
|
|
|
dispatch(actions.showAccountDetail(account))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:25:38 +01:00
|
|
|
function createNewVaultAndRestore (password, seed) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2016-11-01 19:25:38 +01:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.createNewVaultAndRestore`)
|
2016-11-16 02:12:13 +01:00
|
|
|
background.createNewVaultAndRestore(password, seed, (err) => {
|
2017-03-21 21:38:27 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-11-01 19:25:38 +01:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2016-11-23 22:49:54 +01:00
|
|
|
dispatch(actions.showAccountsPage())
|
2016-11-01 19:25:38 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-22 00:49:03 +01:00
|
|
|
function createNewVaultAndKeychain (password) {
|
2017-01-25 00:33:33 +01:00
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.createNewVaultAndKeychain`)
|
2017-02-03 01:46:56 +01:00
|
|
|
background.createNewVaultAndKeychain(password, (err) => {
|
2017-01-25 00:33:33 +01:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.placeSeedWords`)
|
2017-02-03 01:46:56 +01:00
|
|
|
background.placeSeedWords((err) => {
|
2017-01-25 00:33:33 +01:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
|
|
|
dispatch(actions.hideLoadingIndication())
|
2017-02-03 01:46:56 +01:00
|
|
|
forceUpdateMetamaskState(dispatch)
|
2017-01-25 00:33:33 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 06:19:04 +01:00
|
|
|
function revealSeedConfirmation () {
|
|
|
|
return {
|
|
|
|
type: this.REVEAL_SEED_CONFIRMATION,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestRevealSeed (password) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.submitPassword`)
|
2016-11-16 02:12:13 +01:00
|
|
|
background.submitPassword(password, (err) => {
|
2017-03-21 14:57:49 +01:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.placeSeedWords`)
|
2017-03-28 17:23:25 +02:00
|
|
|
background.placeSeedWords((err, result) => {
|
2016-11-22 05:08:36 +01:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2017-03-28 17:23:25 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
dispatch(actions.showNewVaultSeed(result))
|
2016-11-22 05:08:36 +01:00
|
|
|
})
|
2016-11-02 06:19:04 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-21 01:44:31 +02:00
|
|
|
function addNewKeyring (type, opts) {
|
2017-01-18 01:22:22 +01:00
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.addNewKeyring`)
|
2017-01-27 07:30:12 +01:00
|
|
|
background.addNewKeyring(type, opts, (err) => {
|
2017-01-18 01:22:22 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
|
|
|
dispatch(actions.showAccountsPage())
|
|
|
|
})
|
|
|
|
}
|
2016-10-21 01:44:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-19 00:17:08 +01:00
|
|
|
function importNewAccount (strategy, args) {
|
|
|
|
return (dispatch) => {
|
2017-01-19 01:45:39 +01:00
|
|
|
dispatch(actions.showLoadingIndication('This may take a while, be patient.'))
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.importAccountWithStrategy`)
|
2017-02-03 01:46:56 +01:00
|
|
|
background.importAccountWithStrategy(strategy, args, (err) => {
|
2017-01-19 00:17:08 +01:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.getState`)
|
2017-02-03 01:46:56 +01:00
|
|
|
background.getState((err, newState) => {
|
2017-03-22 17:18:13 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2017-02-03 01:46:56 +01:00
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
|
|
|
dispatch(actions.updateMetamaskState(newState))
|
|
|
|
dispatch({
|
|
|
|
type: actions.SHOW_ACCOUNT_DETAIL,
|
|
|
|
value: newState.selectedAddress,
|
|
|
|
})
|
2017-01-19 00:17:08 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-27 06:05:45 +02:00
|
|
|
function navigateToNewAccountScreen () {
|
2016-11-04 20:00:56 +01:00
|
|
|
return {
|
2016-11-04 20:31:03 +01:00
|
|
|
type: this.NEW_ACCOUNT_SCREEN,
|
2016-11-04 20:00:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 21:06:59 +01:00
|
|
|
function addNewAccount () {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.addNewAccount`)
|
2017-01-24 21:06:59 +01:00
|
|
|
return callBackgroundThenUpdate(background.addNewAccount)
|
2016-10-28 21:10:35 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 01:06:16 +01:00
|
|
|
function setCurrentCurrency (currencyCode) {
|
2016-07-21 18:30:58 +02:00
|
|
|
return (dispatch) => {
|
2016-08-10 01:33:58 +02:00
|
|
|
dispatch(this.showLoadingIndication())
|
2017-03-15 01:06:16 +01:00
|
|
|
log.debug(`background.setCurrentCurrency`)
|
2017-02-03 08:32:24 +01:00
|
|
|
background.setCurrentCurrency(currencyCode, (err, data) => {
|
2016-08-10 01:33:58 +02:00
|
|
|
dispatch(this.hideLoadingIndication())
|
2017-02-03 08:32:24 +01:00
|
|
|
if (err) {
|
2017-06-14 23:21:50 +02:00
|
|
|
log.error(err.stack)
|
2017-02-03 08:32:24 +01:00
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
2016-07-21 18:30:58 +02:00
|
|
|
dispatch({
|
|
|
|
type: this.SET_CURRENT_FIAT,
|
2016-07-21 19:15:34 +02:00
|
|
|
value: {
|
2017-03-15 01:06:16 +01:00
|
|
|
currentCurrency: data.currentCurrency,
|
2016-07-21 19:15:34 +02:00
|
|
|
conversionRate: data.conversionRate,
|
2016-07-21 23:08:26 +02:00
|
|
|
conversionDate: data.conversionDate,
|
2016-07-22 19:15:39 +02:00
|
|
|
},
|
2016-07-21 18:30:58 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function signMsg (msgData) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug('action - signMsg')
|
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
|
|
|
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`actions calling background.signMessage`)
|
|
|
|
background.signMessage(msgData, (err, newState) => {
|
|
|
|
log.debug('signMessage called back')
|
|
|
|
dispatch(actions.updateMetamaskState(newState))
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-02-23 23:23:45 +01:00
|
|
|
if (err) log.error(err)
|
2016-05-25 21:39:12 +02:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2017-02-23 23:23:45 +01:00
|
|
|
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.completedTx(msgData.metamaskId))
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:23:13 +01:00
|
|
|
function signPersonalMsg (msgData) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug('action - signPersonalMsg')
|
2017-02-23 01:23:13 +01:00
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
|
|
|
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`actions calling background.signPersonalMessage`)
|
|
|
|
background.signPersonalMessage(msgData, (err, newState) => {
|
|
|
|
log.debug('signPersonalMessage called back')
|
|
|
|
dispatch(actions.updateMetamaskState(newState))
|
2017-02-23 01:23:13 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
|
2017-02-23 23:23:45 +01:00
|
|
|
if (err) log.error(err)
|
2017-02-23 01:23:13 +01:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2017-02-23 23:23:45 +01:00
|
|
|
|
2016-05-25 21:39:12 +02:00
|
|
|
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) => {
|
2017-05-08 21:29:08 +02:00
|
|
|
global.ethQuery.sendTransaction(txData, (err, data) => {
|
2017-02-28 23:08:00 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-05-25 21:39:12 +02:00
|
|
|
if (err) return dispatch(actions.displayWarning(err.message))
|
2017-02-28 23:08:00 +01:00
|
|
|
dispatch(actions.hideWarning())
|
2016-05-06 23:46:04 +02:00
|
|
|
})
|
2017-02-28 23:08:00 +01:00
|
|
|
dispatch(this.showConfTxPage())
|
2016-05-06 23:46:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function sendTx (txData) {
|
2017-02-28 23:45:21 +01:00
|
|
|
log.info(`actions - sendTx: ${JSON.stringify(txData.txParams)}`)
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`actions calling background.approveTransaction`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.approveTransaction(txData.id, (err) => {
|
2016-04-14 00:28:44 +02:00
|
|
|
if (err) {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.txError(err))
|
2017-06-14 23:21:50 +02:00
|
|
|
return log.error(err.message)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.completedTx(txData.id))
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-28 03:26:04 +01:00
|
|
|
function updateAndApproveTx (txData) {
|
2017-02-28 23:45:21 +01:00
|
|
|
log.info('actions: updateAndApproveTx: ' + JSON.stringify(txData))
|
2017-02-28 03:26:04 +01:00
|
|
|
return (dispatch) => {
|
|
|
|
log.debug(`actions calling background.updateAndApproveTx`)
|
|
|
|
background.updateAndApproveTransaction(txData, (err) => {
|
2017-03-28 20:46:33 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2017-02-28 03:26:04 +01:00
|
|
|
if (err) {
|
|
|
|
dispatch(actions.txError(err))
|
2017-06-14 23:21:50 +02:00
|
|
|
return log.error(err.message)
|
2017-02-28 03:26:04 +01:00
|
|
|
}
|
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,
|
2017-02-24 01:00:43 +01:00
|
|
|
value: id,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.cancelMessage`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.cancelMessage(msgData.id)
|
2016-05-25 21:39:12 +02:00
|
|
|
return actions.completedTx(msgData.id)
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
|
|
|
|
2017-02-23 01:23:13 +01:00
|
|
|
function cancelPersonalMsg (msgData) {
|
2017-02-24 01:00:43 +01:00
|
|
|
const id = msgData.id
|
|
|
|
background.cancelPersonalMessage(id)
|
|
|
|
return actions.completedTx(id)
|
2017-02-23 01:23:13 +01:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function cancelTx (txData) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.cancelTransaction`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.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-12-20 00:46:09 +01:00
|
|
|
function forgotPassword () {
|
|
|
|
return {
|
|
|
|
type: actions.FORGOT_PASSWORD,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-17 22:47:30 +01:00
|
|
|
function showImportPage () {
|
|
|
|
return {
|
|
|
|
type: actions.SHOW_IMPORT_PAGE,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 02:17:08 +02:00
|
|
|
function backToUnlockView () {
|
|
|
|
return {
|
|
|
|
type: actions.BACK_TO_UNLOCK_VIEW,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-15 19:48:12 +02:00
|
|
|
function showNewKeychain () {
|
|
|
|
return {
|
2016-10-20 20:33:18 +02:00
|
|
|
type: actions.SHOW_NEW_KEYCHAIN,
|
2016-10-15 19:48:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
//
|
|
|
|
// 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-11-02 01:00:17 +01:00
|
|
|
function unlockFailed (message) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.UNLOCK_FAILED,
|
2016-11-02 01:00:17 +01:00
|
|
|
value: message,
|
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 () {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.setLocked`)
|
2017-01-03 19:42:09 +01:00
|
|
|
return callBackgroundThenUpdate(background.setLocked)
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2017-06-14 23:21:50 +02:00
|
|
|
function setCurrentAccountTab (newTabName) {
|
|
|
|
log.debug(`background.setCurrentAccountTab: ${newTabName}`)
|
|
|
|
return callBackgroundThenUpdateNoSpinner(background.setCurrentAccountTab, newTabName)
|
|
|
|
}
|
|
|
|
|
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())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.setSelectedAddress`)
|
2017-01-31 00:08:31 +01:00
|
|
|
background.setSelectedAddress(address, (err) => {
|
2016-05-25 21:39:12 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-06-21 22:56:04 +02:00
|
|
|
if (err) {
|
2016-11-08 01:02:02 +01:00
|
|
|
return dispatch(actions.displayWarning(err.message))
|
2016-06-21 22:56:04 +02:00
|
|
|
}
|
2016-05-13 10:13:14 +02:00
|
|
|
dispatch({
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_ACCOUNT_DETAIL,
|
2017-01-31 00:08:31 +01:00
|
|
|
value: address,
|
2016-05-13 10:13:14 +02:00
|
|
|
})
|
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 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-09-15 19:24:05 +02:00
|
|
|
function showConfTxPage (transForward = true) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_CONF_TX_PAGE,
|
2016-09-15 19:24:05 +02:00
|
|
|
transForward: transForward,
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 02:17:08 +02:00
|
|
|
function goBackToInitView () {
|
|
|
|
return {
|
|
|
|
type: actions.BACK_TO_INIT_MENU,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 23:34:15 +01:00
|
|
|
//
|
|
|
|
// notice
|
|
|
|
//
|
|
|
|
|
|
|
|
function markNoticeRead (notice) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(this.showLoadingIndication())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.markNoticeRead`)
|
2016-12-19 22:35:43 +01:00
|
|
|
background.markNoticeRead(notice, (err, notice) => {
|
2016-12-07 23:34:15 +01:00
|
|
|
dispatch(this.hideLoadingIndication())
|
|
|
|
if (err) {
|
2017-01-03 20:03:25 +01:00
|
|
|
return dispatch(actions.displayWarning(err))
|
2016-12-07 23:34:15 +01:00
|
|
|
}
|
|
|
|
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,
|
|
|
|
}
|
2016-08-24 02:17:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-27 06:05:45 +02:00
|
|
|
function markAccountsFound () {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.markAccountsFound`)
|
2017-01-03 19:42:09 +01:00
|
|
|
return callBackgroundThenUpdate(background.markAccountsFound)
|
2016-12-20 22:53:14 +01:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
//
|
|
|
|
// config
|
|
|
|
//
|
|
|
|
|
2017-03-07 19:25:50 +01:00
|
|
|
// default rpc target refers to localhost:8545 in this instance.
|
|
|
|
function setDefaultRpcTarget (rpcList) {
|
|
|
|
log.debug(`background.setDefaultRpcTarget`)
|
2017-03-08 18:06:41 +01:00
|
|
|
return (dispatch) => {
|
|
|
|
background.setDefaultRpc((err, result) => {
|
|
|
|
if (err) {
|
2017-03-08 18:35:31 +01:00
|
|
|
log.error(err)
|
2017-03-08 18:06:41 +01:00
|
|
|
return dispatch(self.displayWarning('Had a problem changing networks.'))
|
|
|
|
}
|
|
|
|
})
|
2017-03-07 19:25:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function setRpcTarget (newRpc) {
|
2017-03-08 18:08:28 +01:00
|
|
|
log.debug(`background.setRpcTarget`)
|
|
|
|
return (dispatch) => {
|
|
|
|
background.setCustomRpc(newRpc, (err, result) => {
|
|
|
|
if (err) {
|
2017-03-08 18:35:31 +01:00
|
|
|
log.error(err)
|
2017-03-08 18:08:28 +01:00
|
|
|
return dispatch(self.displayWarning('Had a problem changing networks!'))
|
|
|
|
}
|
|
|
|
})
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 14:57:49 +01:00
|
|
|
// Calls the addressBookController to add a new address.
|
2017-03-10 00:10:27 +01:00
|
|
|
function addToAddressBook (recipient, nickname) {
|
|
|
|
log.debug(`background.addToAddressBook`)
|
|
|
|
return (dispatch) => {
|
|
|
|
background.setAddressBook(recipient, nickname, (err, result) => {
|
|
|
|
if (err) {
|
|
|
|
log.error(err)
|
|
|
|
return dispatch(self.displayWarning('Address book failed to update'))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function setProviderType (type) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.setProviderType`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.setProviderType(type)
|
2016-05-11 00:37:13 +02:00
|
|
|
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 () {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.useEtherscanProvider`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.useEtherscanProvider()
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.USE_ETHERSCAN_PROVIDER,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 01:45:39 +01:00
|
|
|
function showLoadingIndication (message) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2016-05-25 21:39:12 +02:00
|
|
|
type: actions.SHOW_LOADING,
|
2017-01-19 01:45:39 +01:00
|
|
|
value: message,
|
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-08-10 22:43:01 +02:00
|
|
|
function showSubLoadingIndication () {
|
|
|
|
return {
|
|
|
|
type: actions.SHOW_SUB_LOADING_INDICATION,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideSubLoadingIndication () {
|
|
|
|
return {
|
|
|
|
type: actions.HIDE_SUB_LOADING_INDICATION,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 16:53:34 +01:00
|
|
|
function exportAccount (password, 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())
|
|
|
|
|
2017-03-21 16:53:34 +01:00
|
|
|
log.debug(`background.submitPassword`)
|
|
|
|
background.submitPassword(password, function (err) {
|
2016-04-14 00:28:44 +02:00
|
|
|
if (err) {
|
2017-03-21 16:53:34 +01:00
|
|
|
log.error('Error in submiting password.')
|
|
|
|
dispatch(self.hideLoadingIndication())
|
|
|
|
return dispatch(self.displayWarning('Incorrect Password.'))
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
2017-03-21 16:53:34 +01:00
|
|
|
log.debug(`background.exportAccount`)
|
|
|
|
background.exportAccount(address, function (err, result) {
|
|
|
|
dispatch(self.hideLoadingIndication())
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-03-21 16:53:34 +01:00
|
|
|
if (err) {
|
|
|
|
log.error(err)
|
|
|
|
return dispatch(self.displayWarning('Had a problem exporting the account.'))
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(self.showPrivateKey(result))
|
|
|
|
})
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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())
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.saveAccountLabel`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.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-11-08 01:02:02 +01:00
|
|
|
return dispatch(actions.displayWarning(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
|
|
|
}
|
|
|
|
}
|
2016-08-10 22:43:01 +02:00
|
|
|
|
2017-04-05 03:23:46 +02:00
|
|
|
function buyEth (opts) {
|
2016-08-10 22:43:01 +02:00
|
|
|
return (dispatch) => {
|
2017-04-05 03:23:46 +02:00
|
|
|
const url = getBuyEthUrl(opts)
|
|
|
|
global.platform.openWindow({ url })
|
2016-08-10 22:43:01 +02:00
|
|
|
dispatch({
|
|
|
|
type: actions.BUY_ETH,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 00:41:59 +02:00
|
|
|
function buyEthView (address) {
|
2016-08-10 22:43:01 +02:00
|
|
|
return {
|
2016-08-13 00:41:59 +02:00
|
|
|
type: actions.BUY_ETH_VIEW,
|
|
|
|
value: address,
|
2016-08-10 22:43:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function coinBaseSubview () {
|
|
|
|
return {
|
|
|
|
type: actions.COINBASE_SUBVIEW,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function pairUpdate (coin) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showSubLoadingIndication())
|
|
|
|
dispatch(actions.hideWarning())
|
|
|
|
shapeShiftRequest('marketinfo', {pair: `${coin.toLowerCase()}_eth`}, (mktResponse) => {
|
|
|
|
dispatch(actions.hideSubLoadingIndication())
|
|
|
|
dispatch({
|
|
|
|
type: actions.PAIR_UPDATE,
|
|
|
|
value: {
|
|
|
|
marketinfo: mktResponse,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function shapeShiftSubview (network) {
|
2016-08-15 03:39:19 +02:00
|
|
|
var pair = 'btc_eth'
|
2016-08-10 22:43:01 +02:00
|
|
|
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showSubLoadingIndication())
|
|
|
|
shapeShiftRequest('marketinfo', {pair}, (mktResponse) => {
|
|
|
|
shapeShiftRequest('getcoins', {}, (response) => {
|
|
|
|
dispatch(actions.hideSubLoadingIndication())
|
2016-11-08 01:02:02 +01:00
|
|
|
if (mktResponse.error) return dispatch(actions.displayWarning(mktResponse.error))
|
2016-08-10 22:43:01 +02:00
|
|
|
dispatch({
|
|
|
|
type: actions.SHAPESHIFT_SUBVIEW,
|
|
|
|
value: {
|
|
|
|
marketinfo: mktResponse,
|
|
|
|
coinOptions: response,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-13 02:43:24 +02:00
|
|
|
function coinShiftRquest (data, marketData) {
|
2016-08-10 22:43:01 +02:00
|
|
|
return (dispatch) => {
|
2016-08-13 00:41:59 +02:00
|
|
|
dispatch(actions.showLoadingIndication())
|
2016-08-10 22:43:01 +02:00
|
|
|
shapeShiftRequest('shift', { method: 'POST', data}, (response) => {
|
2017-02-04 05:45:20 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
2016-11-08 01:02:02 +01:00
|
|
|
if (response.error) return dispatch(actions.displayWarning(response.error))
|
2016-08-13 02:43:24 +02:00
|
|
|
var message = `
|
|
|
|
Deposit your ${response.depositType} to the address bellow:`
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.createShapeShiftTx`)
|
2016-10-20 18:58:33 +02:00
|
|
|
background.createShapeShiftTx(response.deposit, response.depositType)
|
2016-09-13 02:27:14 +02:00
|
|
|
dispatch(actions.showQrView(response.deposit, [message].concat(marketData)))
|
2016-08-13 00:41:59 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-13 02:27:14 +02:00
|
|
|
function showQrView (data, message) {
|
|
|
|
return {
|
|
|
|
type: actions.SHOW_QR_VIEW,
|
|
|
|
value: {
|
|
|
|
message: message,
|
|
|
|
data: data,
|
|
|
|
},
|
2016-08-10 22:43:01 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-18 19:40:35 +02:00
|
|
|
function reshowQrCode (data, coin) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
|
|
|
shapeShiftRequest('marketinfo', {pair: `${coin.toLowerCase()}_eth`}, (mktResponse) => {
|
2016-11-08 01:02:02 +01:00
|
|
|
if (mktResponse.error) return dispatch(actions.displayWarning(mktResponse.error))
|
2016-08-18 19:40:35 +02:00
|
|
|
|
2016-08-19 00:20:26 +02:00
|
|
|
var message = [
|
2016-08-18 19:40:35 +02:00
|
|
|
`Deposit your ${coin} to the address bellow:`,
|
|
|
|
`Deposit Limit: ${mktResponse.limit}`,
|
|
|
|
`Deposit Minimum:${mktResponse.minimum}`,
|
|
|
|
]
|
|
|
|
|
2016-09-13 02:27:14 +02:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
return dispatch(actions.showQrView(data, message))
|
2016-08-18 19:40:35 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2016-08-13 00:41:59 +02:00
|
|
|
|
2016-08-10 22:43:01 +02:00
|
|
|
function shapeShiftRequest (query, options, cb) {
|
|
|
|
var queryResponse, method
|
|
|
|
!options ? options = {} : null
|
|
|
|
options.method ? method = options.method : method = 'GET'
|
|
|
|
|
|
|
|
var requestListner = function (request) {
|
|
|
|
queryResponse = JSON.parse(this.responseText)
|
|
|
|
cb ? cb(queryResponse) : null
|
|
|
|
return queryResponse
|
|
|
|
}
|
|
|
|
|
|
|
|
var shapShiftReq = new XMLHttpRequest()
|
|
|
|
shapShiftReq.addEventListener('load', requestListner)
|
|
|
|
shapShiftReq.open(method, `https://shapeshift.io/${query}/${options.pair ? options.pair : ''}`, true)
|
|
|
|
|
|
|
|
if (options.method === 'POST') {
|
|
|
|
var jsonObj = JSON.stringify(options.data)
|
|
|
|
shapShiftReq.setRequestHeader('Content-Type', 'application/json')
|
|
|
|
return shapShiftReq.send(jsonObj)
|
|
|
|
} else {
|
|
|
|
return shapShiftReq.send()
|
|
|
|
}
|
|
|
|
}
|
2017-01-03 19:39:34 +01:00
|
|
|
|
|
|
|
// 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.
|
2017-06-14 23:21:50 +02:00
|
|
|
function callBackgroundThenUpdateNoSpinner (method, ...args) {
|
|
|
|
return (dispatch) => {
|
|
|
|
method.call(background, ...args, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
|
|
|
forceUpdateMetamaskState(dispatch)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 19:39:34 +01:00
|
|
|
function callBackgroundThenUpdate (method, ...args) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(actions.showLoadingIndication())
|
2017-02-03 01:46:56 +01:00
|
|
|
method.call(background, ...args, (err) => {
|
2017-01-03 19:39:34 +01:00
|
|
|
dispatch(actions.hideLoadingIndication())
|
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
2017-02-03 01:46:56 +01:00
|
|
|
forceUpdateMetamaskState(dispatch)
|
2017-01-03 19:39:34 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-02-03 01:46:56 +01:00
|
|
|
|
2017-04-27 06:05:45 +02:00
|
|
|
function forceUpdateMetamaskState (dispatch) {
|
2017-02-23 23:23:45 +01:00
|
|
|
log.debug(`background.getState`)
|
2017-02-03 01:46:56 +01:00
|
|
|
background.getState((err, newState) => {
|
|
|
|
if (err) {
|
|
|
|
return dispatch(actions.displayWarning(err.message))
|
|
|
|
}
|
|
|
|
dispatch(actions.updateMetamaskState(newState))
|
|
|
|
})
|
2017-02-04 05:45:20 +01:00
|
|
|
}
|