call the UpdateAlias if the account has an Aias
This commit is contained in:
parent
0fcadd4634
commit
ea3a6d8382
@ -2570,6 +2570,7 @@ func (h *MenuHandlers) persistLanguageCode(ctx context.Context, code string) err
|
|||||||
// 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) {
|
func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
var alias string
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return res, fmt.Errorf("missing session")
|
return res, fmt.Errorf("missing session")
|
||||||
@ -2601,21 +2602,35 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sanitizedInput := sanitizeAliasHint(string(input))
|
sanitizedInput := sanitizeAliasHint(string(input))
|
||||||
|
// Check if an alias already exists
|
||||||
|
existingAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
|
||||||
|
if err == nil && len(existingAlias) > 0 {
|
||||||
|
// Update existing alias
|
||||||
|
aliasResult, err := h.accountService.UpdateAlias(ctx, sanitizedInput, string(pubKey))
|
||||||
|
if err != nil {
|
||||||
|
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||||
|
logg.ErrorCtxf(ctx, "failed to update alias", "alias", sanitizedInput, "error", err)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
alias := aliasResult.Alias
|
||||||
|
logg.InfoCtxf(ctx, "Updated alias", "alias", alias)
|
||||||
|
} else {
|
||||||
|
// Register a new alias
|
||||||
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
|
aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.FlagSet = append(res.FlagSet, flag_api_error)
|
res.FlagSet = append(res.FlagSet, flag_api_error)
|
||||||
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err)
|
logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", sanitizedInput, "error_alias_request", err)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
res.FlagReset = append(res.FlagReset, flag_api_error)
|
res.FlagReset = append(res.FlagReset, flag_api_error)
|
||||||
|
|
||||||
alias := aliasResult.Alias
|
alias := aliasResult.Alias
|
||||||
logg.InfoCtxf(ctx, "Suggested alias ", "alias", alias)
|
logg.InfoCtxf(ctx, "Suggested alias", "alias", alias)
|
||||||
|
}
|
||||||
//Store the returned alias,wait for user to confirm it as new account alias
|
//Store the returned alias,wait for user to confirm it as new account alias
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS, []byte(alias))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS, []byte(alias))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to write account alias", "key", storedb.DATA_TEMPORARY_VALUE, "value", alias, "error", err)
|
logg.ErrorCtxf(ctx, "failed to write suggested alias", "key", storedb.DATA_SUGGESTED_ALIAS, "value", alias, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user