From 4b103fc627e035ec9ec11e7912914d657478fe1c Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Tue, 9 Jan 2024 08:47:44 +0100 Subject: [PATCH] (BIDS-2914) fix balance for current day + currency conversion --- db/statistics.go | 5 +++-- services/rewards.go | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/db/statistics.go b/db/statistics.go index c2310d0eac..93292cd150 100644 --- a/db/statistics.go +++ b/db/statistics.go @@ -1309,8 +1309,9 @@ func GetValidatorIncomeHistory(validatorIndices []uint64, lowerBoundDay uint64, } result = append(result, types.ValidatorIncomeHistory{ - Day: int64(currentDay), - ClRewards: int64(totalBalance - lastBalance - lastDeposits + lastWithdrawals), + Day: int64(currentDay), + ClRewards: int64(totalBalance - lastBalance - lastDeposits + lastWithdrawals), + EndBalance: sql.NullInt64{Int64: int64(totalBalance), Valid: true}, // show the latest balance for todays income }) } diff --git a/services/rewards.go b/services/rewards.go index ba4f153965..2250d2da88 100644 --- a/services/rewards.go +++ b/services/rewards.go @@ -29,6 +29,10 @@ func GetValidatorHist(validatorArr []uint64, currency string, start uint64, end var pricesDb []types.Price // we get prices with a 1 day buffer to so we have no problems in different time zones var oneDay = uint64(24 * 60 * 60) + + if start == end { // no date range was provided, use the current day as ending boundary + end = uint64(time.Now().Unix()) + } err = db.WriterDb.Select(&pricesDb, `select ts, eur, usd, gbp, cad, jpy, cny, rub, aud from price where ts >= TO_TIMESTAMP($1) and ts <= TO_TIMESTAMP($2) order by ts desc`, start-oneDay, end+oneDay) if err != nil {