mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-23 06:35:13 +01:00
Code cleanups
This commit is contained in:
parent
df4d370524
commit
c7a8523b77
10 changed files with 56 additions and 67 deletions
|
@ -121,15 +121,15 @@ namespace BTCPayServer.Controllers
|
||||||
var derivationByCryptoCode =
|
var derivationByCryptoCode =
|
||||||
store
|
store
|
||||||
.GetPaymentMethodConfigs<DerivationSchemeSettings>(_handlers)
|
.GetPaymentMethodConfigs<DerivationSchemeSettings>(_handlers)
|
||||||
.ToDictionary(c => ((IHasNetwork)_handlers[c.Key]).Network.CryptoCode, c => (DerivationSchemeSettings)c.Value);
|
.ToDictionary(c => ((IHasNetwork)_handlers[c.Key]).Network.CryptoCode, c => c.Value);
|
||||||
|
|
||||||
var lightningByCryptoCode = store
|
var lightningByCryptoCode = store
|
||||||
.GetPaymentMethodConfigs(_handlers)
|
.GetPaymentMethodConfigs(_handlers)
|
||||||
.Where(c => c.Value is LightningPaymentMethodConfig)
|
.Where(c => c.Value is LightningPaymentMethodConfig)
|
||||||
.ToDictionary(c => ((IHasNetwork)_handlers[c.Key]).Network.CryptoCode, c => (LightningPaymentMethodConfig)c.Value);
|
.ToDictionary(c => ((IHasNetwork)_handlers[c.Key]).Network.CryptoCode, c => (LightningPaymentMethodConfig)c.Value);
|
||||||
|
|
||||||
derivationSchemes = new List<StoreDerivationScheme>();
|
derivationSchemes = [];
|
||||||
lightningNodes = new List<StoreLightningNode>();
|
lightningNodes = [];
|
||||||
|
|
||||||
foreach (var handler in _handlers)
|
foreach (var handler in _handlers)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace BTCPayServer.Controllers
|
||||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
public async Task<IActionResult> StoreEmails(string storeId, StoreEmailRuleViewModel vm, string command)
|
public async Task<IActionResult> StoreEmails(string storeId, StoreEmailRuleViewModel vm, string command)
|
||||||
{
|
{
|
||||||
vm.Rules ??= new List<StoreEmailRule>();
|
vm.Rules ??= [];
|
||||||
int commandIndex = 0;
|
int commandIndex = 0;
|
||||||
|
|
||||||
var indSep = command.Split(':', StringSplitOptions.RemoveEmptyEntries);
|
var indSep = command.Split(':', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
@ -72,8 +72,8 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
var rule = vm.Rules[i];
|
var rule = vm.Rules[i];
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(rule.To) && (rule.To.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
if (!string.IsNullOrEmpty(rule.To) && rule.To.Split(',', StringSplitOptions.RemoveEmptyEntries)
|
||||||
.Any(s => !MailboxAddressValidator.TryParse(s, out _))))
|
.Any(s => !MailboxAddressValidator.TryParse(s, out _)))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError($"{nameof(vm.Rules)}[{i}].{nameof(rule.To)}",
|
ModelState.AddModelError($"{nameof(vm.Rules)}[{i}].{nameof(rule.To)}",
|
||||||
"Invalid mailbox address provided. Valid formats are: 'test@example.com' or 'Firstname Lastname <test@example.com>'");
|
"Invalid mailbox address provided. Valid formats are: 'test@example.com' or 'Firstname Lastname <test@example.com>'");
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace BTCPayServer.Controllers
|
||||||
public async Task<IActionResult> Webhooks()
|
public async Task<IActionResult> Webhooks()
|
||||||
{
|
{
|
||||||
var webhooks = await _storeRepo.GetWebhooks(CurrentStore.Id);
|
var webhooks = await _storeRepo.GetWebhooks(CurrentStore.Id);
|
||||||
return View(nameof(Webhooks), new WebhooksViewModel()
|
return View(nameof(Webhooks), new WebhooksViewModel
|
||||||
{
|
{
|
||||||
Webhooks = webhooks.Select(async w =>
|
Webhooks = webhooks.Select(async w =>
|
||||||
{
|
{
|
||||||
|
@ -146,11 +146,11 @@ namespace BTCPayServer.Controllers
|
||||||
|
|
||||||
if (result.Success)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.SuccessMessage] = $"{viewModel.Type.ToString()} event delivered successfully! Delivery ID is {result.DeliveryId}";
|
TempData[WellKnownTempData.SuccessMessage] = $"{viewModel.Type} event delivered successfully! Delivery ID is {result.DeliveryId}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.ErrorMessage] = $"{viewModel.Type.ToString()} event could not be delivered. Error message received: {(result.ErrorMessage ?? "unknown")}";
|
TempData[WellKnownTempData.ErrorMessage] = $"{viewModel.Type} event could not be delivered. Error message received: {(result.ErrorMessage ?? "unknown")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(nameof(TestWebhook));
|
return View(nameof(TestWebhook));
|
||||||
|
|
|
@ -122,7 +122,7 @@ namespace BTCPayServer.Controllers
|
||||||
|
|
||||||
var paymentMethodId = PaymentTypes.LN.GetPaymentMethodId(network.CryptoCode);
|
var paymentMethodId = PaymentTypes.LN.GetPaymentMethodId(network.CryptoCode);
|
||||||
|
|
||||||
LightningPaymentMethodConfig? paymentMethod = null;
|
LightningPaymentMethodConfig? paymentMethod;
|
||||||
if (vm.LightningNodeType == LightningNodeType.Internal)
|
if (vm.LightningNodeType == LightningNodeType.Internal)
|
||||||
{
|
{
|
||||||
paymentMethod = new LightningPaymentMethodConfig();
|
paymentMethod = new LightningPaymentMethodConfig();
|
||||||
|
@ -135,8 +135,7 @@ namespace BTCPayServer.Controllers
|
||||||
ModelState.AddModelError(nameof(vm.ConnectionString), "Please provide a connection string");
|
ModelState.AddModelError(nameof(vm.ConnectionString), "Please provide a connection string");
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
paymentMethod = new LightningPaymentMethodConfig();
|
paymentMethod = new LightningPaymentMethodConfig { ConnectionString = vm.ConnectionString };
|
||||||
paymentMethod.ConnectionString = vm.ConnectionString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var handler = (LightningLikePaymentHandler)_handlers[paymentMethodId];
|
var handler = (LightningLikePaymentHandler)_handlers[paymentMethodId];
|
||||||
|
@ -153,7 +152,7 @@ namespace BTCPayServer.Controllers
|
||||||
case "save":
|
case "save":
|
||||||
var lnurl = PaymentTypes.LNURL.GetPaymentMethodId(vm.CryptoCode);
|
var lnurl = PaymentTypes.LNURL.GetPaymentMethodId(vm.CryptoCode);
|
||||||
store.SetPaymentMethodConfig(_handlers[paymentMethodId], paymentMethod);
|
store.SetPaymentMethodConfig(_handlers[paymentMethodId], paymentMethod);
|
||||||
store.SetPaymentMethodConfig(_handlers[lnurl], new LNURLPaymentMethodConfig()
|
store.SetPaymentMethodConfig(_handlers[lnurl], new LNURLPaymentMethodConfig
|
||||||
{
|
{
|
||||||
UseBech32Scheme = true,
|
UseBech32Scheme = true,
|
||||||
LUD12Enabled = false
|
LUD12Enabled = false
|
||||||
|
@ -293,10 +292,10 @@ namespace BTCPayServer.Controllers
|
||||||
if (store == null)
|
if (store == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (cryptoCode == null)
|
var network = _explorerProvider.GetNetwork(cryptoCode);
|
||||||
|
if (network == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var network = _explorerProvider.GetNetwork(cryptoCode);
|
|
||||||
var lightning = GetConfig<LightningPaymentMethodConfig>(PaymentTypes.LN.GetPaymentMethodId(cryptoCode), store);
|
var lightning = GetConfig<LightningPaymentMethodConfig>(PaymentTypes.LN.GetPaymentMethodId(cryptoCode), store);
|
||||||
if (lightning == null)
|
if (lightning == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
|
@ -103,7 +103,9 @@ namespace BTCPayServer.Controllers
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
// ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileContent is null || !_onChainWalletParsers.TryParseWalletFile(fileContent, network, out strategy, out _))
|
if (fileContent is null || !_onChainWalletParsers.TryParseWalletFile(fileContent, network, out strategy, out _))
|
||||||
{
|
{
|
||||||
ModelState.AddModelError(nameof(vm.WalletFile), $"Import failed, make sure you import a compatible wallet format");
|
ModelState.AddModelError(nameof(vm.WalletFile), $"Import failed, make sure you import a compatible wallet format");
|
||||||
|
@ -430,7 +432,7 @@ namespace BTCPayServer.Controllers
|
||||||
.Select(e => new WalletSettingsAccountKeyViewModel
|
.Select(e => new WalletSettingsAccountKeyViewModel
|
||||||
{
|
{
|
||||||
AccountKey = e.AccountKey.ToString(),
|
AccountKey = e.AccountKey.ToString(),
|
||||||
MasterFingerprint = e.RootFingerprint is HDFingerprint fp ? fp.ToString() : null,
|
MasterFingerprint = e.RootFingerprint is { } fp ? fp.ToString() : null,
|
||||||
AccountKeyPath = e.AccountKeyPath == null ? "" : $"m/{e.AccountKeyPath}"
|
AccountKeyPath = e.AccountKeyPath == null ? "" : $"m/{e.AccountKeyPath}"
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
Config = ProtectString(JToken.FromObject(derivation, handler.Serializer).ToString()),
|
Config = ProtectString(JToken.FromObject(derivation, handler.Serializer).ToString()),
|
||||||
|
@ -521,7 +523,7 @@ namespace BTCPayServer.Controllers
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rootFingerprint = string.IsNullOrWhiteSpace(vm.AccountKeys[i].MasterFingerprint)
|
rootFingerprint = string.IsNullOrWhiteSpace(vm.AccountKeys[i].MasterFingerprint)
|
||||||
? (HDFingerprint?)null
|
? null
|
||||||
: new HDFingerprint(Encoders.Hex.DecodeData(vm.AccountKeys[i].MasterFingerprint));
|
: new HDFingerprint(Encoders.Hex.DecodeData(vm.AccountKeys[i].MasterFingerprint));
|
||||||
|
|
||||||
if (rootFingerprint != null && derivation.AccountKeySettings[i].RootFingerprint != rootFingerprint)
|
if (rootFingerprint != null && derivation.AccountKeySettings[i].RootFingerprint != rootFingerprint)
|
||||||
|
@ -603,17 +605,16 @@ namespace BTCPayServer.Controllers
|
||||||
|
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "Payment settings successfully updated";
|
TempData[WellKnownTempData.SuccessMessage] = "Payment settings successfully updated";
|
||||||
|
|
||||||
|
|
||||||
if (payjoinChanged && blob.PayJoinEnabled && network.SupportPayJoin)
|
if (payjoinChanged && blob.PayJoinEnabled && network.SupportPayJoin)
|
||||||
{
|
{
|
||||||
var config = store.GetPaymentMethodConfig<DerivationSchemeSettings>(PaymentTypes.CHAIN.GetPaymentMethodId(network.CryptoCode), _handlers);
|
var config = store.GetPaymentMethodConfig<DerivationSchemeSettings>(PaymentTypes.CHAIN.GetPaymentMethodId(network.CryptoCode), _handlers);
|
||||||
if (!config.IsHotWallet)
|
if (config?.IsHotWallet is not true)
|
||||||
{
|
{
|
||||||
TempData.Remove(WellKnownTempData.SuccessMessage);
|
TempData.Remove(WellKnownTempData.SuccessMessage);
|
||||||
TempData.SetStatusMessageModel(new StatusMessageModel()
|
TempData.SetStatusMessageModel(new StatusMessageModel
|
||||||
{
|
{
|
||||||
Severity = StatusMessageModel.StatusSeverity.Warning,
|
Severity = StatusMessageModel.StatusSeverity.Warning,
|
||||||
Html = $"The payment settings were updated successfully. However, PayJoin will not work, as this isn't a <a href='https://docs.btcpayserver.org/HotWallet/' class='alert-link' target='_blank'>hot wallet</a>."
|
Html = "The payment settings were updated successfully. However, PayJoin will not work, as this isn't a <a href='https://docs.btcpayserver.org/HotWallet/' class='alert-link' target='_blank'>hot wallet</a>."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -798,7 +799,7 @@ namespace BTCPayServer.Controllers
|
||||||
private async Task<string> GetSeed(ExplorerClient client, DerivationSchemeSettings derivation)
|
private async Task<string> GetSeed(ExplorerClient client, DerivationSchemeSettings derivation)
|
||||||
{
|
{
|
||||||
return derivation.IsHotWallet &&
|
return derivation.IsHotWallet &&
|
||||||
await client.GetMetadataAsync<string>(derivation.AccountDerivation, WellknownMetadataKeys.MasterHDKey) is string seed &&
|
await client.GetMetadataAsync<string>(derivation.AccountDerivation, WellknownMetadataKeys.MasterHDKey) is { } seed &&
|
||||||
!string.IsNullOrEmpty(seed) ? seed : null;
|
!string.IsNullOrEmpty(seed) ? seed : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace BTCPayServer.Controllers
|
||||||
[HttpGet("{storeId}/rates")]
|
[HttpGet("{storeId}/rates")]
|
||||||
public IActionResult Rates()
|
public IActionResult Rates()
|
||||||
{
|
{
|
||||||
var exchanges = GetSupportedExchanges();
|
var exchanges = GetSupportedExchanges().ToList();
|
||||||
var storeBlob = CurrentStore.GetStoreBlob();
|
var storeBlob = CurrentStore.GetStoreBlob();
|
||||||
var vm = new RatesViewModel();
|
var vm = new RatesViewModel();
|
||||||
vm.SetExchangeRates(exchanges, storeBlob.PreferredExchange ?? storeBlob.GetRecommendedExchange());
|
vm.SetExchangeRates(exchanges, storeBlob.PreferredExchange ?? storeBlob.GetRecommendedExchange());
|
||||||
|
@ -43,13 +43,13 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
return RedirectToAction(nameof(ShowRateRules), new { scripting = true, storeId = model.StoreId });
|
return RedirectToAction(nameof(ShowRateRules), new { scripting = true, storeId = model.StoreId });
|
||||||
}
|
}
|
||||||
else if (command == "scripting-off")
|
if (command == "scripting-off")
|
||||||
{
|
{
|
||||||
return RedirectToAction(nameof(ShowRateRules), new { scripting = false, storeId = model.StoreId });
|
return RedirectToAction(nameof(ShowRateRules), new { scripting = false, storeId = model.StoreId });
|
||||||
}
|
}
|
||||||
|
|
||||||
var exchanges = GetSupportedExchanges();
|
var exchanges = GetSupportedExchanges().ToList();
|
||||||
model.SetExchangeRates(exchanges, model.PreferredExchange ?? this.HttpContext.GetStoreData().GetStoreBlob().GetRecommendedExchange());
|
model.SetExchangeRates(exchanges, model.PreferredExchange ?? HttpContext.GetStoreData().GetStoreBlob().GetRecommendedExchange());
|
||||||
model.StoreId = storeId ?? model.StoreId;
|
model.StoreId = storeId ?? model.StoreId;
|
||||||
CurrencyPair[]? currencyPairs = null;
|
CurrencyPair[]? currencyPairs = null;
|
||||||
try
|
try
|
||||||
|
@ -85,13 +85,13 @@ namespace BTCPayServer.Controllers
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RateRules? rules = null;
|
RateRules? rules;
|
||||||
if (model.ShowScripting)
|
if (model.ShowScripting)
|
||||||
{
|
{
|
||||||
if (!RateRules.TryParse(model.Script, out rules, out var errors))
|
if (!RateRules.TryParse(model.Script, out rules, out var errors))
|
||||||
{
|
{
|
||||||
errors = errors ?? new List<RateRulesErrors>();
|
errors ??= [];
|
||||||
var errorString = String.Join(", ", errors.ToArray());
|
var errorString = string.Join(", ", errors.ToArray());
|
||||||
ModelState.AddModelError(nameof(model.Script), $"Parsing error ({errorString})");
|
ModelState.AddModelError(nameof(model.Script), $"Parsing error ({errorString})");
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ namespace BTCPayServer.Controllers
|
||||||
foreach (var fetch in fetchs)
|
foreach (var fetch in fetchs)
|
||||||
{
|
{
|
||||||
var testResult = await (fetch.Value);
|
var testResult = await (fetch.Value);
|
||||||
testResults.Add(new RatesViewModel.TestResultViewModel()
|
testResults.Add(new RatesViewModel.TestResultViewModel
|
||||||
{
|
{
|
||||||
CurrencyPair = fetch.Key.ToString(),
|
CurrencyPair = fetch.Key.ToString(),
|
||||||
Error = testResult.Errors.Count != 0,
|
Error = testResult.Errors.Count != 0,
|
||||||
|
@ -140,8 +140,8 @@ namespace BTCPayServer.Controllers
|
||||||
model.TestRateRules = testResults;
|
model.TestRateRules = testResults;
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
else // command == Save
|
|
||||||
{
|
// command == Save
|
||||||
if (CurrentStore.SetStoreBlob(blob))
|
if (CurrentStore.SetStoreBlob(blob))
|
||||||
{
|
{
|
||||||
await _storeRepo.UpdateStore(CurrentStore);
|
await _storeRepo.UpdateStore(CurrentStore);
|
||||||
|
@ -152,7 +152,6 @@ namespace BTCPayServer.Controllers
|
||||||
storeId = CurrentStore.Id
|
storeId = CurrentStore.Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{storeId}/rates/confirm")]
|
[HttpGet("{storeId}/rates/confirm")]
|
||||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace BTCPayServer.Controllers
|
||||||
[FromServices] StoreRepository storeRepository,
|
[FromServices] StoreRepository storeRepository,
|
||||||
[FromRoute] string role, UpdateRoleViewModel viewModel)
|
[FromRoute] string role, UpdateRoleViewModel viewModel)
|
||||||
{
|
{
|
||||||
string successMessage = null;
|
string successMessage;
|
||||||
StoreRoleId roleId;
|
StoreRoleId roleId;
|
||||||
if (role == "create")
|
if (role == "create")
|
||||||
{
|
{
|
||||||
|
@ -122,7 +122,7 @@ namespace BTCPayServer.Controllers
|
||||||
[FromServices] StoreRepository storeRepository,
|
[FromServices] StoreRepository storeRepository,
|
||||||
string role)
|
string role)
|
||||||
{
|
{
|
||||||
var roleData = await storeRepository.GetStoreRole(new StoreRoleId(storeId, role), true);;
|
var roleData = await storeRepository.GetStoreRole(new StoreRoleId(storeId, role), true);
|
||||||
if (roleData == null)
|
if (roleData == null)
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,7 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
var paymentMethodId = PaymentMethodId.Parse(newCriteria.PaymentMethod);
|
var paymentMethodId = PaymentMethodId.Parse(newCriteria.PaymentMethod);
|
||||||
if (_handlers.TryGet(paymentMethodId) is LightningLikePaymentHandler h)
|
if (_handlers.TryGet(paymentMethodId) is LightningLikePaymentHandler h)
|
||||||
model.PaymentMethodCriteria.Add(new PaymentMethodCriteriaViewModel()
|
model.PaymentMethodCriteria.Add(new PaymentMethodCriteriaViewModel
|
||||||
{
|
{
|
||||||
PaymentMethod = PaymentTypes.LNURL.GetPaymentMethodId(h.Network.CryptoCode).ToString(),
|
PaymentMethod = PaymentTypes.LNURL.GetPaymentMethodId(h.Network.CryptoCode).ToString(),
|
||||||
Type = newCriteria.Type,
|
Type = newCriteria.Type,
|
||||||
|
@ -419,7 +419,7 @@ namespace BTCPayServer.Controllers
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetCryptoCurrencies(CheckoutAppearanceViewModel vm, Data.StoreData storeData)
|
void SetCryptoCurrencies(CheckoutAppearanceViewModel vm, StoreData storeData)
|
||||||
{
|
{
|
||||||
var choices = GetEnabledPaymentMethodChoices(storeData);
|
var choices = GetEnabledPaymentMethodChoices(storeData);
|
||||||
var chosen = GetDefaultPaymentMethodChoice(storeData);
|
var chosen = GetDefaultPaymentMethodChoice(storeData);
|
||||||
|
@ -432,7 +432,7 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
var enabled = storeData.GetEnabledPaymentIds();
|
var enabled = storeData.GetEnabledPaymentIds();
|
||||||
var defaultPaymentId = storeData.GetDefaultPaymentId();
|
var defaultPaymentId = storeData.GetDefaultPaymentId();
|
||||||
var defaultChoice = defaultPaymentId is not null ? defaultPaymentId.FindNearest(enabled) : null;
|
var defaultChoice = defaultPaymentId?.FindNearest(enabled);
|
||||||
if (defaultChoice is null)
|
if (defaultChoice is null)
|
||||||
{
|
{
|
||||||
defaultChoice = enabled.FirstOrDefault(e => e == PaymentTypes.CHAIN.GetPaymentMethodId(_networkProvider.DefaultNetwork.CryptoCode)) ??
|
defaultChoice = enabled.FirstOrDefault(e => e == PaymentTypes.CHAIN.GetPaymentMethodId(_networkProvider.DefaultNetwork.CryptoCode)) ??
|
||||||
|
|
|
@ -33,10 +33,7 @@ namespace BTCPayServer.Controllers
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
model.ApiKey = (await _tokenRepository.GetLegacyAPIKeys(CurrentStore.Id)).FirstOrDefault();
|
model.ApiKey = (await _tokenRepository.GetLegacyAPIKeys(CurrentStore.Id)).FirstOrDefault();
|
||||||
if (model.ApiKey == null)
|
model.EncodedApiKey = model.ApiKey == null ? "*API Key*" : Encoders.Base64.EncodeData(Encoders.ASCII.DecodeData(model.ApiKey));
|
||||||
model.EncodedApiKey = "*API Key*";
|
|
||||||
else
|
|
||||||
model.EncodedApiKey = Encoders.Base64.EncodeData(Encoders.ASCII.DecodeData(model.ApiKey));
|
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +91,7 @@ namespace BTCPayServer.Controllers
|
||||||
{
|
{
|
||||||
return View(nameof(CreateToken), model);
|
return View(nameof(CreateToken), model);
|
||||||
}
|
}
|
||||||
model.Label = model.Label ?? string.Empty;
|
model.Label ??= string.Empty;
|
||||||
var userId = GetUserId();
|
var userId = GetUserId();
|
||||||
if (userId == null)
|
if (userId == null)
|
||||||
return Challenge(AuthenticationSchemes.Cookie);
|
return Challenge(AuthenticationSchemes.Cookie);
|
||||||
|
@ -111,7 +108,7 @@ namespace BTCPayServer.Controllers
|
||||||
Id = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey).Compress())
|
Id = model.PublicKey == null ? null : NBitpayClient.Extensions.BitIdExtensions.GetBitIDSIN(new PubKey(model.PublicKey).Compress())
|
||||||
};
|
};
|
||||||
|
|
||||||
string? pairingCode = null;
|
string? pairingCode;
|
||||||
if (model.PublicKey == null)
|
if (model.PublicKey == null)
|
||||||
{
|
{
|
||||||
tokenRequest.PairingCode = await _tokenRepository.CreatePairingCodeAsync();
|
tokenRequest.PairingCode = await _tokenRepository.CreatePairingCodeAsync();
|
||||||
|
@ -245,20 +242,16 @@ namespace BTCPayServer.Controllers
|
||||||
if (pairingResult == PairingResult.Complete || pairingResult == PairingResult.Partial)
|
if (pairingResult == PairingResult.Complete || pairingResult == PairingResult.Partial)
|
||||||
{
|
{
|
||||||
var excludeFilter = store.GetStoreBlob().GetExcludedPaymentMethods();
|
var excludeFilter = store.GetStoreBlob().GetExcludedPaymentMethods();
|
||||||
StoreNotConfigured = !store.GetPaymentMethodConfigs(_handlers)
|
StoreNotConfigured = store.GetPaymentMethodConfigs(_handlers).All(p => excludeFilter.Match(p.Key));
|
||||||
.Where(p => !excludeFilter.Match(p.Key))
|
|
||||||
.Any();
|
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "Pairing is successful";
|
TempData[WellKnownTempData.SuccessMessage] = "Pairing is successful";
|
||||||
if (pairingResult == PairingResult.Partial)
|
if (pairingResult == PairingResult.Partial)
|
||||||
TempData[WellKnownTempData.SuccessMessage] = "Server initiated pairing code: " + pairingCode;
|
TempData[WellKnownTempData.SuccessMessage] = "Server initiated pairing code: " + pairingCode;
|
||||||
return RedirectToAction(nameof(ListTokens), new
|
return RedirectToAction(nameof(ListTokens), new
|
||||||
{
|
{
|
||||||
storeId = store.Id,
|
storeId = store.Id, pairingCode
|
||||||
pairingCode = pairingCode
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
TempData[WellKnownTempData.ErrorMessage] = $"Pairing failed ({pairingResult})";
|
TempData[WellKnownTempData.ErrorMessage] = $"Pairing failed ({pairingResult})";
|
||||||
return RedirectToAction(nameof(ListTokens), new
|
return RedirectToAction(nameof(ListTokens), new
|
||||||
{
|
{
|
||||||
|
@ -267,4 +260,3 @@ namespace BTCPayServer.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -158,9 +158,7 @@ namespace BTCPayServer.Controllers
|
||||||
|
|
||||||
private string? GetUserId()
|
private string? GetUserId()
|
||||||
{
|
{
|
||||||
if (User.Identity?.AuthenticationType != AuthenticationSchemes.Cookie)
|
return User.Identity?.AuthenticationType != AuthenticationSchemes.Cookie ? null : _userManager.GetUserId(User);
|
||||||
return null;
|
|
||||||
return _userManager.GetUserId(User);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue