From 1a7c992e5b89bdb1fef02fd2187dc9fec6f3217f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 29 Aug 2024 22:54:52 +0300 Subject: [PATCH 1/3] Return without setting the flag that's already set --- internal/handlers/ussd/menuhandler.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 5b53b73..7dbdec8 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -89,10 +89,9 @@ func (h *Handlers) CreateAccount(ctx context.Context, sym string, input []byte) return res, err } - // if an account exists, set the flag and return + // if an account exists, return to prevent duplicate account creation existingAccountData, err := h.accountFileHandler.ReadAccountData() if existingAccountData != nil { - res.FlagSet = append(res.FlagSet, models.USERFLAG_ACCOUNT_CREATED) return res, err } From 75ca39b01298446c46061b51a7de5c58b2db581f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 29 Aug 2024 22:57:19 +0300 Subject: [PATCH 2/3] Define the regex pattern as a constant --- internal/handlers/ussd/menuhandler.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 7dbdec8..d4cd430 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -59,6 +59,15 @@ func NewHandlers(path string, st *state.State) *Handlers { } } +// Define the regex pattern as a constant +const pinPattern = `^\d{4}$` + +// isValidPIN checks whether the given input is a 4 digit number +func isValidPIN(pin string) bool { + match, _ := regexp.MatchString(pinPattern, pin) + return match +} + // SetLanguage sets the language across the menu func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { inputStr := string(input) @@ -192,13 +201,6 @@ func (h *Handlers) VerifyPin(ctx context.Context, sym string, input []byte) (res return res, nil } -// isValidPIN checks whether the given input is a 4 digit number -func isValidPIN(pin string) bool { - match, _ := regexp.MatchString(`^\d{4}$`, pin) - return match -} - - //codeFromCtx retrieves language codes from the context that can be used for handling translations func codeFromCtx(ctx context.Context) string { var code string From ca86ef15073f10c91386f3b0587b240671c7d9b3 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 29 Aug 2024 23:05:41 +0300 Subject: [PATCH 3/3] Use gettext for the Quit function --- internal/handlers/ussd/menuhandler.go | 12 ++++++------ services/registration/locale/swa/default.po | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index d4cd430..87447e7 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -452,12 +452,12 @@ func (h *Handlers) CheckAccountStatus(ctx context.Context, sym string, input []b // Quit displays the Thank you message and exits the menu func (h *Handlers) Quit(ctx context.Context, sym string, input []byte) (resource.Result, error) { res := resource.Result{} - switch codeFromCtx(ctx) { - case "swa": - res.Content = "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" - default: - res.Content = "Thank you for using Sarafu. Goodbye!" - } + + code := codeFromCtx(ctx) + l := gotext.NewLocale(translationDir, code) + l.AddDomain("default") + + res.Content = l.Get("Thank you for using Sarafu. Goodbye!") res.FlagReset = append(res.FlagReset, models.USERFLAG_ACCOUNT_UNLOCKED) return res, nil } diff --git a/services/registration/locale/swa/default.po b/services/registration/locale/swa/default.po index 12f6e6c..0a63d07 100644 --- a/services/registration/locale/swa/default.po +++ b/services/registration/locale/swa/default.po @@ -3,3 +3,6 @@ msgstr "Salio lako ni %s" msgid "Your request has been sent. %s will receive %s from %s." msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s." + +msgid "Thank you for using Sarafu. Goodbye!" +msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"