Show more info about bitcoin average quota

This commit is contained in:
nicolas.dorier 2018-04-20 01:01:39 +09:00
parent 41978f1c59
commit 3822358096
4 changed files with 46 additions and 28 deletions

View file

@ -374,7 +374,7 @@ namespace BTCPayServer.Controllers
model.Invoices.Add(new InvoiceModel() model.Invoices.Add(new InvoiceModel()
{ {
Status = invoice.Status, Status = invoice.Status,
Date = Prettify(invoice.InvoiceTime), Date = (DateTimeOffset.UtcNow - invoice.InvoiceTime).Prettify() + " ago",
InvoiceId = invoice.Id, InvoiceId = invoice.Id,
OrderId = invoice.OrderId ?? string.Empty, OrderId = invoice.OrderId ?? string.Empty,
RedirectUrl = invoice.RedirectURL ?? string.Empty, RedirectUrl = invoice.RedirectURL ?? string.Empty,
@ -387,30 +387,6 @@ namespace BTCPayServer.Controllers
return View(model); return View(model);
} }
private string Prettify(DateTimeOffset invoiceTime)
{
var ago = DateTime.UtcNow - invoiceTime;
if (ago.TotalMinutes < 1)
{
return $"{(int)ago.TotalSeconds} second{Plural((int)ago.TotalSeconds)} ago";
}
if (ago.TotalHours < 1)
{
return $"{(int)ago.TotalMinutes} minute{Plural((int)ago.TotalMinutes)} ago";
}
if (ago.Days < 1)
{
return $"{(int)ago.TotalHours} hour{Plural((int)ago.TotalHours)} ago";
}
return $"{(int)ago.TotalDays} day{Plural((int)ago.TotalDays)} ago";
}
private string Plural(int totalDays)
{
return totalDays > 1 ? "s" : string.Empty;
}
[HttpGet] [HttpGet]
[Route("invoices/create")] [Route("invoices/create")]
[Authorize(AuthenticationSchemes = "Identity.Application")] [Authorize(AuthenticationSchemes = "Identity.Application")]

View file

@ -34,6 +34,28 @@ namespace BTCPayServer
{ {
public static class Extensions public static class Extensions
{ {
public static string Prettify(this TimeSpan timeSpan)
{
if (timeSpan.TotalMinutes < 1)
{
return $"{(int)timeSpan.TotalSeconds} second{Plural((int)timeSpan.TotalSeconds)}";
}
if (timeSpan.TotalHours < 1)
{
return $"{(int)timeSpan.TotalMinutes} minute{Plural((int)timeSpan.TotalMinutes)}";
}
if (timeSpan.Days < 1)
{
return $"{(int)timeSpan.TotalHours} hour{Plural((int)timeSpan.TotalHours)}";
}
return $"{(int)timeSpan.TotalDays} day{Plural((int)timeSpan.TotalDays)}";
}
private static string Plural(int totalDays)
{
return totalDays > 1 ? "s" : string.Empty;
}
public static string PrettyPrint(this TimeSpan expiration) public static string PrettyPrint(this TimeSpan expiration)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View file

@ -183,7 +183,21 @@ namespace BTCPayServer.Services.Rates
var jobj = JObject.Parse(await resp.Content.ReadAsStringAsync()); var jobj = JObject.Parse(await resp.Content.ReadAsStringAsync());
var response = new GetRateLimitsResponse(); var response = new GetRateLimitsResponse();
response.CounterReset = TimeSpan.FromSeconds(jobj["counter_reset"].Value<int>()); response.CounterReset = TimeSpan.FromSeconds(jobj["counter_reset"].Value<int>());
var totalPeriod = jobj["total_period"].Value<string>();
if (totalPeriod == "24h")
{
response.TotalPeriod = TimeSpan.FromHours(24);
}
else if (totalPeriod == "30d")
{
response.TotalPeriod = TimeSpan.FromDays(30);
}
else
{
response.TotalPeriod = TimeSpan.FromSeconds(jobj["total_period"].Value<int>());
}
response.RequestsLeft = jobj["requests_left"].Value<int>(); response.RequestsLeft = jobj["requests_left"].Value<int>();
response.RequestsPerPeriod = jobj["requests_per_period"].Value<int>();
return response; return response;
} }
@ -213,5 +227,7 @@ namespace BTCPayServer.Services.Rates
{ {
public TimeSpan CounterReset { get; set; } public TimeSpan CounterReset { get; set; }
public int RequestsLeft { get; set; } public int RequestsLeft { get; set; }
public int RequestsPerPeriod { get; set; }
public TimeSpan TotalPeriod { get; set; }
} }
} }

View file

@ -40,12 +40,16 @@
<h5>Current Bitcoin Average Quotas:</h5> <h5>Current Bitcoin Average Quotas:</h5>
<table class="table table-sm"> <table class="table table-sm">
<tr> <tr>
<th>Requests left</th> <th>Quota period</th>
<td>@Model.RateLimits.RequestsLeft</td> <td>@Model.RateLimits.TotalPeriod.Prettify()</td>
</tr>
<tr>
<th>Requests quota</th>
<td>@Model.RateLimits.RequestsLeft/@Model.RateLimits.RequestsPerPeriod</td>
</tr> </tr>
<tr> <tr>
<th>Quota reset in</th> <th>Quota reset in</th>
<td>@Model.RateLimits.CounterReset</td> <td>@Model.RateLimits.CounterReset.Prettify()</td>
</tr> </tr>
</table> </table>
} }