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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user