Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate address qrcode #18

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Angor/Client/Angor.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.5" PrivateAssets="all" />
<PackageReference Include="NBitcoin" Version="7.0.25" />
<PackageReference Include="Nostr.Client" Version="1.4.3" />
<PackageReference Include="QRCoder" Version="1.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 31 additions & 5 deletions src/Angor/Client/Pages/Wallet.razor
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,13 @@
<div class="col-lg-6">
<h4 class="card-title">QR Code</h4>
<!-- Replace the src with your actual QR code -->
<img src="https://via.placeholder.com/150" class="card-img-top qrcode" alt="QR Code" />
<img src="data:image /png;base64,@base64qrcode" class="card-img-top qrcode" alt="QR Code" />
</div>
</div>
</div>
</div>
</div>
</div>





Expand Down Expand Up @@ -391,6 +389,8 @@
private int _feeMax = 3;
DateTime _lastFeeRefresh = DateTime.MinValue;

private string base64qrcode;

protected override Task OnInitializedAsync()
{
hasWallet = _walletStorage.HasWallet();
Expand All @@ -399,6 +399,9 @@
{
localAccountInfo = GetAccountInfoFromStorage();
}

GenerateQRCode();

return Task.CompletedTask;
}

Expand Down Expand Up @@ -475,7 +478,7 @@
ClearWalletWords();
StateHasChanged();
}

private void ClearWalletWords()
{
walletWords = null;
Expand Down Expand Up @@ -520,7 +523,30 @@

await _clipboardService.WriteTextAsync(address);
}


private static string lastqrcode;
private static string lastaddress;

private void GenerateQRCode()
{
if (lastaddress == localAccountInfo.GetNextReceiveAddress())
{
base64qrcode = lastqrcode;
return;
}

Task.Run(() =>
{
var address = localAccountInfo.GetNextReceiveAddress();

base64qrcode = Util.GenerateQRCode(address);
lastqrcode = base64qrcode;
lastaddress = address;

StateHasChanged();
});
dangershony marked this conversation as resolved.
Show resolved Hide resolved
}

private async Task RefreshFee()
{
// refresh fee if last refresh was 60 seconds ago
Expand Down
19 changes: 19 additions & 0 deletions src/Angor/Client/Shared/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Angor.Client.Storage;
using Angor.Shared.Models;
using Microsoft.AspNetCore.Components;
using QRCoder;

namespace Angor.Client.Shared
{
public class Util
{
public static string GenerateQRCode(string content)
dangershony marked this conversation as resolved.
Show resolved Hide resolved
{
using QRCodeGenerator qrGenerator = new QRCodeGenerator();
using QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
using PngByteQRCode pngByteQRCode = new PngByteQRCode(qrCodeData);
return Convert.ToBase64String(pngByteQRCode.GetGraphic(10));
}

}
}
Loading