diff --git a/BTCPayServer.Data/Data/AppData.cs b/BTCPayServer.Data/Data/AppData.cs index 168fe6503..34885548d 100644 --- a/BTCPayServer.Data/Data/AppData.cs +++ b/BTCPayServer.Data/Data/AppData.cs @@ -15,7 +15,6 @@ namespace BTCPayServer.Data public bool TagAllInvoices { get; set; } public string Settings { get; set; } - internal static void OnModelCreating(ModelBuilder builder) { builder.Entity() @@ -28,9 +27,7 @@ namespace BTCPayServer.Data // utility methods public T GetSettings() where T : class, new() { - if (String.IsNullOrEmpty(Settings)) - return new T(); - return JsonConvert.DeserializeObject(Settings); + return string.IsNullOrEmpty(Settings) ? new T() : JsonConvert.DeserializeObject(Settings); } public void SetSettings(object value) diff --git a/BTCPayServer/Controllers/UIAppsController.Crowdfund.cs b/BTCPayServer/Controllers/UIAppsController.Crowdfund.cs index cb42c69e4..104e895bd 100644 --- a/BTCPayServer/Controllers/UIAppsController.Crowdfund.cs +++ b/BTCPayServer/Controllers/UIAppsController.Crowdfund.cs @@ -32,6 +32,7 @@ namespace BTCPayServer.Controllers return NotFound(); var settings = app.GetSettings(); + var resetEvery = Enum.GetName(typeof(CrowdfundResetEvery), settings.ResetEvery); var vm = new UpdateCrowdfundViewModel { Title = settings.Title, @@ -57,7 +58,8 @@ namespace BTCPayServer.Controllers DisqusShortname = settings.DisqusShortname, AnimationsEnabled = settings.AnimationsEnabled, ResetEveryAmount = settings.ResetEveryAmount, - ResetEvery = Enum.GetName(typeof(CrowdfundResetEvery), settings.ResetEvery), + ResetEvery = resetEvery, + IsRecurring = resetEvery != nameof(CrowdfundResetEvery.Never), UseAllStoreInvoices = app.TagAllInvoices, AppId = appId, SearchTerm = app.TagAllInvoices ? $"storeid:{app.StoreDataId}" : $"orderid:{AppService.GetCrowdfundOrderId(appId)}", @@ -94,6 +96,11 @@ namespace BTCPayServer.Controllers vm.TargetAmount = null; } + if (!vm.IsRecurring) + { + vm.ResetEvery = nameof(CrowdfundResetEvery.Never); + } + if (Enum.Parse(vm.ResetEvery) != CrowdfundResetEvery.Never && !vm.StartDate.HasValue) { ModelState.AddModelError(nameof(vm.StartDate), "A start date is needed when the goal resets every X amount of time."); diff --git a/BTCPayServer/Controllers/UIAppsController.cs b/BTCPayServer/Controllers/UIAppsController.cs index 678c14b0f..8499e8f6c 100644 --- a/BTCPayServer/Controllers/UIAppsController.cs +++ b/BTCPayServer/Controllers/UIAppsController.cs @@ -128,21 +128,20 @@ namespace BTCPayServer.Controllers var empty = new PointOfSaleSettings { Currency = defaultCurrency }; appData.SetSettings(empty); break; + default: + throw new ArgumentOutOfRangeException(); } await _appService.UpdateOrCreateApp(appData); TempData[WellKnownTempData.SuccessMessage] = "App successfully created"; CreatedAppId = appData.Id; - switch (appType) + return appType switch { - case AppType.PointOfSale: - return RedirectToAction(nameof(UpdatePointOfSale), new { appId = appData.Id }); - case AppType.Crowdfund: - return RedirectToAction(nameof(UpdateCrowdfund), new { appId = appData.Id }); - default: - return RedirectToAction(nameof(ListApps), new { storeId = appData.StoreDataId }); - } + AppType.PointOfSale => RedirectToAction(nameof(UpdatePointOfSale), new { appId = appData.Id }), + AppType.Crowdfund => RedirectToAction(nameof(UpdateCrowdfund), new { appId = appData.Id }), + _ => throw new ArgumentOutOfRangeException() + }; } [HttpGet("{appId}/delete")] diff --git a/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs b/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs index e3c5d72b7..5c42b9224 100644 --- a/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs +++ b/BTCPayServer/Models/AppViewModels/UpdateCrowdfundViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.Linq; using BTCPayServer.Services.Apps; using BTCPayServer.Validation; @@ -28,7 +29,7 @@ namespace BTCPayServer.Models.AppViewModels [Required] public string Description { get; set; } - [Display(Name = "Featured Image")] + [Display(Name = "Featured Image URL")] public string MainImageUrl { get; set; } [Display(Name = "Callback Notification URL")] @@ -68,11 +69,15 @@ namespace BTCPayServer.Models.AppViewModels [Range(0, double.PositiveInfinity)] public decimal? TargetAmount { get; set; } - public IEnumerable ResetEveryValues = Enum.GetNames(typeof(CrowdfundResetEvery)); + public IEnumerable ResetEveryValues = Enum.GetNames(typeof(CrowdfundResetEvery)) + .Where(i => i != nameof(CrowdfundResetEvery.Never)); + + public bool IsRecurring { get; set; } [Display(Name = "Reset goal every")] public string ResetEvery { get; set; } = nameof(CrowdfundResetEvery.Never); + [Display(Name = "Reset goal every")] public int ResetEveryAmount { get; set; } = 1; [Display(Name = "Do not allow additional contributions after target has been reached")] diff --git a/BTCPayServer/Services/Apps/CrowdfundSettings.cs b/BTCPayServer/Services/Apps/CrowdfundSettings.cs index f1ad60990..2b303c0ba 100644 --- a/BTCPayServer/Services/Apps/CrowdfundSettings.cs +++ b/BTCPayServer/Services/Apps/CrowdfundSettings.cs @@ -6,12 +6,11 @@ namespace BTCPayServer.Services.Apps { public string Title { get; set; } public string Description { get; set; } - public bool Enabled { get; set; } - + public bool Enabled { get; set; } = true; public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } - public string TargetCurrency { get; set; } + decimal? _TargetAmount; public decimal? TargetAmount { @@ -38,7 +37,7 @@ namespace BTCPayServer.Services.Apps public bool DisqusEnabled { get; set; } public bool SoundsEnabled { get; set; } public string DisqusShortname { get; set; } - public bool AnimationsEnabled { get; set; } = true; + public bool AnimationsEnabled { get; set; } public int ResetEveryAmount { get; set; } = 1; public CrowdfundResetEvery ResetEvery { get; set; } = CrowdfundResetEvery.Never; [Obsolete("Use AppData.TagAllInvoices instead")] @@ -53,46 +52,33 @@ namespace BTCPayServer.Services.Apps public string[] Sounds { get; set; } = { - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/dominating.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/doublekill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/doublekill2.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/eagleeye.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/firstblood.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/firstblood2.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/firstblood3.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/flawless.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/godlike.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/hattrick.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/headhunter.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/headshot.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/headshot2.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/headshot3.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/holyshit.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/killingspree.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/knife.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/knife2.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/knife3.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/ludicrouskill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/megakill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/monsterkill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/multikill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/nade.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/ownage.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/payback.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/prepare.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/prepare2.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/prepare3.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/prepare4.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/rampage.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/suicide.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/suicide2.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/suicide3.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/suicide4.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/teamkiller.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/triplekill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/ultrakill.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/unstoppable.wav", - "//github.com/ClaudiuHKS/AdvancedQuakeSounds/raw/master/sound/QuakeSounds/whickedsick.wav" + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/dominating.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/doublekill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/doublekill2.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/eagleeye.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/firstblood.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/firstblood2.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/firstblood3.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/godlike.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/hattrick.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/headhunter.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/headshot.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/headshot2.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/headshot3.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/holyshit.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/killingspree.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/ludicrouskill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/megakill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/monsterkill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/multikill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/ownage.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/payback.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/rampage.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/teamkiller.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/triplekill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/ultrakill.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/unstoppable.wav", + "https://github.com/ClaudiuHKS/AdvancedQuakeSounds/tree/master/sound/AQS/whickedsick.wav" }; } public enum CrowdfundResetEvery diff --git a/BTCPayServer/Views/UIApps/UpdateCrowdfund.cshtml b/BTCPayServer/Views/UIApps/UpdateCrowdfund.cshtml index 6c62f5e6f..8240848f4 100644 --- a/BTCPayServer/Views/UIApps/UpdateCrowdfund.cshtml +++ b/BTCPayServer/Views/UIApps/UpdateCrowdfund.cshtml @@ -63,22 +63,24 @@ -
-
+
+
- +
+ + + + +
- - -
-
+

Goal

-
-
+
+
@@ -90,50 +92,60 @@
-
-
-
- -
- - -
- +
+
+ +
+ +
+
-
-
- -
- - -
- +
+ +
+ +
+
- @@ -181,58 +193,88 @@
- -

Sound

-
-
- - - -
-
-
-
- - - -
-
- -

Animation

-
-
- - - -
-
-
-
- - - -
-
- -

Discussion

-
-
- - - -
-
-
-
- - - -
-

Additional Options

+
+

+ +

+
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+
+
+

+ +

+
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+
+
+

+ +

+
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+