From e274967c8e767c7c468ddfd2c7a0a5fe919d1392 Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Mon, 25 Aug 2025 10:52:22 +0300 Subject: [PATCH] update the handlePhoneNumber logic to cover new users or those without an active voucher --- handlers/application/send.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/handlers/application/send.go b/handlers/application/send.go index 5ccc58d..805539a 100644 --- a/handlers/application/send.go +++ b/handlers/application/send.go @@ -94,23 +94,31 @@ func (h *MenuHandlers) handlePhoneNumber(ctx context.Context, sessionId, recipie logg.ErrorCtxf(ctx, "Failed to read sender activeSym", "error", err) return *res, err } - recipientActiveToken, err := store.ReadEntry(ctx, formattedNumber, storedb.DATA_ACTIVE_SYM) - if err != nil { - logg.ErrorCtxf(ctx, "Failed to read recipient activeSym", "error", err) - return *res, err - } + + recipientActiveToken, _ := store.ReadEntry(ctx, formattedNumber, storedb.DATA_ACTIVE_SYM) txType := "swap" - if senderSym != nil && recipientActiveToken != nil && string(senderSym) == string(recipientActiveToken) { + + // recipient has no active token → normal transaction + if recipientActiveToken == nil { + txType = "normal" + } else if senderSym != nil && string(senderSym) == string(recipientActiveToken) { + // recipient has active token same as sender → normal transaction txType = "normal" } + + // save transaction type if err := store.WriteEntry(ctx, sessionId, storedb.DATA_SEND_TRANSACTION_TYPE, []byte(txType)); err != nil { logg.ErrorCtxf(ctx, "Failed to write tx type", "type", txType, "error", err) return *res, err } - if err := store.WriteEntry(ctx, sessionId, storedb.DATA_RECIPIENT_ACTIVE_TOKEN, recipientActiveToken); err != nil { - logg.ErrorCtxf(ctx, "Failed to write recipient active token", "error", err) - return *res, err + + // only save recipient’s active token if it exists + if recipientActiveToken != nil { + if err := store.WriteEntry(ctx, sessionId, storedb.DATA_RECIPIENT_ACTIVE_TOKEN, recipientActiveToken); err != nil { + logg.ErrorCtxf(ctx, "Failed to write recipient active token", "error", err) + return *res, err + } } return *res, nil