mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 15:04:19 +01:00
Setting hints during store creation and update
This commit is contained in:
@@ -210,6 +210,7 @@ namespace BTCPayServer.Controllers
|
|||||||
vm.AvailableExchanges = exchanges;
|
vm.AvailableExchanges = exchanges;
|
||||||
vm.DefaultCurrencyPairs = storeBlob.GetDefaultCurrencyPairString();
|
vm.DefaultCurrencyPairs = storeBlob.GetDefaultCurrencyPairString();
|
||||||
vm.ShowScripting = storeBlob.RateScripting;
|
vm.ShowScripting = storeBlob.RateScripting;
|
||||||
|
vm.HintRates = storeBlob.Hints?.Rates == true;
|
||||||
return View(vm);
|
return View(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +256,7 @@ namespace BTCPayServer.Controllers
|
|||||||
blob.PreferredExchange = model.PreferredExchange;
|
blob.PreferredExchange = model.PreferredExchange;
|
||||||
blob.Spread = (decimal)model.Spread / 100.0m;
|
blob.Spread = (decimal)model.Spread / 100.0m;
|
||||||
blob.DefaultCurrencyPairs = currencyPairs;
|
blob.DefaultCurrencyPairs = currencyPairs;
|
||||||
|
blob.Hints.Rates = false;
|
||||||
if (!model.ShowScripting)
|
if (!model.ShowScripting)
|
||||||
{
|
{
|
||||||
if (!exchanges.Any(provider => provider.Id.Equals(model.PreferredExchange, StringComparison.InvariantCultureIgnoreCase)))
|
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)
|
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]
|
[HttpPost]
|
||||||
[Route("{storeId}")]
|
[Route("{storeId}")]
|
||||||
public async Task<IActionResult> UpdateStore(StoreViewModel model, string command = null)
|
public async Task<IActionResult> UpdateStore(StoreViewModel model, string command = null)
|
||||||
@@ -625,7 +631,6 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
storeId = CurrentStore.Id
|
storeId = CurrentStore.Id
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|||||||
@@ -37,6 +37,23 @@ namespace BTCPayServer.Controllers
|
|||||||
return View();
|
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
|
public string CreatedStoreId
|
||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
@@ -119,23 +136,6 @@ namespace BTCPayServer.Controllers
|
|||||||
return View(result);
|
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()
|
private string GetUserId()
|
||||||
{
|
{
|
||||||
return _UserManager.GetUserId(User);
|
return _UserManager.GetUserId(User);
|
||||||
|
|||||||
@@ -188,6 +188,14 @@ namespace BTCPayServer.Data
|
|||||||
public bool RedirectAutomatically { get; set; }
|
public bool RedirectAutomatically { get; set; }
|
||||||
public bool PayJoinEnabled { 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()
|
public IPaymentFilter GetExcludedPaymentMethods()
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ namespace BTCPayServer.Data
|
|||||||
var result = storeData.StoreBlob == null ? new StoreBlob() : new Serializer(null).ToObject<StoreBlob>(Encoding.UTF8.GetString(storeData.StoreBlob));
|
var result = storeData.StoreBlob == null ? new StoreBlob() : new Serializer(null).ToObject<StoreBlob>(Encoding.UTF8.GetString(storeData.StoreBlob));
|
||||||
if (result.PreferredExchange == null)
|
if (result.PreferredExchange == null)
|
||||||
result.PreferredExchange = CoinGeckoRateProvider.CoinGeckoName;
|
result.PreferredExchange = CoinGeckoRateProvider.CoinGeckoName;
|
||||||
|
|
||||||
|
if (result.Hints == null)
|
||||||
|
result.Hints = new StoreBlob.StoreHints();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public string DefaultCurrencyPairs { get; set; }
|
public string DefaultCurrencyPairs { get; set; }
|
||||||
public string StoreId { get; set; }
|
public string StoreId { get; set; }
|
||||||
public IEnumerable<AvailableRateProvider> AvailableExchanges { get; set; }
|
public IEnumerable<AvailableRateProvider> AvailableExchanges { get; set; }
|
||||||
|
public bool HintRates { get; set; }
|
||||||
|
|
||||||
[Display(Name = "Add a spread on exchange rate of ... %")]
|
[Display(Name = "Add a spread on exchange rate of ... %")]
|
||||||
[Range(0.0, 100.0)]
|
[Range(0.0, 100.0)]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using BTCPayServer.Client.Models;
|
using BTCPayServer.Client.Models;
|
||||||
using BTCPayServer.Validation;
|
using BTCPayServer.Validation;
|
||||||
|
using static BTCPayServer.Data.StoreBlob;
|
||||||
|
|
||||||
namespace BTCPayServer.Models.StoreViewModels
|
namespace BTCPayServer.Models.StoreViewModels
|
||||||
{
|
{
|
||||||
@@ -90,6 +91,9 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
[Display(Name = "Enable Payjoin/P2EP")]
|
[Display(Name = "Enable Payjoin/P2EP")]
|
||||||
public bool PayJoinEnabled { get; set; }
|
public bool PayJoinEnabled { get; set; }
|
||||||
|
|
||||||
|
public bool HintWallet { get; set; }
|
||||||
|
public bool HintLightning { get; set; }
|
||||||
|
|
||||||
public class LightningNode
|
public class LightningNode
|
||||||
{
|
{
|
||||||
public string CryptoCode { get; set; }
|
public string CryptoCode { get; set; }
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ namespace BTCPayServer.Services.Stores
|
|||||||
{
|
{
|
||||||
StoreDataId = storeData.Id,
|
StoreDataId = storeData.Id,
|
||||||
ApplicationUserId = ownerId,
|
ApplicationUserId = ownerId,
|
||||||
Role = StoreRoles.Owner
|
Role = StoreRoles.Owner,
|
||||||
};
|
};
|
||||||
ctx.Add(storeData);
|
ctx.Add(storeData);
|
||||||
ctx.Add(userStore);
|
ctx.Add(userStore);
|
||||||
@@ -182,6 +182,14 @@ namespace BTCPayServer.Services.Stores
|
|||||||
public async Task<StoreData> CreateStore(string ownerId, string name)
|
public async Task<StoreData> CreateStore(string ownerId, string name)
|
||||||
{
|
{
|
||||||
var store = new StoreData() { StoreName = 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);
|
await CreateStore(ownerId, store);
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@model BTCPayServer.Models.StoreViewModels.RatesViewModel
|
@model BTCPayServer.Models.StoreViewModels.RatesViewModel
|
||||||
@{
|
@{
|
||||||
Layout = "../Shared/_NavLayout.cshtml";
|
Layout = "../Shared/_NavLayout.cshtml";
|
||||||
ViewData.SetActivePageAndTitle(StoreNavPages.Rates, "Rates");
|
ViewData.SetActivePageAndTitle(StoreNavPages.Rates, "Rates");
|
||||||
@@ -18,6 +18,16 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<form method="post">
|
<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">×</span>
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
}
|
||||||
@if (Model.ShowScripting)
|
@if (Model.ShowScripting)
|
||||||
{
|
{
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -159,7 +169,7 @@
|
|||||||
<select asp-for="PreferredExchange" asp-items="Model.Exchanges" class="form-control"></select>
|
<select asp-for="PreferredExchange" asp-items="Model.Exchanges" class="form-control"></select>
|
||||||
<span asp-validation-for="PreferredExchange" class="text-danger"></span>
|
<span asp-validation-for="PreferredExchange" class="text-danger"></span>
|
||||||
<p id="PreferredExchangeHelpBlock" class="form-text text-muted">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div>
|
<div>
|
||||||
<h4 class="mb-3">Wallet <span class="text-muted small">On-chain payments</span></h4>
|
<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">
|
<p class="alert alert-warning">
|
||||||
<span class="fa fa-warning"></span>
|
<span class="fa fa-warning"></span>
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h4 class="mt-5 mb-3">Lightning <span class="text-muted small">Off-chain payments</span></h4>
|
<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">
|
<p class="alert alert-warning">
|
||||||
<span class="fa fa-warning"></span>
|
<span class="fa fa-warning"></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user