diff --git a/community_server/src/Controller/AppRequestsController.php b/community_server/src/Controller/AppRequestsController.php index dfc11d4a2..1993e3559 100644 --- a/community_server/src/Controller/AppRequestsController.php +++ b/community_server/src/Controller/AppRequestsController.php @@ -22,6 +22,7 @@ class AppRequestsController extends AppController { parent::initialize(); $this->loadComponent('JsonRequestClient'); + $this->loadComponent('GradidoNumber'); //$this->loadComponent('JsonRpcRequestClient'); //$this->Auth->allow(['add', 'edit']); $this->Auth->allow(['index', 'sendCoins', 'createCoins', 'getBalance', 'listTransactions']); @@ -115,9 +116,10 @@ class AppRequestsController extends AppController return $required_fields; } - if(intval($param['amount']) <= 0) { + if(floatval($param['amount']) <= 0.0) { return ['state' => 'error', 'msg' => 'amount is invalid', 'details' => $param['amount']]; } + $param['amount'] = $this->GradidoNumber->parseInputNumberToCentNumber($param['amount']); if(isset($data->memo)) { $param['memo'] = $data->memo; @@ -268,7 +270,7 @@ class AppRequestsController extends AppController public function getBalance($session_id = 0) { - + $this->viewBuilder()->setLayout('ajax'); $login_result = $this->requestLogin($session_id, false); if($login_result !== true) { return $this->returnJson($login_result); @@ -284,16 +286,18 @@ class AppRequestsController extends AppController return $this->returnJson(['state' => 'success', 'balance' => 0]); } $now = new FrozenTime(); - return $this->returnJson([ + $body = [ 'state' => 'success', 'balance' => $state_balance->amount, 'decay' => $state_balance->partDecay($now), 'decay_date' => $now - ]); + ]; + $this->set('body', $body); } public function listTransactions($page = 1, $count = 25, $orderDirection = 'ASC', $session_id = 0) { + $this->viewBuilder()->setLayout('ajax'); $startTime = microtime(true); $login_result = $this->requestLogin($session_id, false); if($login_result !== true) { @@ -337,14 +341,29 @@ class AppRequestsController extends AppController $transactions = array_reverse($transactions); } } - return $this->returnJson([ - 'state' => 'success', - 'transactions' => $transactions, - 'transactionExecutingCount' => $session->read('Transactions.executing'), - 'count' => count($transactions), - 'gdtSum' => $gdtSum, - 'timeUsed' => microtime(true) - $startTime - ]); + + $state_balance = $stateBalancesTable->find()->where(['state_user_id' => $user['id']])->first(); + + $body = [ + 'state' => 'success', + 'transactions' => $transactions, + 'transactionExecutingCount' => $session->read('Transactions.executing'), + 'count' => count($transactions), + 'gdtSum' => $gdtSum, + 'timeUsed' => microtime(true) - $startTime + ]; + $now = new FrozenTime(); + $body['decay_date'] = $now; + + if(!$state_balance) { + $body['balance'] = 0.0; + $body['decay'] = 0.0; + } else { + $body['balance'] = $state_balance->amount; + $body['decay'] = $state_balance->partDecay($now); + } + + $this->set('body', $body); } private function acquireAccessToken($session_id) diff --git a/community_server/src/Model/Entity/StateBalance.php b/community_server/src/Model/Entity/StateBalance.php index 0860d15b7..7d595653e 100644 --- a/community_server/src/Model/Entity/StateBalance.php +++ b/community_server/src/Model/Entity/StateBalance.php @@ -3,6 +3,7 @@ namespace App\Model\Entity; use Cake\ORM\Entity; use Cake\I18n\Time; +use Cake\I18n\Number; /** * StateBalance Entity @@ -34,7 +35,7 @@ class StateBalance extends Entity 'state_user' => true ]; - protected $_virtual = ['decay']; + protected $_virtual = ['decay','amount_float']; private function convertToTimestamp($dateOrTime) { @@ -67,6 +68,7 @@ class StateBalance extends Entity return intval($this->amount * pow(0.99999997802044727, $decay_duration)); } + public function partDecay($target_date) { $decay_duration = intval($this->convertToTimestamp($target_date) - $this->convertToTimestamp($this->record_date)); diff --git a/community_server/src/Model/Table/StateUsersTable.php b/community_server/src/Model/Table/StateUsersTable.php index f36f84d82..5b01609f3 100644 --- a/community_server/src/Model/Table/StateUsersTable.php +++ b/community_server/src/Model/Table/StateUsersTable.php @@ -122,9 +122,9 @@ class StateUsersTable extends Table // exchange back $involvedUserIds = array_flip($involvedUser_temp); $involvedUser = $this->find('all', [ - 'contain' => false, + 'contain' => [], 'where' => ['id IN' => $involvedUserIds], - 'fields' => ['id', 'first_name', 'last_name', 'email'] + 'fields' => ['id', 'first_name', 'last_name', 'email'], ]); //var_dump($involvedUser->toArray()); $involvedUserIndices = []; diff --git a/community_server/src/Model/Table/TransactionsTable.php b/community_server/src/Model/Table/TransactionsTable.php index b577afd7d..587b70c0f 100644 --- a/community_server/src/Model/Table/TransactionsTable.php +++ b/community_server/src/Model/Table/TransactionsTable.php @@ -6,7 +6,7 @@ use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; use Cake\ORM\TableRegistry; - +use Cake\I18n\Number; /** * Transactions Model * @@ -260,7 +260,7 @@ class TransactionsTable extends Table $state_balance->record_date = $su_transaction->balance_date; $final_transactions[] = [ 'type' => 'decay', - 'balance' => -intval($su_transaction->balance - $state_balance->decay), + 'balance' => floatval(intval($su_transaction->balance - $state_balance->decay)), 'decay_duration' => $su_transaction->balance_date->timeAgoInWords(), 'memo' => '' ]; diff --git a/community_server/src/Model/Transactions/TransactionTransfer.php b/community_server/src/Model/Transactions/TransactionTransfer.php index 26e41f0ad..3156e2cae 100644 --- a/community_server/src/Model/Transactions/TransactionTransfer.php +++ b/community_server/src/Model/Transactions/TransactionTransfer.php @@ -99,12 +99,12 @@ class TransactionTransfer extends TransactionBase { ->where(['public_key' => $senderPublic]) ->contain(['StateBalances' => ['fields' => ['amount', 'state_user_id']]])->first(); if(!$user) { - $this->addError($functionName, 'couldn\'t find sender ' . $i .' in db' ); + $this->addError($functionName, 'couldn\'t find sender in db' ); return false; } //var_dump($user); if(intval($user->state_balances[0]->amount) < intval($amount)) { - $this->addError($functionName, 'sender ' . $i . ' hasn\t enough GDD'); + $this->addError($functionName, 'sender hasn\t enough GDD'); return false; } @@ -116,7 +116,7 @@ class TransactionTransfer extends TransactionBase { // check if receiver exist $receiver_user = $stateUsersTable->find('all')->select(['id'])->where(['public_key' => $receiver_public_key])->first(); if(!$receiver_user) { - $this->addError($functionName, 'couldn\'t find receiver ' . $i .' in db' ); + $this->addError($functionName, 'couldn\'t find receiver in db' ); return false; } if($amount < 0) { diff --git a/community_server/src/Template/AppRequests/get_balance.ctp b/community_server/src/Template/AppRequests/get_balance.ctp new file mode 100644 index 000000000..618ec4c2e --- /dev/null +++ b/community_server/src/Template/AppRequests/get_balance.ctp @@ -0,0 +1,11 @@ +element('centToFloat', ['cent' => $body['balance'], 'precision' => 4]); +$body['decay'] = $this->element('centToFloat', ['cent' => $body['decay'], 'precision' => 4]); +?> \ No newline at end of file diff --git a/community_server/src/Template/AppRequests/list_transactions.ctp b/community_server/src/Template/AppRequests/list_transactions.ctp new file mode 100644 index 000000000..f829b5f16 --- /dev/null +++ b/community_server/src/Template/AppRequests/list_transactions.ctp @@ -0,0 +1,17 @@ +element('centToFloat', ['cent' => $body['balance'], 'precision' => 4]); +$body['decay'] = $this->element('centToFloat', ['cent' => $body['decay'], 'precision' => 4]); +$body['gdtSum'] = $this->element('centToFloat', ['cent' => $body['gdtSum'], 'precision' => 2]); + +foreach($body['transactions'] as $i => $transaction) { + $body['transactions'][$i]['balance'] = $this->element('centToFloat', ['cent' => $transaction['balance'], 'precision' => 4]); +} + +?> \ No newline at end of file diff --git a/community_server/src/Template/Element/centToFloat.ctp b/community_server/src/Template/Element/centToFloat.ctp new file mode 100644 index 000000000..2fade18b2 --- /dev/null +++ b/community_server/src/Template/Element/centToFloat.ctp @@ -0,0 +1,18 @@ + 0) { + $transformAmount = floor($cent / pow(10, $cut_places)); +} +if($cut_places < 0) { + $cut_places = 0; +} +echo $transformAmount / pow(10, $precision - $cut_places); + diff --git a/docu/community-server.api.md b/docu/community-server.api.md index 1c95c74b3..9354bf232 100644 --- a/docu/community-server.api.md +++ b/docu/community-server.api.md @@ -23,13 +23,13 @@ Additional session can be provided as GET-Parameter ```json { "state":"success", - "balance":15906078, + "balance":1590.60, "decay":15873851, "decay_date":"2021-04-16T11:47:21+00:00" } ``` -- `balance` : balance describes gradido cents which are 4 digits behind the separator. A balance value of 174500 equals therefor 17,45 GDD +- `balance` : balance describes gradido - `decay` : balance with decay on it at the time in decay_date, so it is the precise balance of user at time of calling this function - `decay_date`: date and time for decay amount, should be the time and date of function call @@ -65,7 +65,7 @@ Assuming: session is valid "type": "send", "transaction_id": 2, "date": "2021-02-19T13:25:36+00:00", - "balance": 1920000, + "balance": 192.0, "memo": "a piece of cake :)", "pubkey": "038a6f93270dc57b91d76bf110ad3863fcb7d1b08e7692e793fcdb4467e5b6a7" } @@ -95,7 +95,7 @@ Transaction: - `receiver`: user has received gradidos from another user - `transaction_id`: id of transaction in db, in stage2 also the hedera sequence number of transaction - `date`: date of ordering transaction (booking date) -- `balance`: Gradido Cent, 4 Nachkommastellen (2 Reserve), 1920000 = 192,00 GDD +- `balance`: Gradido - `memo`: Details about transaction ## Creation transaction @@ -245,4 +245,3 @@ Without auto-sign the transaction is pending on the login-server and waits for t // TODO Is this in line with our usability goals? // TODO Should this not be handled client side? - diff --git a/frontend/README.md b/frontend/README.md index 71dfcd39c..d94034c15 100755 --- a/frontend/README.md +++ b/frontend/README.md @@ -176,7 +176,7 @@ Wenn alles okay: "type": "creation|send|receive", "transaction_id": , // db id not id from blockchain "date": "", - "balance": , + "balance": , "memo": "", "pubkey": "" @@ -319,7 +319,7 @@ Wenn alles okay: "type": "creation|send|receive", "transaction_id": , // db id not id from blockchain "date": "", - "balance": , + "balance": , "memo": "", "pubkey": "" diff --git a/frontend/src/apis/communityAPI.js b/frontend/src/apis/communityAPI.js index 589794635..d2e71439c 100644 --- a/frontend/src/apis/communityAPI.js +++ b/frontend/src/apis/communityAPI.js @@ -35,8 +35,10 @@ const communityAPI = { balance: async (session_id) => { return apiGet(CONFIG.COMMUNITY_API_URL + 'getBalance/' + session_id) }, - transactions: async (session_id) => { - return apiGet(CONFIG.COMMUNITY_API_URL + 'listTransactions/1/25/ASC/' + session_id) + transactions: async (session_id, firstPage = 1, items = 25, order = 'DESC') => { + return apiGet( + `${CONFIG.COMMUNITY_API_URL}listTransactions/${firstPage}/${items}/${order}/${session_id}`, + ) }, /*create: async (session_id, email, amount, memo, target_date = new Date() ) => { const payload = { diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 363b8fbc6..b297bfc81 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -21,6 +21,7 @@ "form": { "attention": "Achtung! Bitte überprüfe alle deine Eingaben sehr genau. Du bist alleine Verantwortlich für deine Entscheidungen. Versendete Gradidos können nicht wieder zurück geholt werden.", "cancel":"Abbrechen", + "reset": "Zurücksetzen", "close":"schließen", "receiver":"Empfänger", "sender":"Absender", @@ -45,6 +46,9 @@ "thx":"Danke,", "send_success":"deine Transaktion wurde erfolgreich ausgeführt" }, + "error": { + "error":"Fehler" + }, "transaction":{ "show_all":"Alle {count} Transaktionen ansehen", "nullTransactions":"Du hast noch keine Transaktionen auf deinem Konto.", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 6f9a790d9..a49d6fc3d 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -21,6 +21,7 @@ "form": { "attention": "Achtung! Bitte überprüfe alle deine Eingaben sehr genau. Du bist alleine Verantwortlich für deine Entscheidungen. Versendete Gradidos können nicht wieder zurück geholt werden.", "cancel":"Cancel", + "reset": "Reset", "close":"Close", "receiver":"Receiver", "sender":"Sender", @@ -45,8 +46,12 @@ "thx":"Thank you,", "send_success":"your transaction was successfully completed" }, + "error": { + "error":"Error" + }, "transaction":{ - "show_part": "The last {count} transactions", + "show_all":"View all {count} transactions.", + "show_part": "The last {count} transactions.", "nullTransactions":"You don't have any transactions on your account yet.", "more": "more" }, diff --git a/frontend/src/views/Layout/AuthLayout_gdd.vue b/frontend/src/views/Layout/AuthLayout_gdd.vue index 5da4d8386..9aef55915 100644 --- a/frontend/src/views/Layout/AuthLayout_gdd.vue +++ b/frontend/src/views/Layout/AuthLayout_gdd.vue @@ -1,11 +1,9 @@