add a helper function FormatVoucherList to combine the voucher symbols with their balances

This commit is contained in:
Alfred Kamanda 2025-06-30 13:14:34 +03:00
parent dd56d52f4c
commit a543569236
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -182,3 +182,30 @@ func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, d
return nil return nil
} }
// FormatVoucherList combines the voucher symbols with their balances (SRF 0.11)
func FormatVoucherList(ctx context.Context, symbolsData, balancesData string) []string {
symbols := strings.Split(symbolsData, "\n")
balances := strings.Split(balancesData, "\n")
var combined []string
for i := 0; i < len(symbols) && i < len(balances); i++ {
symbolParts := strings.SplitN(symbols[i], ":", 2)
balanceParts := strings.SplitN(balances[i], ":", 2)
if len(symbolParts) == 2 && len(balanceParts) == 2 {
index := strings.TrimSpace(symbolParts[0])
symbol := strings.TrimSpace(symbolParts[1])
rawBalance := strings.TrimSpace(balanceParts[1])
formattedBalance, err := TruncateDecimalString(rawBalance, 2)
if err != nil {
logg.ErrorCtxf(ctx, "failed to format balance", "balance", rawBalance, "error", err)
formattedBalance = rawBalance
}
combined = append(combined, fmt.Sprintf("%s: %s %s", index, symbol, formattedBalance))
}
}
return combined
}