From 09805de03ea59067d6fa78ebcaacaa3c58897c09 Mon Sep 17 00:00:00 2001 From: Michael Harding Date: Tue, 27 Aug 2019 15:23:17 -0400 Subject: [PATCH] Validate fills before allowing save --- src/web/ui/src/Accounts/State.fs | 2 +- src/web/ui/src/Accounts/View.fs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/web/ui/src/Accounts/State.fs b/src/web/ui/src/Accounts/State.fs index 4e3c9fa91..c4290a9eb 100644 --- a/src/web/ui/src/Accounts/State.fs +++ b/src/web/ui/src/Accounts/State.fs @@ -51,7 +51,7 @@ let validateManualFill (fill:TempFillData) = fill.SecurityId <> "0" && fill.user <> "" && parsedQty |> fst - && snd parsedQty >= 0 + && snd parsedQty >= 1 && System.Double.TryParse fill.price |> fst let convertTempManualFIll (tempFill:TempFillData) (model: Model) = diff --git a/src/web/ui/src/Accounts/View.fs b/src/web/ui/src/Accounts/View.fs index e48bb8006..3534c39d3 100644 --- a/src/web/ui/src/Accounts/View.fs +++ b/src/web/ui/src/Accounts/View.fs @@ -43,12 +43,20 @@ let isDirty model = || marginDirty | None -> false +let validate model = + List.fold (fun a e -> a && validateManualFill e) true model.ManualFillData.newFills + let saveButton (model:Model) dispatch = let isNew = isNewAccount model.scratch let buttonText = if isNew then "Create" else "Save" let dirty = isDirty model || isNew - let enabled = if dirty then Button.Enabled else Button.Disabled - let flavor = if dirty then "is-success" else "" + let valid = validate model + let enabled = if dirty && valid then Button.Enabled else Button.Disabled + let flavor = match dirty, valid with + | true, true -> "is-success" + | true, false -> "is-danger" + | false, _ -> "" + Button.button buttonText flavor "" enabled (fun _ -> dispatch SaveScratch) let accountControls model (dispatch:Msg->unit) = @@ -827,7 +835,6 @@ let DayPositionView model dispatch = TableControl.Cell (str "Side") { content = (str "Qty"); className = "is-100-width"; isHeader = false; colSpan = 1 } { content = (str "Price"); className = "is-100-width"; isHeader = false; colSpan = 1 } - TableControl.Cell (str "") ] className = "" header = None @@ -900,7 +907,8 @@ let DayPositionView model dispatch = ) (Some securityMap.[uint32 ulimit.SecurityId].securityName) (Some ulimit.SecurityId) - (fun v -> (ulimit.id, v, "SecurityId", false) |> UpdateManualFill |> dispatch)) + (fun v -> (ulimit.id, v, "SecurityId", false) |> UpdateManualFill |> dispatch) + ) TableControl.Cell (Fields.simpleSelect "" extantUsersMap ulimit.user (fun v -> (ulimit.id, v, "user", false) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.simpleSelect "" ["Buy"; "Sell"] ulimit.side (fun v -> (ulimit.id, v, "side", false) |> UpdateManualFill |> dispatch)) TableControl.Cell (Fields.positiveIntNumber @@ -916,7 +924,6 @@ let DayPositionView model dispatch = (fun _ -> true) (fun v -> (ulimit.id, v, "price", false) |> UpdateManualFill |> dispatch) ) - TableControl.Cell (str "") ] className = "" header = None @@ -935,7 +942,6 @@ let DayPositionView model dispatch = TableControl.Cell (str (match limit.side with | bts.api.Side.BUY -> "Buy" | bts.api.Side.SELL -> "Sell" | _ -> "")) TableControl.Cell (str (sprintf "%i" limit.quantity)) TableControl.Cell (str (sprintf "%f" limit.price)) - TableControl.Cell (str "") ] className = "" header = None @@ -979,14 +985,13 @@ let DayPositionView model dispatch = (fun _ -> true) (fun v -> (limit.newId, v, "price", true) |> UpdateManualFill |> dispatch) ) - TableControl.Cell (str "") ] className = match validateManualFill limit with true -> "" | false -> "is-invalid" header = None onClick = None }] - let dividerRow = match newRows.Length with 0 -> [] | _ -> [({ cells = [{ content = str ""; className = "border-row"; isHeader = false; colSpan = 10 }]; className = ""; header = None; onClick = None }:TableControl.row)] + let dividerRow = match newRows.Length with 0 -> [] | _ -> [({ cells = [{ content = str ""; className = "border-row"; isHeader = false; colSpan = 9 }]; className = ""; header = None; onClick = None }:TableControl.row)] let rws:TableControl.row list = fillRows @ dividerRow @ newRows div []