Merge pull request 'New alias flow' (#96) from new-alias-flow into master
Some checks failed
release / docker (push) Has been cancelled
Some checks failed
release / docker (push) Has been cancelled
Reviewed-on: #96
This commit is contained in:
commit
823133aa37
@ -1495,7 +1495,7 @@ func (h *MenuHandlers) ShowBlockedAccount(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadUserContent loads the main user content in the main menu: the alias,balance associated with active voucher
|
// loadUserContent loads the main user content in the main menu: the alias, balance and active symbol associated with active voucher
|
||||||
func loadUserContent(ctx context.Context, activeSym string, balance string, alias string) (string, error) {
|
func loadUserContent(ctx context.Context, activeSym string, balance string, alias string) (string, error) {
|
||||||
var content string
|
var content string
|
||||||
|
|
||||||
@ -1512,7 +1512,7 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
|
|||||||
// format the final output
|
// format the final output
|
||||||
balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
|
balStr := fmt.Sprintf("%s %s", formattedAmount, activeSym)
|
||||||
if alias != "" {
|
if alias != "" {
|
||||||
content = l.Get("%s balance: %s\n", alias, balStr)
|
content = l.Get("%s\nBalance: %s\n", alias, balStr)
|
||||||
} else {
|
} else {
|
||||||
content = l.Get("Balance: %s\n", balStr)
|
content = l.Get("Balance: %s\n", balStr)
|
||||||
}
|
}
|
||||||
@ -1525,7 +1525,6 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
|
|||||||
var (
|
var (
|
||||||
res resource.Result
|
res resource.Result
|
||||||
err error
|
err error
|
||||||
alias string
|
|
||||||
content string
|
content string
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1560,11 +1559,8 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
|
|||||||
logg.ErrorCtxf(ctx, "failed to read account alias entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "error", err)
|
logg.ErrorCtxf(ctx, "failed to read account alias entry with", "key", storedb.DATA_ACCOUNT_ALIAS, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
alias = strings.Split(string(accAlias), ".")[0]
|
|
||||||
}
|
}
|
||||||
|
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), string(accAlias))
|
||||||
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -2585,6 +2581,7 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
|
|
||||||
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
|
flag_alias_unavailable, _ := h.flagManager.GetFlag("flag_alias_unavailable")
|
||||||
|
|
||||||
store := h.userdataStore
|
store := h.userdataStore
|
||||||
aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
||||||
@ -2608,9 +2605,19 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
sanitizedInput := sanitizeAliasHint(string(input))
|
sanitizedInput := sanitizeAliasHint(string(input))
|
||||||
// Check if an alias already exists
|
// 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 {
|
if err == nil && len(existingAlias) > 0 {
|
||||||
logg.InfoCtxf(ctx, "Current alias", "alias", string(existingAlias))
|
logg.InfoCtxf(ctx, "Current alias", "alias", string(existingAlias))
|
||||||
|
|
||||||
|
unavailable, err := h.isAliasUnavailable(ctx, sanitizedInput)
|
||||||
|
if err == nil && unavailable {
|
||||||
|
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
|
// Update existing alias
|
||||||
aliasResult, err := h.accountService.UpdateAlias(ctx, sanitizedInput, string(publicKey))
|
aliasResult, err := h.accountService.UpdateAlias(ctx, sanitizedInput, string(publicKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2622,6 +2629,16 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
logg.InfoCtxf(ctx, "Updated alias", "alias", alias)
|
logg.InfoCtxf(ctx, "Updated alias", "alias", alias)
|
||||||
} else {
|
} else {
|
||||||
logg.InfoCtxf(ctx, "Registering a new alias", "err", err)
|
logg.InfoCtxf(ctx, "Registering a new alias", "err", err)
|
||||||
|
|
||||||
|
unavailable, err := h.isAliasUnavailable(ctx, sanitizedInput)
|
||||||
|
if err == nil && unavailable {
|
||||||
|
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
|
// Register a new alias
|
||||||
aliasResult, err := h.accountService.RequestAlias(ctx, string(publicKey), sanitizedInput)
|
aliasResult, err := h.accountService.RequestAlias(ctx, string(publicKey), sanitizedInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2632,16 +2649,18 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input
|
|||||||
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, "Registered 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)
|
//Store the new account alias
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS, []byte(alias))
|
logg.InfoCtxf(ctx, "Final registered alias", "alias", alias)
|
||||||
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(alias))
|
||||||
if err != nil {
|
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, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2656,54 +2675,19 @@ func sanitizeAliasHint(input string) string {
|
|||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSuggestedAlias loads and displays the suggested alias name from the temporary value
|
func (h *MenuHandlers) isAliasUnavailable(ctx context.Context, alias string) (bool, error) {
|
||||||
func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
fqdn := fmt.Sprintf("%s.%s", alias, "sarafu.eth")
|
||||||
var res resource.Result
|
logg.InfoCtxf(ctx, "Checking if the fqdn alias is taken", "fqdn", fqdn)
|
||||||
store := h.userdataStore
|
|
||||||
|
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
aliasAddress, err := h.accountService.CheckAliasAddress(ctx, fqdn)
|
||||||
if !ok {
|
|
||||||
return res, fmt.Errorf("missing session")
|
|
||||||
}
|
|
||||||
suggestedAlias, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SUGGESTED_ALIAS)
|
|
||||||
if err != nil && len(suggestedAlias) <= 0 {
|
|
||||||
logg.ErrorCtxf(ctx, "failed to read suggested alias", "key", storedb.DATA_SUGGESTED_ALIAS, "error", err)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
res.Content = string(suggestedAlias)
|
|
||||||
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 {
|
if err != nil {
|
||||||
return res, nil
|
return false, err
|
||||||
}
|
}
|
||||||
logg.InfoCtxf(ctx, "Confirming new alias", "alias", string(newAlias))
|
if len(aliasAddress.Address) > 0 {
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(string(newAlias)))
|
return true, nil
|
||||||
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))
|
return false, nil
|
||||||
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
|
// ClearTemporaryValue empties the DATA_TEMPORARY_VALUE at the main menu to prevent
|
||||||
|
@ -130,8 +130,6 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
|||||||
ls.DbRs.AddLocalFunc("clear_temporary_value", appHandlers.ClearTemporaryValue)
|
ls.DbRs.AddLocalFunc("clear_temporary_value", appHandlers.ClearTemporaryValue)
|
||||||
ls.DbRs.AddLocalFunc("reset_invalid_pin", appHandlers.ResetInvalidPIN)
|
ls.DbRs.AddLocalFunc("reset_invalid_pin", appHandlers.ResetInvalidPIN)
|
||||||
ls.DbRs.AddLocalFunc("request_custom_alias", appHandlers.RequestCustomAlias)
|
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("check_account_created", appHandlers.CheckAccountCreated)
|
||||||
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
|
ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure)
|
||||||
ls.DbRs.AddLocalFunc("swap_to_list", appHandlers.LoadSwapToList)
|
ls.DbRs.AddLocalFunc("swap_to_list", appHandlers.LoadSwapToList)
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
LOAD confirm_new_alias 0
|
|
||||||
RELOAD confirm_new_alias
|
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
MOUT quit 9
|
MOUT quit 9
|
||||||
HALT
|
HALT
|
@ -1,2 +0,0 @@
|
|||||||
Your full alias will be: {{.get_suggested_alias}}
|
|
||||||
Please enter your PIN to confirm:
|
|
@ -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
|
|
@ -1,2 +0,0 @@
|
|||||||
Lakabu yako kamili itakuwa: {{.get_suggested_alias}}
|
|
||||||
Tafadhali weka PIN yako ili kuthibitisha:
|
|
1
services/registration/home_menu
Normal file
1
services/registration/home_menu
Normal file
@ -0,0 +1 @@
|
|||||||
|
Home
|
1
services/registration/home_menu_swa
Normal file
1
services/registration/home_menu_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Mwanzo
|
@ -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
|
LOAD get_current_profile_info 0
|
||||||
MAP get_current_profile_info
|
MAP get_current_profile_info
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
@ -5,5 +9,7 @@ HALT
|
|||||||
INCMP _ 0
|
INCMP _ 0
|
||||||
LOAD request_custom_alias 0
|
LOAD request_custom_alias 0
|
||||||
RELOAD request_custom_alias
|
RELOAD request_custom_alias
|
||||||
|
MAP request_custom_alias
|
||||||
|
CATCH unavailable_alias flag_alias_unavailable 1
|
||||||
CATCH api_failure flag_api_call_error 1
|
CATCH api_failure flag_api_call_error 1
|
||||||
INCMP confirm_new_alias *
|
INCMP alias_updated *
|
||||||
|
@ -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_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_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_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.
|
1
services/registration/unavailable_alias
Normal file
1
services/registration/unavailable_alias
Normal file
@ -0,0 +1 @@
|
|||||||
|
The alias {{.request_custom_alias}} isn't available
|
8
services/registration/unavailable_alias.vis
Normal file
8
services/registration/unavailable_alias.vis
Normal 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
|
1
services/registration/unavailable_alias_swa
Normal file
1
services/registration/unavailable_alias_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Lakabu ulilochagua {{.request_custom_alias}} halipatikani
|
Loading…
Reference in New Issue
Block a user