diff --git a/community_server/src/Controller/AppRequestsController.php b/community_server/src/Controller/AppRequestsController.php index 15c68cece..4b81b8ac9 100644 --- a/community_server/src/Controller/AppRequestsController.php +++ b/community_server/src/Controller/AppRequestsController.php @@ -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,21 @@ class AppRequestsController extends AppController $limit = $count; $offset = 0; + $skip_first_transaction = false; if($page == 1) { $limit--; } else { $offset = (( $page - 1 ) * $count) - 1; } + if($offset && $orderDirection == 'ASC') { + // 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; + } else if($orderDirection == 'DESC') { + $limit++; + $skip_first_transaction = true; + } $stateUserTransactionsQuery = $stateUserTransactionsTable ->find() @@ -362,7 +372,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); @@ -393,6 +403,16 @@ class AppRequestsController extends AppController $this->set('body', $body); } + public function getDecayStartBlock() + { + $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); + $decayStartBlock = $transactionsTable->find()->where(['transaction_type_id' => 9]); + if(!$decayStartBlock->count()) { + return $this->returnJson(['state' => 'error', 'msg' => 'not found']); + } + return $this->returnJson(['state' => 'success', 'decay_start' => $decayStartBlock->first()->received]); + } + private function acquireAccessToken($session_id) { diff --git a/community_server/src/Model/Table/TransactionsTable.php b/community_server/src/Model/Table/TransactionsTable.php index 8fcd81489..925f6f31e 100644 --- a/community_server/src/Model/Table/TransactionsTable.php +++ b/community_server/src/Model/Table/TransactionsTable.php @@ -133,11 +133,12 @@ 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'); $stateBalancesTable = TableRegistry::getTableLocator()->get('StateBalances'); + $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); $transaction_ids = []; $involved_user_ids = []; @@ -162,11 +163,15 @@ class TransactionsTable extends Table $state_balance = $stateBalancesTable->newEntity(); $final_transactions = []; + $decay_start_transaction = $transactionsTable->find()->where(['transaction_type_id' => 9]); + $decay_start_transaction_id = 0; + if($decay_start_transaction->count()) { + $decay_start_transaction_id = $decay_start_transaction->first()->id; + } + $decay_start_time = $stateBalancesTable->getDecayStartDateCached()->getTimestamp(); foreach($stateUserTransactions as $i => $su_transaction) { - - // sender or receiver when user has sended money // group name if creation // type: gesendet / empfangen / geschöpft @@ -187,7 +192,8 @@ class TransactionsTable extends Table } if($prev) { - if($prev->balance > 0) { + if($prev->balance > 0) + { $current = $su_transaction; $calculated_decay = $stateBalancesTable->calculateDecay($prev->balance, $prev->balance_date, $current->balance_date, true); $balance = floatval($prev->balance - $calculated_decay['balance']); @@ -199,7 +205,19 @@ class TransactionsTable extends Table 'decay_duration' => $calculated_decay['interval']->format('%a days, %H hours, %I minutes, %S seconds'), 'decay_start' => $calculated_decay['start_date'], 'decay_end' => $calculated_decay['end_date'] - ]; + ]; + if($prev->transaction_id < $decay_start_transaction_id && + $current->transaction_id > $decay_start_transaction_id) { + $final_transaction['decay']['decay_start_block'] = $decay_start_time; + } + // hint: use transaction id + /*if($calculated_decay['start_date'] < $decay_start_time && $calculated_decay['end_date'] > $decay_start_time) { + $final_transaction['decay']['decay_start_block'] = $decay_start_time; + } else { + echo "start block: " . $decay_start_time . "
"; + echo "start date: " . $calculated_decay['start_date'] . "
"; + echo "end date: " . $calculated_decay['end_date']. "
"; + }*/ } } } @@ -249,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(); diff --git a/community_server/tests/TestCase/Controller/AppRequestControllerTest.php b/community_server/tests/TestCase/Controller/AppRequestControllerTest.php index 5aeb64d8b..5ee1f3c53 100644 --- a/community_server/tests/TestCase/Controller/AppRequestControllerTest.php +++ b/community_server/tests/TestCase/Controller/AppRequestControllerTest.php @@ -205,11 +205,12 @@ class AppRequestControllerTest extends TestCase "transaction_id": 7, "date": "2021-04-14T09:02:28+00:00", "memo": "test time 3", - "decay": { + "decay": { "balance": 6, "decay_duration": "0 days, 00 hours, 00 minutes, 28 seconds", "decay_start": 1618390920, - "decay_end": 1618390948 + "decay_end": 1618390948, + "decay_start_block": 1618390920 }, "balance": 100000, "type": "receive", @@ -237,7 +238,7 @@ class AppRequestControllerTest extends TestCase "transaction_id": 9, "date": "2021-04-14T09:31:28+00:00", "memo": "test login crash", - "decay": { + "decay": { "balance": 33, "decay_duration": "0 days, 00 hours, 02 minutes, 42 seconds", "decay_start": 1618392526, @@ -251,20 +252,20 @@ class AppRequestControllerTest extends TestCase }, { "type": "decay", - "balance": 1222493, + "balance": 1345726, "decay_duration": "on 14.04.21", "decay_start": 1618392688, - "decay_end": 1624956464, + "decay_end": 1625673853, "memo": "" } ], "transactionExecutingCount": 0, "count": 7, "gdtSum": 180000, - "timeUsed": 0.6441609859466553, - "decay_date": "2021-06-29T08:47:44+00:00", + "timeUsed": 0.44154810905456545, + "decay_date": "2021-07-07T16:04:13+00:00", "balance": 9099652, - "decay": 7877159 + "decay": 7753926 }'; $this->getAndParse('/api/list-transactions/', json_decode($expectedResult, true)); } diff --git a/frontend/src/components/DecayInformation.vue b/frontend/src/components/DecayInformation.vue new file mode 100644 index 000000000..8a134b490 --- /dev/null +++ b/frontend/src/components/DecayInformation.vue @@ -0,0 +1,97 @@ + + diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 3904cd7f7..7de64ff6a 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -18,7 +18,25 @@ "de": "Deutsch", "en": "English" }, - "decay": "Vergänglichkeit", + "decay": { + "decay": "Vergänglichkeit", + "decay_since_last_transaction":"Vergänglichkeit seit der letzten Transaktion", + "calculation_decay":"Berechnung der Vergänglichkeit", + "Starting_block_decay":"Startblock Vergänglichkeit", + "decay_introduced":"Die Vergänglichkeit wurde Eingeführt am", + "last_transaction":"Letzte Transaktion", + "past_time":"Vergangene Zeit", + "since_introduction":"seit Einführung der Vergänglichkeit", + "year":"Jahre", + "months":"Monate", + "days":"Tage", + "hours":"Stunden", + "minutes":"Minuten", + "seconds":"Sekunden", + "received":"empfangen", + "sent":"gesendet", + "created":"geschöpft" + }, "form": { "cancel": "Abbrechen", "reset": "Zurücksetzen", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 95016d810..ac75c90f0 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -18,7 +18,25 @@ "de": "Deutsch", "en": "English" }, - "decay": "Decay", + "decay": { + "decay": "Decay", + "decay_since_last_transaction":"Decay since the last transaction", + "calculation_decay": "Calculation of Decay", + "Starting_block_decay": "Starting Block Decay", + "decay_introduced": "Decay was Introduced on", + "last_transaction": "Last transaction:", + "past_time": "Past time", + "since_introduction": "Since the introduction of Decay", + "year": "Years", + "months": "Months", + "days": "Days", + "hours": "Hours", + "minutes": "Minutes", + "seconds": "Seconds", + "received":"received", + "sent":"sent", + "created":"created" + }, "form": { "cancel":"Cancel", "reset": "Reset", diff --git a/frontend/src/views/Pages/AccountOverview.vue b/frontend/src/views/Pages/AccountOverview.vue index b47a6fbf2..08eb503ad 100644 --- a/frontend/src/views/Pages/AccountOverview.vue +++ b/frontend/src/views/Pages/AccountOverview.vue @@ -30,7 +30,7 @@ { }) it('shows the name of the receiver', () => { - expect(transaction.findAll('div').at(3).text()).toBe('decay') + expect(transaction.findAll('div').at(3).text()).toBe('decay.decay_since_last_transaction') }) }) }) diff --git a/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue b/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue index fdc3a7607..35ff5c5bd 100644 --- a/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue +++ b/frontend/src/views/Pages/AccountOverview/GddTransactionList.vue @@ -2,69 +2,79 @@
-
+ +
+
- +
+
- {{ getProperties(item).operator }} - {{ $n(item.balance, 'decimal') }} + {{ getProperties(type).operator }} + {{ $n(balance, 'decimal') }} + + {{ $n(balance, 'decimal') }} + +
+
+ +
+
- {{ item.name ? item.name : $t('decay') }} -
{{ $d($moment(item.date), 'long') }}
+ {{ name ? name : '' }} + + {{ $t('decay.decay_since_last_transaction') }} + +
{{ $d($moment(date), 'long') }}
+
-
+ +
i
- - - - - {{ $t('form.receiver') }} - {{ item.name }} - - - {{ $t('form.sender') }} - {{ item.name }} - - - - type - {{ item.type }} - - - id - {{ item.transaction_id }} - - - {{ $t('form.date') }} - {{ item.date }} - - - gdd - {{ item.balance }} - - - {{ $t('form.memo') }} - {{ item.memo }} - - - - {{ $t('transaction.more') }} - - - {{ item }} - - + + + + + +
+
+ {{ type === 'receive' ? 'von:' : 'an:' }} +
+
+ {{ name }} + +
+
+
+
+ {{ type === 'receive' ? 'Nachricht:' : 'Nachricht:' }} +
+
+ {{ memo }} +
+
+
+
+ + +
+
Schöpfung
+
Aus der Community
+
+
+
+
+ import PaginationButtons from '../../../components/PaginationButtons' +import DecayInformation from '../../../components/DecayInformation' const iconsByType = { send: { icon: 'arrow-left-circle', classes: 'text-danger', operator: '-' }, @@ -96,10 +107,12 @@ export default { name: 'gdd-transaction-list', components: { PaginationButtons, + DecayInformation, }, data() { return { currentPage: 1, + startDecay: 0, } }, props: { @@ -133,8 +146,8 @@ export default { items: this.pageSize, }) }, - getProperties(item) { - const type = iconsByType[item.type] + getProperties(givenType) { + const type = iconsByType[givenType] if (type) return { icon: type.icon,