Fix MS17215: Auto-show Confirmed txns in Recent Activity when many Pending txns present

This commit is contained in:
Zach Fox 2018-08-01 15:34:53 -07:00
parent 7905c91289
commit 67528cb646
2 changed files with 72 additions and 11 deletions

View file

@ -142,7 +142,7 @@ Item {
Timer {
id: refreshTimer;
interval: 4000;
interval: 6000;
onTriggered: {
if (transactionHistory.atYBeginning) {
console.log("Refreshing 1st Page of Recent Activity...");
@ -211,6 +211,7 @@ Item {
HifiModels.PSFListModel {
id: transactionHistoryModel;
property int lastPendingCount: 0;
listModelName: "transaction history"; // For debugging. Alternatively, we could specify endpoint for that purpose, even though it's not used directly.
listView: transactionHistory;
itemsPerPage: 6;
@ -221,8 +222,26 @@ Item {
processPage: function (data) {
console.debug('processPage', transactionHistoryModel.listModelName, JSON.stringify(data));
var result, pending; // Set up or get the accumulator for pending.
if (transactionHistoryModel.currentPageToRetrieve == 1) {
pending = {transaction_type: "pendingCount", count: 0};
if (transactionHistoryModel.currentPageToRetrieve === 1) {
// The initial data elements inside the ListModel MUST contain all keys
// that will be used in future data.
pending = {
transaction_type: "pendingCount",
count: 0,
created_at: 0,
hfc_text: "",
id: "",
message: "",
place_name: "",
received_certs: 0,
received_money: 0,
recipient_name: "",
sender_name: "",
sent_certs: 0,
sent_money: 0,
status: "",
transaction_text: ""
};
result = [pending];
} else {
pending = transactionHistoryModel.get(0);
@ -239,6 +258,15 @@ Item {
}
});
if (lastPendingCount === 0) {
lastPendingCount = pending.count;
} else {
if (lastPendingCount !== pending.count) {
transactionHistoryModel.getNextPageIfNotEnoughVerticalResults();
}
lastPendingCount = pending.count;
}
// Only auto-refresh if the user hasn't scrolled
// and there is more data to grab
if (transactionHistory.atYBeginning && data.history.length) {
@ -257,13 +285,13 @@ Item {
ListView {
id: transactionHistory;
ScrollBar.vertical: ScrollBar {
policy: transactionHistory.contentHeight > parent.parent.height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded;
parent: transactionHistory.parent;
anchors.top: transactionHistory.top;
anchors.left: transactionHistory.right;
anchors.leftMargin: 4;
anchors.bottom: transactionHistory.bottom;
width: 20;
policy: transactionHistory.contentHeight > parent.parent.height ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded;
parent: transactionHistory.parent;
anchors.top: transactionHistory.top;
anchors.left: transactionHistory.right;
anchors.leftMargin: 4;
anchors.bottom: transactionHistory.bottom;
width: 20;
}
anchors.centerIn: parent;
width: parent.width - 12;
@ -340,7 +368,7 @@ Item {
}
HifiControlsUit.Separator {
colorScheme: 1;
colorScheme: 1;
anchors.left: parent.left;
anchors.right: parent.right;
anchors.bottom: parent.bottom;

View file

@ -38,6 +38,16 @@ ListModel {
onSearchFilterChanged: if (initialized) { getFirstPage('delayClear'); }
onTagsFilterChanged: if (initialized) { getFirstPage('delayClear'); }
// When considering a value for `itemsPerPage` in YOUR model, consider the following:
// - If your ListView delegates are of variable width/height, ensure you select
// an `itemsPerPage` value that would be sufficient to show one full page of data
// if all of the delegates were at their minimum heights.
// - If your first ListView delegate contains some special data (as in WalletHome's
// "Recent Activity" view), beware that your `itemsPerPage` value may _never_ reasonably be
// high enough such that the first page of data causes the view to be one-screen in height
// after retrieving the first page. This means data will automatically pop-in (after a short delay)
// until the combined heights of your View's delegates reach one-screen in height OR there is
// no more data to retrieve. See "needsMoreVerticalResults()" below.
property int itemsPerPage: 100;
// State.
@ -81,12 +91,35 @@ ListModel {
function getNextPageIfVerticalScroll() {
if (needsEarlyYFetch()) { getNextPage(); }
}
function needsMoreHorizontalResults() {
return flickable
&& currentPageToRetrieve > 0
&& flickable.contentWidth < flickable.width;
}
function needsMoreVerticalResults() {
return flickable
&& currentPageToRetrieve > 0
&& flickable.contentHeight < flickable.height;
}
function getNextPageIfNotEnoughHorizontalResults() {
if (needsMoreHorizontalResults()) {
getNextPage();
}
}
function getNextPageIfNotEnoughVerticalResults() {
if (needsMoreVerticalResults()) {
getNextPage();
}
}
Component.onCompleted: {
initialized = true;
if (flickable && pageAhead > 0.0) {
// Pun: Scrollers are usually one direction or another, such that only one of the following will actually fire.
flickable.contentXChanged.connect(getNextPageIfHorizontalScroll);
flickable.contentYChanged.connect(getNextPageIfVerticalScroll);
flickable.contentWidthChanged.connect(getNextPageIfNotEnoughHorizontalResults);
flickable.contentHeightChanged.connect(getNextPageIfNotEnoughVerticalResults);
}
}