3using System.Collections.ObjectModel;
4using System.ComponentModel;
7using System.Threading.Tasks;
8using CommunityToolkit.Mvvm.ComponentModel;
9using Microsoft.Maui.ApplicationModel;
19 public partial class KycPage : ObservableObject, IDisposable
21 private bool disposed;
22 private readonly List<IDisposable> subscriptions =
new();
23 private IDictionary<string, string?> values =
null!;
34 public string Id {
get; init; } =
string.Empty;
51 public ObservableCollection<ObservableKycField>
AllFields {
get; } =
new();
64 public ObservableCollection<KycSection>
AllSections {
get; } =
new();
82 Field.IsVisible = Field.
Condition?.Evaluate(Values) ??
true;
86 Section.UpdateVisibilities(Values);
98 public bool IsVisible(IDictionary<string, string?> Values)
100 return this.
Condition?.Evaluate(Values) ??
true;
103 protected virtual void Dispose(
bool Disposing)
113 this.subscriptions.ForEach(Sub => Sub.Dispose());
114 this.subscriptions.Clear();
116 this.disposed =
true;
119 public void Dispose()
122 GC.SuppressFinalize(
this);
129 internal void InitFieldValueNotifications(IDictionary<string, string?> Values)
131 this.values = Values;
134 Field.PropertyChanged += this.Field_ValueChanged;
140 Field.PropertyChanged += this.Field_ValueChanged;
145 private void Field_ValueChanged(
object? Sender, PropertyChangedEventArgs E)
149 this.values[Field.Id] = Field.StringValue;
151 if (Field.FieldType ==
FieldType.Country &&
string.Equals(Field.Id,
"country", StringComparison.OrdinalIgnoreCase))
152 this.HandleCountryFieldChanged(Field);
158 if (CountryField is
null)
161 string CountryCode = CountryField.StringValue ??
string.Empty;
162 if (CountryField.TryGetOwnerProcess(out KycProcess? Process))
167 MainThread.BeginInvokeOnMainThread(() =>
169 foreach (KycPage Page
in Process.Pages)
171 this.UpdatePersonalNumberFields(Page.VisibleFields, CountryCode, PlaceholderExample);
172 foreach (KycSection Section in Page.VisibleSections)
173 this.UpdatePersonalNumberFields(Section.VisibleFields, CountryCode, PlaceholderExample);
179 private void UpdatePersonalNumberFields(IEnumerable<ObservableKycField> Fields,
string CountryCode,
string PlaceholderExample)
183 if (!Field.IsVisible)
186 if (!MapsToPersonalNumber(Field))
189 this.ApplyPersonalNumberPlaceholder(Field, CountryCode, PlaceholderExample);
191 Field.ValidationTask.
Run();
195 private void ApplyPersonalNumberPlaceholder(
ObservableKycField Field,
string CountryCode,
string PlaceholderExample)
198 Field.Placeholder =
new KycLocalizedText();
200 string PlaceholderKey =
string.IsNullOrEmpty(CountryCode) ?
"en" :
CountryCode;
201 string PlaceholderValue = PlaceholderExample ??
string.Empty;
202 Field.
Placeholder.Add(PlaceholderKey, PlaceholderValue);
207 foreach (KycMapping Mapping
in Field.
Mappings)
213 return string.Equals(Field.
Id,
"personalNumber", StringComparison.OrdinalIgnoreCase);
XMPP Protocol Properties.
const string PersonalNumber
Personal number
A set of never changing property constants and helpful values.
Personal Number Schemes available in different countries.
static ? string DisplayStringForCountry(string CountryCode)
Gets the expected personal number format for the given country.
Represents a set of localized strings, addressable by language code (e.g. "en", "sv").
Represents a page in a KYC process containing fields and sections.
ReadOnlyObservableCollection< ObservableKycField > VisibleFields
Gets the read-only collection of visible fields in the page.
ObservableCollection< KycSection > AllSections
Gets all sections contained in the page.
FilteredObservableCollection< KycSection > VisibleSectionsCollection
Backing collection tracking sections whose KycSection.IsVisible is true.
string Id
Gets the page identifier.
void UpdateVisibilities(IDictionary< string, string?> Values)
Updates visibility flags for fields and sections based on current values.
FilteredObservableCollection< ObservableKycField > VisibleFieldsCollection
Backing collection tracking fields whose ObservableKycField.IsVisible is true.
KycLocalizedText? Description
Gets or sets the localized page description.
ReadOnlyObservableCollection< KycSection > VisibleSections
Gets the read-only collection of visible sections in the page.
KycCondition? Condition
Gets or sets an optional page condition controlling visibility.
KycLocalizedText? Title
Gets or sets the localized page title.
bool IsVisible(IDictionary< string, string?> Values)
Gets a value indicating whether the page is visible based on current values and its condition.
ObservableCollection< ObservableKycField > AllFields
Gets all fields directly contained in the page (excluding sections).
The base KYC field model. Use as-is for generic fields, or subclass for custom logic.
string Id
The unique identifier for the field.
ObservableCollection< KycMapping > Mappings
Mappings to apply output.
KycCondition? Condition
Conditional display of this field.
void ForceSynchronousValidation()
Forces immediate synchronous validation (used when advancing pages or explicit full validation is req...
KycLocalizedText? Placeholder
Placeholder text for the field input.
Provides a live, read-only filtered view of an ObservableCollection<T> that stays in sync and maintai...
void Run()
Start the configured task now (no CanExecute gating).
class CountryCode(ScriptNode Argument, int Start, int Length, Expression Expression)
Looks up a Country Name and returns the corresponding Country Code.
FieldType
Enumeration of all supported field types in the KYC process.