* Move most settings files into new dir 'Model/Settings' * Conform code style to our current practices
42 lines
1.6 KiB
C#
42 lines
1.6 KiB
C#
#nullable enable
|
|
namespace mbts.spark {
|
|
using bts;
|
|
using bts.api;
|
|
|
|
using mbts.persist;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reactive.Linq;
|
|
|
|
static class UserSettingsExtensions {
|
|
/// <summary>
|
|
/// Gets the ladder settings profile for a particular security
|
|
/// </summary>
|
|
public static LadderSettingsProfile? get_ladder_profile(
|
|
this UserSettings settings, SecurityImmutable security) =>
|
|
settings.ladder_profiles.FirstOrDefault(lsp =>
|
|
lsp?.security_criteria?.includes(security) ?? false);
|
|
|
|
public static IObservable<LadderSettingsProfile?> subscribe_ladder_profile(
|
|
this UserSettingsHub settings_hub, SecurityImmutable security) =>
|
|
settings_hub.subscribe_default_settings().Select(s =>
|
|
s.get_ladder_profile(security));
|
|
|
|
/// <summary>
|
|
/// Gets the default account for a particular security (from the
|
|
/// <see cref="LadderSettingsProfile"/> associated with that security)
|
|
/// </summary>
|
|
public static IObservable<AccountTuple?> subscribe_default_account(
|
|
this UserSettingsHub settings_hub, IBus bus, SecurityImmutable security) {
|
|
var acc_id_src = settings_hub.subscribe_default_settings().Select(s =>
|
|
s.get_ladder_profile(security)?.value?.default_account);
|
|
return acc_id_src.CombineLatest(
|
|
bus.subscribe(SparkTags.AccountsTag),
|
|
(acc_id, accs) => acc_id.HasValue && accs.TryGetValue(acc_id.Value, out var acc_tup) ?
|
|
acc_tup : (AccountTuple?)null);
|
|
}
|
|
}
|
|
}
|