Compare commits
No commits in common. "e27905765c7badb0cce12a4349f6303f830f748b" and "35d9d134421478dd432392e01585bc2e656af5e3" have entirely different histories.
e27905765c
...
35d9d13442
@ -51,9 +51,6 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
|
||||
res.FlagReset = append(res.FlagReset, flag_no_active_voucher)
|
||||
|
||||
// add a variable to filter out the active voucher
|
||||
activeSymStr := ""
|
||||
|
||||
// Check if user has an active voucher with proper error handling
|
||||
activeSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||
if err != nil {
|
||||
@ -65,8 +62,6 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
defaultDec := firstVoucher.TokenDecimals
|
||||
defaultAddr := firstVoucher.TokenAddress
|
||||
|
||||
activeSymStr = defaultSym
|
||||
|
||||
// Scale down the balance
|
||||
scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec)
|
||||
|
||||
@ -94,8 +89,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
return res, err
|
||||
}
|
||||
} else {
|
||||
// Update active voucher balance
|
||||
activeSymStr := string(activeSym)
|
||||
|
||||
// Find the matching voucher data
|
||||
activeSymStr = string(activeSym)
|
||||
var activeData *dataserviceapi.TokenHoldings
|
||||
for _, voucher := range vouchersResp {
|
||||
if voucher.TokenSymbol == activeSymStr {
|
||||
@ -105,10 +102,9 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
}
|
||||
|
||||
if activeData == nil {
|
||||
logg.InfoCtxf(ctx, "activeSym not found in vouchers, setting the first voucher as the default", "activeSym", activeSymStr)
|
||||
logg.ErrorCtxf(ctx, "activeSym not found in vouchers, setting the first voucher as the default", "activeSym", activeSymStr)
|
||||
firstVoucher := vouchersResp[0]
|
||||
activeData = &firstVoucher
|
||||
activeSymStr = string(activeData.TokenSymbol)
|
||||
}
|
||||
|
||||
// Scale down the balance
|
||||
@ -124,17 +120,8 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out the active voucher from vouchersResp
|
||||
filteredVouchers := make([]dataserviceapi.TokenHoldings, 0, len(vouchersResp))
|
||||
for _, v := range vouchersResp {
|
||||
if v.TokenSymbol != activeSymStr {
|
||||
filteredVouchers = append(filteredVouchers, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Store all voucher data (excluding the current active voucher)
|
||||
data := store.ProcessVouchers(filteredVouchers)
|
||||
|
||||
// Store all voucher data
|
||||
data := store.ProcessVouchers(vouchersResp)
|
||||
dataMap := map[storedb.DataTyp]string{
|
||||
storedb.DATA_VOUCHER_SYMBOLS: data.Symbols,
|
||||
storedb.DATA_VOUCHER_BALANCES: data.Balances,
|
||||
@ -153,7 +140,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// GetVoucherList fetches the list of vouchers from the store and formats them.
|
||||
// GetVoucherList fetches the list of vouchers and formats them.
|
||||
func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
@ -204,10 +191,6 @@ func (h *MenuHandlers) ViewVoucher(ctx context.Context, sym string, input []byte
|
||||
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
|
||||
|
||||
inputStr := string(input)
|
||||
if inputStr == "0" || inputStr == "99" || inputStr == "88" || inputStr == "98" {
|
||||
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
metadata, err := store.GetVoucherData(ctx, h.userdataStore, sessionId, inputStr)
|
||||
if err != nil {
|
||||
|
||||
@ -73,8 +73,8 @@ func TestManageVouchers(t *testing.T) {
|
||||
Balance: "100",
|
||||
},
|
||||
},
|
||||
expectedVoucherSymbols: []byte(""),
|
||||
expectedUpdatedAddress: []byte(""),
|
||||
expectedVoucherSymbols: []byte("1:TOKEN1"),
|
||||
expectedUpdatedAddress: []byte("0x123"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||
},
|
||||
@ -86,7 +86,7 @@ func TestManageVouchers(t *testing.T) {
|
||||
{TokenAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"},
|
||||
},
|
||||
storedActiveVoucher: "SRF",
|
||||
expectedVoucherSymbols: []byte("1:MILO"),
|
||||
expectedVoucherSymbols: []byte("1:SRF\n2:MILO"),
|
||||
expectedUpdatedAddress: []byte("0xd4c288865Ce"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user