Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/actions/ControlActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,20 @@ export const getPeerInfo = () => (dispatch, getState) => {
})
.catch((error) => dispatch({ type: GETPEERINFO_FAILED, error }));
};

export const GETRECEIVEDBYADDRESS_ATTEMPT = "GETRECEIVEDBYADDRESS_ATTEMPT";
export const GETRECEIVEDBYADDRESS_FAILED = "GETRECEIVEDBYADDRESS_FAILED";
export const GETRECEIVEDBYADDRESS_SUCCESS = "GETRECEIVEDBYADDRESS_SUCCESS";

export const getReceivedByAddress = (address) => async (dispatch, getState) => {
dispatch({ type: GETRECEIVEDBYADDRESS_ATTEMPT });
const walletService = sel.walletService(getState());
try {
const { amount } = await wallet.getReceivedByAddress(walletService, address);
dispatch({ type: GETRECEIVEDBYADDRESS_SUCCESS });
return { isValid: true, amount };
} catch (error) {
dispatch({ error, type: GETRECEIVEDBYADDRESS_FAILED });
return { isValid: false, error };
}
};
33 changes: 11 additions & 22 deletions app/actions/TransactionActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
VSP_FEE_PROCESS_PAID
} from "constants";
import { TICKET, VOTE, VOTED, REVOKED } from "constants/Decrediton";
import { getNextAddressAttempt } from "./ControlActions";
import { getNextAddressAttempt, getReceivedByAddress } from "./ControlActions";
export const { TRANSACTION_TYPES } = wallet;

export const GETTRANSACTIONS_CANCEL = "GETTRANSACTIONS_CANCEL";
Expand All @@ -47,20 +47,14 @@ function checkAccountsToUpdate(txs, accountsToUpdate) {
return accountsToUpdate;
}

// getNewAccountAddresses get accounts which received new inputs and get
// new addresses for avoiding reuse.
export const getNewAccountAddresses = (txs) => (dispatch) => {
const acctAddressUpdated = [];
txs.forEach((tx) => {
tx.tx.getCreditsList().forEach((credit) => {
const acctNumber = credit.getAccount();
// if account address not updated yet, update it
if (acctAddressUpdated.find(eq(acctNumber)) === undefined) {
acctAddressUpdated.push(acctNumber);
dispatch(getNextAddressAttempt(acctNumber));
}
});
});
// getNewAccountAddress generates a new address for the current account if
// its current address was already used.
export const getNewAccountAddress = () => async (dispatch, getState) => {
const nextAddress = sel.nextAddress(getState());
const nextAddressAccountNumber = sel.nextAddressAccountNumber(getState());
const { isValid, amount } = await dispatch(getReceivedByAddress(nextAddress));
if (isValid && amount > 0)
dispatch(getNextAddressAttempt(nextAddressAccountNumber));
};

function checkForStakeTransactions(txs) {
Expand Down Expand Up @@ -179,13 +173,8 @@ export const newTransactionsReceived = (
accountsToUpdate = Array.from(new Set(accountsToUpdate));
accountsToUpdate.forEach((v) => dispatch(getBalanceUpdateAttempt(v, 0)));

// get new addresses for accounts which received decred
dispatch(
getNewAccountAddresses([
...newlyUnminedTransactions,
...newlyMinedTransactions
])
);
// get new address for the current account, if it already received decred
dispatch(getNewAccountAddress());

// Update mixer accounts balances
const changeAccount = sel.getChangeAccount(getState());
Expand Down
Loading