Setting hints during store creation and update

This commit is contained in:
rockstardev 2020-10-15 23:30:46 -05:00
parent 17c8ac8248
commit 15af66de55
9 changed files with 88 additions and 49 deletions

View File

@ -210,6 +210,7 @@ namespace BTCPayServer.Controllers
vm.AvailableExchanges = exchanges;
vm.DefaultCurrencyPairs = storeBlob.GetDefaultCurrencyPairString();
vm.ShowScripting = storeBlob.RateScripting;
vm.HintRates = storeBlob.Hints?.Rates == true;
return View(vm);
}
@ -255,6 +256,7 @@ namespace BTCPayServer.Controllers
blob.PreferredExchange = model.PreferredExchange;
blob.Spread = (decimal)model.Spread / 100.0m;
blob.DefaultCurrencyPairs = currencyPairs;
blob.Hints.Rates = false;
if (!model.ShowScripting)
{
if (!exchanges.Any(provider => provider.Id.Equals(model.PreferredExchange, StringComparison.InvariantCultureIgnoreCase)))
@ -471,32 +473,6 @@ namespace BTCPayServer.Controllers
});
}
[HttpGet]
[Route("{storeId}")]
public IActionResult UpdateStore()
{
var store = HttpContext.GetStoreData();
if (store == null)
return NotFound();
var storeBlob = store.GetStoreBlob();
var vm = new StoreViewModel();
vm.Id = store.Id;
vm.StoreName = store.StoreName;
vm.StoreWebsite = store.StoreWebsite;
vm.NetworkFeeMode = storeBlob.NetworkFeeMode;
vm.AnyoneCanCreateInvoice = storeBlob.AnyoneCanInvoice;
vm.SpeedPolicy = store.SpeedPolicy;
vm.CanDelete = _Repo.CanDeleteStores();
AddPaymentMethods(store, storeBlob, vm);
vm.MonitoringExpiration = (int)storeBlob.MonitoringExpiration.TotalMinutes;
vm.InvoiceExpiration = (int)storeBlob.InvoiceExpiration.TotalMinutes;
vm.LightningDescriptionTemplate = storeBlob.LightningDescriptionTemplate;
vm.PaymentTolerance = storeBlob.PaymentTolerance;
vm.PayJoinEnabled = storeBlob.PayJoinEnabled;
return View(vm);
}
private void AddPaymentMethods(StoreData store, StoreBlob storeBlob, StoreViewModel vm)
{
@ -556,6 +532,36 @@ namespace BTCPayServer.Controllers
}
[HttpGet]
[Route("{storeId}")]
public IActionResult UpdateStore()
{
var store = HttpContext.GetStoreData();
if (store == null)
return NotFound();
var storeBlob = store.GetStoreBlob();
var vm = new StoreViewModel();
vm.Id = store.Id;
vm.StoreName = store.StoreName;
vm.StoreWebsite = store.StoreWebsite;
vm.NetworkFeeMode = storeBlob.NetworkFeeMode;
vm.AnyoneCanCreateInvoice = storeBlob.AnyoneCanInvoice;
vm.SpeedPolicy = store.SpeedPolicy;
vm.CanDelete = _Repo.CanDeleteStores();
AddPaymentMethods(store, storeBlob, vm);
vm.MonitoringExpiration = (int)storeBlob.MonitoringExpiration.TotalMinutes;
vm.InvoiceExpiration = (int)storeBlob.InvoiceExpiration.TotalMinutes;
vm.LightningDescriptionTemplate = storeBlob.LightningDescriptionTemplate;
vm.PaymentTolerance = storeBlob.PaymentTolerance;
vm.PayJoinEnabled = storeBlob.PayJoinEnabled;
vm.HintWallet = storeBlob.Hints.Wallet;
vm.HintLightning = storeBlob.Hints.Lighting;
return View(vm);
}
[HttpPost]
[Route("{storeId}")]
public async Task<IActionResult> UpdateStore(StoreViewModel model, string command = null)
@ -625,7 +631,6 @@ namespace BTCPayServer.Controllers
{
storeId = CurrentStore.Id
});
}
[HttpGet]

View File

