Skip to content

Commit

Permalink
Invoices list
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed Apr 19, 2024
1 parent b8579c6 commit 20c7b78
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 18 deletions.
48 changes: 48 additions & 0 deletions BTCPayApp.UI/Components/InvoiceItem.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@using BTCPayApp.UI.Models

<a href="@Routes.InvoicePath(Id)" class="invoice list-group-item list-group-item-action d-flex align-items-center gap-3 py-3 px-4">
<div class="d-flex align-items-baseline justify-content-between flex-wrap flex-grow-1 gap-2">
<DateDisplay DateTimeOffset="@Date" Format="DateDisplay.DateDisplayFormat.Localized"/>
<TruncateCenter Text="@OrderId"></TruncateCenter>
<span class="amount">@Amount @Currency</span>
<div class="badge-container">
<span class="badge badge-@State">@State</span>
</div>
</div>
<Icon symbol="caret-right"/>
</a>

@code {
[Parameter]
public string? Id { get; set; }

[Parameter]
public string? OrderId { get; set; }

[Parameter]
public string? Status { get; set; }

[Parameter]
public DateTimeOffset Date { get; set; }

[Parameter]
public string? Currency { get; set; }

[Parameter]
public decimal Amount { get; set; }

[Parameter]
public Invoice Invoice {
set
{
Id = value.Id;
OrderId = value.OrderId;
Status = value.Status;
Date = value.Date;
Currency = value.Currency;
Amount = value.Amount;
}
}

private string State => Status?.ToLowerInvariant() ?? "unknown";
}
10 changes: 10 additions & 0 deletions BTCPayApp.UI/Components/InvoiceItem.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.invoice .badge-container {
flex: 0 0 5.125rem;
text-align: right;
}

@media (max-width: 359px) {
.invoice .badge-container {
flex-grow: 1;
}
}
6 changes: 6 additions & 0 deletions BTCPayApp.UI/Components/Layout/NavbarBottom.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
<span>Wallet</span>
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="@Routes.Invoices" Match="NavLinkMatch.Prefix">
<Icon symbol="nav-invoices"/>
<span>Invoices</span>
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link" href="@Routes.PointOfSale" Match="NavLinkMatch.All">
<Icon symbol="nav-keypad"/>
Expand Down
41 changes: 41 additions & 0 deletions BTCPayApp.UI/Components/TruncateCenter.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<span class="truncate-center truncate-center-id @(Copy ? "truncate-center--copy" : null)">
<span class="truncate-center-truncated" data-bs-toggle="@(IsTruncated ? "tooltip" : null)" title="@(IsTruncated ? Text : null)">
<span class="truncate-center-start">@(IsTruncated ? $"{Start}…" : Text)</span>
@if (IsTruncated)
{
<span class="truncate-center-end">@End</span>
}
</span>
<span class="truncate-center-text">@Text</span>
@if (Copy)
{
<button type="button" class="btn btn-link p-0" data-clipboard="@Text">
<Icon Symbol="copy" />
</button>
}
@if (!string.IsNullOrEmpty(Link))
{
<a href="@Link" rel="noreferrer noopener" target="@(Link.StartsWith("http") ? "_blank" : null)">
<Icon Symbol="info" />
</a>
}
</span>

@code {
[Parameter, EditorRequired]
public string? Text { get; set; }

[Parameter]
public string? Link { get; set; }

[Parameter]
public int Padding { get; set; } = 7;

[Parameter]
public bool Copy { get; set; }

private bool IsTruncated => !string.IsNullOrEmpty(Start) && !string.IsNullOrEmpty(End);

private string? Start => Text?.Length > 2 * Padding ? Text[..Padding] : null;
private string? End => Text?.Length > 2 * Padding ? Text[^Padding..] : null;
}
55 changes: 55 additions & 0 deletions BTCPayApp.UI/Components/TruncateCenter.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.truncate-center {
display: inline-flex;
align-items: center;
gap: var(--btcpay-space-s);
max-width: 100%;
}

.truncate-center-end,
.truncate-center-start {
white-space: nowrap;
}

.truncate-center-id {
font-family: var(--btcpay-font-monospace);
font-size: .875em;
}

.truncate-center-text {
word-wrap: break-word;
word-break: break-word;
}

