simplify code

This commit is contained in:
nicolas.dorier 2019-08-03 21:52:47 +09:00
parent ddf8b20091
commit 6d4ea6a951
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
3 changed files with 15 additions and 41 deletions

View File

@ -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.

View File

@ -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()

View File

@ -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;
}