From 5c8e03dcbf07a6a85991003becb821ecdd8097ce Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 1 Aug 2018 15:59:29 +0900 Subject: [PATCH] More user friendly Update Store screen --- .../Controllers/StoresController.BTCLike.cs | 59 +++++++++++-------- BTCPayServer/Views/Stores/UpdateStore.cshtml | 47 ++++++++++++--- 2 files changed, 71 insertions(+), 35 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.BTCLike.cs b/BTCPayServer/Controllers/StoresController.BTCLike.cs index cc0c3cc91..5d2fff689 100644 --- a/BTCPayServer/Controllers/StoresController.BTCLike.cs +++ b/BTCPayServer/Controllers/StoresController.BTCLike.cs @@ -79,6 +79,11 @@ namespace BTCPayServer.Controllers } PaymentMethodId paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike); + var exisingStrategy = store.GetSupportedPaymentMethods(_NetworkProvider) + .Where(c => c.PaymentId == paymentMethodId) + .OfType() + .Select(c => c.DerivationStrategyBase.ToString()) + .FirstOrDefault(); DerivationStrategy strategy = null; try { @@ -94,9 +99,33 @@ namespace BTCPayServer.Controllers vm.Confirmation = false; return View(vm); } - if (!vm.Confirmation && strategy != null) - return ShowAddresses(vm, strategy); - if (vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress)) + + var showAddress = (vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress)) || // Testing hint address + (!vm.Confirmation && strategy != null && exisingStrategy != strategy.DerivationStrategyBase.ToString()); // Checking addresses after setting xpub + + if (!showAddress) + { + try + { + if (strategy != null) + await wallet.TrackAsync(strategy.DerivationStrategyBase); + store.SetSupportedPaymentMethod(paymentMethodId, strategy); + + var storeBlob = store.GetStoreBlob(); + storeBlob.SetExcluded(paymentMethodId, !vm.Enabled); + store.SetStoreBlob(storeBlob); + } + catch + { + ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid Derivation Scheme"); + return View(vm); + } + + await _Repo.UpdateStore(store); + StatusMessage = $"Derivation scheme for {network.CryptoCode} has been modified."; + return RedirectToAction(nameof(UpdateStore), new { storeId = storeId }); + } + else if (!string.IsNullOrEmpty(vm.HintAddress)) { BitcoinAddress address = null; try @@ -122,30 +151,8 @@ namespace BTCPayServer.Controllers vm.StatusMessage = "Address successfully found, please verify that the rest is correct and click on \"Confirm\""; ModelState.Remove(nameof(vm.HintAddress)); ModelState.Remove(nameof(vm.DerivationScheme)); - return ShowAddresses(vm, strategy); - } - else - { - try - { - if (strategy != null) - await wallet.TrackAsync(strategy.DerivationStrategyBase); - store.SetSupportedPaymentMethod(paymentMethodId, strategy); - - var storeBlob = store.GetStoreBlob(); - storeBlob.SetExcluded(paymentMethodId, !vm.Enabled); - store.SetStoreBlob(storeBlob); - } - catch - { - ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid Derivation Scheme"); - return View(vm); - } - - await _Repo.UpdateStore(store); - StatusMessage = $"Derivation scheme for {network.CryptoCode} has been modified."; - return RedirectToAction(nameof(UpdateStore), new { storeId = storeId }); } + return ShowAddresses(vm, strategy); } private IActionResult ShowAddresses(DerivationSchemeViewModel vm, DerivationStrategy strategy) diff --git a/BTCPayServer/Views/Stores/UpdateStore.cshtml b/BTCPayServer/Views/Stores/UpdateStore.cshtml index 2218887f4..53cfc9ae5 100644 --- a/BTCPayServer/Views/Stores/UpdateStore.cshtml +++ b/BTCPayServer/Views/Stores/UpdateStore.cshtml @@ -5,6 +5,21 @@ ViewData.AddActivePage(BTCPayServer.Views.Stores.StoreNavPages.Index); } + + + + +

@ViewData["Title"]

@@ -70,8 +85,8 @@ Crypto Derivation Scheme - Enabled - Actions + Enabled + Actions @@ -79,9 +94,16 @@ { @scheme.Crypto - @scheme.Value - - @(scheme.Enabled ? "Yes" : "No") + @scheme.Value + + @if(scheme.Enabled) + { + + } + else + { + + } @if(!string.IsNullOrWhiteSpace(scheme.Value)) @@ -110,7 +132,7 @@ Crypto Address - Enabled + Enabled Actions @@ -119,9 +141,16 @@ { @scheme.CryptoCode - @scheme.Address - - @(scheme.Enabled ? "Yes" : "No") + @scheme.Address + + @if(scheme.Enabled) + { + + } + else + { + + } Modify