From 6811cc12ec9d91a8f8fc10d2438860c9869dfc6d Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Thu, 23 Oct 2025 10:29:14 +0300 Subject: [PATCH] clear the current active voucher data if it exists when no vouchers exist --- handlers/application/vouchers.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index 056f989..1d9d9aa 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -45,6 +45,26 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b res.FlagReset = append(res.FlagReset, flag_api_error) if len(vouchersResp) == 0 { + // clear the current active voucher data if it exists + _, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM) + if err == nil { + firstVoucherMap := map[storedb.DataTyp]string{ + storedb.DATA_ACTIVE_SYM: "", + storedb.DATA_ACTIVE_BAL: "", + storedb.DATA_ACTIVE_DECIMAL: "", + storedb.DATA_ACTIVE_ADDRESS: "", + } + + for key, value := range firstVoucherMap { + if err := userStore.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil { + logg.ErrorCtxf(ctx, "Failed to reset active voucher data", "key", key, "error", err) + return res, err + } + } + + logg.InfoCtxf(ctx, "Default voucher reset") + } + res.FlagSet = append(res.FlagSet, flag_no_active_voucher) return res, nil } -- 2.45.2