From 58b86ad1afff422ca205f92516cea638f4072371 Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Fri, 12 Jun 2026 10:21:16 +0200 Subject: [PATCH] feat(app): QR code for receive address Adds QRCoder 1.8.0 and generates a PNG QR code in-memory each time the receive address changes (OnReceiveAddressChanged). The bitmap is displayed in the Receive tab inside a white-background border with pixel-perfect scaling (BitmapInterpolationMode=None). Previous bitmap is disposed to avoid memory leaks. --- src/App/PalladiumWallet.App.csproj | 1 + src/App/ViewModels/MainWindowViewModel.cs | 29 +++++++++++++++++++++++ src/App/Views/MainWindow.axaml | 6 +++++ 3 files changed, 36 insertions(+) diff --git a/src/App/PalladiumWallet.App.csproj b/src/App/PalladiumWallet.App.csproj index a1cf37f..0ab328f 100644 --- a/src/App/PalladiumWallet.App.csproj +++ b/src/App/PalladiumWallet.App.csproj @@ -22,6 +22,7 @@ All + diff --git a/src/App/ViewModels/MainWindowViewModel.cs b/src/App/ViewModels/MainWindowViewModel.cs index ce8edfd..c1342be 100644 --- a/src/App/ViewModels/MainWindowViewModel.cs +++ b/src/App/ViewModels/MainWindowViewModel.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Threading.Tasks; +using Avalonia.Media.Imaging; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -15,6 +16,7 @@ using PalladiumWallet.Core.Net; using PalladiumWallet.Core.Spv; using PalladiumWallet.Core.Storage; using PalladiumWallet.Core.Wallet; +using QRCoder; namespace PalladiumWallet.App.ViewModels; @@ -240,6 +242,33 @@ public partial class MainWindowViewModel : ViewModelBase [ObservableProperty] private string receiveAddress = ""; + /// QR code dell'indirizzo di ricezione corrente (PNG in-memory). + [ObservableProperty] + private Bitmap? receiveQr; + + // Rigenera il QR ogni volta che l'indirizzo di ricezione cambia. + partial void OnReceiveAddressChanged(string value) + { + var previous = ReceiveQr; + ReceiveQr = string.IsNullOrEmpty(value) ? null : GenerateQr(value); + previous?.Dispose(); + } + + private static Bitmap? GenerateQr(string text) + { + try + { + using var generator = new QRCodeGenerator(); + using var data = generator.CreateQrCode(text, QRCodeGenerator.ECCLevel.M); + var png = new PngByteQRCode(data).GetGraphic(8); + return new Bitmap(new MemoryStream(png)); + } + catch + { + return null; + } + } + [ObservableProperty] private string serverHost = ""; diff --git a/src/App/Views/MainWindow.axaml b/src/App/Views/MainWindow.axaml index 1a33d84..14d3694 100644 --- a/src/App/Views/MainWindow.axaml +++ b/src/App/Views/MainWindow.axaml @@ -255,6 +255,12 @@ + + +