From a984c9dd06ff2c9f5e3dddbb19f72ccbe80a278d Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 14:37:54 +0300 Subject: [PATCH 01/26] add invalid and account alias flags --- services/registration/pp.csv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/registration/pp.csv b/services/registration/pp.csv index aa1eb05..e34de5d 100644 --- a/services/registration/pp.csv +++ b/services/registration/pp.csv @@ -29,4 +29,5 @@ flag,flag_location_set,35,this is set when the location of the profile is set flag,flag_offerings_set,36,this is set when the offerings of the profile is set flag,flag_back_set,37,this is set when it is a back navigation flag,flag_account_blocked,38,this is set when an account has been blocked after the allowed incorrect PIN attempts have been exceeded - +flag,flag_invalid_pin,39,this is set when the given PIN is invalid(is less than or more than 4 digits) +flag,flag_alias_set,40,this is set when an account alias has been assigned to a user From 1f0e7c016ec75dc806b9acc23e3d29a098751bb0 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 14:40:17 +0300 Subject: [PATCH 02/26] add check for account alias data type --- store/db/db.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/store/db/db.go b/store/db/db.go index 10f360a..73c9c5d 100644 --- a/store/db/db.go +++ b/store/db/db.go @@ -130,7 +130,8 @@ func StringToDataTyp(str string) (DataTyp, error) { return DATA_GENDER, nil case "DATA_OFFERINGS": return DATA_OFFERINGS, nil - + case "DATA_ACCOUNT_ALIAS": + return DATA_ACCOUNT_ALIAS, nil default: return 0, errors.New("invalid DataTyp string") } From c09ce320105880eab4b18530d6bee22bfa956e81 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 14:46:09 +0300 Subject: [PATCH 03/26] feat: reset invalid pin flag,update template text --- services/registration/invalid_pin | 2 +- services/registration/invalid_pin.vis | 9 +++++++-- services/registration/invalid_pin_swa | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/registration/invalid_pin b/services/registration/invalid_pin index dd984ea..607c151 100644 --- a/services/registration/invalid_pin +++ b/services/registration/invalid_pin @@ -1 +1 @@ -The PIN you entered is invalid.The PIN must be different from your current PIN.For help call +254757628885 \ No newline at end of file +The PIN you entered is invalid.The PIN must be a 4 digit number. \ No newline at end of file diff --git a/services/registration/invalid_pin.vis b/services/registration/invalid_pin.vis index 3790a08..34e4193 100644 --- a/services/registration/invalid_pin.vis +++ b/services/registration/invalid_pin.vis @@ -1,3 +1,8 @@ -MOUT back 0 +LOAD reset_invalid_pin 6 +RELOAD reset_invalid_pin +MOUT retry 1 +MOUT quit 9 HALT -INCMP _ 0 +INCMP _ 1 +INCMP quit 9 +INCMP . * diff --git a/services/registration/invalid_pin_swa b/services/registration/invalid_pin_swa index 7512242..bba32c7 100644 --- a/services/registration/invalid_pin_swa +++ b/services/registration/invalid_pin_swa @@ -1 +1 @@ -PIN mpya na udhibitisho wa PIN mpya hazilingani.Tafadhali jaribu tena.Kwa usaidizi piga simu +254757628885. +PIN uliyoweka si sahihi. PIN lazima iwe nambari 4. \ No newline at end of file From 939df35c8c4914a8a3db1b8d5ce66451e1d0991a Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 14:48:19 +0300 Subject: [PATCH 04/26] register new menu handlers --- handlers/local.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/handlers/local.go b/handlers/local.go index 7d66c7d..2103c2f 100644 --- a/handlers/local.go +++ b/handlers/local.go @@ -124,6 +124,11 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) ls.DbRs.AddLocalFunc("set_back", appHandlers.SetBack) ls.DbRs.AddLocalFunc("show_blocked_account", appHandlers.ShowBlockedAccount) ls.DbRs.AddLocalFunc("clear_temporary_value", appHandlers.ClearTemporaryValue) + ls.DbRs.AddLocalFunc("reset_invalid_pin", appHandlers.ResetInvalidPIN) + ls.DbRs.AddLocalFunc("request_custom_alias", appHandlers.RequestCustomAlias) + ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias) + ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias) + ls.first = appHandlers.Init return appHandlers, nil From d92dc026f5582eec4cab388943e4e531d0212b92 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 14:51:16 +0300 Subject: [PATCH 05/26] check for invalid PIN --- services/registration/old_pin.vis | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/registration/old_pin.vis b/services/registration/old_pin.vis index aa6eabf..de66e2c 100644 --- a/services/registration/old_pin.vis +++ b/services/registration/old_pin.vis @@ -1,8 +1,8 @@ -RELOAD reset_allow_update +RELOAD reset_incorrect MOUT back 0 HALT INCMP _ 0 RELOAD authorize_account CATCH incorrect_pin flag_incorrect_pin 1 -CATCH _ flag_allow_update 0 +CATCH invalid_pin flag_invalid_pin 1 INCMP new_pin * From 28e734e0ba8df5747f773be020ebfde766474832 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 15:02:28 +0300 Subject: [PATCH 06/26] feat: add my alias menu option --- services/registration/my_account.vis | 3 +++ services/registration/my_account_alias.vis | 8 ++++++++ services/registration/my_account_alias_menu | 1 + services/registration/my_account_alias_menu_swa | 1 + 4 files changed, 13 insertions(+) create mode 100644 services/registration/my_account_alias.vis create mode 100644 services/registration/my_account_alias_menu create mode 100644 services/registration/my_account_alias_menu_swa diff --git a/services/registration/my_account.vis b/services/registration/my_account.vis index e3956d2..c0b624e 100644 --- a/services/registration/my_account.vis +++ b/services/registration/my_account.vis @@ -1,3 +1,4 @@ +LOAD authorize_account 16 LOAD reset_allow_update 0 MOUT profile 1 MOUT change_language 2 @@ -5,6 +6,7 @@ MOUT check_balance 3 MOUT check_statement 4 MOUT pin_options 5 MOUT my_address 6 +MOUT my_account_alias 7 MOUT back 0 HALT INCMP main 0 @@ -14,4 +16,5 @@ INCMP balances 3 INCMP check_statement 4 INCMP pin_management 5 INCMP address 6 +INCMP my_account_alias 7 INCMP . * diff --git a/services/registration/my_account_alias.vis b/services/registration/my_account_alias.vis new file mode 100644 index 0000000..506f432 --- /dev/null +++ b/services/registration/my_account_alias.vis @@ -0,0 +1,8 @@ +LOAD get_current_profile_info 0 +MAP get_current_profile_info +MOUT back 0 +HALT +INCMP _ 0 +LOAD request_custom_alias 0 +RELOAD request_custom_alias +INCMP confirm_new_alias * diff --git a/services/registration/my_account_alias_menu b/services/registration/my_account_alias_menu new file mode 100644 index 0000000..3351fdf --- /dev/null +++ b/services/registration/my_account_alias_menu @@ -0,0 +1 @@ +My Alias \ No newline at end of file diff --git a/services/registration/my_account_alias_menu_swa b/services/registration/my_account_alias_menu_swa new file mode 100644 index 0000000..fdb3f58 --- /dev/null +++ b/services/registration/my_account_alias_menu_swa @@ -0,0 +1 @@ +Lakabu yangu \ No newline at end of file From 0816190469cfb84675c163cf1293366fc04eeaad Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 15:08:29 +0300 Subject: [PATCH 07/26] feat: add node to update your alias --- services/registration/update_alias | 1 + services/registration/update_alias.vis | 7 +++++++ services/registration/update_alias_swa | 1 + 3 files changed, 9 insertions(+) create mode 100644 services/registration/update_alias create mode 100644 services/registration/update_alias.vis create mode 100644 services/registration/update_alias_swa diff --git a/services/registration/update_alias b/services/registration/update_alias new file mode 100644 index 0000000..30f4a65 --- /dev/null +++ b/services/registration/update_alias @@ -0,0 +1 @@ +Your alias has been updated successfully \ No newline at end of file diff --git a/services/registration/update_alias.vis b/services/registration/update_alias.vis new file mode 100644 index 0000000..fcbfc17 --- /dev/null +++ b/services/registration/update_alias.vis @@ -0,0 +1,7 @@ +LOAD confirm_new_alias 0 +RELOAD confirm_new_alias +MOUT back 0 +MOUT quit 9 +HALT +INCMP ^ 0 +INCMP quit 9 diff --git a/services/registration/update_alias_swa b/services/registration/update_alias_swa new file mode 100644 index 0000000..bc60faf --- /dev/null +++ b/services/registration/update_alias_swa @@ -0,0 +1 @@ +Ombi lako la kubadilisha lakabu limefanikiwa. \ No newline at end of file From b887c67e5da16cc8052a23a3aa5888088003439f Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 15:14:04 +0300 Subject: [PATCH 08/26] add node to confirm your alias --- services/registration/confirm_new_alias | 2 ++ services/registration/confirm_new_alias.vis | 12 ++++++++++++ services/registration/confirm_new_alias_swa | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 services/registration/confirm_new_alias create mode 100644 services/registration/confirm_new_alias.vis create mode 100644 services/registration/confirm_new_alias_swa diff --git a/services/registration/confirm_new_alias b/services/registration/confirm_new_alias new file mode 100644 index 0000000..6cc2cc3 --- /dev/null +++ b/services/registration/confirm_new_alias @@ -0,0 +1,2 @@ +Your full alias will be: {{.get_suggested_alias}} +Please enter your PIN to confirm: diff --git a/services/registration/confirm_new_alias.vis b/services/registration/confirm_new_alias.vis new file mode 100644 index 0000000..ad56fe0 --- /dev/null +++ b/services/registration/confirm_new_alias.vis @@ -0,0 +1,12 @@ +LOAD reset_invalid_pin 6 +RELOAD reset_invalid_pin +LOAD get_suggested_alias 0 +RELOAD get_suggested_alias +MAP get_suggested_alias +MOUT back 0 +HALT +INCMP _ 0 +RELOAD authorize_account +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH invalid_pin flag_invalid_pin 1 +CATCH update_alias flag_allow_update 1 diff --git a/services/registration/confirm_new_alias_swa b/services/registration/confirm_new_alias_swa new file mode 100644 index 0000000..e622e9c --- /dev/null +++ b/services/registration/confirm_new_alias_swa @@ -0,0 +1,2 @@ +Lakabu yako kamili itakuwa: {{.get_suggested_alias}} +Tafadhali weka PIN yako ili kuthibitisha: From 78af4d225fe6b8c2bf078294f1083e1b36633138 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 15:47:17 +0300 Subject: [PATCH 09/26] add alias account template --- services/registration/my_account_alias | 2 ++ services/registration/my_account_alias_swa | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 services/registration/my_account_alias create mode 100644 services/registration/my_account_alias_swa diff --git a/services/registration/my_account_alias b/services/registration/my_account_alias new file mode 100644 index 0000000..678037b --- /dev/null +++ b/services/registration/my_account_alias @@ -0,0 +1,2 @@ +Current alias: {{.get_current_profile_info}} +Edit my alias: \ No newline at end of file diff --git a/services/registration/my_account_alias_swa b/services/registration/my_account_alias_swa new file mode 100644 index 0000000..9024a2e --- /dev/null +++ b/services/registration/my_account_alias_swa @@ -0,0 +1,2 @@ +Lakabu ya sasa +Badilisha Lakabu yangu: \ No newline at end of file From f922fb6d43ce994c63b9c97224f36d47a84d809c Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 15:48:25 +0300 Subject: [PATCH 10/26] update authorize_account sink value --- services/registration/pin_management.vis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/registration/pin_management.vis b/services/registration/pin_management.vis index 409b3c8..34d5e79 100644 --- a/services/registration/pin_management.vis +++ b/services/registration/pin_management.vis @@ -1,5 +1,5 @@ LOAD set_back 6 -LOAD authorize_account 5 +LOAD authorize_account 16 LOAD reset_allow_update 4 LOAD verify_new_pin 2 LOAD save_temporary_pin 1 From 8f7d5ff66d760fa531ae61b6b84cd10a6d16e790 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 26 Feb 2025 16:34:00 +0300 Subject: [PATCH 11/26] feat: add request for ens based names from user input --- handlers/application/menuhandler.go | 126 ++++++++++++++++++++++++++-- 1 file changed, 119 insertions(+), 7 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index b4cbd7b..176cff8 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -1,6 +1,7 @@ package application import ( + "bytes" "context" "fmt" "path" @@ -453,6 +454,14 @@ func (h *MenuHandlers) CheckBlockedNumPinMisMatch(ctx context.Context, sym strin return res, nil } +// ResetInvalidPIN resets the invalid PIN flag +func (h *MenuHandlers) ResetInvalidPIN(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + flag_invalid_pin, _ := h.flagManager.GetFlag("flag_invalid_pin") + res.FlagReset = append(res.FlagReset, flag_invalid_pin) + return res, nil +} + // ConfirmPinChange validates user's new PIN. If input matches the temporary PIN, saves it as the new account PIN. func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result @@ -707,10 +716,6 @@ func (h *MenuHandlers) SaveFirstname(ctx context.Context, sym string, input []by logg.ErrorCtxf(ctx, "failed to write firstName entry with", "key", storedb.DATA_FIRST_NAME, "value", temporaryFirstName, "error", err) return res, err } - err := h.constructAccountAlias(ctx) - if err != nil { - return res, err - } res.FlagSet = append(res.FlagSet, flag_firstname_set) } else { if firstNameSet { @@ -1104,6 +1109,18 @@ func (h *MenuHandlers) GetCurrentProfileInfo(ctx context.Context, sym string, in } res.FlagSet = append(res.FlagSet, flag_offerings_set) res.Content = string(profileInfo) + case storedb.DATA_ACCOUNT_ALIAS: + profileInfo, err = store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS) + if err != nil { + if db.IsNotFound(err) { + res.Content = defaultValue + break + } + logg.ErrorCtxf(ctx, "Failed to read account alias entry with", "key", "error", storedb.DATA_ACCOUNT_ALIAS, err) + return res, err + } + res.FlagSet = append(res.FlagSet, flag_offerings_set) + res.Content = string(profileInfo) default: break } @@ -1229,13 +1246,19 @@ func (h *MenuHandlers) UpdateAllProfileItems(ctx context.Context, sym string, in if !ok { return res, fmt.Errorf("missing session") } + flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set") + aliasSet := h.st.MatchFlag(flag_alias_set, true) + err := h.insertProfileItems(ctx, sessionId, &res) if err != nil { return res, err } - err = h.constructAccountAlias(ctx) - if err != nil { - return res, err + //Only request an alias if it has not been set yet: + if !aliasSet { + err = h.constructAccountAlias(ctx) + if err != nil { + return res, err + } } return res, nil } @@ -1275,6 +1298,7 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte) flag_incorrect_pin, _ := h.flagManager.GetFlag("flag_incorrect_pin") flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized") flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") + flag_invalid_pin, _ := h.flagManager.GetFlag("flag_invalid_pin") store := h.userdataStore AccountPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_PIN) @@ -1311,6 +1335,9 @@ func (h *MenuHandlers) Authorize(ctx context.Context, sym string, input []byte) return res, nil } } else { + if string(input) != "0" { + res.FlagSet = append(res.FlagSet, flag_invalid_pin) + } return res, nil } return res, nil @@ -2393,6 +2420,91 @@ func (h *MenuHandlers) constructAccountAlias(ctx context.Context) error { } return nil } +//RequestCustomAlias requests an ENS based alias name based on a user's input,then saves it as temporary value +func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + store := h.userdataStore + aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) + if err != nil { + if db.IsNotFound(err) { + return res, nil + } + return res, err + } + //Ensures that the call doesn't happen twice for the same alias hint + if !bytes.Equal(aliasHint, input) { + err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(string(input))) + if err != nil { + return res, err + } + pubKey, err := store.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) + if err != nil { + if db.IsNotFound(err) { + return res, nil + } + } + aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), string(input)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err) + return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error()) + } + alias := aliasResult.Alias + + //Store the returned alias,wait for user to confirm it as new account alias + err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(alias)) + if err != nil { + logg.ErrorCtxf(ctx, "failed to write account alias", "key", storedb.DATA_TEMPORARY_VALUE, "value", alias, "error", err) + return res, err + } + } + return res, nil +} + +//GetSuggestedAlias loads and displays the suggested alias name from the temporary value +func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + store := h.userdataStore + + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + suggestedAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) + if err != nil { + return res, nil + } + res.Content = string(suggestedAlias) + return res, nil +} + +//ConfirmNewAlias reads the suggested alias from the temporary value and confirms it as the new account alias. +func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + store := h.userdataStore + + flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set") + + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + newAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) + if err != nil { + return res, nil + } + err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(string(newAlias))) + if err != nil { + logg.ErrorCtxf(ctx, "failed to clear DATA_ACCOUNT_ALIAS_VALUE entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "value", "empty", "error", err) + return res, err + } + + res.FlagSet = append(res.FlagSet, flag_alias_set) + return res, nil +} // ClearTemporaryValue empties the DATA_TEMPORARY_VALUE at the main menu to prevent // previously stored data from being accessed From 5ed63cec39aa508e35dcbaf0fc729227c381c288 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 09:41:02 +0300 Subject: [PATCH 12/26] reset invalid PIN flag --- services/registration/pin_management.vis | 1 + 1 file changed, 1 insertion(+) diff --git a/services/registration/pin_management.vis b/services/registration/pin_management.vis index 34d5e79..ca54ee4 100644 --- a/services/registration/pin_management.vis +++ b/services/registration/pin_management.vis @@ -4,6 +4,7 @@ LOAD reset_allow_update 4 LOAD verify_new_pin 2 LOAD save_temporary_pin 1 LOAD reset_incorrect 0 +LOAD reset_invalid_pin 6 MOUT change_pin 1 MOUT reset_pin 2 MOUT back 0 From 7a6e5b094f8d3a30b7d4f469f9026138d9c7dd1f Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 09:42:25 +0300 Subject: [PATCH 13/26] load current alias --- services/registration/my_account_alias_swa | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/registration/my_account_alias_swa b/services/registration/my_account_alias_swa index 9024a2e..6d88e89 100644 --- a/services/registration/my_account_alias_swa +++ b/services/registration/my_account_alias_swa @@ -1,2 +1,2 @@ -Lakabu ya sasa +Lakabu ya sasa: {{.get_current_profile_info}} Badilisha Lakabu yangu: \ No newline at end of file From 3e422f269fab0341a5dcd062adf89a390ebc204e Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 13:14:27 +0300 Subject: [PATCH 14/26] feat: show alias if set on main node --- handlers/application/menuhandler.go | 40 ++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 176cff8..0d2a427 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -1441,8 +1441,13 @@ func (h *MenuHandlers) ShowBlockedAccount(ctx context.Context, sym string, input // CheckBalance retrieves the balance of the active voucher and sets // the balance as the result content. func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { - var res resource.Result - var err error + + var ( + res resource.Result + err error + alias string + content string + ) sessionId, ok := ctx.Value("SessionId").(string) if !ok { @@ -1455,12 +1460,27 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt store := h.userdataStore + accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS) + if err != nil { + if !db.IsNotFound(err) { + logg.ErrorCtxf(ctx, "failed to read account alias entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "error", err) + return res, err + } + } else { + alias = strings.Split(string(accAlias), ".")[0] + } + // get the active sym and active balance activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM) if err != nil { if db.IsNotFound(err) { balance := "0.00" - res.Content = l.Get("Balance: %s\n", balance) + if alias != "" { + content = l.Get("Alias: %s\nBalance: %s\n", alias, balance) + } else { + content = l.Get("Balance: %s\n", balance) + } + res.Content = content return res, nil } @@ -1484,7 +1504,12 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt // Format to 2 decimal places balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym) - res.Content = l.Get("Balance: %s\n", balStr) + if alias != "" { + content = l.Get("Alias: %s\nBalance: %s\n", alias, balStr) + } else { + content = l.Get("Balance: %s\n", balStr) + } + res.Content = content return res, nil } @@ -2420,7 +2445,8 @@ func (h *MenuHandlers) constructAccountAlias(ctx context.Context) error { } return nil } -//RequestCustomAlias requests an ENS based alias name based on a user's input,then saves it as temporary value + +// RequestCustomAlias requests an ENS based alias name based on a user's input,then saves it as temporary value func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result sessionId, ok := ctx.Value("SessionId").(string) @@ -2464,7 +2490,7 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input return res, nil } -//GetSuggestedAlias loads and displays the suggested alias name from the temporary value +// GetSuggestedAlias loads and displays the suggested alias name from the temporary value func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result store := h.userdataStore @@ -2481,7 +2507,7 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input return res, nil } -//ConfirmNewAlias reads the suggested alias from the temporary value and confirms it as the new account alias. +// ConfirmNewAlias reads the suggested alias from the temporary value and confirms it as the new account alias. func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result store := h.userdataStore From 226d1f5697f159fc7e13324a2d11fd9fb962fb99 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 13:21:42 +0300 Subject: [PATCH 15/26] fix: update authorize test function --- handlers/application/menuhandler_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index f008085..2a2263f 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -1037,6 +1037,7 @@ func TestAuthorize(t *testing.T) { flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin") flag_account_authorized, _ := fm.GetFlag("flag_account_authorized") flag_allow_update, _ := fm.GetFlag("flag_allow_update") + flag_invalid_pin, _ := fm.GetFlag("flag_invalid_pin") // Set 1234 is the correct account pin accountPIN := "1234" @@ -1070,9 +1071,11 @@ func TestAuthorize(t *testing.T) { }, }, { - name: "Test with pin that is not a 4 digit", - input: []byte("1235aqds"), - expectedResult: resource.Result{}, + name: "Test with pin that is not a 4 digit", + input: []byte("1235aqds"), + expectedResult: resource.Result{ + FlagSet: []uint32{flag_invalid_pin}, + }, }, } From 0cbe391209760dc56cb16f7506ec9de6987c2521 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 16:00:54 +0300 Subject: [PATCH 16/26] update test data file to include my alias menu option --- menutraversal_test/group_test.json | 38 +++++++++---------- .../profile_edit_start_familyname.json | 2 +- .../profile_edit_start_firstname.json | 2 +- .../profile_edit_start_gender.json | 2 +- .../profile_edit_start_location.json | 2 +- .../profile_edit_start_offerings.json | 2 +- .../profile_edit_start_yob.json | 2 +- .../profile_edit_when_adjacent_item_set.json | 2 +- menutraversal_test/test_setup.json | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index f4bc2df..d1041df 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -71,7 +71,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "5", @@ -108,11 +108,11 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "2", @@ -149,7 +149,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "5", @@ -173,7 +173,7 @@ }, { "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "0", @@ -190,7 +190,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "5", @@ -239,7 +239,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "5", @@ -264,7 +264,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "3", @@ -292,7 +292,7 @@ }, { "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "0", @@ -309,7 +309,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "3", @@ -337,7 +337,7 @@ }, { "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "0", @@ -354,7 +354,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -411,7 +411,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -448,7 +448,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -489,7 +489,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -526,7 +526,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -563,7 +563,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -600,7 +600,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", @@ -633,7 +633,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_start_familyname.json b/menutraversal_test/profile_edit_start_familyname.json index 98325b0..bb8bf0d 100644 --- a/menutraversal_test/profile_edit_start_familyname.json +++ b/menutraversal_test/profile_edit_start_familyname.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_start_firstname.json b/menutraversal_test/profile_edit_start_firstname.json index 0f6be8b..1fa2ca6 100644 --- a/menutraversal_test/profile_edit_start_firstname.json +++ b/menutraversal_test/profile_edit_start_firstname.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_start_gender.json b/menutraversal_test/profile_edit_start_gender.json index afca12a..d95420f 100644 --- a/menutraversal_test/profile_edit_start_gender.json +++ b/menutraversal_test/profile_edit_start_gender.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_start_location.json b/menutraversal_test/profile_edit_start_location.json index 8852911..86541a3 100644 --- a/menutraversal_test/profile_edit_start_location.json +++ b/menutraversal_test/profile_edit_start_location.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_start_offerings.json b/menutraversal_test/profile_edit_start_offerings.json index 6aa40f6..2fc976a 100644 --- a/menutraversal_test/profile_edit_start_offerings.json +++ b/menutraversal_test/profile_edit_start_offerings.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_start_yob.json b/menutraversal_test/profile_edit_start_yob.json index 45227f7..10c1d11 100644 --- a/menutraversal_test/profile_edit_start_yob.json +++ b/menutraversal_test/profile_edit_start_yob.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/profile_edit_when_adjacent_item_set.json b/menutraversal_test/profile_edit_when_adjacent_item_set.json index f8d7263..ec7c880 100644 --- a/menutraversal_test/profile_edit_when_adjacent_item_set.json +++ b/menutraversal_test/profile_edit_when_adjacent_item_set.json @@ -9,7 +9,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "1", diff --git a/menutraversal_test/test_setup.json b/menutraversal_test/test_setup.json index 8728640..375be80 100644 --- a/menutraversal_test/test_setup.json +++ b/menutraversal_test/test_setup.json @@ -116,7 +116,7 @@ }, { "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n7:My Alias\n0:Back" }, { "input": "6", From 830d867ac850b57e32200546b12f0a20b38fce89 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 16:35:17 +0300 Subject: [PATCH 17/26] chore: remove alias tag,use lower case b for balance --- handlers/application/menuhandler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 0d2a427..497c501 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -1476,9 +1476,9 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt if db.IsNotFound(err) { balance := "0.00" if alias != "" { - content = l.Get("Alias: %s\nBalance: %s\n", alias, balance) + content = l.Get("%s balance: %s\n", alias, balance) } else { - content = l.Get("Balance: %s\n", balance) + content = l.Get("balance: %s\n", balance) } res.Content = content return res, nil @@ -1505,9 +1505,9 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym) if alias != "" { - content = l.Get("Alias: %s\nBalance: %s\n", alias, balStr) + content = l.Get("%s balance: %s\n", alias, balStr) } else { - content = l.Get("Balance: %s\n", balStr) + content = l.Get("balance: %s\n", balStr) } res.Content = content From 101afd5ebd2a581a0e1be43d54861bb645d8c56e Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 27 Feb 2025 16:35:41 +0300 Subject: [PATCH 18/26] update check balance test --- menutraversal_test/group_test.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index d1041df..b3177a9 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -284,7 +284,7 @@ }, { "input": "1234", - "expectedContent": "Balance: {balance}\n\n0:Back\n9:Quit" + "expectedContent": "{balance}\n\n0:Back\n9:Quit" }, { "input": "0", From 20c8af582c223e912de97017d80fe208f1c6dc94 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 28 Feb 2025 17:29:18 +0300 Subject: [PATCH 19/26] switch to use ens api endpoint for the aliases requests --- services/remote.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/remote.go b/services/remote.go index baad08f..07e78fe 100644 --- a/services/remote.go +++ b/services/remote.go @@ -14,6 +14,6 @@ import ( func New(ctx context.Context, storageService storage.StorageService) remote.AccountService { return &httpremote.HTTPAccountService{ SS: storageService, - UseApi: false, + UseApi: true, } } From c2a0b05c84462067456970de472e5240dd6a0cd9 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 3 Mar 2025 12:12:46 +0300 Subject: [PATCH 20/26] fix: update expected content in checkbalance function --- handlers/application/menuhandler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index 2a2263f..d8ef9b2 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -1727,7 +1727,7 @@ func TestCheckBalance(t *testing.T) { publicKey: "0X98765432109", activeSym: "ETH", activeBal: "1.5", - expectedResult: resource.Result{Content: "Balance: 1.50 ETH\n"}, + expectedResult: resource.Result{Content: "balance: 1.50 ETH\n"}, expectError: false, }, } From e97d4be296ee2dd35197b28aabb7487fc3061886 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 3 Mar 2025 12:16:45 +0300 Subject: [PATCH 21/26] refactor: break down checkbalance function to avoild code redandancy,remove misplaced flag setting --- handlers/application/menuhandler.go | 68 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 497c501..f90012d 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -3,6 +3,7 @@ package application import ( "bytes" "context" + "errors" "fmt" "path" "strconv" @@ -1119,7 +1120,6 @@ func (h *MenuHandlers) GetCurrentProfileInfo(ctx context.Context, sym string, in logg.ErrorCtxf(ctx, "Failed to read account alias entry with", "key", "error", storedb.DATA_ACCOUNT_ALIAS, err) return res, err } - res.FlagSet = append(res.FlagSet, flag_offerings_set) res.Content = string(profileInfo) default: break @@ -1438,6 +1438,33 @@ func (h *MenuHandlers) ShowBlockedAccount(ctx context.Context, sym string, input return res, nil } +// loadUserContent loads the main user content in the main menu: the alias,balance associated with active voucher +func loadUserContent(ctx context.Context, activeSym string, balance string, alias string) (string, error) { + var content string + + code := codeFromCtx(ctx) + l := gotext.NewLocale(translationDir, code) + l.AddDomain("default") + + balFloat, err := strconv.ParseFloat(balance, 64) + if err != nil { + //Only exclude ErrSyntax error to avoid returning an error if the active bal is not available yet + if !errors.Is(err, strconv.ErrSyntax) { + logg.ErrorCtxf(ctx, "failed to parse activeBal as float", "value", balance, "error", err) + return "", err + } + balFloat = 0.00 + } + // Format to 2 decimal places + balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym) + if alias != "" { + content = l.Get("%s balance: %s\n", alias, balStr) + } else { + content = l.Get("balance: %s\n", balStr) + } + return content, nil +} + // CheckBalance retrieves the balance of the active voucher and sets // the balance as the result content. func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { @@ -1454,10 +1481,6 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt return res, fmt.Errorf("missing session") } - code := codeFromCtx(ctx) - l := gotext.NewLocale(translationDir, code) - l.AddDomain("default") - store := h.userdataStore accAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS) @@ -1473,42 +1496,25 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt // get the active sym and active balance activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM) if err != nil { - if db.IsNotFound(err) { - balance := "0.00" - if alias != "" { - content = l.Get("%s balance: %s\n", alias, balance) - } else { - content = l.Get("balance: %s\n", balance) - } - res.Content = content - return res, nil + if !db.IsNotFound(err) { + logg.ErrorCtxf(ctx, "failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err) + return res, err } - - logg.ErrorCtxf(ctx, "failed to read activeSym entry with", "key", storedb.DATA_ACTIVE_SYM, "error", err) - return res, err } activeBal, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL) if err != nil { - logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err) - return res, err + if !db.IsNotFound(err) { + logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err) + return res, err + } + } - // Convert activeBal from []byte to float64 - balFloat, err := strconv.ParseFloat(string(activeBal), 64) + content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias) if err != nil { - logg.ErrorCtxf(ctx, "failed to parse activeBal as float", "value", string(activeBal), "error", err) return res, err } - - // Format to 2 decimal places - balStr := fmt.Sprintf("%.2f %s", balFloat, activeSym) - - if alias != "" { - content = l.Get("%s balance: %s\n", alias, balStr) - } else { - content = l.Get("balance: %s\n", balStr) - } res.Content = content return res, nil From 4dba5f2ab5b36ee71b49e6885489dc9d2c5c948d Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 7 Mar 2025 09:48:30 +0300 Subject: [PATCH 22/26] dep: upgrade sarafu-api dep --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index a75e399..23d306c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69 + git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index 1cd58c7..9b864a3 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69 h1:cbBpm9uNJak58MpFpNXJuvgCmz+A8kquXr9har4expg= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae h1:C8k2d/QY6KPjz+3uzX5IJiRgwGjRniP14UBPcroAT94= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 h1:BXotWSKg04U97sf/xeWJuUTSVgKk2aEK+5BtBrnafXQ= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E= From bd0e7822ed9656b436710144b443351a6a25eb30 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 7 Mar 2025 16:13:23 +0300 Subject: [PATCH 23/26] dep: upgrade sarafu-api dep --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 23d306c..52af43b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae + git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033 git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index 9b864a3..a40aff7 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944- git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250206112944-31eb30de0f69/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae h1:C8k2d/QY6KPjz+3uzX5IJiRgwGjRniP14UBPcroAT94= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033 h1:nFesCueH+xTUKRtzRlrD/ha42MJBE1D7r/JjD/MwbHU= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 h1:BXotWSKg04U97sf/xeWJuUTSVgKk2aEK+5BtBrnafXQ= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E= From f7e7f7bd1cfa7e84014d942dd277909b0aff28b2 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 10 Mar 2025 11:51:02 +0300 Subject: [PATCH 24/26] add for check back,add logs for the alias --- handlers/application/menuhandler.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index f90012d..1aeda8e 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -1619,6 +1619,7 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input //Perform a search for each search domain,break on first match for _, domain := range config.SearchDomains() { fqdn := fmt.Sprintf("%s.%s", recipient, domain) + logg.InfoCtxf(ctx, "Resolving with fqdn alias", "alias", fqdn) AliasAddress, err = h.accountService.CheckAliasAddress(ctx, fqdn) if err == nil { AliasAddressResult = AliasAddress.Address @@ -2459,6 +2460,10 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input if !ok { return res, fmt.Errorf("missing session") } + if string(input) == "0" { + return res, nil + } + store := h.userdataStore aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) if err != nil { From 38ef3b623e09fc6bf70adaec9f2a9ddd1f7e5da8 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 10 Mar 2025 11:53:47 +0300 Subject: [PATCH 25/26] dep: update sarafu-api dep --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 52af43b..f9551c8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033 + git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310084949-dda02852bf46 git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index a40aff7..150df2c 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509- git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307064509-9c8a3df971ae/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033 h1:nFesCueH+xTUKRtzRlrD/ha42MJBE1D7r/JjD/MwbHU= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310084949-dda02852bf46 h1:ikchtIvwd2MYWWvKZ8xFiozeON5JyIUnFZNq7pUgXlg= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310084949-dda02852bf46/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 h1:BXotWSKg04U97sf/xeWJuUTSVgKk2aEK+5BtBrnafXQ= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E= From 1af826e87fa4f2565748a4b05d1a1ed1dcbca59f Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 10 Mar 2025 12:41:16 +0300 Subject: [PATCH 26/26] dep: update sarafu-api dep --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f9551c8..0063d15 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.4 require ( git.defalsify.org/vise.git v0.2.3-0.20250205173834-d1f6647211ac git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d - git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310084949-dda02852bf46 + git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 github.com/alecthomas/assert/v2 v2.2.2 diff --git a/go.sum b/go.sum index 150df2c..fc169cb 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040- git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250307131040-6e437cb8e033/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310084949-dda02852bf46 h1:ikchtIvwd2MYWWvKZ8xFiozeON5JyIUnFZNq7pUgXlg= git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310084949-dda02852bf46/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b h1:xiTpaqWWoF5qcnarY/9ZkT6aVdnKwqztb2gzIahJn4w= +git.grassecon.net/grassrootseconomics/sarafu-api v0.9.0-beta.1.0.20250310093912-8145b4bd004b/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244 h1:BXotWSKg04U97sf/xeWJuUTSVgKk2aEK+5BtBrnafXQ= git.grassecon.net/grassrootseconomics/visedriver v0.9.0-beta.1.0.20250204132347-1eb0b1555244/go.mod h1:6B6ByxXOiRY0NR7K02Bf3fEu7z+2c/6q8PFVNjC5G8w= git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250129070628-5a539172c694 h1:DjJlBSz0S13acft5XZDWk7ZYnzElym0xLMYEVgyNJ+E=