Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/stable'
Browse files Browse the repository at this point in the history
To bring fixes for bugs 245 and 246.

Fixes #245
Fixes #246
  • Loading branch information
knocte committed Jan 20, 2024
2 parents 0b7c420 + b0d3f83 commit f7a8d56
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/GWallet.Backend/Account.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ open System.Threading.Tasks

open GWallet.Backend.FSharpUtil.UwpHacks

// this exception, if it happens, it would cause a crash because we don't handle it yet
type InconsistentResultFromDifferentServersOfSameCurrency(currency: Currency,
innerException: ResultInconsistencyException) =
inherit Exception (SPrintF2 "Inconsistent results retrieving info for currency %A: %s"
currency
innerException.Message,
innerException)

module Account =

let private GetShowableBalanceAndImminentPaymentInternal (account: IAccount)
Expand Down Expand Up @@ -35,18 +43,22 @@ module Account =
return Fresh 1m,Some false
else

let! maybeBalanceAndImminentIncomingPayment =
GetShowableBalanceAndImminentPaymentInternal account mode cancelSourceOption
match maybeBalanceAndImminentIncomingPayment with
| None ->
let cachedBalance = Caching.Instance.RetrieveLastCompoundBalance account.PublicAddress account.Currency
return (NotFresh cachedBalance, None)
| Some (balance,imminentIncomingPayment) ->
let compoundBalance,_ =
Caching.Instance.RetrieveAndUpdateLastCompoundBalance account.PublicAddress
account.Currency
balance
return (Fresh compoundBalance, imminentIncomingPayment)
try
let! maybeBalanceAndImminentIncomingPayment =
GetShowableBalanceAndImminentPaymentInternal account mode cancelSourceOption
match maybeBalanceAndImminentIncomingPayment with
| None ->
let cachedBalance = Caching.Instance.RetrieveLastCompoundBalance account.PublicAddress account.Currency
return (NotFresh cachedBalance, None)
| Some (balance,imminentIncomingPayment) ->
let compoundBalance,_ =
Caching.Instance.RetrieveAndUpdateLastCompoundBalance account.PublicAddress
account.Currency
balance
return (Fresh compoundBalance, imminentIncomingPayment)
with
| :? ResultInconsistencyException as innerEx ->
return raise <| InconsistentResultFromDifferentServersOfSameCurrency(account.Currency, innerEx)
}

let mutable wiped = false
Expand Down
3 changes: 3 additions & 0 deletions src/GWallet.Frontend.Console/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,12 @@ let rec ProgramMainLoop() =

Console.WriteLine ()
Console.WriteLine "*** STATUS ***"
Console.WriteLine ()

let lines =
UserInteraction.DisplayAccountStatuses(WhichAccount.All activeAccounts)
|> Async.RunSynchronously
Console.WriteLine Environment.NewLine
Console.WriteLine (String.concat Environment.NewLine lines)
Console.WriteLine ()

Expand Down
7 changes: 7 additions & 0 deletions src/GWallet.Frontend.Console/UserInteraction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ module UserInteraction =
// we don't need to query the fiat value at all (micro-optimization?)
let! (balance,_),usdValue = FSharpUtil.AsyncExtensions.MixedParallel2 balanceJob usdValueJob

let progressIteration = sprintf " %A" account.Currency
Console.Write progressIteration

return (account,balance,usdValue)
}

Expand All @@ -265,6 +268,7 @@ module UserInteraction =
let private GetAccountBalances (accounts: seq<IAccount>)
: Async<array<IAccount*MaybeCached<decimal>*MaybeCached<decimal>>> =
let accountAndBalancesToBeQueried = accounts |> Seq.map GetAccountBalanceInner
Console.Write "Retrieving balances..."
Async.Parallel accountAndBalancesToBeQueried

let DisplayAccountStatuses(whichAccount: WhichAccount): Async<seq<string>> =
Expand Down Expand Up @@ -344,6 +348,9 @@ module UserInteraction =
let! accountsWithBalances = GetAccountBalances accounts
let statuses, currencyTotals = displayAllAndSumBalance accountsWithBalances 0 Map.empty

// All balances are fetched and their currency names printed, put a dot at the end of "Retrieving balances... " line.
Console.Write '.'

let maybeTotalInUsd, totals = displayTotalAndSumFiatBalance currencyTotals
return
seq {
Expand Down

0 comments on commit f7a8d56

Please sign in to comment.