1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

actions - remove use of 'this'

This commit is contained in:
kumavis 2016-05-25 12:39:12 -07:00
parent b6a2d388f7
commit c5e5842424

View File

@ -110,7 +110,7 @@ function _setAccountManager(accountManager){
function goHome() { function goHome() {
return { return {
type: this.GO_HOME, type: actions.GO_HOME,
} }
} }
@ -118,13 +118,13 @@ function goHome() {
function toggleMenu() { function toggleMenu() {
return { return {
type: this.TOGGLE_MENU, type: actions.TOGGLE_MENU,
} }
} }
function closeMenu() { function closeMenu() {
return { return {
type: this.SET_MENU_STATE, type: actions.SET_MENU_STATE,
value: false, value: false,
} }
} }
@ -133,12 +133,12 @@ function closeMenu() {
function tryUnlockMetamask(password) { function tryUnlockMetamask(password) {
return (dispatch) => { return (dispatch) => {
dispatch(this.unlockInProgress()) dispatch(actions.unlockInProgress())
_accountManager.submitPassword(password, (err, selectedAccount) => { _accountManager.submitPassword(password, (err, selectedAccount) => {
if (err) { if (err) {
dispatch(this.unlockFailed()) dispatch(actions.unlockFailed())
} else { } else {
dispatch(this.unlockMetamask(selectedAccount)) dispatch(actions.unlockMetamask(selectedAccount))
} }
}) })
} }
@ -146,30 +146,30 @@ function tryUnlockMetamask(password) {
function createNewVault(password, entropy) { function createNewVault(password, entropy) {
return (dispatch) => { return (dispatch) => {
dispatch(this.createNewVaultInProgress()) dispatch(actions.createNewVaultInProgress())
_accountManager.createNewVault(password, entropy, (err, result) => { _accountManager.createNewVault(password, entropy, (err, result) => {
dispatch(this.showNewVaultSeed(result)) dispatch(actions.showNewVaultSeed(result))
}) })
} }
} }
function recoverFromSeed(password, seed) { function recoverFromSeed(password, seed) {
return (dispatch) => { return (dispatch) => {
// dispatch(this.createNewVaultInProgress()) // dispatch(actions.createNewVaultInProgress())
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
_accountManager.recoverFromSeed(password, seed, (err, metamaskState) => { _accountManager.recoverFromSeed(password, seed, (err, metamaskState) => {
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(this.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
var account = Object.keys(metamaskState.identities)[0] var account = Object.keys(metamaskState.identities)[0]
dispatch(this.unlockMetamask(account)) dispatch(actions.unlockMetamask(account))
}) })
} }
} }
function showInfoPage() { function showInfoPage() {
return { return {
type: this.SHOW_INFO_PAGE, type: actions.SHOW_INFO_PAGE,
} }
} }
@ -181,12 +181,12 @@ function setSelectedAddress(address) {
function revealAccount() { function revealAccount() {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
_accountManager.revealAccount((err) => { _accountManager.revealAccount((err) => {
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(this.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
dispatch({ dispatch({
type: this.REVEAL_ACCOUNT, type: actions.REVEAL_ACCOUNT,
}) })
}) })
} }
@ -194,27 +194,27 @@ function revealAccount() {
function signMsg(msgData) { function signMsg(msgData) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
_accountManager.signMessage(msgData, (err) => { _accountManager.signMessage(msgData, (err) => {
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(this.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
dispatch(this.completedTx(msgData.metamaskId)) dispatch(actions.completedTx(msgData.metamaskId))
}) })
} }
} }
function signTx(txData) { function signTx(txData) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
web3.eth.sendTransaction(txData, (err, data) => { web3.eth.sendTransaction(txData, (err, data) => {
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) return dispatch(this.displayWarning(err.message)) if (err) return dispatch(actions.displayWarning(err.message))
dispatch(this.hideWarning()) dispatch(actions.hideWarning())
dispatch(this.goHome()) dispatch(actions.goHome())
}) })
} }
} }
@ -224,36 +224,36 @@ function sendTx(txData) {
_accountManager.approveTransaction(txData.id, (err) => { _accountManager.approveTransaction(txData.id, (err) => {
if (err) { if (err) {
alert(err.message) alert(err.message)
dispatch(this.txError(err)) dispatch(actions.txError(err))
return console.error(err.message) return console.error(err.message)
} }
dispatch(this.completedTx(txData.id)) dispatch(actions.completedTx(txData.id))
}) })
} }
} }
function completedTx(id) { function completedTx(id) {
return { return {
type: this.COMPLETED_TX, type: actions.COMPLETED_TX,
id, id,
} }
} }
function txError(err) { function txError(err) {
return { return {
type: this.TRANSACTION_ERROR, type: actions.TRANSACTION_ERROR,
message: err.message, message: err.message,
} }
} }
function cancelMsg(msgData){ function cancelMsg(msgData){
_accountManager.cancelMessage(msgData.id) _accountManager.cancelMessage(msgData.id)
return this.completedTx(msgData.id) return actions.completedTx(msgData.id)
} }
function cancelTx(txData){ function cancelTx(txData){
_accountManager.cancelTransaction(txData.id) _accountManager.cancelTransaction(txData.id)
return this.completedTx(txData.id) return actions.completedTx(txData.id)
} }
// //
@ -263,31 +263,31 @@ function cancelTx(txData){
function showCreateVault() { function showCreateVault() {
return { return {
type: this.SHOW_CREATE_VAULT, type: actions.SHOW_CREATE_VAULT,
} }
} }
function showRestoreVault() { function showRestoreVault() {
return { return {
type: this.SHOW_RESTORE_VAULT, type: actions.SHOW_RESTORE_VAULT,
} }
} }
function showInitializeMenu() { function showInitializeMenu() {
return { return {
type: this.SHOW_INIT_MENU, type: actions.SHOW_INIT_MENU,
} }
} }
function createNewVaultInProgress() { function createNewVaultInProgress() {
return { return {
type: this.CREATE_NEW_VAULT_IN_PROGRESS, type: actions.CREATE_NEW_VAULT_IN_PROGRESS,
} }
} }
function showNewVaultSeed(seed) { function showNewVaultSeed(seed) {
return { return {
type: this.SHOW_NEW_VAULT_SEED, type: actions.SHOW_NEW_VAULT_SEED,
value: seed, value: seed,
} }
} }
@ -298,26 +298,26 @@ function showNewVaultSeed(seed) {
function unlockInProgress() { function unlockInProgress() {
return { return {
type: this.UNLOCK_IN_PROGRESS, type: actions.UNLOCK_IN_PROGRESS,
} }
} }
function unlockFailed() { function unlockFailed() {
return { return {
type: this.UNLOCK_FAILED, type: actions.UNLOCK_FAILED,
} }
} }
function unlockMetamask(account) { function unlockMetamask(account) {
return { return {
type: this.UNLOCK_METAMASK, type: actions.UNLOCK_METAMASK,
value: account, value: account,
} }
} }
function updateMetamaskState(newState) { function updateMetamaskState(newState) {
return { return {
type: this.UPDATE_METAMASK_STATE, type: actions.UPDATE_METAMASK_STATE,
value: newState, value: newState,
} }
} }
@ -326,20 +326,20 @@ function lockMetamask() {
return (dispatch) => { return (dispatch) => {
_accountManager.setLocked((err) => { _accountManager.setLocked((err) => {
dispatch({ dispatch({
type: this.LOCK_METAMASK, type: actions.LOCK_METAMASK,
}) })
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
}) })
} }
} }
function showAccountDetail(address) { function showAccountDetail(address) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
_accountManager.setSelectedAddress(address, (err, address) => { _accountManager.setSelectedAddress(address, (err, address) => {
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
dispatch({ dispatch({
type: this.SHOW_ACCOUNT_DETAIL, type: actions.SHOW_ACCOUNT_DETAIL,
value: address, value: address,
}) })
}) })
@ -348,54 +348,54 @@ function showAccountDetail(address) {
function backToAccountDetail(address) { function backToAccountDetail(address) {
return { return {
type: this.BACK_TO_ACCOUNT_DETAIL, type: actions.BACK_TO_ACCOUNT_DETAIL,
value: address, value: address,
} }
} }
function clearSeedWordCache(account) { function clearSeedWordCache(account) {
return { return {
type: this.CLEAR_SEED_WORD_CACHE, type: actions.CLEAR_SEED_WORD_CACHE,
value: account, value: account,
} }
} }
function confirmSeedWords() { function confirmSeedWords() {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
_accountManager.clearSeedWordCache((err, account) => { _accountManager.clearSeedWordCache((err, account) => {
console.log('Seed word cache cleared. ' + account) console.log('Seed word cache cleared. ' + account)
dispatch(this.showAccountDetail(account)) dispatch(actions.showAccountDetail(account))
}) })
} }
} }
function showAccountsPage() { function showAccountsPage() {
return { return {
type: this.SHOW_ACCOUNTS_PAGE, type: actions.SHOW_ACCOUNTS_PAGE,
} }
} }
function showConfTxPage() { function showConfTxPage() {
return { return {
type: this.SHOW_CONF_TX_PAGE, type: actions.SHOW_CONF_TX_PAGE,
} }
} }
function nextTx() { function nextTx() {
return { return {
type: this.NEXT_TX, type: actions.NEXT_TX,
} }
} }
function previousTx() { function previousTx() {
return { return {
type: this.PREVIOUS_TX, type: actions.PREVIOUS_TX,
} }
} }
function showConfigPage() { function showConfigPage() {
return { return {
type: this.SHOW_CONFIG_PAGE, type: actions.SHOW_CONFIG_PAGE,
} }
} }
@ -406,7 +406,7 @@ function showConfigPage() {
function setRpcTarget(newRpc) { function setRpcTarget(newRpc) {
_accountManager.setRpcTarget(newRpc) _accountManager.setRpcTarget(newRpc)
return { return {
type: this.SET_RPC_TARGET, type: actions.SET_RPC_TARGET,
value: newRpc, value: newRpc,
} }
} }
@ -414,7 +414,7 @@ function setRpcTarget(newRpc) {
function setProviderType(type) { function setProviderType(type) {
_accountManager.setProviderType(type) _accountManager.setProviderType(type)
return { return {
type: this.SET_PROVIDER_TYPE, type: actions.SET_PROVIDER_TYPE,
value: type, value: type,
} }
} }
@ -422,38 +422,38 @@ function setProviderType(type) {
function useEtherscanProvider() { function useEtherscanProvider() {
_accountManager.useEtherscanProvider() _accountManager.useEtherscanProvider()
return { return {
type: this.USE_ETHERSCAN_PROVIDER, type: actions.USE_ETHERSCAN_PROVIDER,
} }
} }
function showLoadingIndication() { function showLoadingIndication() {
return { return {
type: this.SHOW_LOADING, type: actions.SHOW_LOADING,
} }
} }
function hideLoadingIndication() { function hideLoadingIndication() {
return { return {
type: this.HIDE_LOADING, type: actions.HIDE_LOADING,
} }
} }
function displayWarning(text) { function displayWarning(text) {
return { return {
type: this.DISPLAY_WARNING, type: actions.DISPLAY_WARNING,
value: text, value: text,
} }
} }
function hideWarning() { function hideWarning() {
return { return {
type: this.HIDE_WARNING, type: actions.HIDE_WARNING,
} }
} }
function requestExportAccount() { function requestExportAccount() {
return { return {
type: this.REQUEST_ACCOUNT_EXPORT, type: actions.REQUEST_ACCOUNT_EXPORT,
} }
} }
@ -478,21 +478,21 @@ function exportAccount(address) {
function showPrivateKey(key) { function showPrivateKey(key) {
return { return {
type: this.SHOW_PRIVATE_KEY, type: actions.SHOW_PRIVATE_KEY,
value: key, value: key,
} }
} }
function saveAccountLabel(account, label) { function saveAccountLabel(account, label) {
return (dispatch) => { return (dispatch) => {
dispatch(this.showLoadingIndication()) dispatch(actions.showLoadingIndication())
_accountManager.saveAccountLabel(account, label, (err) => { _accountManager.saveAccountLabel(account, label, (err) => {
dispatch(this.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
if (err) { if (err) {
return dispatch(this.showWarning(err.message)) return dispatch(actions.showWarning(err.message))
} }
dispatch({ dispatch({
type: this.SAVE_ACCOUNT_LABEL, type: actions.SAVE_ACCOUNT_LABEL,
value: { account, label }, value: { account, label },
}) })
}) })
@ -501,6 +501,6 @@ function saveAccountLabel(account, label) {
function showSendPage() { function showSendPage() {
return { return {
type: this.SHOW_SEND_PAGE, type: actions.SHOW_SEND_PAGE,
} }
} }