From 1f4d810e14483bdeb110b281ab65368cbe7bfc4b Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 10:23:00 +0300 Subject: [PATCH 01/10] update the GetVoucherList comment description --- handlers/application/vouchers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index 72bb6b2..7eeeeef 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -140,7 +140,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b return res, nil } -// GetVoucherList fetches the list of vouchers and formats them. +// GetVoucherList fetches the list of vouchers from the store 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) -- 2.45.2 From e47415cc225dac5742bed921305e8577423467a4 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 11:25:33 +0300 Subject: [PATCH 02/10] remove the active voucher from the list of stored vouchers --- handlers/application/vouchers.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index 7eeeeef..1f05614 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -51,6 +51,9 @@ 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 { @@ -62,6 +65,8 @@ 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) @@ -89,10 +94,8 @@ 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 { @@ -102,9 +105,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b } if activeData == nil { - logg.ErrorCtxf(ctx, "activeSym not found in vouchers, setting the first voucher as the default", "activeSym", activeSymStr) + logg.InfoCtxf(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 @@ -120,8 +124,17 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b } } - // Store all voucher data - data := store.ProcessVouchers(vouchersResp) + // 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) + dataMap := map[storedb.DataTyp]string{ storedb.DATA_VOUCHER_SYMBOLS: data.Symbols, storedb.DATA_VOUCHER_BALANCES: data.Balances, -- 2.45.2 From 4ce9baa3792c0568146ca072ad137b46476ca6e7 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 11:27:20 +0300 Subject: [PATCH 03/10] return on navigation inputs to prevent data processing --- handlers/application/vouchers.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index 1f05614..c7196c8 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -204,6 +204,10 @@ 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 { -- 2.45.2 From e27905765c7badb0cce12a4349f6303f830f748b Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 11:28:05 +0300 Subject: [PATCH 04/10] updated TestManageVouchers to match filtering of active vouchers --- handlers/application/vouchers_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handlers/application/vouchers_test.go b/handlers/application/vouchers_test.go index e380829..1113a72 100644 --- a/handlers/application/vouchers_test.go +++ b/handlers/application/vouchers_test.go @@ -73,8 +73,8 @@ func TestManageVouchers(t *testing.T) { Balance: "100", }, }, - expectedVoucherSymbols: []byte("1:TOKEN1"), - expectedUpdatedAddress: []byte("0x123"), + expectedVoucherSymbols: []byte(""), + expectedUpdatedAddress: []byte(""), 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:SRF\n2:MILO"), + expectedVoucherSymbols: []byte("1:MILO"), expectedUpdatedAddress: []byte("0xd4c288865Ce"), expectedResult: resource.Result{ FlagReset: []uint32{flag_api_error, flag_no_active_voucher}, -- 2.45.2 From 7e90124199cc5dd6aae2d56858fbfe564867412d Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 11:50:50 +0300 Subject: [PATCH 05/10] filter out the active pool from the list of available pools --- handlers/application/pools.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/handlers/application/pools.go b/handlers/application/pools.go index 65e5f4c..d4d7242 100644 --- a/handlers/application/pools.go +++ b/handlers/application/pools.go @@ -9,6 +9,7 @@ import ( "git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/sarafu-vise/store" storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" + dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" "gopkg.in/leonelquinteros/gotext.v1" ) @@ -36,9 +37,26 @@ func (h *MenuHandlers) GetPools(ctx context.Context, sym string, input []byte) ( return res, nil } - data := store.ProcessPools(topPools) + activePoolSymStr := "" - // Store all Pool data + activePoolSym, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_POOL_SYM) + 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{ storedb.DATA_POOL_NAMES: data.PoolNames, storedb.DATA_POOL_SYMBOLS: data.PoolSymbols, -- 2.45.2 From 3e40a09d393d6da448221a461ae049b25522890c Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 12:22:05 +0300 Subject: [PATCH 06/10] format the balance to 2 d.p. before displaying it --- handlers/application/vouchers.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index c7196c8..d3d219c 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -224,8 +224,16 @@ func (h *MenuHandlers) ViewVoucher(ctx context.Context, sym string, input []byte 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.Content = l.Get("Symbol: %s\nBalance: %s", metadata.TokenSymbol, metadata.Balance) + res.Content = l.Get("Symbol: %s\nBalance: %s", metadata.TokenSymbol, formattedAmount) return res, nil } -- 2.45.2 From 61f48abb7d42d2850bddddf49ca920b20f736cba Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 12:30:05 +0300 Subject: [PATCH 07/10] return on navigation inputs to prevent data processing --- handlers/application/poolswap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/application/poolswap.go b/handlers/application/poolswap.go index ca728e6..9f1c9bb 100644 --- a/handlers/application/poolswap.go +++ b/handlers/application/poolswap.go @@ -161,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) inputStr := string(input) - if inputStr == "0" { + if inputStr == "0" || inputStr == "99" || inputStr == "88" || inputStr == "98" { return res, nil } -- 2.45.2 From 1234723e10b7b7f72071e6c4adb5f24c23d5000f Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 12:30:30 +0300 Subject: [PATCH 08/10] add navigation inputs for the swap_to list --- services/registration/swap_to_list.vis | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/registration/swap_to_list.vis b/services/registration/swap_to_list.vis index e966fee..e4b0733 100644 --- a/services/registration/swap_to_list.vis +++ b/services/registration/swap_to_list.vis @@ -4,7 +4,14 @@ RELOAD swap_to_list MAP swap_to_list CATCH missing_voucher flag_incorrect_voucher 1 MOUT back 0 +MOUT quit 99 +MNEXT next 88 +MPREV prev 98 HALT +INCMP > 88 +INCMP < 98 +INCMP _ 0 +INCMP quit 99 LOAD swap_max_limit 64 RELOAD swap_max_limit CATCH api_failure flag_api_call_error 1 -- 2.45.2 From 36a3c592871fc1783d48d4c3dc4b19791e7660ec Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 12:34:45 +0300 Subject: [PATCH 09/10] removed existing INCMP statement --- services/registration/swap_to_list.vis | 1 - 1 file changed, 1 deletion(-) diff --git a/services/registration/swap_to_list.vis b/services/registration/swap_to_list.vis index e4b0733..1cd7c08 100644 --- a/services/registration/swap_to_list.vis +++ b/services/registration/swap_to_list.vis @@ -17,5 +17,4 @@ RELOAD swap_max_limit CATCH api_failure flag_api_call_error 1 CATCH . flag_incorrect_voucher 1 CATCH low_swap_amount flag_low_swap_amount 1 -INCMP _ 0 INCMP swap_limit * -- 2.45.2 From 193c9c119a464dbe2c3c0328377da24cd1bd8b1b Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 21 Jul 2025 13:01:06 +0300 Subject: [PATCH 10/10] filter out the active voucher from swapToList --- handlers/application/poolswap.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/handlers/application/poolswap.go b/handlers/application/poolswap.go index 9f1c9bb..a226d33 100644 --- a/handlers/application/poolswap.go +++ b/handlers/application/poolswap.go @@ -10,6 +10,7 @@ import ( "git.grassecon.net/grassrootseconomics/sarafu-vise/config" "git.grassecon.net/grassrootseconomics/sarafu-vise/store" storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" + dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api" "gopkg.in/leonelquinteros/gotext.v1" ) @@ -121,7 +122,16 @@ func (h *MenuHandlers) LoadSwapToList(ctx context.Context, sym string, input []b return res, nil } - data := store.ProcessVouchers(swapToList) + // Filter out the active voucher from 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) -- 2.45.2