From 601de0126a2c2f8f5281cacce471f2010bef1ac4 Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Fri, 6 Feb 2026 16:20:20 +0300 Subject: [PATCH] store the list of stable coins that the user has --- handlers/application/vouchers.go | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/handlers/application/vouchers.go b/handlers/application/vouchers.go index 895d9c6..6d0756d 100644 --- a/handlers/application/vouchers.go +++ b/handlers/application/vouchers.go @@ -16,7 +16,8 @@ import ( // ManageVouchers retrieves the token holdings from the API using the "PublicKey" and // 1. sets the first as the default voucher if no active voucher is set. // 2. Stores list of vouchers -// 3. updates the balance of the active voucher +// 3. Stores list of filtered stable vouchers +// 4. updates the balance of the active voucher func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result userStore := h.userdataStore @@ -29,6 +30,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher") flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") + flag_no_stable_vouchers, _ := h.flagManager.GetFlag("flag_no_stable_vouchers") publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) if err != nil { @@ -170,6 +172,41 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b } } + // Filter stable vouchers + filteredStableVouchers := make([]dataserviceapi.TokenHoldings, 0) + for _, v := range vouchersResp { + + if isStableVoucher(v.TokenAddress) { + filteredStableVouchers = append(filteredStableVouchers, v) + } + } + + // No stable vouchers + if len(filteredStableVouchers) == 0 { + res.FlagSet = append(res.FlagSet, flag_no_stable_vouchers) + return res, nil + } + + res.FlagReset = append(res.FlagReset, flag_no_stable_vouchers) + + // Process stable vouchers for later use + stableVoucherData := store.ProcessVouchers(filteredStableVouchers) + + stableVoucherDataMap := map[storedb.DataTyp]string{ + storedb.DATA_STABLE_VOUCHER_SYMBOLS: stableVoucherData.Symbols, + storedb.DATA_STABLE_VOUCHER_BALANCES: stableVoucherData.Balances, + storedb.DATA_STABLE_VOUCHER_DECIMALS: stableVoucherData.Decimals, + storedb.DATA_STABLE_VOUCHER_ADDRESSES: stableVoucherData.Addresses, + } + + // Write data entries + for key, value := range stableVoucherDataMap { + if err := userStore.WriteEntry(ctx, sessionId, key, []byte(value)); err != nil { + logg.ErrorCtxf(ctx, "Failed to write data entry for sessionId: %s", sessionId, "key", key, "error", err) + continue + } + } + return res, nil }