.truncate-center a,
.truncate-center button {
line-height: 1;
}

.truncate-center-truncated {
text-align: left;
display: inline-flex;
max-width: 100%;
}

.truncate-center button.btn .icon {
--icon-size: 1rem;
}

.truncate-center.form-control-plaintext {
padding-right: 3px;
}

.truncate-center.form-control-plaintext button.btn .icon {
--icon-size: 1.25rem;
}

.truncate-center-id {
background: var(--btcpay-neutral-100);
border: 1px solid var(--btcpay-neutral-200);
border-radius: var(--btcpay-border-radius-l);
padding: var(--btcpay-space-xs) var(--btcpay-space-s);
}

.truncate-center-text {
display: none;
}
1 change: 1 addition & 0 deletions BTCPayApp.UI/Layout/SimpleLayout.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
flex-direction: column;
gap: 1.5rem;
max-width: 24rem;
margin: 0 auto;
padding-top: var(--padding-vertical);
padding-bottom: 3rem;
}
Expand Down
11 changes: 11 additions & 0 deletions BTCPayApp.UI/Models/Invoice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace BTCPayApp.UI.Models;

public class Invoice
{
public string? Id { get; set; }
public string? OrderId { get; set; }
public string? Status { get; set; }
public DateTimeOffset Date { get; set; }
public string? Currency { get; set; }
public decimal Amount { get; set; }
}
10 changes: 10 additions & 0 deletions BTCPayApp.UI/Models/Notification.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BTCPayApp.UI.Models;

public class Notification
{
public string? Id { get; set; }
public string? Type { get; set; }
public DateTimeOffset Created { get; set; }
public string? Body { get; set; }
public bool Seen { get; set; }
}
18 changes: 11 additions & 7 deletions BTCPayApp.UI/Pages/DashboardPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<Icon symbol="payment-send"/>
<span>Send</span>
</NavLink>
<NavLink class="btn btn-light rounded-pill w-125px" href="@Routes.WalletSend" Match="NavLinkMatch.All">
<NavLink class="btn btn-light rounded-pill w-125px" href="@Routes.WalletReceive" Match="NavLinkMatch.All">
<Icon symbol="payment-receive"/>
<span>Receive</span>
</NavLink>
Expand Down Expand Up @@ -77,22 +77,26 @@
<h2>Recent Activity</h2>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="d-flex align-items-center justify-content-between">
<span>3940..CkGJ</span>
<div class="d-flex align-items-center justify-content-between mb-1">
<TruncateCenter Text="CDOy6cOibCWEdsRiZuaHf8dSGGJRYuBGC" Link="@Routes.InvoicePath("CDOy6cOibCWEdsRiZuaHf8dSGGJRYuBGC")"/>
<span class="text-end">$29.13</span>
</div>
<div class="d-flex align-items-center justify-content-between">
<span class="text-muted">March 21 at 6:15am</span>
<span class="text-muted">
<DateDisplay DateTimeOffset="@(DateTimeOffset.Now - TimeSpan.FromMinutes(21))" />
</span>
<span class="text-muted text-end">177,032 sats</span>
</div>
</li>
<li class="list-group-item">
<div class="d-flex align-items-center justify-content-between">
<span>CkGJ..3940</span>
<div class="d-flex align-items-center justify-content-between mb-1">
<TruncateCenter Text="WpYu7PQz4QOOjznTuLwp1PNZXZKP8U1pB2" Link="@Routes.InvoicePath("WpYu7PQz4QOOjznTuLwp1PNZXZKP8U1pB2")"/>
<span class="text-end">$29.13</span>
</div>
<div class="d-flex align-items-center justify-content-between">
<span class="text-muted">March 21 at 6:15am</span>
<span class="text-muted">
<DateDisplay DateTimeOffset="@(DateTimeOffset.Now - TimeSpan.FromHours(6))" />
</span>
<span class="text-muted text-end">177,032 sats</span>
</div>
</li>
Expand Down
45 changes: 45 additions & 0 deletions BTCPayApp.UI/Pages/InvoicePage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@attribute [Route(Routes.Invoice)]
@using BTCPayApp.UI.Components.Layout
@using BTCPayApp.UI.Models
@inherits Fluxor.Blazor.Web.Components.FluxorComponent

