Compare commits

..

7 Commits

Author SHA1 Message Date
Alfred Kamanda
8d6cbde66c sanitize invalid characters while showing the token details 2025-10-03 17:25:34 +03:00
Alfred Kamanda
48ebc922be removed invalid tracked file 2025-10-03 17:03:46 +03:00
Alfred Kamanda
610ecc4b7e changed the word Commodity to Product 2025-10-03 17:01:08 +03:00
Alfred Kamanda
0e5454ae5d added a test case for the invalid symbol replacement 2025-10-03 16:57:04 +03:00
Alfred Kamanda
8585203c0a added a mapping to replace invalid characters on voucher symbols 2025-10-03 16:56:48 +03:00
2cd875eb4d rebuild: with logtrace
Some checks failed
release / docker (push) Has been cancelled
2025-08-15 16:28:37 +03:00
3d57150465 Merge pull request 'Set crucial missing flags if the data exists' (#100) from sync-flags into master
Reviewed-on: #100
2025-07-29 13:04:18 +02:00
5 changed files with 28 additions and 8 deletions

View File

@@ -21,7 +21,7 @@ RUN make VISE_PATH=/build/go-vise -B
WORKDIR /build/sarafu-vise
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
RUN go mod download
RUN go build -tags logdebug,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
RUN go build -tags logtrace,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
FROM debian:bookworm-slim

View File

@@ -289,8 +289,11 @@ func (h *MenuHandlers) GetVoucherDetails(ctx context.Context, sym string, input
}
res.FlagReset = append(res.FlagReset, flag_api_error)
// sanitize invalid characters
symbol := strings.ReplaceAll(voucherData.TokenSymbol, "USD₮", "USDT")
res.Content = fmt.Sprintf(
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation,
"Name: %s\nSymbol: %s\nProduct: %s\nLocation: %s", voucherData.TokenName, symbol, voucherData.TokenCommodity, voucherData.TokenLocation,
)
return res, nil

View File

@@ -272,7 +272,7 @@ func TestGetVoucherDetails(t *testing.T) {
TokenCommodity: "Farming",
}
expectedResult.Content = fmt.Sprintf(
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
"Name: %s\nSymbol: %s\nProduct: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
)
mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil)
res, err := h.GetVoucherDetails(ctx, "SessionId", []byte(""))

View File

@@ -15,6 +15,11 @@ 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
@@ -23,13 +28,24 @@ 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 {
symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, h.TokenSymbol))
// normalize token symbol before use
cleanSymbol := sanitizeSymbol(h.TokenSymbol)
symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, cleanSymbol))
// Scale down the balance
scaledBalance := ScaleDownBalance(h.Balance, h.TokenDecimals)

View File

@@ -61,13 +61,14 @@ 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",
Balances: "1:100\n2:20000",
Decimals: "1:6\n2:4",
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
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",
}
result := ProcessVouchers(holdings)