Compare commits

...

8 Commits

15 changed files with 54 additions and 58 deletions

View File

@ -2585,6 +2585,7 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
}
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
flag_alias_unavailable, _ := h.flagManager.GetFlag("flag_alias_unavailable")
store := h.userdataStore
aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
@ -2608,9 +2609,22 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
}
sanitizedInput := sanitizeAliasHint(string(input))
// Check if an alias already exists
existingAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS)
existingAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS)
if err == nil && len(existingAlias) > 0 {
logg.InfoCtxf(ctx, "Current alias", "alias", string(existingAlias))
// Call the alias resolver to check if the preferred alias is available
fqdn := fmt.Sprintf("%s.%s", sanitizedInput, "sarafu.eth")
logg.InfoCtxf(ctx, "Checking if the fqdn alias is taken", "fqdn", fqdn)
AliasAddress, err := h.accountService.CheckAliasAddress(ctx, fqdn)
if err == nil && len(AliasAddress.Address) > 0 { // if the alias exists / is not available
res.FlagSet = append(res.FlagSet, flag_alias_unavailable)
res.FlagReset = append(res.FlagReset, flag_api_error)
return res, nil
}
res.FlagReset = append(res.FlagReset, flag_alias_unavailable)
// Update existing alias
aliasResult, err := h.accountService.UpdateAlias(ctx, sanitizedInput, string(publicKey))
if err != nil {
@ -2622,6 +2636,19 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
logg.InfoCtxf(ctx, "Updated alias", "alias", alias)
} else {
logg.InfoCtxf(ctx, "Registering a new alias", "err", err)
// Call the alias resolver to check if the preferred alias is available
fqdn := fmt.Sprintf("%s.%s", sanitizedInput, "sarafu.eth")
logg.InfoCtxf(ctx, "Checking if the fqdn alias is taken", "fqdn", fqdn)
_, err = h.accountService.CheckAliasAddress(ctx, fqdn)
if err == nil { // if the alias exists / is not available
res.FlagSet = append(res.FlagSet, flag_alias_unavailable)
res.FlagReset = append(res.FlagReset, flag_api_error)
return res, nil
}
res.FlagReset = append(res.FlagReset, flag_alias_unavailable)
// Register a new alias
aliasResult, err := h.accountService.RequestAlias(ctx, string(publicKey), sanitizedInput)
if err != nil {
@ -2634,14 +2661,16 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
alias = aliasResult.Alias
logg.InfoCtxf(ctx, "Suggested alias", "alias", alias)
}
//Store the returned alias,wait for user to confirm it as new account alias
logg.InfoCtxf(ctx, "Final suggested alias", "alias", alias)
err = store.WriteEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS, []byte(alias))
//Store the new account alias
logg.InfoCtxf(ctx, "Final registered alias", "alias", alias)
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(alias))
if err != nil {
logg.ErrorCtxf(ctx, "failed to write suggested alias", "key", storedb.DATA_SUGGESTED_ALIAS, "value", alias, "error", err)
logg.ErrorCtxf(ctx, "failed to write account alias", "key", storedb.DATA_ACCOUNT_ALIAS, "value", alias, "error", err)
return res, err
}
}
return res, nil
}
@ -2674,38 +2703,6 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input
return res, nil
}
// ConfirmNewAlias reads the suggested alias from the [DATA_SUGGECTED_ALIAS] key 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
logdb := h.logDb
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_SUGGESTED_ALIAS)
if err != nil {
return res, nil
}
logg.InfoCtxf(ctx, "Confirming new alias", "alias", string(newAlias))
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
}
err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(newAlias))
if err != nil {
logg.DebugCtxf(ctx, "Failed to write account alias db log entry", "key", storedb.DATA_ACCOUNT_ALIAS, "value", newAlias)
}
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
func (h *MenuHandlers) ClearTemporaryValue(ctx context.Context, sym string, input []byte) (resource.Result, error) {

View File

@ -131,7 +131,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
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.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated)
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
ls.DbRs.AddLocalFunc("swap_to_list", appHandlers.LoadSwapToList)

View File

@ -1,5 +1,3 @@
LOAD confirm_new_alias 0
RELOAD confirm_new_alias
MOUT back 0
MOUT quit 9
HALT

View File

@ -1,2 +0,0 @@
Your full alias will be: {{.get_suggested_alias}}
Please enter your PIN to confirm:

View File

@ -1,12 +0,0 @@
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

View File

@ -1,2 +0,0 @@
Lakabu yako kamili itakuwa: {{.get_suggested_alias}}
Tafadhali weka PIN yako ili kuthibitisha:

View File

@ -0,0 +1 @@
Home

View File

@ -0,0 +1 @@
Mwanzo

View File

@ -1,3 +1,7 @@
LOAD reset_account_authorized 0
LOAD reset_incorrect_pin 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH pin_entry flag_account_authorized 0
LOAD get_current_profile_info 0
MAP get_current_profile_info
MOUT back 0
@ -5,5 +9,7 @@ HALT
INCMP _ 0
LOAD request_custom_alias 0
RELOAD request_custom_alias
MAP request_custom_alias
CATCH unavailable_alias flag_alias_unavailable 1
CATCH api_failure flag_api_call_error 1
INCMP confirm_new_alias *
INCMP alias_updated *

View File

@ -34,4 +34,4 @@ flag,flag_alias_set,40,this is set when an account alias has been assigned to a
flag,flag_account_pin_reset,41,this is set on an account when an admin triggers a PIN reset for themflag,flag_incorrect_pool,39,this is set when the user selects an invalid pool
flag,flag_incorrect_pool,42,this is set when the user selects an invalid pool
flag,flag_low_swap_amount,43,this is set when the swap max limit is less than 0.1
flag,flag_alias_unavailable,44,this is set when the preferred alias is not available

Can't render this file because it has a wrong number of fields in line 34.

View File

@ -0,0 +1 @@
The alias {{.request_custom_alias}} isn't available

View File

@ -0,0 +1,8 @@
MAP request_custom_alias
MOUT back 0
MOUT home 9
MOUT quit 99
HALT
INCMP _ 0
INCMP ^ 9
INCMP quit 99

View File

@ -0,0 +1 @@
Lakabu ulilochagua {{.request_custom_alias}} halipatikani