Skip to content

Commit

Permalink
gui: Show pool payments. (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
jholdstock authored Oct 6, 2020
1 parent 78b5738 commit b45a0d3
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 119 deletions.
40 changes: 25 additions & 15 deletions gui/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import (
// accountPageData contains all of the necessary information to render the
// account template.
type accountPageData struct {
HeaderData headerData
MinedWork []*minedWork
ArchivedPayments []*archivedPayment
PendingPayments []*pendingPayment
ConnectedClients []*client
AccountID string
Address string
BlockExplorerURL string
HeaderData headerData
MinedWork []*minedWork
ArchivedPaymentsTotal string
ArchivedPayments []*archivedPayment
PendingPaymentsTotal string
PendingPayments []*pendingPayment
ConnectedClients []*client
AccountID string
Address string
BlockExplorerURL string
}

// account is the handler for "GET /account". Renders the account template if
Expand All @@ -43,6 +45,12 @@ func (ui *GUI) account(w http.ResponseWriter, r *http.Request) {
return
}

totalPending := ui.cache.getPendingPaymentsTotal(accountID)
totalArchived := ui.cache.getArchivedPaymentsTotal(accountID)

// We don't need to handle errors on the following cache access because we
// are passing hard-coded, good params.

// Get the 10 most recently mined blocks by this account.
_, recentWork, _ := ui.cache.getMinedWorkByAccount(0, 9, accountID)

Expand All @@ -61,13 +69,15 @@ func (ui *GUI) account(w http.ResponseWriter, r *http.Request) {
Designation: ui.cfg.Designation,
ShowMenu: true,
},
MinedWork: recentWork,
PendingPayments: pendingPmts,
ArchivedPayments: archivedPmts,
ConnectedClients: clients,
AccountID: accountID,
Address: address,
BlockExplorerURL: ui.cfg.BlockExplorerURL,
MinedWork: recentWork,
PendingPaymentsTotal: totalPending,
PendingPayments: pendingPmts,
ArchivedPaymentsTotal: totalArchived,
ArchivedPayments: archivedPmts,
ConnectedClients: clients,
AccountID: accountID,
Address: address,
BlockExplorerURL: ui.cfg.BlockExplorerURL,
}

ui.renderTemplate(w, "account", data)
Expand Down
29 changes: 25 additions & 4 deletions gui/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ package gui
import (
"net/http"

"github.com/decred/dcrpool/pool"
"github.com/gorilla/csrf"
"github.com/gorilla/sessions"
)

// adminPageData contains all of the necessary information to render the admin
// template.
type adminPageData struct {
HeaderData headerData
PoolStatsData poolStatsData
ConnectedClients map[string][]*client
HeaderData headerData
PoolStatsData poolStatsData
ConnectedClients map[string][]*client
ArchivedPaymentsTotal string
ArchivedPayments []*archivedPayment
PendingPaymentsTotal string
PendingPayments []*pendingPayment
}

// adminPage is the handler for "GET /admin". If the current session is
Expand All @@ -32,6 +37,18 @@ func (ui *GUI) adminPage(w http.ResponseWriter, r *http.Request) {

clients := ui.cache.getClients()

totalPending := ui.cache.getPendingPaymentsTotal(pool.PoolFeesK)
totalArchived := ui.cache.getArchivedPaymentsTotal(pool.PoolFeesK)

// We don't need to handle errors on the following cache access because we
// are passing hard-coded, good params.

// Get the 10 most recent pending payments.
_, pendingPmts, _ := ui.cache.getPendingPayments(0, 9, pool.PoolFeesK)

// Get the 10 most recent archived payments.
_, archivedPmts, _ := ui.cache.getArchivedPayments(0, 9, pool.PoolFeesK)

pageData := adminPageData{
HeaderData: headerData{
CSRF: csrf.TemplateField(r),
Expand All @@ -47,7 +64,11 @@ func (ui *GUI) adminPage(w http.ResponseWriter, r *http.Request) {
PoolFee: ui.cfg.PoolFee,
SoloPool: ui.cfg.SoloPool,
},
ConnectedClients: clients,
ConnectedClients: clients,
PendingPaymentsTotal: totalPending,
PendingPayments: pendingPmts,
ArchivedPaymentsTotal: totalArchived,
ArchivedPayments: archivedPmts,
}

ui.renderTemplate(w, "admin", pageData)
Expand Down
5 changes: 5 additions & 0 deletions gui/assets/public/css/dcrpool.css
Original file line number Diff line number Diff line change
Expand Up @@ -8781,6 +8781,11 @@ table td {
padding-bottom: 10px;
}

.block__content h2 {
color: #3D5873;
font-size: 22px;
}

.dcr-label {
background: #D3F0FD 0% 0% no-repeat padding-box;
border-radius: 3px;
Expand Down
39 changes: 39 additions & 0 deletions gui/assets/public/js/admin-pagination.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$.fn["pagination"].defaults.locator = "data";
$.fn["pagination"].defaults.totalNumberLocator = function(response) { return response.count; };
$.fn["pagination"].defaults.nextText = '<div class="pagination-arrow pagination-arrow-right"></div>';
$.fn["pagination"].defaults.prevText = '<div class="pagination-arrow pagination-arrow-left"></div>';
$.fn["pagination"].defaults.hideWhenLessThanOnePage = true;

if ($('#pending-payments-page-select').length) {
$('#pending-payments-page-select').pagination({
dataSource: "/admin/payments/pending",
callback: function (data) {
var html = '';
if (data.length > 0) {
$.each(data, function (_, item) {
html += '<tr><td><a href="' + item.workheighturl + '" rel="noopener noreferrer">' + item.workheight + '</a></td><td>' + item.createdon + '</td><td>' + item.amount + '</td></tr>';
});
} else {
html += '<tr><td colspan="100%"><span class="no-data">No pending payments</span></td></tr>';
}
$('#pending-payments-table').html(html);
}
});
};

if ($('#archived-payments-page-select').length) {
$('#archived-payments-page-select').pagination({
dataSource: "/admin/payments/archived",
callback: function (data) {
var html = '';
if (data.length > 0) {
$.each(data, function (_, item) {
html += '<tr><td><a href="' + item.workheighturl + '" rel="noopener noreferrer">' + item.workheight + '</a></td><td><a href="' + item.paidheighturl + '" rel="noopener noreferrer">' + item.paidheight + '</a></td><td>' + item.createdon + '</td><td>' + item.amount + '</td><td><a href="' + item.txurl + '" rel="noopener noreferrer">' + item.txid + '</a></td></tr>';
});
} else {
html += '<tr><td colspan="100%"><span class="no-data">No received payments</span></td></tr>';
}
$('#archived-payments-table').html(html);
}
});
};
77 changes: 1 addition & 76 deletions gui/assets/templates/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,84 +35,9 @@ <h1>Account Information</h1>


<div class="container">

{{ if .PendingPayments }}
<div class="row">
<div class="col-12 p-3">
<div class="block__content">

<h1>Pending Payments</h1>

<table class="table">
<thead>
<tr>
<th>Work Height</th>
<th>Created On</th>
<th>Amount</th>
</tr>
</thead>
<tbody id="pending-payments-table">
{{ range .PendingPayments }}
<tr>
<td><a href="{{ .WorkHeightURL }}"
rel="noopener noreferrer">{{ .WorkHeight }}</a></td>
<td>{{ .CreatedOn }}</td>
<td>{{ .Amount }}</td>
</tr>
{{end}}
</tbody>
</table>

<div id="pending-payments-page-select" class="page-select"></div>

</div>
</div>
</div>
{{end}}
{{template "payments" . }}

<div class="row">
<div class="col-12 p-3">
<div class="block__content">
<h1>Payments Received</h1>

<table class="table">
<thead>
<tr>
<th>Work Height</th>
<th>Payment Height</th>
<th>Created On</th>
<th>Amount</th>
<th>Tx ID</th>
</tr>
</thead>
<tbody id="archived-payments-table">
{{ range .ArchivedPayments }}
<tr>
<td><a href="{{ .WorkHeightURL }}"
rel="noopener noreferrer">{{ .WorkHeight }}</a></td>
<td><a href="{{ .PaidHeightURL }}"
rel="noopener noreferrer">{{ .PaidHeight }}</a></td>
<td>{{ .CreatedOn }}</td>
<td>{{ .Amount }}</td>
<td><a href="{{ .TxURL }}"
rel="noopener noreferrer">{{ .TxID }}</a>
</td>
</tr>
{{else}}
<tr>
<td colspan="100%"><span class="no-data">No payments received by account</span></td>
</tr>
{{end}}
</tbody>
</table>

<div id="archived-payments-page-select" class="page-select"></div>

</div>
</div>

</div>

<div class="row">

<div class="col-lg-6 col-12 p-3">
Expand Down
3 changes: 3 additions & 0 deletions gui/assets/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ <h1>All Connected Miners</h1>

</div>

{{template "payments" . }}

</div>

<script src='/assets/js/socket.js'></script>
<script src='/assets/js/admin-pagination.js'></script>

</body>
</html>
Expand Down
93 changes: 93 additions & 0 deletions gui/assets/templates/payments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{{define "payments"}}

{{ if .PendingPayments }}
<div class="row">
<div class="col-12 p-3">
<div class="block__content">

<div class="d-flex flex-wrap">
<h1 class="mr-auto text-nowrap">Pending Payments</h1>

<h2 class="row mr-1">
Total:&nbsp;{{ .PendingPaymentsTotal }}
</h2>
</div>

<table class="table">
<thead>
<tr>
<th>Work Height</th>
<th>Created On</th>
<th>Amount</th>
</tr>
</thead>
<tbody id="pending-payments-table">
{{ range .PendingPayments }}
<tr>
<td><a href="{{ .WorkHeightURL }}"
rel="noopener noreferrer">{{ .WorkHeight }}</a></td>
<td>{{ .CreatedOn }}</td>
<td>{{ .Amount }}</td>
</tr>
{{end}}
</tbody>
</table>

<div id="pending-payments-page-select" class="page-select"></div>

</div>
</div>
</div>
{{end}}

<div class="row">
<div class="col-12 p-3">
<div class="block__content">

<div class="d-flex flex-wrap">
<h1 class="mr-auto text-nowrap">Payments Received</h1>

<h2 class="row mr-1">
Total:&nbsp;{{ .ArchivedPaymentsTotal }}
</h2>
</div>

<table class="table">
<thead>
<tr>
<th>Work Height</th>
<th>Payment Height</th>
<th>Created On</th>
<th>Amount</th>
<th>Tx ID</th>
</tr>
</thead>
<tbody id="archived-payments-table">
{{ range .ArchivedPayments }}
<tr>
<td><a href="{{ .WorkHeightURL }}"
rel="noopener noreferrer">{{ .WorkHeight }}</a></td>
<td><a href="{{ .PaidHeightURL }}"
rel="noopener noreferrer">{{ .PaidHeight }}</a></td>
<td>{{ .CreatedOn }}</td>
<td>{{ .Amount }}</td>
<td><a href="{{ .TxURL }}"
rel="noopener noreferrer">{{ .TxID }}</a>
</td>
</tr>
{{else}}
<tr>
<td colspan="100%"><span class="no-data">No payments received</span></td>
</tr>
{{end}}
</tbody>
</table>

<div id="archived-payments-page-select" class="page-select"></div>

</div>
</div>

</div>

{{end}}
Loading

0 comments on commit b45a0d3

Please sign in to comment.