Validate fills before allowing save

This commit is contained in:
Michael Harding committed 2019-08-27 15:23:17 -04:00
1 parent 5e84af4f8f
commit 09805de03e
2 files changed
+14 -9

No files matched your search

+1 -1
View File
@@ -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) =
+13 -8
View File
@@ -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 []