fix(wallet): reject amounts with sub-satoshi precision

Replace the silent (long) cast with an explicit fractional check:
if value * factor has a non-zero remainder, TryParseIn/TryParseCoins
return false. The caller already shows "Importo non valido." to the
user, so no UI change is needed.

Covers TryParseIn (all units) and TryParseCoins. Adds CoinAmountTests
with valid and invalid cases including the triggering example (1.9 sat).
This commit is contained in:
2026-06-13 20:39:05 +02:00
parent 70cce640aa
commit 008e9c395a
2 changed files with 64 additions and 2 deletions
+8 -2
View File
@@ -46,7 +46,10 @@ public static class CoinAmount
return false;
try
{
sats = (long)(value * factor);
var satsDecimal = value * factor;
if (satsDecimal % 1 != 0)
return false;
sats = (long)satsDecimal;
}
catch (OverflowException)
{
@@ -65,7 +68,10 @@ public static class CoinAmount
return false;
try
{
sats = (long)(coins * SatsPerCoin);
var satsDecimal = coins * SatsPerCoin;
if (satsDecimal % 1 != 0)
return false;
sats = (long)satsDecimal;
}
catch (OverflowException)
{