menu-voucherlist #101

Merged
lash merged 63 commits from menu-voucherlist into master 2024-10-25 15:59:47 +02:00
Showing only changes of commit a5b1c5b74e - Show all commits

View File

@ -233,28 +233,6 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt
return res, nil
}
// GetVoucherList fetches the list of vouchers and formats them
// checks whether they are stored internally before calling the API
func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
// check if the vouchers exist internally and if not
// fetch from the API
// Read vouchers from the store
store := h.userdataStore
prefixdb := storage.NewSubPrefixDb(store, []byte("token_holdings"))
voucherData, err := prefixdb.Get(ctx, []byte("tokens"))
if err != nil {
return res, nil
}
res.Content = string(voucherData)
return res, nil
}
func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
sessionId, ok := ctx.Value("SessionId").(string)
@ -1057,13 +1035,13 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
voucherSymbolList := strings.Join(numberedSymbols, "\n")
voucherBalanceList := strings.Join(numberedBalances, "\n")
prefixdb := storage.NewSubPrefixDb(store, []byte("token_holdings"))
err = prefixdb.Put(ctx, []byte("tokens"), []byte(voucherSymbolList))
prefixdb := storage.NewSubPrefixDb(store, []byte("pfx"))
err = prefixdb.Put(ctx, []byte("sym"), []byte(voucherSymbolList))
if err != nil {
return res, nil
}
err = prefixdb.Put(ctx, []byte(voucherSymbolList), []byte(voucherBalanceList))
err = prefixdb.Put(ctx, []byte("bal"), []byte(voucherBalanceList))
if err != nil {
return res, nil
}
@ -1071,6 +1049,24 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
return res, nil
}
// GetVoucherList fetches the list of vouchers and formats them
func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
// Read vouchers from the store
store := h.userdataStore
prefixdb := storage.NewSubPrefixDb(store, []byte("pfx"))
voucherData, err := prefixdb.Get(ctx, []byte("sym"))
if err != nil {
return res, nil
}
res.Content = string(voucherData)
return res, nil
}
// ViewVoucher retrieves the token holding and balance from the subprefixDB
func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
@ -1082,25 +1078,25 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r
return res, fmt.Errorf("missing session")
}
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
inputStr := string(input)
if inputStr == "0" || inputStr == "99" {
lash marked this conversation as resolved Outdated
Outdated
Review

Now this is code smell; we don't want to use menu selectors in branching here.

But I assume it is done because it is necessary to determine whether we are selecting token or merely navigating laterally? If that is the case, I will make an issue for go-vise to provide whether lateral is indeed the case.

Now this is code smell; we don't want to use menu selectors in branching here. But I assume it is done because it is necessary to determine whether we are selecting token or merely navigating laterally? If that is the case, I will make an issue for go-vise to provide whether lateral is indeed the case.

This was added because the vise runs the function when we're navigating, instead of prioritizing the INCMP and navigate to the specified node

This was added because the vise runs the function when we're navigating, instead of prioritizing the INCMP and navigate to the specified node
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
return res, nil
}
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
// Initialize the store and prefix database
prefixdb := storage.NewSubPrefixDb(store, []byte("token_holdings"))
prefixdb := storage.NewSubPrefixDb(store, []byte("pfx"))
// Retrieve the voucher symbol list
voucherSymbolList, err := prefixdb.Get(ctx, []byte("tokens"))
voucherSymbolList, err := prefixdb.Get(ctx, []byte("sym"))
if err != nil {
return res, fmt.Errorf("failed to retrieve voucher symbol list: %v", err)
}
// Retrieve the voucher balance list
voucherBalanceList, err := prefixdb.Get(ctx, []byte(voucherSymbolList))
voucherBalanceList, err := prefixdb.Get(ctx, []byte("bal"))
if err != nil {
return res, fmt.Errorf("failed to retrieve voucher balance list: %v", err)
}
@ -1134,7 +1130,7 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r
}
}
// If a match is found, write the temporary sym , then return the symbol and balance
// If a match is found, write the temporary sym, then return the symbol and balance
if matchedSymbol != "" && matchedBalance != "" {
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_SYM, []byte(matchedSymbol))
if err != nil {
@ -1153,8 +1149,9 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r
return res, nil
}
// SetVoucher retrieves the temporary voucher, sets it as the active voucher and
// clears the temporary voucher/sym
// SetVoucher retrieves the temporary sym and balance,
// sets them as the active data and
// clears the temporary data
func (h *Handlers) SetVoucher(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
var err error