Compare commits
No commits in common. "bcccd79e7026cb183532ee0810d19aa6d7f5d069" and "35d9d134421478dd432392e01585bc2e656af5e3" have entirely different histories.
bcccd79e70
...
35d9d13442
@ -9,7 +9,6 @@ import (
|
|||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
|
||||||
"gopkg.in/leonelquinteros/gotext.v1"
|
"gopkg.in/leonelquinteros/gotext.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,26 +36,9 @@ func (h *MenuHandlers) GetPools(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
activePoolSymStr := ""
|
data := store.ProcessPools(topPools)
|
||||||
|
|
||||||
activePoolSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_POOL_SYM)
|
// Store all Pool data
|
||||||
if err != nil {
|
|
||||||
activePoolSymStr = config.DefaultPoolSymbol()
|
|
||||||
} else {
|
|
||||||
activePoolSymStr = string(activePoolSym)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out the active pool from topPools
|
|
||||||
filteredPools := make([]dataserviceapi.PoolDetails, 0, len(topPools))
|
|
||||||
for _, p := range topPools {
|
|
||||||
if p.PoolSymbol != activePoolSymStr {
|
|
||||||
filteredPools = append(filteredPools, p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data := store.ProcessPools(filteredPools)
|
|
||||||
|
|
||||||
// Store the filtered Pool data
|
|
||||||
dataMap := map[storedb.DataTyp]string{
|
dataMap := map[storedb.DataTyp]string{
|
||||||
storedb.DATA_POOL_NAMES: data.PoolNames,
|
storedb.DATA_POOL_NAMES: data.PoolNames,
|
||||||
storedb.DATA_POOL_SYMBOLS: data.PoolSymbols,
|
storedb.DATA_POOL_SYMBOLS: data.PoolSymbols,
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import (
|
|||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||||
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
|
|
||||||
"gopkg.in/leonelquinteros/gotext.v1"
|
"gopkg.in/leonelquinteros/gotext.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -122,16 +121,7 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out the active voucher from swapToList
|
data := store.ProcessVouchers(swapToList)
|
||||||
filteredSwapToList := make([]dataserviceapi.TokenHoldings, 0, len(swapToList))
|
|
||||||
for _, s := range swapToList {
|
|
||||||
if s.TokenSymbol != string(activeSym) {
|
|
||||||
filteredSwapToList = append(filteredSwapToList, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store filtered swap to list data (excluding the current active voucher)
|
|
||||||
data := store.ProcessVouchers(filteredSwapToList)
|
|
||||||
|
|
||||||
logg.InfoCtxf(ctx, "ProcessVouchers", "data", data)
|
logg.InfoCtxf(ctx, "ProcessVouchers", "data", data)
|
||||||
|
|
||||||
@ -171,7 +161,7 @@ func (h *MenuHandlers) SwapMaxLimit(ctx context.Context, sym string, input []byt
|
|||||||
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher, flag_low_swap_amount)
|
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher, flag_low_swap_amount)
|
||||||
|
|
||||||
inputStr := string(input)
|
inputStr := string(input)
|
||||||
if inputStr == "0" || inputStr == "99" || inputStr == "88" || inputStr == "98" {
|
if inputStr == "0" {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,9 +51,6 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
|||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_no_active_voucher)
|
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
|
// Check if user has an active voucher with proper error handling
|
||||||
activeSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
activeSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SYM)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -65,8 +62,6 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
|||||||
defaultDec := firstVoucher.TokenDecimals
|
defaultDec := firstVoucher.TokenDecimals
|
||||||
defaultAddr := firstVoucher.TokenAddress
|
defaultAddr := firstVoucher.TokenAddress
|
||||||
|
|
||||||
activeSymStr = defaultSym
|
|
||||||
|
|
||||||
// Scale down the balance
|
// Scale down the balance
|
||||||
scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec)
|
scaledBalance := store.ScaleDownBalance(defaultBal, defaultDec)
|
||||||
|
|
||||||
@ -94,8 +89,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Update active voucher balance
|
||||||
|
activeSymStr := string(activeSym)
|
||||||
|
|
||||||
// Find the matching voucher data
|
// Find the matching voucher data
|
||||||
activeSymStr = string(activeSym)
|
|
||||||
var activeData *dataserviceapi.TokenHoldings
|
var activeData *dataserviceapi.TokenHoldings
|
||||||
for _, voucher := range vouchersResp {
|
for _, voucher := range vouchersResp {
|
||||||
if voucher.TokenSymbol == activeSymStr {
|
if voucher.TokenSymbol == activeSymStr {
|
||||||
@ -105,10 +102,9 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
|||||||
}
|
}
|
||||||
|
|
||||||
if activeData == nil {
|
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]
|
firstVoucher := vouchersResp[0]
|
||||||
activeData = &firstVoucher
|
activeData = &firstVoucher
|
||||||
activeSymStr = string(activeData.TokenSymbol)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale down the balance
|
// 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
|
// Store all voucher data
|
||||||
filteredVouchers := make([]dataserviceapi.TokenHoldings, 0, len(vouchersResp))
|
data := store.ProcessVouchers(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)
|
|
||||||
|
|
||||||
dataMap := map[storedb.DataTyp]string{
|
dataMap := map[storedb.DataTyp]string{
|
||||||
storedb.DATA_VOUCHER_SYMBOLS: data.Symbols,
|
storedb.DATA_VOUCHER_SYMBOLS: data.Symbols,
|
||||||
storedb.DATA_VOUCHER_BALANCES: data.Balances,
|
storedb.DATA_VOUCHER_BALANCES: data.Balances,
|
||||||
@ -153,7 +140,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b
|
|||||||
return res, nil
|
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) {
|
func (h *MenuHandlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
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")
|
flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
|
||||||
|
|
||||||
inputStr := string(input)
|
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)
|
metadata, err := store.GetVoucherData(ctx, h.userdataStore, sessionId, inputStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -224,16 +207,8 @@ func (h *MenuHandlers) ViewVoucher(ctx context.Context, sym string, input []byte
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the balance to 2 decimal places
|
|
||||||
formattedAmount, err := store.TruncateDecimalString(metadata.Balance, 2)
|
|
||||||
if err != nil {
|
|
||||||
logg.ErrorCtxf(ctx, "failed to TruncateDecimalString on ViewVoucher", "error", err)
|
|
||||||
res.FlagSet = append(res.FlagSet, flag_incorrect_voucher)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
|
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
|
||||||
res.Content = l.Get("Symbol: %s\nBalance: %s", metadata.TokenSymbol, formattedAmount)
|
res.Content = l.Get("Symbol: %s\nBalance: %s", metadata.TokenSymbol, metadata.Balance)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,8 +73,8 @@ func TestManageVouchers(t *testing.T) {
|
|||||||
Balance: "100",
|
Balance: "100",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedVoucherSymbols: []byte(""),
|
expectedVoucherSymbols: []byte("1:TOKEN1"),
|
||||||
expectedUpdatedAddress: []byte(""),
|
expectedUpdatedAddress: []byte("0x123"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
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"},
|
{TokenAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"},
|
||||||
},
|
},
|
||||||
storedActiveVoucher: "SRF",
|
storedActiveVoucher: "SRF",
|
||||||
expectedVoucherSymbols: []byte("1:MILO"),
|
expectedVoucherSymbols: []byte("1:SRF\n2:MILO"),
|
||||||
expectedUpdatedAddress: []byte("0xd4c288865Ce"),
|
expectedUpdatedAddress: []byte("0xd4c288865Ce"),
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
FlagReset: []uint32{flag_api_error, flag_no_active_voucher},
|
||||||
|
|||||||
@ -4,17 +4,11 @@ RELOAD swap_to_list
|
|||||||
MAP swap_to_list
|
MAP swap_to_list
|
||||||
CATCH missing_voucher flag_incorrect_voucher 1
|
CATCH missing_voucher flag_incorrect_voucher 1
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
MOUT quit 99
|
|
||||||
MNEXT next 88
|
|
||||||
MPREV prev 98
|
|
||||||
HALT
|
HALT
|
||||||
INCMP > 88
|
|
||||||
INCMP < 98
|
|
||||||
INCMP _ 0
|
|
||||||
INCMP quit 99
|
|
||||||
LOAD swap_max_limit 64
|
LOAD swap_max_limit 64
|
||||||
RELOAD swap_max_limit
|
RELOAD swap_max_limit
|
||||||
CATCH api_failure flag_api_call_error 1
|
CATCH api_failure flag_api_call_error 1
|
||||||
CATCH . flag_incorrect_voucher 1
|
CATCH . flag_incorrect_voucher 1
|
||||||
CATCH low_swap_amount flag_low_swap_amount 1
|
CATCH low_swap_amount flag_low_swap_amount 1
|
||||||
|
INCMP _ 0
|
||||||
INCMP swap_limit *
|
INCMP swap_limit *
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user