From 6811cc12ec9d91a8f8fc10d2438860c9869dfc6d Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Thu, 23 Oct 2025 10:29:14 +0300 Subject: [PATCH 1/3] 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 } From 3fdb0e342622b1b6cc8ab10020abbeb699b9f926 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 26 Nov 2025 12:56:04 +0300 Subject: [PATCH 2/3] update the symbol to send_max_amount with debug output --- handlers/application/send.go | 7 +++++-- handlers/application/send_test.go | 2 +- handlers/local.go | 2 +- services/registration/amount | 2 +- services/registration/amount.vis | 6 +++--- services/registration/amount_swa | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/handlers/application/send.go b/handlers/application/send.go index 4132dc8..f681926 100644 --- a/handlers/application/send.go +++ b/handlers/application/send.go @@ -313,6 +313,8 @@ func (h *MenuHandlers) ResetTransactionAmount(ctx context.Context, sym string, i func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result + fmt.Println("running in MaxAmount with sym:", sym) + sessionId, ok := ctx.Value("SessionId").(string) if !ok { return res, fmt.Errorf("missing session") @@ -335,10 +337,11 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte) // Format the active balance amount to 2 decimal places formattedBalance, _ := store.TruncateDecimalString(string(activeBal), 2) - // If normal transaction, or if the sym is max_amount, return balance - if string(transactionType) == "normal" || sym == "max_amount" { + // If normal transaction, or if the sym is send_max_amount, return balance + if string(transactionType) == "normal" || sym == "send_max_amount" { res.FlagReset = append(res.FlagReset, flag_swap_transaction) + fmt.Println("running in send_max_amount with:", formattedBalance, string(activeSym)) res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym)) return res, nil diff --git a/handlers/application/send_test.go b/handlers/application/send_test.go index cde3598..207032a 100644 --- a/handlers/application/send_test.go +++ b/handlers/application/send_test.go @@ -277,7 +277,7 @@ func TestMaxAmount(t *testing.T) { } } - res, err := h.MaxAmount(ctx, "max_amount", []byte("")) + res, err := h.MaxAmount(ctx, "send_max_amount", []byte("")) if tt.expectedError { assert.Error(t, err) diff --git a/handlers/local.go b/handlers/local.go index 0319a47..25c59cf 100644 --- a/handlers/local.go +++ b/handlers/local.go @@ -85,7 +85,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) ls.DbRs.AddLocalFunc("validate_recipient", appHandlers.ValidateRecipient) ls.DbRs.AddLocalFunc("transaction_reset", appHandlers.TransactionReset) ls.DbRs.AddLocalFunc("invite_valid_recipient", appHandlers.InviteValidRecipient) - ls.DbRs.AddLocalFunc("max_amount", appHandlers.MaxAmount) + ls.DbRs.AddLocalFunc("send_max_amount", appHandlers.MaxAmount) ls.DbRs.AddLocalFunc("credit_max_amount", appHandlers.MaxAmount) ls.DbRs.AddLocalFunc("validate_amount", appHandlers.ValidateAmount) ls.DbRs.AddLocalFunc("reset_transaction_amount", appHandlers.ResetTransactionAmount) diff --git a/services/registration/amount b/services/registration/amount index b50e87a..5f5edfa 100644 --- a/services/registration/amount +++ b/services/registration/amount @@ -1 +1 @@ -{{.max_amount}} \ No newline at end of file +{{.send_max_amount}} \ No newline at end of file diff --git a/services/registration/amount.vis b/services/registration/amount.vis index f8ff102..a752c82 100644 --- a/services/registration/amount.vis +++ b/services/registration/amount.vis @@ -1,8 +1,8 @@ LOAD reset_transaction_amount 10 RELOAD reset_transaction_amount -LOAD max_amount 0 -RELOAD max_amount -MAP max_amount +LOAD send_max_amount 0 +RELOAD send_max_amount +MAP send_max_amount MOUT back 0 HALT LOAD validate_amount 64 diff --git a/services/registration/amount_swa b/services/registration/amount_swa index b50e87a..5f5edfa 100644 --- a/services/registration/amount_swa +++ b/services/registration/amount_swa @@ -1 +1 @@ -{{.max_amount}} \ No newline at end of file +{{.send_max_amount}} \ No newline at end of file From 398610924b5b0c40bdb818dfd0bd244c114b6b4f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 26 Nov 2025 13:02:26 +0300 Subject: [PATCH 3/3] removed the debug output --- handlers/application/send.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/handlers/application/send.go b/handlers/application/send.go index f681926..15751e1 100644 --- a/handlers/application/send.go +++ b/handlers/application/send.go @@ -313,8 +313,6 @@ func (h *MenuHandlers) ResetTransactionAmount(ctx context.Context, sym string, i func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result - fmt.Println("running in MaxAmount with sym:", sym) - sessionId, ok := ctx.Value("SessionId").(string) if !ok { return res, fmt.Errorf("missing session") @@ -341,7 +339,6 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte) if string(transactionType) == "normal" || sym == "send_max_amount" { res.FlagReset = append(res.FlagReset, flag_swap_transaction) - fmt.Println("running in send_max_amount with:", formattedBalance, string(activeSym)) res.Content = l.Get("Maximum amount: %s %s\nEnter amount:", formattedBalance, string(activeSym)) return res, nil