fix converters so they comply with WPF / Avalonia docs and dont throw exceptions but return UnsetValue
in the case of conversion failure or that conversion is not possible.
MODIFY
WalletWasabi.Fluent/Converters/FeeTargetTimeConverter.cs
WalletWasabi.Fluent/Converters/FeeTargetTimeConverter.cs
using Avalonia.Data.Converters;
using System.Globalization;
+using Avalonia;
using WalletWasabi.Helpers;
using WalletWasabi.Fluent.Models;
using WalletWasabi.Exceptions;
@@ -47,17 +48,12 @@ public class FeeTargetTimeConverter : IValueConverter
return Convert(feeTarget, " minutes", " hour", " hours", " day", " days");
}
- if (value is { })
- {
- throw new TypeArgumentException(value, typeof(SmartCoinStatus), nameof(value));
- }
-
- return null;
+ return AvaloniaProperty.UnsetValue;
}
- public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+ public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- return null;
+ throw new NotSupportedException();
}
private static string IfPlural(int val, string singular, string plural)

MODIFY
WalletWasabi.Fluent/Converters/NavBarIconConverter.cs
WalletWasabi.Fluent/Converters/NavBarIconConverter.cs
@@ -12,21 +12,21 @@ public class NavBarIconConverter : IValueConverter
{
}
- object? IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ object IValueConverter.Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (Application.Current is { } && value is string iconName)
{
if (Application.Current.Styles.TryGetResource(iconName, out object? resource))
{
- return resource;
+ return resource ?? AvaloniaProperty.UnsetValue;
}
}
- return null;
+ return AvaloniaProperty.UnsetValue;
}
object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- return null;
+ throw new NotSupportedException();
}
}

MODIFY
WalletWasabi.Fluent/Converters/StatusBarStateVisibilityConverter.cs
WalletWasabi.Fluent/Converters/StatusBarStateVisibilityConverter.cs
using System.Globalization;
+using Avalonia;
using Avalonia.Data.Converters;
using WalletWasabi.Fluent.Models;
@@ -19,11 +20,11 @@ public class StatusBarStateVisibilityConverter : IValueConverter
return state == paramState;
}
- return null;
+ return AvaloniaProperty.UnsetValue;
}
object? IValueConverter.ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
- return null;
+ throw new NotSupportedException();
}
}

MODIFY
WalletWasabi.Fluent/Converters/WalletIconConverter.cs
WalletWasabi.Fluent/Converters/WalletIconConverter.cs
+using System.Globalization;
+using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media.Imaging;
using WalletWasabi.Fluent.Helpers;
@@ -5,12 +7,35 @@ using WalletWasabi.Wallets;
namespace WalletWasabi.Fluent.Converters;
-public static class WalletIconConverter
+public class WalletIconConverter : IValueConverter
{
- public static readonly IValueConverter WalletTypeToImage =
- new FuncValueConverter<WalletType, Bitmap?>(GetBitmap);
+ public static readonly IValueConverter WalletTypeToImage = new WalletIconConverter();
- private static Bitmap? GetBitmap(WalletType type)
+
+
+ public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ if (value is WalletType type)
+ {
+ try
+ {
+ return GetBitmap(type);
+ }
+ catch
+ {
+ // ignored
+ }
+ }
+
+ return AvaloniaProperty.UnsetValue;
+ }
+
+ public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+ {
+ throw new NotSupportedException();
+ }
+
+ private static Bitmap GetBitmap(WalletType type)
{
Uri uri = new($"avares://WalletWasabi.Fluent/Assets/WalletIcons/{ThemeHelper.CurrentTheme}/generic.png");

MODIFY
WalletWasabi.Fluent/Helpers/AssetHelpers.cs
WalletWasabi.Fluent/Helpers/AssetHelpers.cs
@@ -6,7 +6,7 @@ namespace WalletWasabi.Fluent.Helpers;
public static class AssetHelpers
{
- public static Bitmap? GetBitmapAsset(Uri uri)
+ public static Bitmap GetBitmapAsset(Uri uri)
{
var assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
@@ -16,10 +16,10 @@ public static class AssetHelpers
return new Bitmap(image);
}
- return null;
+ throw new Exception("Program is not initialised or is in an inconsistent state.");
}
- public static Bitmap? GetBitmapAsset(string path)
+ public static Bitmap GetBitmapAsset(string path)
{
return GetBitmapAsset(new Uri(path));
}

fix converters so they comply with WPF / Avalonia docs and dont throw exceptions but return UnsetValue

in the case of conversion failure or that conversion is not possible.