From 672eebb8fb43ac8947730532a5d0830c1da93587 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Fri, 11 Oct 2024 09:42:08 +0300 Subject: [PATCH] display the balance based on the symbol --- internal/handlers/ussd/menuhandler.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index e459975..fb1db3f 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -660,11 +660,28 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) ( return res, err } - balance, err := h.accountService.CheckBalance(string(publicKey)) + // check if the user has an active sym + activeSym, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM) if err != nil { - return res, nil + if db.IsNotFound(err) { + logg.Printf(logging.LVL_INFO, "Using the default sym to fetch balance") + balance, err := h.accountService.CheckBalance(string(publicKey)) + if err != nil { + return res, err + } + + res.Content = balance + + return res, nil + } } - res.Content = balance + + activeBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL) + if err != nil { + return res, err + } + + res.Content = fmt.Sprintf("%s %s", activeBal, activeSym) return res, nil }