Fix Save button
This commit is contained in:
1 parent
4f7fcc5634
commit
ebad5b389f
3 files changed
+17
-11
No files matched your search
@@ -2,6 +2,7 @@ module Accounts.State
|
||||
|
||||
open Accounts.Types
|
||||
open bts.api.admin
|
||||
open Global
|
||||
open Elmish
|
||||
open Fable.PowerPack.PromiseImpl
|
||||
open Fable.Import
|
||||
@@ -212,8 +213,8 @@ let update msg (model:Model) : Model * Cmd<Msg> =
|
||||
| UpdateMarginData newData ->
|
||||
let cmd = Cmd.ofPromise (fun _ -> promise { do! Promise.sleep 10000 } ) () (fun _ -> GetMarginData) (fun _ -> GetMarginData)
|
||||
match (model.marginScratch = emptyMargin || model.marginScratch.account <> model.scratch.name),
|
||||
(model.marginData.leverageFactor = model.marginScratch.leverageFactor),
|
||||
(model.marginData.cashBalance = model.marginScratch.cashBalance) with
|
||||
(compareDouble model.marginData.leverageFactor model.marginScratch.leverageFactor 10000u),
|
||||
(compareDouble model.marginData.cashBalance model.marginScratch.cashBalance 10000u) with
|
||||
| true, _, _ -> {model with marginData = newData; marginScratch = newData}, cmd
|
||||
| false, true, true -> {model with marginData = newData; marginScratch = newData}, cmd
|
||||
| false, false, true -> {model with marginData = newData; marginScratch = {model.marginScratch with cashBalance = newData.cashBalance}}, cmd
|
||||
@@ -237,7 +238,7 @@ let update msg (model:Model) : Model * Cmd<Msg> =
|
||||
| SaveScratch ->
|
||||
match isNewAccount model.scratch with
|
||||
| true -> model, Cmd.ofExistingPromise (createAccount model.admin model.scratch model ) id (box>>ErrorOccured)
|
||||
| false -> model, Cmd.ofExistingPromise (saveAccount model.admin model.scratch model ) id (box>>ErrorOccured)
|
||||
| false -> { model with marginScratch = model.marginData }, Cmd.ofExistingPromise (saveAccount model.admin model.scratch model ) id (box>>ErrorOccured)
|
||||
| ErrorOccured msg ->
|
||||
Global.alert Global.Error (string msg)
|
||||
Browser.console.log msg
|
||||
|
||||
@@ -16,9 +16,12 @@ open Fable.Core
|
||||
|
||||
let accountIsSelected (initialState:BTSAccount) (scratch:BTSAccount) = scratch <> initialState
|
||||
|
||||
[<Emit("$0.toLocaleString('en-US', {maximumFractionDigits: 2})")>]
|
||||
[<Emit("$0.toLocaleString('en-US')")>]
|
||||
let withCommas (n:float) : string = jsNative
|
||||
|
||||
[<Emit("$0.toLocaleString('en-US', {maximumFractionDigits: 2})")>]
|
||||
let withCommasAndTwoDigits (n:float) : string = jsNative
|
||||
|
||||
let selectedAccount model =
|
||||
match model.adminData with
|
||||
| Some data ->
|
||||
@@ -117,12 +120,12 @@ let marginView model dispatch =
|
||||
TableControl.Cell (str model.marginData.account)
|
||||
TableControl.Cell (str (withCommas model.marginData.leverageFactor))
|
||||
TableControl.Cell (str (withCommas model.marginData.cashBalance))
|
||||
TableControl.Cell (str (withCommas model.marginData.marginResult.nonoptValue))
|
||||
TableControl.Cell (str (withCommas model.marginData.marginResult.optValue))
|
||||
TableControl.Cell (str (withCommas model.marginData.marginResult.initialMargin))
|
||||
TableControl.Cell (str (withCommas model.marginData.marginResult.maintMargin))
|
||||
TableControl.Cell (str (withCommas model.marginData.accountPnl.dayPnl))
|
||||
TableControl.Cell (str (withCommas model.marginData.excessLiquidity))
|
||||
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.nonoptValue))
|
||||
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.optValue))
|
||||
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.initialMargin))
|
||||
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.marginResult.maintMargin))
|
||||
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.accountPnl.dayPnl))
|
||||
TableControl.Cell (str (withCommasAndTwoDigits model.marginData.excessLiquidity))
|
||||
]
|
||||
className = ""
|
||||
header = None
|
||||
|
||||
@@ -11,6 +11,8 @@ type AlertLevel =
|
||||
[<Emit("alert($1)")>]
|
||||
let alert (_:AlertLevel) (_:string) = Fable.Core.Exceptions.jsNative
|
||||
|
||||
let compareDouble (d1:double) (d2:double) (precision: uint32) = (int (d1 * (double precision))) = (int (d2 * (double precision)))
|
||||
|
||||
|
||||
module Reflection =
|
||||
open Fable.Core.JsInterop
|
||||
@@ -21,7 +23,7 @@ module Reflection =
|
||||
[<Emit("Object.values($0)")>]
|
||||
let values<'a> x : 'a[] = jsNative
|
||||
|
||||
let iterate<'a> x : (string*'a)[] =
|
||||
let iterate<'a> x : (string*'a)[] =
|
||||
Array.zip (keys x) (values x)
|
||||
|
||||
let spread<'a> (a:'a) (b:obj) : 'a = Imports.DynamicService.merge (a,b)
|
||||
|
||||
Reference in new issue
Block a user