From 4bffe117a9511cb69957c045ffc8517cf529e620 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 25 Jul 2023 10:50:34 +0900 Subject: [PATCH] Do not show cheatmode in release, fix warnigns --- ...AutomatedLightningPayoutProcessorsController.cs | 2 +- .../Reporting/OnChainWalletReportProvider.cs | 4 ++-- BTCPayServer/Services/Reporting/QueryContext.cs | 11 +++++++---- BTCPayServer/TagHelpers/CheatModeTagHelper.cs | 14 ++++---------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoreAutomatedLightningPayoutProcessorsController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoreAutomatedLightningPayoutProcessorsController.cs index 70020dea1..f1070ec05 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoreAutomatedLightningPayoutProcessorsController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoreAutomatedLightningPayoutProcessorsController.cs @@ -53,7 +53,7 @@ namespace BTCPayServer.Controllers.Greenfield private static LightningAutomatedPayoutSettings ToModel(PayoutProcessorData data) { - var blob = data.HasTypedBlob().GetBlob(); + var blob = data.HasTypedBlob().GetBlob() ?? new LightningAutomatedPayoutBlob(); return new LightningAutomatedPayoutSettings() { PaymentMethod = data.PaymentMethod, diff --git a/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs b/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs index 2827e10ea..f5f65b4dc 100644 --- a/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs +++ b/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs @@ -106,13 +106,13 @@ public class OnChainWalletReportProvider : ReportProvider } var objects = await WalletRepository.GetWalletObjects(new GetWalletObjectsQuery() { - Ids = queryContext.Data.Select(d => (string)d[2]).ToArray(), + Ids = queryContext.Data.Select(d => (string)d[2]!).ToArray(), WalletId = walletId, Type = "tx" }); foreach (var row in queryContext.Data) { - if (!objects.TryGetValue(new WalletObjectId(walletId, "tx", (string)row[2]), out var txObject)) + if (!objects.TryGetValue(new WalletObjectId(walletId, "tx", (string)row[2]!), out var txObject)) continue; var invoiceId = txObject.GetLinks().Where(t => t.type == "invoice").Select(t => t.id).FirstOrDefault(); row[3] = invoiceId; diff --git a/BTCPayServer/Services/Reporting/QueryContext.cs b/BTCPayServer/Services/Reporting/QueryContext.cs index 4f0955531..1d953d92b 100644 --- a/BTCPayServer/Services/Reporting/QueryContext.cs +++ b/BTCPayServer/Services/Reporting/QueryContext.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections; using System.Collections.Generic; @@ -17,18 +18,20 @@ namespace BTCPayServer.Services.Reporting public DateTimeOffset To { get; } public ViewDefinition? ViewDefinition { get; set; } - public IList AddData() + public IList AddData() { var l = CreateData(); Data.Add(l); return l; } - public IList CreateData() + public IList CreateData() { - return new List(ViewDefinition.Fields.Count); + if (ViewDefinition is null) + throw new InvalidOperationException("You need to initialize ViewDefinition first"); + return new List(ViewDefinition.Fields.Count); } - public IList> Data { get; set; } = new List>(); + public IList> Data { get; set; } = new List>(); } } diff --git a/BTCPayServer/TagHelpers/CheatModeTagHelper.cs b/BTCPayServer/TagHelpers/CheatModeTagHelper.cs index 147371780..d597b146d 100644 --- a/BTCPayServer/TagHelpers/CheatModeTagHelper.cs +++ b/BTCPayServer/TagHelpers/CheatModeTagHelper.cs @@ -1,26 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.TagHelpers; -using System.Xml.Linq; using BTCPayServer.Configuration; namespace BTCPayServer.TagHelpers; -[HtmlTargetElement(Attributes = "[cheat-mode]")] -public class CheatModeTagHelper +[HtmlTargetElement(Attributes = "cheat-mode")] +public class CheatModeTagHelper : TagHelper { public CheatModeTagHelper(BTCPayServerOptions env) { Env = env; } - public BTCPayServerOptions Env { get; } + BTCPayServerOptions Env { get; } public bool CheatMode { get; set; } - public void Process(TagHelperContext context, TagHelperOutput output) + public override void Process(TagHelperContext context, TagHelperOutput output) { if (Env.CheatMode != CheatMode) {