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

Validations system refactor. #2223

merged 24 commits into from Sep 10, 2019
Changes from 1 commit
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

Serialize then Deserialize via Converter the ErrorDescriptor as a wor…

…karound. Remove this hack when we update to Avalonia 0.9.
  • Loading branch information...
jmacato committed Sep 9, 2019
commit 11bad9dd8858a2dcaad4bd3f5937923ace7571c3
@@ -0,0 +1,31 @@
using Avalonia;
using Avalonia.Data.Converters;
using NBitcoin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using WalletWasabi.Models;

namespace WalletWasabi.Gui.Converters
public class ErrorDescriptorsJsonConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
if (value is IEnumerable<Exception> jsonStr)
return JsonConvert.DeserializeObject<ErrorDescriptors>(jsonStr.First().Message);
This conversation was marked as resolved by jmacato

This comment has been minimized.

Copy link

danwalmsley Sep 9, 2019


Why first? Could be more than 1 error / warning?

Shouldnt it convert them to a multiline string?

This comment has been minimized.

Copy link

nopara73 Sep 10, 2019


I think this was guiding his decision: #2204 (comment)

This comment has been minimized.

Copy link

molnard Sep 10, 2019


IMO it is because of the Avalonia bug. Currently, @jmacato did a workaround to make it work but he has to follow the "old" solution where an array was passed and only the first element was passed to the View.

This comment has been minimized.

Copy link

jmacato Sep 10, 2019

Author Collaborator

I covered all my bases and processed all the exceptions instead of processing only the first one :)


return ErrorDescriptors.Empty;

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
return null;
@@ -1,7 +1,8 @@
<Styles xmlns=""
@@ -20,6 +21,7 @@
<converters:ErrorDescriptorsJsonConverter x:Key="ErrorDescriptorsJsonConverter" />
<Style Selector="shell|MetroWindow /template/ Button#minimiseButton">
@@ -139,7 +141,7 @@
ContentTemplate="{TemplateBinding ErrorTemplate}"
DataContext="{TemplateBinding Owner}"
Content="{Binding (DataValidationErrors.Errors)}"
Content="{Binding (DataValidationErrors.Errors), Converter={StaticResource ErrorDescriptorsJsonConverter}}"
IsVisible="{Binding (DataValidationErrors.HasErrors)}" />
@@ -1,3 +1,4 @@
using Newtonsoft.Json;
using ReactiveUI;
using System;
using System.Collections;
@@ -30,12 +31,11 @@ public IEnumerable GetErrors(string propertyName)
var error = Validator.ValidateProperty(this, propertyName, ValidationMethodCache);

This conversation was marked as resolved by jmacato

This comment has been minimized.

Copy link

yahiheb Sep 9, 2019


Empty line can be removed.

Suggested change
if (error.HasErrors)
return error.Select(p => p.Message);
if (!error.HasErrors) return null;

return ErrorDescriptors.Empty;
// HACK: Need to serialize this in order to pass through IndeiValidationPlugin on Avalonia 0.8.2.
// Should be removed when Avalonia has the hotfix update.
return new List<string>() { JsonConvert.SerializeObject(error) };

protected void NotifyErrorsChanged(string propertyName)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.