From 873c9a44caa3678eb740daae67ed114414c54da8 Mon Sep 17 00:00:00 2001 From: Zaptoss Date: Tue, 30 Jul 2024 16:36:12 +0300 Subject: [PATCH] Add referrals when balance activates --- internal/service/handlers/activate_balance.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/service/handlers/activate_balance.go b/internal/service/handlers/activate_balance.go index bdb16bc..445db20 100644 --- a/internal/service/handlers/activate_balance.go +++ b/internal/service/handlers/activate_balance.go @@ -97,6 +97,20 @@ func ActivateBalance(w http.ResponseWriter, r *http.Request) { if !balance.IsVerified() { log.Debug("Balance is not verified, events will not be claimed") + + // By default, inactive user have 0 lvl, we must up lvl when user activate balance + level, err := DoLevelRefUpgrade(Levels(r), ReferralsQ(r), balance, 0) + if err != nil { + return fmt.Errorf("failed to do lvlup and referrals updates: %w", err) + } + + err = BalancesQ(r).FilterByNullifier(balance.Nullifier).Update(map[string]any{ + data.ColLevel: level, + }) + if err != nil { + return fmt.Errorf("update balance amount and level: %w", err) + } + return nil }