<PageTitle>@GetTitle()</PageTitle>

<SectionContent SectionName="top">
<Titlebar Back="@Routes.Invoices">
<h1>@GetTitle()</h1>
</Titlebar>
</SectionContent>

<section class="container">
<div class="invoice">
ID: @Model.Invoice.Id
</div>
</section>

@code {
[Parameter, EditorRequired]
public string? InvoiceId { get; set; }

private InvoiceModel Model { get; set; } = new();

protected override async Task OnInitializedAsync()
{
Model.Invoice = new Invoice
{
Id = InvoiceId,
OrderId = "CDOy6cOibCWEdsRiZuaHf8dSG",
Date = DateTimeOffset.Now - TimeSpan.FromSeconds(21),
Status = "Settled",
Currency = "USD",
Amount = 61.5m
};
}

private class InvoiceModel
{
public Invoice Invoice { get; set; }
}

private string GetTitle() => $"Invoice {Model.Invoice.Id}";
}
71 changes: 71 additions & 0 deletions BTCPayApp.UI/Pages/InvoicesPage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@attribute [Route(Routes.Invoices)]
@using BTCPayApp.UI.Components.Layout
@using BTCPayApp.UI.Models
@inherits Fluxor.Blazor.Web.Components.FluxorComponent

<PageTitle>Invoices</PageTitle>

<SectionContent SectionName="top">
<Titlebar Back="@Routes.Dashboard">
<h1>Invoices</h1>
</Titlebar>
</SectionContent>

<section>
@if (Model.Invoices.Any())
{
<div class="list-group list-group-flush">
@foreach (var i in Model.Invoices)
{
<InvoiceItem Invoice="@i"/>
}
</div>
}
else
{
<p class="text-muted">There are no invoices, yet.</p>
}
</section>

@code {
private InvoicesModel Model { get; set; } = new();

protected override async Task OnInitializedAsync()
{
Model.Invoices =
[
new Invoice
{
Id = "CDOy6cOibCWEdsRiZuaHf8dSG",
OrderId = "1",
Date = DateTimeOffset.Now - TimeSpan.FromSeconds(21),
Status = "Settled",
Currency = "USD",
Amount = 61.5m
},
new Invoice
{
Id = "jRY5cKmdYQrS6zu863wEFXtn4",
OrderId = "2",
Date = DateTimeOffset.Now - TimeSpan.FromHours(6),
Status = "Processing",
Currency = "SATS",
Amount = 210000m
},
new Invoice
{
Id = "RNuhcG8UUGJRYuBGCNuhcG8",
OrderId = "3",
Date = DateTimeOffset.Now - TimeSpan.FromDays(3),
Status = "Expired",
Currency = "USD",
Amount = 6.15m
}
];
}

private class InvoicesModel
{
public Invoice[] Invoices { get; set; } = [];
}
}
13 changes: 2 additions & 11 deletions BTCPayApp.UI/Pages/NotificationsPage.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@attribute [AllowAnonymous]
@attribute [Route(Routes.Notifications)]
@attribute [Route(Routes.Notifications)]
@using BTCPayApp.UI.Components.Layout
@using BTCPayApp.UI.Models
@inherits Fluxor.Blazor.Web.Components.FluxorComponent

<PageTitle>Notifications</PageTitle>
Expand Down Expand Up @@ -65,13 +65,4 @@
{
public Notification[] Notifications { get; set; } = [];
}

private class Notification
{
public string? Id { get; set; }
public string? Type { get; set; }
public DateTimeOffset Created { get; set; }
public string? Body { get; set; }
public bool Seen { get; set; }
}
}
4 changes: 4 additions & 0 deletions BTCPayApp.UI/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static class Routes
public const string WalletSetup = "/wallet/setup";
public const string WalletSend = "/wallet/send";
public const string WalletReceive = "/wallet/receive";
public const string Invoices = "/invoices";
public const string Invoice = "/invoices/{InvoiceId}";
public const string PointOfSale = "/pos";
public const string Logout = "/logout";

public static string InvoicePath(string invoiceId) => Invoice.Replace("{InvoiceId}", invoiceId);
}

0 comments on commit 20c7b78

Please sign in to comment.