fix-multiple-alias-requests #38

Merged
carlos merged 7 commits from fix-multiple-alias-requests into master 2025-03-24 15:47:27 +01:00
4 changed files with 29 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import (
"path" "path"
"strconv" "strconv"
"strings" "strings"
"unicode"
"gopkg.in/leonelquinteros/gotext.v1" "gopkg.in/leonelquinteros/gotext.v1"
@ -1143,7 +1144,12 @@ 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) logg.ErrorCtxf(ctx, "Failed to read account alias entry with", "key", "error", storedb.DATA_ACCOUNT_ALIAS, err)
return res, err return res, err
} }
res.Content = string(profileInfo) alias := string(profileInfo)
if alias == "" {
res.Content = defaultValue
} else {
res.Content = alias
}
default: default:
break break
} }
@ -1187,8 +1193,10 @@ func (h *MenuHandlers) GetProfileInfo(ctx context.Context, sym string, input []b
offerings := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS)) offerings := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_OFFERINGS))
alias := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)) alias := getEntryOrDefault(store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS))
if alias != defaultValue { if alias != defaultValue && alias != "" {
alias = strings.Split(alias, ".")[0] alias = strings.Split(alias, ".")[0]
} else {
alias = defaultValue
} }
// Construct the full name // Construct the full name
@ -1269,20 +1277,10 @@ func (h *MenuHandlers) UpdateAllProfileItems(ctx context.Context, sym string, in
if !ok { if !ok {
return res, fmt.Errorf("missing session") 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) err := h.insertProfileItems(ctx, sessionId, &res)
if err != nil { if err != nil {
return res, err 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 return res, nil
} }
@ -2534,7 +2532,8 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
return res, nil return res, nil
} }
} }
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), string(input)) sanitizedInput := sanitizeAliasHint(string(input))
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
if err != nil { if err != nil {
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err) 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()) return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error())
@ -2551,6 +2550,17 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
return res, nil return res, nil
} }
func sanitizeAliasHint(input string) string {
for i, r := range input {
// Check if the character is a special character (non-alphanumeric)
if !unicode.IsLetter(r) && !unicode.IsNumber(r) {
return input[:i]
}
}
// If no special character is found, return the whole input
return input
}
// 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) { func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result

View File

@ -30,3 +30,7 @@ msgstr "Salio la Kikundi: 0.00"
msgid "Symbol: %s\nBalance: %s" msgid "Symbol: %s\nBalance: %s"
msgstr "Sarafu: %s\nSalio: %s" msgstr "Sarafu: %s\nSalio: %s"
msgid "%s balance: %s\n"
msgstr "%s salio: %s\n"

View File

@ -1,2 +1,2 @@
Current alias: {{.get_current_profile_info}} Current alias: {{.get_current_profile_info}}
Edit my alias: Enter your preferred alias::

View File

@ -1,2 +1,2 @@
Lakabu ya sasa: {{.get_current_profile_info}} Lakabu ya sasa: {{.get_current_profile_info}}
Badilisha Lakabu yangu: Weka lakabu unalopendelea::