Skip to content

Commit 22430e6

Browse files
Added maximum XRP value to XrpToDropsString. (#17)
1 parent 1ae0d8e commit 22430e6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/XUMM.NET.SDK/Extensions/CurrencyExtensions.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public static class CurrencyExtensions
1212
private static readonly string HexReplacementPattern = "(00)+$";
1313
private static readonly string XRP = "XRP";
1414
private static readonly decimal XrpDrops = 1000000m;
15+
private static readonly decimal MaximumXrpValue = 100000000000m;
16+
1517
/// <summary>
1618
/// Format currency to standard currency code
1719
/// </summary>
@@ -63,9 +65,15 @@ public static string ToFormattedCurrency(this string currency, int maxLength = 1
6365
/// <seealso href="https://xrpl.org/currency-formats.html" />
6466
/// </summary>
6567
/// <param name="value">Value in XRP</param>
66-
/// <returns>Returns XRP represented in drops. For example, 1 XRP is represented as 1000000 drops.</returns>
68+
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="value"/> is set to be more than <see cref="MaximumXrpValue"/>.</exception>
69+
/// <returns>Returns XRP represented in drops. For example, 1 XRP is represented as <see cref="XrpDrops"/> drops.</returns>
6770
public static string XrpToDropsString(this decimal value)
6871
{
69-
return ((int)(value * XrpDrops)).ToString();
72+
if (value > MaximumXrpValue)
73+
{
74+
throw new ArgumentOutOfRangeException(nameof(value), $"Maximum value of XRP is {MaximumXrpValue}");
75+
}
76+
77+
return Math.Truncate(value * XrpDrops).ToString();
7078
}
7179
}

0 commit comments

Comments
 (0)