Skip to content

Commit

Permalink
[tickets] Add search limit for live tickets (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 committed Dec 14, 2020
1 parent b636bd8 commit c4c6ee3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 23 deletions.
16 changes: 11 additions & 5 deletions app/actions/TransactionActions.js
Expand Up @@ -514,7 +514,7 @@ export const getTransactions = (isStake) => async (dispatch, getState) => {
stakeTransactions,
regularTransactions
} = getState().grpc;
let { noMoreTransactions, lastTransaction } = isStake
let { noMoreTransactions, lastTransaction, noMoreLiveTickets } = isStake
? getStakeTxsAux
: getRegularTxsAux;
const listDirection = isStake
Expand All @@ -541,15 +541,20 @@ export const getTransactions = (isStake) => async (dispatch, getState) => {
unmined = await normalizeBatchTx(walletService, chainParams, unmined);
transactions.push(...unmined);

const reachedGenesis = false;

let startRequestHeight, endRequestHeight;
while (!noMoreTransactions && !reachedGenesis) {
while (!noMoreTransactions) {
if (listDirection === DESC) {
endRequestHeight = 1;
startRequestHeight = lastTransaction
? lastTransaction.height - 1
: currentBlockHeight;
// if already down ticket expiry + coinbase maturity, than no more live tickets
// will be find.
if (
currentBlockHeight - chainParams.TicketExpiry - chainParams.CoinbaseMaturity > startRequestHeight
) {
noMoreLiveTickets = true;
}
// Reached genesis.
if (startRequestHeight < 1) {
noMoreTransactions = true;
Expand Down Expand Up @@ -611,7 +616,8 @@ export const getTransactions = (isStake) => async (dispatch, getState) => {
getStakeTxsAux,
stakeTransactions,
regularTransactions,
startRequestHeight
startRequestHeight,
noMoreLiveTickets
});
};

Expand Down
20 changes: 14 additions & 6 deletions app/components/indicators/LoadingMoreTickets/LoadingMoreTickets.js
Expand Up @@ -26,7 +26,8 @@ const AscMessage = ({ startRequestHeight, currentBlockHeight }) => (
);

const LoadingMoreTicketsIndicator = ({
className
className,
isLiveTickets
}) => {
const {
startRequestHeight,
Expand Down Expand Up @@ -75,11 +76,18 @@ const LoadingMoreTicketsIndicator = ({
m="Loading more tickets..."
/>
<div className="loading-more-tickets-progress-line">
{ticketsFilter.listDirection === "desc" ? (
<DescMessage {...{ startRequestHeight, currentBlockHeight }} />
) : (
<AscMessage {...{ startRequestHeight, currentBlockHeight }} />
)}
{
// removing this for now on live tickets, but it should
// have its own proportion between 0-100%
!isLiveTickets && (
ticketsFilter.listDirection === "desc" ? (
<DescMessage {...{ startRequestHeight, currentBlockHeight }} />
) : (
<AscMessage {...{ startRequestHeight, currentBlockHeight }} />
)
)
}
{}
</div>
</>
</div>
Expand Down
Expand Up @@ -58,13 +58,14 @@ const MyVSPTickets = ({ toggleIsLegacy }) => {
ticketsFilter,
window,
goBackHistory,
getTickets,
getLiveTickets,
changeTicketsFilter,
vspTickets,
getVSPTicketsByFeeStatus,
hasVSPTicketsError,
defaultSpendingAccount,
syncVSPTicketsRequest
syncVSPTicketsRequest,
noMoreLiveTickets
} = useVSPTicketsList();

const [tickets, setTickets] = useState([]);
Expand Down Expand Up @@ -138,15 +139,16 @@ const MyVSPTickets = ({ toggleIsLegacy }) => {
onChangeSortType,
onChangeSelectedType,
tsDate,
getTickets,
getLiveTickets,
goBackHistory,
noMoreTickets,
hasVSPTicketsError,
account,
setAccount,
vsp,
setVSP,
onSyncVspTicketsRequest
onSyncVspTicketsRequest,
noMoreLiveTickets
}}
/>
);
Expand Down
11 changes: 6 additions & 5 deletions app/components/views/TicketsPage/VSPTicketsStatusTab/Page.jsx
Expand Up @@ -33,7 +33,7 @@ const subtitleMenu = ({
const TicketListPage = ({
tickets,
noMoreTickets,
getTickets,
getLiveTickets,
onChangeSortType,
onChangeSelectedType,
selectedSortOrderKey,
Expand All @@ -46,15 +46,16 @@ const TicketListPage = ({
setVSP,
setAccount,
onSyncVspTicketsRequest,
isValid
isValid,
noMoreLiveTickets
}) => {
const isOverview = window.innerWidth < 768; // small width
const loadMoreThreshold = 90 + Math.max(0, window.innerHeight - 765);

return (
<InfiniteScroll
hasMore={!noMoreTickets}
loadMore={() => getTickets(true)}
loadMore={() => getLiveTickets(true)}
initialLoad={!noMoreTickets}
useWindow={false}
threshold={loadMoreThreshold}>
Expand Down Expand Up @@ -121,8 +122,8 @@ const TicketListPage = ({
/>
</>
)}
{!noMoreTickets ? (
<LoadingMoreTicketsIndicator />
{!noMoreLiveTickets ? (
<LoadingMoreTicketsIndicator isLiveTickets={true} />
) : tickets.length > 0 ? (
<NoMoreTicketsIndicator />
) : (
Expand Down
13 changes: 10 additions & 3 deletions app/components/views/TicketsPage/VSPTicketsStatusTab/hooks.js
Expand Up @@ -14,11 +14,17 @@ export const useVSPTicketsList = () => {
const window = useSelector(sel.mainWindow);
const hasVSPTicketsError = useSelector(sel.getHasVSPTicketsError);
const defaultSpendingAccount = useSelector(sel.defaultSpendingAccount);
const noMoreLiveTickets = useSelector(sel.getNoMoreLiveTickets);

// actions
const dispatch = useDispatch();
const goBackHistory = () => dispatch(ca.goBackHistory());
const getTickets = (isStake) => dispatch(ta.getTransactions(isStake));
const getLiveTickets = (isStake) => {
if (noMoreLiveTickets) {
return;
}
dispatch(ta.getTransactions(isStake));
};
const changeTicketsFilter = (newFilter) =>
dispatch(ta.changeTicketsFilter(newFilter));
const getVSPTicketsByFeeStatus = (feeStatus) => dispatch(vspa.getVSPTicketsByFeeStatus(feeStatus));
Expand All @@ -30,12 +36,13 @@ export const useVSPTicketsList = () => {
ticketsFilter,
window,
goBackHistory,
getTickets,
getLiveTickets,
changeTicketsFilter,
getVSPTicketsByFeeStatus,
vspTickets,
hasVSPTicketsError,
defaultSpendingAccount,
syncVSPTicketsRequest
syncVSPTicketsRequest,
noMoreLiveTickets
};
};
2 changes: 2 additions & 0 deletions app/index.js
Expand Up @@ -181,6 +181,8 @@ const initialState = {
// GetTransactions
// requestHeight of last getTransaction call
startRequestHeight: null,
// noMoreLiveTickets check if no more live tickets can be find.
noMoreLiveTickets: null,
// stakeTransactionsCancel checks if a stake transaction is canceled from
// getting more transactions.
stakeTransactionsCancel: false,
Expand Down
1 change: 1 addition & 0 deletions app/reducers/grpc.js
Expand Up @@ -402,6 +402,7 @@ export default function grpc(state = {}, action) {
getRegularTxsAux: action.getRegularTxsAux || state.getStakeTxsAux,
getStakeTxsAux: action.getStakeTxsAux || state.getStakeTxsAux,
getTransactionsRequestAttempt: false,
noMoreLiveTickets: action.noMoreLiveTickets,
startRequestHeight:
action.startRequestHeight || state.startRequestHeight
};
Expand Down
1 change: 1 addition & 0 deletions app/selectors.js
Expand Up @@ -987,6 +987,7 @@ export const getTransactionsRequestAttempt = get([
export const notifiedBlockHeight = get(["notifications", "currentHeight"]);

export const currentBlockHeight = get(["grpc", "currentBlockHeight"]);
export const getNoMoreLiveTickets = get(["grpc", "noMoreLiveTickets"]);

export const rescanEndBlock = currentBlockHeight;
export const rescanStartBlock = compose(
Expand Down

0 comments on commit c4c6ee3

Please sign in to comment.