correctly format amounts to 2 decimal places using TruncateDecimalString
This commit is contained in:
parent
0af41ea1f1
commit
865dae4b7f
@ -220,7 +220,7 @@ func (h *MenuHandlers) SwapMaxLimit(ctx context.Context, sym string, input []byt
|
||||
}
|
||||
|
||||
// Format to 2 decimal places
|
||||
maxStr := fmt.Sprintf("%.2f", maxAmountFloat)
|
||||
maxStr, _ := store.TruncateDecimalString(string(maxAmountStr), 2)
|
||||
|
||||
if maxAmountFloat < 0.1 {
|
||||
// return with low amount flag
|
||||
@ -319,14 +319,9 @@ func (h *MenuHandlers) SwapPreview(ctx context.Context, sym string, input []byte
|
||||
|
||||
// Scale down the quoted amount
|
||||
quoteAmountStr := store.ScaleDownBalance(r.OutValue, swapData.ActiveSwapToDecimal)
|
||||
qouteAmount, err := strconv.ParseFloat(quoteAmountStr, 64)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to parse quoteAmountStr as float", "value", quoteAmountStr, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Format to 2 decimal places
|
||||
qouteStr := fmt.Sprintf("%.2f", qouteAmount)
|
||||
qouteStr, _ := store.TruncateDecimalString(string(quoteAmountStr), 2)
|
||||
|
||||
res.Content = fmt.Sprintf(
|
||||
"You will swap:\n%s %s for %s %s:",
|
||||
|
||||
@ -751,19 +751,13 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
||||
|
||||
// Scale down the quoted amount
|
||||
quoteAmountStr := store.ScaleDownBalance(r.OutValue, swapData.ActiveSwapToDecimal)
|
||||
|
||||
qouteAmount, err := strconv.ParseFloat(quoteAmountStr, 64)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to parse quoteAmountStr as float", "value", quoteAmountStr, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Format to 2 decimal places
|
||||
qouteStr := fmt.Sprintf("%.2f", qouteAmount)
|
||||
|
||||
// Format the qouteAmount amount to 2 decimal places
|
||||
qouteAmount, _ := store.TruncateDecimalString(quoteAmountStr, 2)
|
||||
|
||||
res.Content = fmt.Sprintf(
|
||||
"%s will receive %s %s",
|
||||
string(recipientPhoneNumber), qouteStr, swapData.ActiveSwapToSym,
|
||||
string(recipientPhoneNumber), qouteAmount, swapData.ActiveSwapToSym,
|
||||
)
|
||||
|
||||
return res, nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user