mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
simplify code
This commit is contained in:
parent
ddf8b20091
commit
6d4ea6a951
@ -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.
|
||||
|
@ -69,35 +69,19 @@ namespace BTCPayServer.Payments.Bitcoin
|
||||
public override async Task<string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
|
||||
Dictionary<CurrencyPair, Task<RateResult>> rate, Money amount, PaymentMethodId paymentMethodId)
|
||||
{
|
||||
|
||||
Func<Money, Money, bool> 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<PaymentMethodId> GetSupportedPaymentMethods()
|
||||
|
@ -146,33 +146,19 @@ namespace BTCPayServer.Payments.Lightning
|
||||
public override async Task<string> IsPaymentMethodAllowedBasedOnInvoiceAmount(StoreBlob storeBlob,
|
||||
Dictionary<CurrencyPair, Task<RateResult>> rate, Money amount, PaymentMethodId paymentMethodId)
|
||||
{
|
||||
|
||||
Func<Money, Money, bool> 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user