Compare commits

..

No commits in common. "0e5454ae5d68c8393c3e1631d87d0ceab2627e06" and "2cd875eb4d47c5cbed79fdcb210e246f06ffde0e" have entirely different histories.

3 changed files with 5 additions and 22 deletions

Binary file not shown.

View File

@ -15,11 +15,6 @@ var (
logg = logging.NewVanilla().WithDomain("vouchers").WithContextKey("SessionId")
)
// symbolReplacements holds mappings of invalid symbols → valid ones
var symbolReplacements = map[string]string{
"USD₮": "USDT",
}
// VoucherMetadata helps organize data fields
type VoucherMetadata struct {
Symbols string
@ -28,24 +23,13 @@ type VoucherMetadata struct {
Addresses string
}
// sanitizeSymbol replaces known invalid token symbols with normalized ones
func sanitizeSymbol(symbol string) string {
if replacement, ok := symbolReplacements[symbol]; ok {
return replacement
}
return symbol
}
// ProcessVouchers converts holdings into formatted strings
func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata {
var data VoucherMetadata
var symbols, balances, decimals, addresses []string
for i, h := range holdings {
// normalize token symbol before use
cleanSymbol := sanitizeSymbol(h.TokenSymbol)
symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, cleanSymbol))
symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, h.TokenSymbol))
// Scale down the balance
scaledBalance := ScaleDownBalance(h.Balance, h.TokenDecimals)

View File

@ -61,14 +61,13 @@ func TestProcessVouchers(t *testing.T) {
holdings := []dataserviceapi.TokenHoldings{
{TokenAddress: "0xd4c288865Ce", TokenSymbol: "SRF", TokenDecimals: "6", Balance: "100000000"},
{TokenAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200000000"},
{TokenAddress: "0x41c143d63Qa", TokenSymbol: "USD₮", TokenDecimals: "6", Balance: "300000000"},
}
expectedResult := VoucherMetadata{
Symbols: "1:SRF\n2:MILO\n3:USDT",
Balances: "1:100\n2:20000\n3:300",
Decimals: "1:6\n2:4\n3:6",
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa\n3:0x41c143d63Qa",
Symbols: "1:SRF\n2:MILO",
Balances: "1:100\n2:20000",
Decimals: "1:6\n2:4",
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
}
result := ProcessVouchers(holdings)