SPARK-1194 modify ticket should default to original quantity (not working)
This commit is contained in:
1 parent
8512b40f50
commit
56b855ea83
3 files changed
+44
-8
No files matched your search
@@ -87,11 +87,8 @@ namespace mbts.spark {
|
||||
key = ort.order.Key;
|
||||
if (DoubleHelper.IsNaNOrInfinity(price))
|
||||
price = ort.order.State.Price;
|
||||
if (!size_calculator.value.HasValue || size_calculator.value.Value == 0) {
|
||||
int wq = ort.order.working_quantity();
|
||||
if (wq > 0)
|
||||
size_calculator.value = (uint)wq;
|
||||
}
|
||||
if (!size_calculator.value.HasValue || !size_calculator.value_setter_called)
|
||||
size_calculator.bypass_value_setter(ort.order.State.Quantity);
|
||||
}),
|
||||
Observable.Merge(_price_dirty, _size_dirty, _account_dirty, _time_in_force_dirty, _order_type_dirty).ObserveOnDispatcher().Subscribe(_ => RaisePropertyChanged(nameof(dirty_items_text))),
|
||||
_price_dirty.observe_current(true).CombineLatest(_size_dirty.observe_current(true), (pd, sd) => pd || sd).DistinctUntilChanged().ObserveOnDispatcher().Subscribe(modify_order));
|
||||
|
||||
@@ -247,6 +247,42 @@ namespace mbts.ui.shell
|
||||
|
||||
public void refresh() => set(_get_model());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A thin wrapper around Property<T> that trips a 'setter_called' flag when the value is set through value-property-setter (i.e., through User interaction).
|
||||
/// <para/>Note: This is class is particularly useful when a default/settings-based value arrives late, and the viewmodel must decide whether or not to override the current value.
|
||||
/// </summary>
|
||||
protected class UserProperty<T> : IObservable<(T oldval, T newval)> {
|
||||
readonly Property<T> _prop_model;
|
||||
|
||||
public UserProperty(Property<T> prop_model) =>
|
||||
_prop_model = prop_model;
|
||||
|
||||
public event PropertyChange<T> Changing { add { _prop_model.Changing += value; } remove { _prop_model.Changing -= value; } }
|
||||
public event PropertyChange<T> Changed { add { _prop_model.Changed += value; } remove { _prop_model.Changed -= value; } }
|
||||
|
||||
public IDisposable Subscribe(IObserver<(T oldval, T newval)> observer) => _prop_model.Subscribe(observer);
|
||||
public IObservable<T> observe_current(bool start_immediately = false) => _prop_model.observe_current(start_immediately);
|
||||
|
||||
public T Value {
|
||||
get => _prop_model.Value;
|
||||
set {
|
||||
setter_called = true;
|
||||
_prop_model.set(value);
|
||||
}
|
||||
}
|
||||
public bool setter_called { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the value without tripping the 'setter_called' flag.
|
||||
/// </summary>
|
||||
public void bypass_setter(T value) => _prop_model.set(value);
|
||||
/// <summary>
|
||||
/// Sets 'setter_called' to false.
|
||||
/// </summary>
|
||||
public void reset() => setter_called = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected class ObservablePropertySink<T> : Property<T>, IObserver<T>
|
||||
|
||||
@@ -6,15 +6,16 @@ using System.Windows.Input;
|
||||
|
||||
namespace mbts.spark {
|
||||
public class CalculatorLogic : DisposableViewModelBase {
|
||||
readonly Property<uint?> _value;
|
||||
readonly UserProperty<uint?> _value;
|
||||
readonly Property<int[]> _buttons;
|
||||
|
||||
public CalculatorLogic(uint? initial_size, IObservable<int[]> buttons_source) {
|
||||
_value = backing(nameof(value), initial_size);
|
||||
_value = new UserProperty<uint?>(backing(nameof(value), initial_size));
|
||||
_buttons = backing(nameof(buttons), buttons_source);
|
||||
}
|
||||
|
||||
public uint? value { get => _value.Value; set => _value.set(value); }
|
||||
public uint? value { get => _value.Value; set => _value.Value = value; }
|
||||
public bool value_setter_called => _value.setter_called;
|
||||
public IObservable<uint?> value_observable => _value.Select(vals => vals.newval);
|
||||
public int[] buttons { get => _buttons.Value; set => _buttons.set(value); }
|
||||
public ICommand click => new DelegateCommand<uint>(handle_calculator_click);
|
||||
@@ -24,6 +25,8 @@ namespace mbts.spark {
|
||||
public IObservable<uint?> observe_current(bool start_immediately = false) =>
|
||||
_value.observe_current(start_immediately);
|
||||
|
||||
public void bypass_value_setter(uint value) => _value.bypass_setter(value);
|
||||
|
||||
public bool validate() {
|
||||
if (!value.HasValue || value.Value == 0) {
|
||||
flash_error(nameof(value)).ignore();
|
||||
|
||||
Reference in new issue
Block a user