wip-account-creation #4

Merged
lash merged 143 commits from wip-account-creation into master 2024-08-30 14:37:58 +02:00
Showing only changes of commit 633d56b0ad - Show all commits

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{}