fix bug with missing decay in last transaction

This commit is contained in:
Dario Rekowski on RockPI 2021-07-07 13:06:12 +00:00
parent 8413ca56f7
commit 1dadb58086
2 changed files with 13 additions and 5 deletions

View File

@ -25,7 +25,7 @@ class AppRequestsController extends AppController
$this->loadComponent('GradidoNumber');
//$this->loadComponent('JsonRpcRequestClient');
//$this->Auth->allow(['add', 'edit']);
$this->Auth->allow(['index', 'sendCoins', 'createCoins', 'getBalance', 'listTransactions']);
$this->Auth->allow(['index', 'sendCoins', 'createCoins', 'getBalance', 'listTransactions', 'getDecayStartBlock']);
}
@ -335,11 +335,18 @@ class AppRequestsController extends AppController
$limit = $count;
$offset = 0;
$skip_first_transaction = false;
if($page == 1) {
$limit--;
} else {
$offset = (( $page - 1 ) * $count) - 1;
}
if($offset) {
// move cursor one step backwards to able to load one transaction previous last which will be shown for decay calculation
$offset--;
$limit++;
$skip_first_transaction = true;
}
$stateUserTransactionsQuery = $stateUserTransactionsTable
->find()
@ -362,7 +369,7 @@ class AppRequestsController extends AppController
$transactions_from_db = array_reverse($transactions_from_db);
}
$transactions = $transactionsTable->listTransactionsHumanReadable($transactions_from_db, $user, $decay);
$transactions = $transactionsTable->listTransactionsHumanReadable($transactions_from_db, $user, $decay, $skip_first_transaction);
if($orderDirection == 'DESC') {
$transactions = array_reverse($transactions);

View File

@ -133,7 +133,7 @@ class TransactionsTable extends Table
}
public function listTransactionsHumanReadable($stateUserTransactions, array $user, $decay = true)
public function listTransactionsHumanReadable($stateUserTransactions, array $user, $decay = true, $skip_first_transaction = false)
{
$stateUsersTable = TableRegistry::getTableLocator()->get('StateUsers');
@ -267,8 +267,9 @@ class TransactionsTable extends Table
$final_transaction['name'] = $otherUser->first_name . ' ' . $otherUser->last_name;
$final_transaction['email'] = $otherUser->email;
}
$final_transactions[] = $final_transaction;
if($i > 0 || !$skip_first_transaction) {
$final_transactions[] = $final_transaction;
}
if($i == $stateUserTransactionsCount-1 && $decay) {
$now = new FrozenTime();