diff --git a/src/web/ui/src/Accounts/State.fs b/src/web/ui/src/Accounts/State.fs index 5976740c3..717c2d43d 100644 --- a/src/web/ui/src/Accounts/State.fs +++ b/src/web/ui/src/Accounts/State.fs @@ -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 = | 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 = | 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 diff --git a/src/web/ui/src/Accounts/View.fs b/src/web/ui/src/Accounts/View.fs index 6e49e415b..f077e2ac2 100644 --- a/src/web/ui/src/Accounts/View.fs +++ b/src/web/ui/src/Accounts/View.fs @@ -16,9 +16,12 @@ open Fable.Core let accountIsSelected (initialState:BTSAccount) (scratch:BTSAccount) = scratch <> initialState -[] +[] let withCommas (n:float) : string = jsNative +[] +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 diff --git a/src/web/ui/src/Global.fs b/src/web/ui/src/Global.fs index 4b6dfe9df..41c76cca2 100644 --- a/src/web/ui/src/Global.fs +++ b/src/web/ui/src/Global.fs @@ -11,6 +11,8 @@ type AlertLevel = [] 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 = [] 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)