diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 8800a137d..874479b1a 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -97,7 +97,11 @@ namespace BTCPayServer.Controllers // addlabelclick is if the user click on existing label. For some reason, reusing the same name attribute for both // does not work [ModelBinder(typeof(WalletIdModelBinder))] - WalletId walletId, string transactionId, string addlabel = null, string addlabelclick = null, string addcomment = null, string removelabel = null) + WalletId walletId, string transactionId, + string addlabel = null, + string addlabelclick = null, + string addcomment = null, + string removelabel = null) { addlabel = addlabel ?? addlabelclick; // Hack necessary when the user enter a empty comment and submit. diff --git a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs index c2cbb71d1..369ea9f2c 100644 --- a/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Bitcoin/BitcoinLikePaymentHandler.cs @@ -69,35 +69,19 @@ namespace BTCPayServer.Payments.Bitcoin public override async Task IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob, Dictionary> rate, Money amount, PaymentMethodId paymentMethodId) { - - Func compare = null; - CurrencyValue limitValue = null; - string errorMessage = null; - if (storeBlob.OnChainMinValue != null) { - compare = (value, limit) => value < limit; - limitValue = storeBlob.OnChainMinValue; - errorMessage = "The amount of the invoice is too low to be paid on chain"; - } - - - if (compare != null) - { - var currentRateToCrypto = await rate[new CurrencyPair(paymentMethodId.CryptoCode, limitValue.Currency)]; - - if (currentRateToCrypto.BidAsk != null) + var currentRateToCrypto = await rate[new CurrencyPair(paymentMethodId.CryptoCode, storeBlob.OnChainMinValue.Currency)]; + if (currentRateToCrypto?.BidAsk != null) { - var limitValueCrypto = Money.Coins(limitValue.Value / currentRateToCrypto.BidAsk.Bid); - if (compare(amount, limitValueCrypto)) + var limitValueCrypto = Money.Coins(storeBlob.OnChainMinValue.Value / currentRateToCrypto.BidAsk.Bid); + if (amount < limitValueCrypto) { - return errorMessage; + return "The amount of the invoice is too low to be paid on chain"; } } } - return string.Empty; - } public override IEnumerable GetSupportedPaymentMethods() diff --git a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs index 0018fdea3..ea3320d66 100644 --- a/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs +++ b/BTCPayServer/Payments/Lightning/LightningLikePaymentHandler.cs @@ -146,33 +146,19 @@ namespace BTCPayServer.Payments.Lightning public override async Task IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob, Dictionary> rate, Money amount, PaymentMethodId paymentMethodId) { - - Func compare = null; - CurrencyValue limitValue = null; - string errorMessage = null; - if (storeBlob.LightningMaxValue != null) { - compare = (value, limit) => value > limit; - limitValue = storeBlob.LightningMaxValue; - errorMessage = "The amount of the invoice is too high to be paid with lightning"; - } + var currentRateToCrypto = await rate[new CurrencyPair(paymentMethodId.CryptoCode, storeBlob.LightningMaxValue.Currency)]; - - if (compare != null) - { - var currentRateToCrypto = await rate[new CurrencyPair(paymentMethodId.CryptoCode, limitValue.Currency)]; - - if (currentRateToCrypto.BidAsk != null) + if (currentRateToCrypto?.BidAsk != null) { - var limitValueCrypto = Money.Coins(limitValue.Value / currentRateToCrypto.BidAsk.Bid); - if (compare(amount, limitValueCrypto)) + var limitValueCrypto = Money.Coins(storeBlob.LightningMaxValue.Value / currentRateToCrypto.BidAsk.Bid); + if (amount > limitValueCrypto) { - return errorMessage; + return "The amount of the invoice is too high to be paid with lightning"; } } } - return string.Empty; }