diff --git a/config/routes.php b/config/routes.php index 6d4870d..8c11f14 100644 --- a/config/routes.php +++ b/config/routes.php @@ -55,6 +55,7 @@ Router::scope('/', function (RouteBuilder $routes) { $routes->connect('/api/v1/address/:addr/tag', ['controller' => 'Main', 'action' => 'apiaddrtag'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]); $routes->connect('/api/v1/address/:addr/utxo', ['controller' => 'Main', 'action' => 'apiaddrutxo'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]); + $routes->connect('/api/v1/address/:addr/transactions', ['controller' => 'Main', 'action' => 'apiaddrtx'], ['addr' => '[A-Za-z0-9,]+', 'pass' => ['addr']]); $routes->connect('/api/v1/realtime/blocks', ['controller' => 'Main', 'action' => 'apirealtimeblocks']); $routes->connect('/api/v1/realtime/tx', ['controller' => 'Main', 'action' => 'apirealtimetx']); diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 4b99045..02c2a0f 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -406,6 +406,11 @@ class MainController extends AppController { return $this->redirect('/'); } + $offset = 0; + $pageLimit = 50; + $numTransactions = 0; + $page = intval($this->request->query('page')); + $canTag = false; $totalRecvAmount = 0; $totalSentAmount = 0; @@ -420,6 +425,7 @@ class MainController extends AppController { $tagRequestAmount = '25.' . rand(11111111, 99999999); } + $address = $this->Addresses->find()->where(['Address' => $addr])->first(); if (!$address) { if (strlen($addr) === 34) { @@ -434,16 +440,28 @@ class MainController extends AppController { $canTag = true; $addressId = $address->Id; + $stmt = $conn->execute('SELECT COUNT(TransactionId) AS Total FROM TransactionsAddresses WHERE AddressId = ?', [$addressId]); + $count = $stmt->fetch(\PDO::FETCH_OBJ); + $numTransactions = $count->Total; + $numPages = ceil($numTransactions / $pageLimit); + if ($page < 1) { + $page = 1; + } + if ($page > $numPages) { + $page = $numPages; + } + + $offset = ($page - 1) * $pageLimit; $stmt = $conn->execute('SELECT A.TotalReceived, A.TotalSent FROM Addresses A WHERE A.Id = ?', [$address->Id]); $totals = $stmt->fetch(\PDO::FETCH_OBJ); - $stmt = $conn->execute('SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' . + $stmt = $conn->execute(sprintf('SELECT T.Id, T.Hash, T.InputCount, T.OutputCount, T.Value, ' . 'TA.DebitAmount, TA.CreditAmount, ' . 'B.Height, B.Confirmations, IFNULL(T.TransactionTime, T.CreatedTime) AS TxTime ' . 'FROM Transactions T ' . 'LEFT JOIN Blocks B ON T.BlockHash = B.Hash ' . 'RIGHT JOIN (SELECT TransactionId, DebitAmount, CreditAmount FROM TransactionsAddresses ' . - ' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT 0, 20) TA ON TA.TransactionId = T.Id', [$addressId]); + ' WHERE AddressId = ? ORDER BY TransactionTime DESC LIMIT %d, %d) TA ON TA.TransactionId = T.Id', $offset, $pageLimit), [$addressId]); $recentTxs = $stmt->fetchAll(\PDO::FETCH_OBJ); $totalRecvAmount = $totals->TotalReceived == 0 ? '0' : $totals->TotalReceived + 0; @@ -451,6 +469,7 @@ class MainController extends AppController { $balanceAmount = bcsub($totalRecvAmount, $totalSentAmount, 8) + 0; } + $this->set('offset', $offset); $this->set('canTag', $canTag); $this->set('pending', $pending); $this->set('tagRequestAmount', $tagRequestAmount); @@ -459,6 +478,9 @@ class MainController extends AppController { $this->set('totalSent', $totalSentAmount); $this->set('balanceAmount', $balanceAmount); $this->set('recentTxs', $recentTxs); + $this->set('numTransactions', $numTransactions); + $this->set('numPages', $numPages); + $this->set('currentPage', $page); } public function qr($data = null) { diff --git a/src/Template/Main/address.ctp b/src/Template/Main/address.ctp index 3429809..38d1054 100644 --- a/src/Template/Main/address.ctp +++ b/src/Template/Main/address.ctp @@ -148,6 +148,14 @@

Recent Transactions

+
+ 0): + $begin = ($currentPage - 1) * 50 + 1; + ?> + Showing - of result + +
+ @@ -189,3 +197,62 @@
+ + 1): ?> + + \ No newline at end of file diff --git a/webroot/css/main.css b/webroot/css/main.css index 09e8d71..6303d93 100644 --- a/webroot/css/main.css +++ b/webroot/css/main.css @@ -247,12 +247,20 @@ footer .content .page-time { position: absolute; right: 12px; bottom: 0px; paddi .address-summary .box .value { font-size: 180%; font-weight: 300; margin-top: 8px } .address-summary .box.last { border-color: transparent } +.recent-transactions { position: relative } .recent-transactions h3 { font-weight: 300; margin: 0; margin-bottom: 12px } .recent-transactions { width: 1200px; margin: 48px auto 0 auto; box-shadow: 0 2px 6px rgba(0,0,0,.175); border: 1px solid rgba(0,0,0,.15); padding: 36px; cursor: default } +.recent-transactions .results-meta { position: absolute; right: 36px; top: 44px; font-size: 75%; color: #aaa } .tx-table td { vertical-align: top; line-height: 24px } .tx-table td.credit, .tx-table td div.credit { color: #00e676 } .tx-table td.debit, .tx-table td div.debit { color: #ff0000 } .tx-table td div.debit { padding-top: 8px } +.pagination { width: 1200px; margin: 36px auto 0 auto; cursor: default } +.pagination .prev { float: left; width: 20%; font-size: 75% } +.pagination .next { float: left; width: 20%; text-align: right; font-size: 75% } +.pagination .pages { float: left; width: 60%; text-align: center } +.pagination .pages .page-number { display: inline-block; width: 28px; height: 28px; line-height: 24px; text-align: center; font-size: 75% } + .clear { clear: both }