Fix nullability issue when encoding QR code
MODIFY
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
@@ -46,12 +46,7 @@ namespace WalletWasabi.Gui.ViewModels
.ObserveOn(RxApp.TaskpoolScheduler)
.Where(x => x)
.Take(1)
- .Select(x =>
- {
- var encoder = new QrEncoder();
- encoder.TryEncode(Address, out var qrCode);
- return qrCode.Matrix.InternalArray;
- })
+ .Select(x => new QrEncoder().Encode(Address).Matrix.InternalArray)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(qr => QrCode = qr, onError: ex => Logger.LogError(ex)); // Catch the exceptions everywhere (e.g.: Select) except in Subscribe.

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/QrCode.cs
WalletWasabi/Gma/QrCodeNet/Encoding/QrCode.cs
@@ -14,12 +14,6 @@ namespace Gma.QrCodeNet.Encoding
IsContainMatrix = true;
}
- public QrCode()
- {
- IsContainMatrix = false;
- Matrix = null;
- }
-
public bool IsContainMatrix
{
get;

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/QrEncoder.cs
WalletWasabi/Gma/QrCodeNet/Encoding/QrEncoder.cs
+using System.Diagnostics.CodeAnalysis;
+
namespace Gma.QrCodeNet.Encoding
{
public class QrEncoder
@@ -36,23 +38,5 @@ namespace Gma.QrCodeNet.Encoding
return new QrCode(QRCodeEncode.Encode(content, ErrorCorrectionLevel));
}
}
-
- /// <summary>
- /// Try to encode content
- /// </summary>
- /// <returns>False if input content is empty, null or too large.</returns>
- public bool TryEncode(string content, out QrCode qrCode)
- {
- try
- {
- qrCode = Encode(content);
- return true;
- }
- catch (InputOutOfBoundaryException)
- {
- qrCode = new QrCode();
- return false;
- }
- }
}
}

Fix nullability issue when encoding QR code