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