diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index f905973b4..d8ce69da2 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -203,7 +203,7 @@ namespace BTCPayServer.Controllers [HttpPost] [Route("{storeId}/derivations")] - public async Task AddDerivationScheme(string storeId, DerivationSchemeViewModel vm, string command, string selectedScheme = null) + public async Task AddDerivationScheme(string storeId, DerivationSchemeViewModel vm, string selectedScheme = null) { selectedScheme = selectedScheme ?? "BTC"; var store = await _Repo.FindStore(storeId, GetUserId()); @@ -224,16 +224,31 @@ namespace BTCPayServer.Controllers return View(vm); } - if (command == "Save") + + DerivationStrategyBase strategy = null; + try + { + if (!string.IsNullOrEmpty(vm.DerivationScheme)) + { + strategy = ParseDerivationStrategy(vm.DerivationScheme, vm.DerivationSchemeFormat, network); + vm.DerivationScheme = strategy.ToString(); + } + store.SetDerivationStrategy(network, vm.DerivationScheme); + } + catch + { + ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid Derivation Scheme"); + vm.Confirmation = false; + return View(vm); + } + + + if (strategy == null || vm.Confirmation) { try { - if (!string.IsNullOrEmpty(vm.DerivationScheme)) - { - var strategy = ParseDerivationStrategy(vm.DerivationScheme, vm.DerivationSchemeFormat, network); + if (strategy != null) await wallet.TrackAsync(strategy); - vm.DerivationScheme = strategy.ToString(); - } store.SetDerivationStrategy(network, vm.DerivationScheme); } catch @@ -250,22 +265,15 @@ namespace BTCPayServer.Controllers { if (!string.IsNullOrEmpty(vm.DerivationScheme)) { - try - { - var scheme = ParseDerivationStrategy(vm.DerivationScheme, vm.DerivationSchemeFormat, network); - var line = scheme.GetLineFor(DerivationFeature.Deposit); + var line = strategy.GetLineFor(DerivationFeature.Deposit); - for (int i = 0; i < 10; i++) - { - var address = line.Derive((uint)i); - vm.AddressSamples.Add((DerivationStrategyBase.GetKeyPath(DerivationFeature.Deposit).Derive((uint)i).ToString(), address.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork).ToString())); - } - } - catch + for (int i = 0; i < 10; i++) { - ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid Derivation Scheme"); + var address = line.Derive((uint)i); + vm.AddressSamples.Add((DerivationStrategyBase.GetKeyPath(DerivationFeature.Deposit).Derive((uint)i).ToString(), address.ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork).ToString())); } } + vm.Confirmation = true; return View(vm); } } diff --git a/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs b/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs index ca7f5334a..ed54c8abc 100644 --- a/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/DerivationSchemeViewModel.cs @@ -48,6 +48,8 @@ namespace BTCPayServer.Models.StoreViewModels set; } + public bool Confirmation { get; set; } + public SelectList CryptoCurrencies { get; set; } public SelectList DerivationSchemeFormats { get; set; } diff --git a/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml b/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml index 6b8e22979..6f3dfe2f6 100644 --- a/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml +++ b/BTCPayServer/Views/Stores/AddDerivationScheme.cshtml @@ -15,29 +15,26 @@
-
-
Derivation Scheme
- @if(Model.AddressSamples.Count == 0) - { + @if(!Model.Confirmation) + { +
+
Derivation Scheme
The DerivationScheme represents the destination of the funds received by your invoice. It is generated by your wallet software. Please, verify that you are generating the right addresses by clicking on 'Check ExtPubKey' -} -
-
- - -
+
+
+ + +
-
- - -
-
- - -
-
- @if(Model.AddressSamples.Count == 0) - { +
+ + +
+
+ + +
+
BTCPay format memo @@ -73,30 +70,39 @@
+
+ } else { - - +
+
Confirm the addresses (@Model.CryptoCurrency)
+ Please check that your @Model.CryptoCurrency wallet is generating the same addresses as below. +
+ + + +
+
+ + + + + + + + @foreach(var sample in Model.AddressSamples) + { - - + + - - - @foreach(var sample in Model.AddressSamples) - { - - - - + } + +
Key pathAddress
Key pathAddress@sample.KeyPath@sample.Address
@sample.KeyPath@sample.Address
+
+ } - - -} -
- -