@ -37,6 +37,23 @@ namespace BTCPayServer.Controllers
return View();
}
[HttpPost]
[Route("create")]
public async Task<IActionResult> CreateStore(CreateStoreViewModel vm)
{
if (!ModelState.IsValid)
{
return View(vm);
}
var store = await _Repo.CreateStore(GetUserId(), vm.Name);
CreatedStoreId = store.Id;
TempData[WellKnownTempData.SuccessMessage] = "Store successfully created";
return RedirectToAction(nameof(StoresController.UpdateStore), "Stores", new
{
storeId = store.Id
});
}
public string CreatedStoreId
{
get; set;
@ -119,23 +136,6 @@ namespace BTCPayServer.Controllers
return View(result);
}
[HttpPost]
[Route("create")]
public async Task<IActionResult> CreateStore(CreateStoreViewModel vm)
{
if (!ModelState.IsValid)
{
return View(vm);
}
var store = await _Repo.CreateStore(GetUserId(), vm.Name);
CreatedStoreId = store.Id;
TempData[WellKnownTempData.SuccessMessage] = "Store successfully created";
return RedirectToAction(nameof(StoresController.UpdateStore), "Stores", new
{
storeId = store.Id
});
}
private string GetUserId()
{
return _UserManager.GetUserId(User);

View File

@ -188,6 +188,14 @@ namespace BTCPayServer.Data
public bool RedirectAutomatically { get; set; }
public bool PayJoinEnabled { get; set; }
public StoreHints Hints { get; set; }
public class StoreHints
{
public bool Wallet { get; set; }
public bool Lighting { get; set; }
public bool Rates { get; set; }
}
public IPaymentFilter GetExcludedPaymentMethods()
{
#pragma warning disable CS0618 // Type or member is obsolete

View File

@ -46,6 +46,9 @@ namespace BTCPayServer.Data
var result = storeData.StoreBlob == null ? new StoreBlob() : new Serializer(null).ToObject<StoreBlob>(Encoding.UTF8.GetString(storeData.StoreBlob));
if (result.PreferredExchange == null)
result.PreferredExchange = CoinGeckoRateProvider.CoinGeckoName;
if (result.Hints == null)
result.Hints = new StoreBlob.StoreHints();
return result;
}

View File

@ -53,6 +53,7 @@ namespace BTCPayServer.Models.StoreViewModels
public string DefaultCurrencyPairs { get; set; }
public string StoreId { get; set; }
public IEnumerable<AvailableRateProvider> AvailableExchanges { get; set; }
public bool HintRates { get; set; }
[Display(Name = "Add a spread on exchange rate of ... %")]
[Range(0.0, 100.0)]

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using BTCPayServer.Client.Models;
using BTCPayServer.Validation;
using static BTCPayServer.Data.StoreBlob;
namespace BTCPayServer.Models.StoreViewModels
{
@ -90,6 +91,9 @@ namespace BTCPayServer.Models.StoreViewModels
[Display(Name = "Enable Payjoin/P2EP")]
public bool PayJoinEnabled { get; set; }
public bool HintWallet { get; set; }
public bool HintLightning { get; set; }
public class LightningNode
{
public string CryptoCode { get; set; }

View File

@ -171,7 +171,7 @@ namespace BTCPayServer.Services.Stores
{
StoreDataId = storeData.Id,
ApplicationUserId = ownerId,
Role = StoreRoles.Owner
Role = StoreRoles.Owner,
};
ctx.Add(storeData);
ctx.Add(userStore);
@ -182,6 +182,14 @@ namespace BTCPayServer.Services.Stores
public async Task<StoreData> CreateStore(string ownerId, string name)
{
var store = new StoreData() { StoreName = name };
var blob = store.GetStoreBlob();
blob.Hints = new Data.StoreBlob.StoreHints
{
Wallet = true,
Lighting = true,
Rates = true
};
store.SetStoreBlob(blob);
await CreateStore(ownerId, store);
return store;
}

View File

@ -1,4 +1,4 @@
@model BTCPayServer.Models.StoreViewModels.RatesViewModel
@model BTCPayServer.Models.StoreViewModels.RatesViewModel
@{
Layout = "../Shared/_NavLayout.cshtml";
ViewData.SetActivePageAndTitle(StoreNavPages.Rates, "Rates");
@ -18,6 +18,16 @@
<div class="row">
<div class="col-md-8">
<form method="post">
@if (Model.HintRates)
{
<p class="alert alert-warning">
<span class="fa fa-warning"></span>
Please verify all Rates settings and test exchange rate currency pairs
<button type="button" class="close only-for-js" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</p>
}
@if (Model.ShowScripting)
{
<div class="form-group">
@ -159,7 +169,7 @@
<select asp-for="PreferredExchange" asp-items="Model.Exchanges" class="form-control"></select>
<span asp-validation-for="PreferredExchange" class="text-danger"></span>
<p id="PreferredExchangeHelpBlock" class="form-text text-muted">
Current price source is <a href="@Model.RateSource" target="_blank">@Model.PreferredExchange</a>.
Current Rates source is <a href="@Model.RateSource" target="_blank">@Model.PreferredExchange</a>.
</p>
</div>
<div class="form-group">

View File

@ -20,7 +20,7 @@
<div class="col-md-8">
<div>
<h4 class="mb-3">Wallet <span class="text-muted small">On-chain payments</span></h4>
@if (!Model.DerivationSchemes.Any(a => !String.IsNullOrEmpty(a.Value)))
@if (Model.HintWallet)
{
<p class="alert alert-warning">
<span class="fa fa-warning"></span>
@ -102,7 +102,7 @@
</table>
<h4 class="mt-5 mb-3">Lightning <span class="text-muted small">Off-chain payments</span></h4>
@if (!Model.DerivationSchemes.Any(a => !String.IsNullOrEmpty(a.Value)))
@if (Model.HintLightning)
{
<p class="alert alert-warning">
<span class="fa fa-warning"></span>