From c57aa220e669ae79892fe1bc2e7652206b9f5cc6 Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Wed, 4 Feb 2026 17:02:24 +0300 Subject: [PATCH] show a default message if the user only has 1 voucher --- handlers/application/vouchers.go | 17 ++++++++++++++++- services/registration/select_voucher | 1 - 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index 1d9d9aa..895d9c6 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -181,8 +181,18 @@ func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []b return res, fmt.Errorf("missing session") } + code := codeFromCtx(ctx) + l := gotext.NewLocale(translationDir, code) + l.AddDomain("default") + userStore := h.userdataStore + // Fetch session data + _, _, activeSym, _, _, _, err := h.getSessionData(ctx, sessionId) + if err != nil { + return res, nil + } + // Read vouchers from the store voucherData, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_SYMBOLS) logg.InfoCtxf(ctx, "reading voucherData in GetVoucherList", "sessionId", sessionId, "key", storedb.DATA_VOUCHER_SYMBOLS, "voucherData", voucherData) @@ -191,6 +201,11 @@ func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []b return res, err } + if len(voucherData) == 0 { + res.Content = l.Get("Your active voucher %s is already set", string(activeSym)) + return res, nil + } + voucherBalances, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_VOUCHER_BALANCES) logg.InfoCtxf(ctx, "reading voucherBalances in GetVoucherList", "sessionId", sessionId, "key", storedb.DATA_VOUCHER_BALANCES, "voucherBalances", voucherBalances) if err != nil { @@ -203,7 +218,7 @@ func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []b logg.InfoCtxf(ctx, "final output for GetVoucherList", "sessionId", sessionId, "finalOutput", finalOutput) - res.Content = finalOutput + res.Content = l.Get("Select number or symbol from your vouchers:\n%s", finalOutput) return res, nil } diff --git a/services/registration/select_voucher b/services/registration/select_voucher index 084b9b8..ed8140f 100644 --- a/services/registration/select_voucher +++ b/services/registration/select_voucher @@ -1,2 +1 @@ -Select number or symbol from your vouchers: {{.get_vouchers}} \ No newline at end of file