diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index fbb254b..e459975 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1123,6 +1123,10 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r if err != nil { return res, err } + err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_BAL, []byte(matchedBalance)) + if err != nil { + return res, err + } res.Content = fmt.Sprintf("%s\n%s", matchedSymbol, matchedBalance) res.FlagReset = append(res.FlagReset, flag_incorrect_voucher) } else { @@ -1149,18 +1153,33 @@ func (h *Handlers) SetVoucher(ctx context.Context, sym string, input []byte) (re if err != nil { return res, err } + // get the current temporary balance + temporaryBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_BAL) + if err != nil { + return res, err + } // set the active symbol err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM, []byte(temporarySym)) if err != nil { return res, err } + // set the active balance + err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL, []byte(temporaryBal)) + if err != nil { + return res, err + } // reset the temporary symbol err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_SYM, []byte("")) if err != nil { return res, err } + // reset the temporary balance + err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_BAL, []byte("")) + if err != nil { + return res, err + } res.Content = string(temporarySym) diff --git a/internal/utils/db.go b/internal/utils/db.go index f70e08b..45e7681 100644 --- a/internal/utils/db.go +++ b/internal/utils/db.go @@ -26,6 +26,8 @@ const ( DATA_VOUCHER_LIST DATA_TEMPORARY_SYM DATA_ACTIVE_SYM + DATA_TEMPORARY_BAL + DATA_ACTIVE_BAL ) func typToBytes(typ DataTyp) []byte {