Remove Default from OnChainPayment Method (#2170)

Makes more sense to do it on the Store endpoint after thinking about it.
This commit is contained in:
Andrew Camilleri 2020-12-29 09:38:31 +01:00 committed by GitHub
parent 553b1f139b
commit 5803512820
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 21 deletions

View file

@ -10,11 +10,6 @@ namespace BTCPayServer.Client.Models
/// </summary> /// </summary>
public bool Enabled { get; set; } public bool Enabled { get; set; }
/// <summary>
/// Whether the payment method is the default
/// </summary>
public bool Default { get; set; }
/// <summary> /// <summary>
/// Crypto code of the payment method /// Crypto code of the payment method
/// </summary> /// </summary>
@ -34,11 +29,9 @@ namespace BTCPayServer.Client.Models
{ {
} }
public OnChainPaymentMethodData(string cryptoCode, string derivationScheme, bool enabled, public OnChainPaymentMethodData(string cryptoCode, string derivationScheme, bool enabled)
bool defaultMethod)
{ {
Enabled = enabled; Enabled = enabled;
Default = defaultMethod;
CryptoCode = cryptoCode; CryptoCode = cryptoCode;
DerivationScheme = derivationScheme; DerivationScheme = derivationScheme;
} }

View file

@ -1238,15 +1238,15 @@ namespace BTCPayServer.Tests
}); });
Assert.Equal(firstAddress, (await viewOnlyClient.PreviewProposedStoreOnChainPaymentMethodAddresses(store.Id, "BTC", Assert.Equal(firstAddress, (await viewOnlyClient.PreviewProposedStoreOnChainPaymentMethodAddresses(store.Id, "BTC",
new OnChainPaymentMethodData() {Default = true, Enabled = true, DerivationScheme = xpub})).Addresses.First().Address); new OnChainPaymentMethodData() {Enabled = true, DerivationScheme = xpub})).Addresses.First().Address);
var method = await client.UpdateStoreOnChainPaymentMethod(store.Id, "BTC", var method = await client.UpdateStoreOnChainPaymentMethod(store.Id, "BTC",
new OnChainPaymentMethodData() {Default = true, Enabled = true, DerivationScheme = xpub}); new OnChainPaymentMethodData() { Enabled = true, DerivationScheme = xpub});
Assert.Equal(xpub,method.DerivationScheme); Assert.Equal(xpub,method.DerivationScheme);
method = await client.UpdateStoreOnChainPaymentMethod(store.Id, "BTC", method = await client.UpdateStoreOnChainPaymentMethod(store.Id, "BTC",
new OnChainPaymentMethodData() { Default = true, Enabled = true, DerivationScheme = xpub, Label = "lol", AccountKeyPath = RootedKeyPath.Parse("01020304/1/2/3") }); new OnChainPaymentMethodData() { Enabled = true, DerivationScheme = xpub, Label = "lol", AccountKeyPath = RootedKeyPath.Parse("01020304/1/2/3") });
method = await client.GetStoreOnChainPaymentMethod(store.Id, "BTC"); method = await client.GetStoreOnChainPaymentMethod(store.Id, "BTC");

View file

@ -42,14 +42,12 @@ namespace BTCPayServer.Controllers.GreenField
{ {
var blob = Store.GetStoreBlob(); var blob = Store.GetStoreBlob();
var excludedPaymentMethods = blob.GetExcludedPaymentMethods(); var excludedPaymentMethods = blob.GetExcludedPaymentMethods();
var defaultPaymentId = Store.GetDefaultPaymentId(_btcPayNetworkProvider);
return Ok(Store.GetSupportedPaymentMethods(_btcPayNetworkProvider) return Ok(Store.GetSupportedPaymentMethods(_btcPayNetworkProvider)
.Where((method) => method.PaymentId.PaymentType == PaymentTypes.BTCLike) .Where((method) => method.PaymentId.PaymentType == PaymentTypes.BTCLike)
.OfType<DerivationSchemeSettings>() .OfType<DerivationSchemeSettings>()
.Select(strategy => .Select(strategy =>
new OnChainPaymentMethodData(strategy.PaymentId.CryptoCode, new OnChainPaymentMethodData(strategy.PaymentId.CryptoCode,
strategy.AccountDerivation.ToString(), !excludedPaymentMethods.Match(strategy.PaymentId), strategy.AccountDerivation.ToString(), !excludedPaymentMethods.Match(strategy.PaymentId)))
defaultPaymentId == strategy.PaymentId))
.Where((result) => !enabledOnly || result.Enabled) .Where((result) => !enabledOnly || result.Enabled)
.ToList() .ToList()
); );
@ -241,7 +239,6 @@ namespace BTCPayServer.Controllers.GreenField
{ {
store ??= Store; store ??= Store;
var storeBlob = store.GetStoreBlob(); var storeBlob = store.GetStoreBlob();
var defaultPaymentMethod = store.GetDefaultPaymentId(_btcPayNetworkProvider);
var id = new PaymentMethodId(cryptoCode, PaymentTypes.BTCLike); var id = new PaymentMethodId(cryptoCode, PaymentTypes.BTCLike);
var paymentMethod = store var paymentMethod = store
.GetSupportedPaymentMethods(_btcPayNetworkProvider) .GetSupportedPaymentMethods(_btcPayNetworkProvider)
@ -252,8 +249,7 @@ namespace BTCPayServer.Controllers.GreenField
return paymentMethod == null return paymentMethod == null
? null ? null
: new OnChainPaymentMethodData(paymentMethod.PaymentId.CryptoCode, : new OnChainPaymentMethodData(paymentMethod.PaymentId.CryptoCode,
paymentMethod.AccountDerivation.ToString(), !excluded, paymentMethod.AccountDerivation.ToString(), !excluded)
defaultPaymentMethod == paymentMethod.PaymentId)
{ {
Label = paymentMethod.Label, Label = paymentMethod.Label,
AccountKeyPath = paymentMethod.GetSigningAccountKeySettings().GetRootedKeyPath() AccountKeyPath = paymentMethod.GetSigningAccountKeySettings().GetRootedKeyPath()

View file

@ -393,10 +393,6 @@
"type": "boolean", "type": "boolean",
"description": "Whether the payment method is enabled" "description": "Whether the payment method is enabled"
}, },
"default": {
"type": "boolean",
"description": "Whether the payment method is the default"
},
"cryptoCode": { "cryptoCode": {
"type": "string", "type": "string",
"description": "Crypto code of the payment method" "description": "Crypto code of the payment method"