mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
272cc3d3c9
* Login Code: Turn into Blazor component and extend with data for the app * POS: Add login code for POS frontend * Improve components, fix test
30 lines
1015 B
Plaintext
30 lines
1015 B
Plaintext
@using QRCoder
|
|
|
|
@if (!string.IsNullOrEmpty(Data))
|
|
{
|
|
<img @attributes="Attrs" style="image-rendering:pixelated;image-rendering:-moz-crisp-edges;min-width:@(Size)px;min-height:@(Size)px" src="data:image/png;base64,@(GetBase64(Data))" class="@CssClass" alt="@Data" />
|
|
}
|
|
|
|
@code {
|
|
[Parameter, EditorRequired]
|
|
public string Data { get; set; }
|
|
|
|
[Parameter]
|
|
public int Size { get; set; } = 256;
|
|
|
|
[Parameter(CaptureUnmatchedValues = true)]
|
|
public Dictionary<string, object> Attrs { get; set; }
|
|
|
|
private static readonly QRCodeGenerator QrGenerator = new();
|
|
|
|
private string GetBase64(string data)
|
|
{
|
|
var qrCodeData = QrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q);
|
|
var qrCode = new PngByteQRCode(qrCodeData);
|
|
var bytes = qrCode.GetGraphic(5, [0, 0, 0, 255], [0xf5, 0xf5, 0xf7, 255]);
|
|
return Convert.ToBase64String(bytes);
|
|
}
|
|
|
|
private string CssClass => $"qr-code {(Attrs?.ContainsKey("class") is true ? Attrs["class"] : "")}".Trim();
|
|
}
|