Add a default alias to remove bug in retrieving the data
Some checks failed
release / docker (push) Has been cancelled
Some checks failed
release / docker (push) Has been cancelled
This commit is contained in:
parent
e681c9cfca
commit
445ca0d0ff
@ -195,6 +195,7 @@ func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId strin
|
||||
data := map[storedb.DataTyp]string{
|
||||
storedb.DATA_TRACKING_ID: trackingId,
|
||||
storedb.DATA_PUBLIC_KEY: publicKey,
|
||||
storedb.DATA_ACCOUNT_ALIAS: "",
|
||||
}
|
||||
store := h.userdataStore
|
||||
for key, value := range data {
|
||||
@ -1460,7 +1461,7 @@ func loadUserContent(ctx context.Context, activeSym string, balance string, alia
|
||||
if alias != "" {
|
||||
content = l.Get("%s balance: %s\n", alias, balStr)
|
||||
} else {
|
||||
content = l.Get("balance: %s\n", balStr)
|
||||
content = l.Get("Balance: %s\n", balStr)
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
@ -1482,16 +1483,6 @@ func (h *MenuHandlers) CheckBalance(ctx context.Context, sym string, input []byt
|
||||
|
||||
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
|
||||
activeSym, err := store.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
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")
|
||||
|
||||
// check if the user has an active sym
|
||||
activeSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||
logg.InfoCtxf(ctx, "The activeSym in SetDefaultVoucher:", "activeSym", string(activeSym))
|
||||
_, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||
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) {
|
||||
publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
@ -1961,8 +1956,6 @@ func (h *MenuHandlers) SetDefaultVoucher(ctx context.Context, sym string, input
|
||||
return res, nil
|
||||
}
|
||||
|
||||
logg.InfoCtxf(ctx, "fetched user vouchers in SetDefaultVoucher", "public_key", string(publicKey), "vouchers", vouchersResp)
|
||||
|
||||
// Return if there is no voucher
|
||||
if len(vouchersResp) == 0 {
|
||||
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
|
||||
scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec)
|
||||
|
||||
logg.InfoCtxf(ctx, "firstVoucher data", "defaultSym", defaultSym, "defaultBal", defaultBal, "defaultDec", defaultDec, "defaultAddr", defaultAddr)
|
||||
|
||||
// TODO: implement atomic transaction
|
||||
// set the active symbol
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM, []byte(defaultSym))
|
||||
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)
|
||||
return res, err
|
||||
}
|
||||
@ -2084,8 +2073,6 @@ func (h *MenuHandlers) CheckVouchers(ctx context.Context, sym string, input []by
|
||||
|
||||
data := store.ProcessVouchers(vouchersResp)
|
||||
|
||||
logg.InfoCtxf(ctx, "The data in CheckVouchers:", "data", data)
|
||||
|
||||
// Store all voucher data
|
||||
dataMap := map[storedb.DataTyp]string{
|
||||
storedb.DATA_VOUCHER_SYMBOLS: data.Symbols,
|
||||
|
Loading…
Reference in New Issue
Block a user