Compare commits

..

No commits in common. "88926480dc6ed80658851309d6ec98534a5cf5f4" and "bc48dddd99879d30a9d07327900d7df7ca712ec9" have entirely different histories.

3 changed files with 7 additions and 15 deletions

View File

@ -1861,11 +1861,8 @@ func (h *MenuHandlers) ValidateAmount(ctx context.Context, sym string, input []b
return res, nil
}
// Format the amount to 2 decimal places before saving (truncated)
cents := int((inputAmount + 1e-9) * 100)
truncated := float64(cents) / 100
formattedAmount := fmt.Sprintf("%.2f", truncated)
// Format the amount with 2 decimal places before saving
formattedAmount := fmt.Sprintf("%.2f", inputAmount)
err = store.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(formattedAmount))
if err != nil {
logg.ErrorCtxf(ctx, "failed to write amount entry with", "key", storedb.DATA_AMOUNT, "value", formattedAmount, "error", err)

View File

@ -1678,14 +1678,6 @@ func TestValidateAmount(t *testing.T) {
Content: "0.02ms",
},
},
{
name: "Test with valid decimal amount",
input: []byte("0.149"),
activeBal: []byte("5"),
expectedResult: resource.Result{
Content: "0.14",
},
},
}
for _, tt := range tests {

View File

@ -38,8 +38,11 @@ func ParseAndScaleAmount(storedAmount, activeDecimal string) (string, error) {
multiplier := new(big.Float).SetInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(tokenDecimal)), nil))
finalAmount := new(big.Float).Mul(amount, multiplier)
// Return finalAmount as a string with 0 decimal places (rounded)
return finalAmount.Text('f', 0), nil
// Convert finalAmount to a string
finalAmountStr := new(big.Int)
finalAmount.Int(finalAmountStr)
return finalAmountStr.String(), nil
}
func ReadTransactionData(ctx context.Context, store DataStore, sessionId string) (TransactionData, error) {