Add a default alias to remove bug in retrieving the data
Some checks failed
release / docker (push) Has been cancelled

This commit is contained in:
Alfred Kamanda 2025-03-20 22:34:04 +03:00
parent e681c9cfca
commit 445ca0d0ff
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -195,6 +195,7 @@ func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId strin
data := map[storedb.DataTyp]string{ data := map[storedb.DataTyp]string{
storedb.DATA_TRACKING_ID: trackingId, storedb.DATA_TRACKING_ID: trackingId,
storedb.DATA_PUBLIC_KEY: publicKey, storedb.DATA_PUBLIC_KEY: publicKey,
storedb.DATA_ACCOUNT_ALIAS: "",
} }
store := h.userdataStore store := h.userdataStore
for key, value := range data { for key, value := range data {
@ -1460,7 +1461,7 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
if alias != "" { if alias != "" {
content = l.Get("%s balance: %s\n", alias, balStr) content = l.Get("%s balance: %s\n", alias, balStr)
} else { } else {
content = l.Get("balance: %s\n", balStr) content = l.Get("Balance: %s\n", balStr)
} }
return content, nil return content, nil
} }
@ -1482,16 +1483,6 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
store := h.userdataStore 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 // get the active sym and active balance
activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM) activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
if err != nil { if err != nil {
@ -1502,8 +1493,6 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
} }
} }
logg.InfoCtxf(ctx, "The active data in CheckBalance:", "activeSym", string(activeSym))
activeBal, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL) activeBal, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_BAL)
if err != nil { if err != nil {
if !db.IsNotFound(err) { if !db.IsNotFound(err) {
@ -1512,6 +1501,16 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
} }
} }
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]
}
content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias) content, err = loadUserContent(ctx, string(activeSym), string(activeBal), alias)
if err != nil { if err != nil {
return res, err return res, err
@ -1941,12 +1940,8 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher") flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
// check if the user has an active sym // check if the user has an active sym
activeSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM) _, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
logg.InfoCtxf(ctx, "The activeSym in SetDefaultVoucher:", "activeSym", string(activeSym))
if err != nil { if err != nil {
logg.ErrorCtxf(ctx, "The err", err)
logg.InfoCtxf(ctx, "Checking the data as no activeSym", "DATA_ACTIVE_SYM", storedb.DATA_ACTIVE_SYM)
if db.IsNotFound(err) { if db.IsNotFound(err) {
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
if err != nil { if err != nil {
@ -1961,8 +1956,6 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
return res, nil return res, nil
} }
logg.InfoCtxf(ctx, "fetched user vouchers in SetDefaultVoucher", "public_key", string(publicKey), "vouchers", vouchersResp)
// Return if there is no voucher // Return if there is no voucher
if len(vouchersResp) == 0 { if len(vouchersResp) == 0 {
res.FlagSet = append(res.FlagSet, flag_no_active_voucher) res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
@ -1979,14 +1972,10 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
// Scale down the balance // Scale down the balance
scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec) scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec)
logg.InfoCtxf(ctx, "firstVoucher data", "defaultSym", defaultSym, "defaultBal", defaultBal, "defaultDec", defaultDec, "defaultAddr", defaultAddr)
// TODO: implement atomic transaction // TODO: implement atomic transaction
// set the active symbol // set the active symbol
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM, []byte(defaultSym)) err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM, []byte(defaultSym))
if err != nil { if err != nil {
logg.InfoCtxf(ctx, "got an error in writing DATA_ACTIVE_SYM", "defaultSym", defaultSym)
logg.ErrorCtxf(ctx, "failed to write defaultSym entry with", "key", storedb.DATA_ACTIVE_SYM, "value", defaultSym, "error", err) logg.ErrorCtxf(ctx, "failed to write defaultSym entry with", "key", storedb.DATA_ACTIVE_SYM, "value", defaultSym, "error", err)
return res, err return res, err
} }
@ -2084,8 +2073,6 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
data := store.ProcessVouchers(vouchersResp) data := store.ProcessVouchers(vouchersResp)
logg.InfoCtxf(ctx, "The data in CheckVouchers:", "data", data)
// Store all voucher data // Store all voucher data
dataMap := map[storedb.DataTyp]string{ dataMap := map[storedb.DataTyp]string{
storedb.DATA_VOUCHER_SYMBOLS: data.Symbols, storedb.DATA_VOUCHER_SYMBOLS: data.Symbols,