Compare commits
No commits in common. "88926480dc6ed80658851309d6ec98534a5cf5f4" and "bc48dddd99879d30a9d07327900d7df7ca712ec9" have entirely different histories.
88926480dc
...
bc48dddd99
@ -1861,11 +1861,8 @@ func (h *MenuHandlers) ValidateAmount(ctx context.Context, sym string, input []b
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the amount to 2 decimal places before saving (truncated)
|
// Format the amount with 2 decimal places before saving
|
||||||
cents := int((inputAmount + 1e-9) * 100)
|
formattedAmount := fmt.Sprintf("%.2f", inputAmount)
|
||||||
truncated := float64(cents) / 100
|
|
||||||
formattedAmount := fmt.Sprintf("%.2f", truncated)
|
|
||||||
|
|
||||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(formattedAmount))
|
err = store.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(formattedAmount))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to write amount entry with", "key", storedb.DATA_AMOUNT, "value", formattedAmount, "error", err)
|
logg.ErrorCtxf(ctx, "failed to write amount entry with", "key", storedb.DATA_AMOUNT, "value", formattedAmount, "error", err)
|
||||||
|
|||||||
@ -1678,14 +1678,6 @@ func TestValidateAmount(t *testing.T) {
|
|||||||
Content: "0.02ms",
|
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 {
|
for _, tt := range tests {
|
||||||
|
|||||||
@ -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))
|
multiplier := new(big.Float).SetInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(tokenDecimal)), nil))
|
||||||
finalAmount := new(big.Float).Mul(amount, multiplier)
|
finalAmount := new(big.Float).Mul(amount, multiplier)
|
||||||
|
|
||||||
// Return finalAmount as a string with 0 decimal places (rounded)
|
// Convert finalAmount to a string
|
||||||
return finalAmount.Text('f', 0), nil
|
finalAmountStr := new(big.Int)
|
||||||
|
finalAmount.Int(finalAmountStr)
|
||||||
|
|
||||||
|
return finalAmountStr.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadTransactionData(ctx context.Context, store DataStore, sessionId string) (TransactionData, error) {
|
func ReadTransactionData(ctx context.Context, store DataStore, sessionId string) (TransactionData, error) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user