Allow users to include 'CELO' in the amount

This commit is contained in:
Alfred Kamanda 2024-08-27 16:16:15 +03:00
parent 2b10f6023f
commit 633d56b0ad
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"regexp"
"strconv"
"strings"
@ -539,9 +540,16 @@ func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte)
return res, fmt.Errorf("failed to parse balance: %v", err)
}
// Parse the input amount
if amountStr != "0" {
inputAmount, err := strconv.ParseFloat(amountStr, 64)
// Extract numeric part from input
re := regexp.MustCompile(`^(\d+(\.\d+)?)\s*(?:CELO)?$`)
matches := re.FindStringSubmatch(strings.TrimSpace(amountStr))
if len(matches) < 2 {
res.FlagSet = append(res.FlagSet, models.USERFLAG_INVALID_AMOUNT)
res.Content = amountStr
return res, nil
}
inputAmount, err := strconv.ParseFloat(matches[1], 64)
if err != nil {
res.FlagSet = append(res.FlagSet, models.USERFLAG_INVALID_AMOUNT)
res.Content = amountStr
@ -554,20 +562,16 @@ func (h *Handlers) ValidateAmount(ctx context.Context, sym string, input []byte)
return res, nil
}
res.Content = amountStr
accountData["Amount"] = amountStr
res.Content = fmt.Sprintf("%.3f", inputAmount) // Format to 3 decimal places
accountData["Amount"] = res.Content
err = h.accountFileHandler.WriteAccountData(accountData)
if err != nil {
return res, err
}
return res, nil
}
return res, nil
}
func (h *Handlers) GetRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
res := resource.Result{}