From 723a38da68f4ea27831f5cd50f88beb9a46fcbd2 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Thu, 20 Jan 2022 12:52:31 +0100 Subject: [PATCH 1/4] Store: Combine General and Payment settings --- .../AltcoinTests/AltcoinTests.cs | 4 +- BTCPayServer.Tests/CheckoutUITests.cs | 2 +- BTCPayServer.Tests/SeleniumTester.cs | 2 - BTCPayServer.Tests/SeleniumTests.cs | 10 +-- BTCPayServer.Tests/TestAccount.cs | 10 +-- BTCPayServer.Tests/UnitTest1.cs | 16 ++-- .../Components/MainNav/Default.cshtml | 2 +- .../Controllers/UIInvoiceController.UI.cs | 4 +- .../Controllers/UIStoresController.Onchain.cs | 4 +- .../Controllers/UIStoresController.cs | 74 ++++++------------ .../GeneralSettingsViewModel.cs | 23 ++++++ .../LNURL/LightningAddressOption.cshtml | 5 +- BTCPayServer/Views/UIApps/ListApps.cshtml | 2 +- .../UIAppsPublic/PointOfSale/Print.cshtml | 3 +- BTCPayServer/Views/UIStores/Dashboard.cshtml | 4 +- .../Views/UIStores/GeneralSettings.cshtml | 58 +++++++++++++- BTCPayServer/Views/UIStores/Payment.cshtml | 75 ------------------- BTCPayServer/Views/UIStores/StoreNavPages.cs | 2 +- .../Views/UIStores/_LayoutWalletSetup.cshtml | 2 +- BTCPayServer/Views/UIStores/_Nav.cshtml | 1 - .../Views/UIWallets/ListWallets.cshtml | 2 +- 21 files changed, 136 insertions(+), 169 deletions(-) delete mode 100644 BTCPayServer/Views/UIStores/Payment.cshtml diff --git a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs index 6802b2fc1..47b43eb7b 100644 --- a/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs +++ b/BTCPayServer.Tests/AltcoinTests/AltcoinTests.cs @@ -386,7 +386,7 @@ namespace BTCPayServer.Tests // BTC crash by 50% s.Server.PayTester.ChangeRate("BTC_USD", new Rating.BidAsk(5000.0m / 2.0m, 5100.0m / 2.0m)); - s.GoToStore(StoreNavPages.Payment); + s.GoToStore(); s.Driver.FindElement(By.Id("BOLT11Expiration")).Clear(); s.Driver.FindElement(By.Id("BOLT11Expiration")).SendKeys("5" + Keys.Enter); s.GoToInvoice(invoice.Id); @@ -438,7 +438,7 @@ namespace BTCPayServer.Tests s.GoToInvoiceCheckout(invoiceId); s.Driver.FindElement(By.ClassName("payment__currencies_noborder")); s.GoToHome(); - s.GoToStore(StoreNavPages.Payment); + s.GoToStore(); s.AddDerivationScheme("LTC"); s.AddLightningNode(LightningConnectionType.CLightning); //there should be three now diff --git a/BTCPayServer.Tests/CheckoutUITests.cs b/BTCPayServer.Tests/CheckoutUITests.cs index d42df0aac..2e293f860 100644 --- a/BTCPayServer.Tests/CheckoutUITests.cs +++ b/BTCPayServer.Tests/CheckoutUITests.cs @@ -204,7 +204,7 @@ namespace BTCPayServer.Tests s.GoToRegister(); s.RegisterNewUser(); s.CreateNewStore(); - s.GoToStore(StoreNavPages.Payment); + s.GoToStore(); s.AddDerivationScheme(); var invoiceId = s.CreateInvoice(0.001m, "BTC", "a@x.com"); var invoice = await s.Server.PayTester.InvoiceRepository.GetInvoice(invoiceId); diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 63210c20b..e5cac541d 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -156,7 +156,6 @@ namespace BTCPayServer.Tests Driver.FindElement(By.Id("StoreNav-StoreSettings")).Click(); Driver.FindElement(By.Id($"SectionNav-{StoreNavPages.General.ToString()}")).Click(); var storeId = Driver.WaitForElement(By.Id("Id")).GetAttribute("value"); - Driver.FindElement(By.Id($"SectionNav-{StoreNavPages.Payment.ToString()}")).Click(); if (keepId) StoreId = storeId; return (name, storeId); @@ -397,7 +396,6 @@ namespace BTCPayServer.Tests public void GoToLightningSettings(string cryptoCode = "BTC") { - GoToStore(StoreNavPages.Payment); Driver.FindElement(By.Id($"StoreNav-Lightning{cryptoCode}")).Click(); // if Lightning is already set up we need to navigate to the settings if (Driver.PageSource.Contains("id=\"SectionNav-LightningSettings\"")) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 1008d705e..cd961b436 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -404,7 +404,7 @@ namespace BTCPayServer.Tests (string storeName, string storeId) = s.CreateNewStore(); var storeUrl = $"/stores/{storeId}"; - s.GoToStore(StoreNavPages.Payment); + s.GoToStore(); Assert.Contains(storeName, s.Driver.PageSource); // verify steps for wallet setup are displayed correctly @@ -793,7 +793,7 @@ namespace BTCPayServer.Tests Assert.Contains(server.ServerUri.AbsoluteUri, s.Driver.PageSource); TestLogs.LogInformation("Let's see if we can generate an event"); - s.GoToStore(StoreNavPages.Payment); + s.GoToStore(); s.AddDerivationScheme(); s.CreateInvoice(); var request = await server.GetNextRequest(); @@ -929,7 +929,7 @@ namespace BTCPayServer.Tests var result = await s.Server.ExplorerNode.GetAddressInfoAsync(BitcoinAddress.Create(address, Network.RegTest)); Assert.True(result.IsWatchOnly); - s.GoToStore(storeId, StoreNavPages.Payment); + s.GoToStore(storeId); var mnemonic = s.GenerateWallet(cryptoCode, "", true, true); //lets import and save private keys @@ -1302,7 +1302,7 @@ namespace BTCPayServer.Tests s.RegisterNewUser(true); s.CreateNewStore(); - s.GoToStore(StoreNavPages.Payment); + s.GoToStore(); s.AddLightningNode(LightningConnectionType.CLightning, false); s.GoToLightningSettings(); s.Driver.SetCheckbox(By.Id("LNURLEnabled"), true); @@ -1345,7 +1345,6 @@ namespace BTCPayServer.Tests s.RegisterNewUser(true); (_, string storeId) = s.CreateNewStore(); var network = s.Server.NetworkProvider.GetNetwork(cryptoCode).NBitcoinNetwork; - s.GoToStore(StoreNavPages.Payment); s.AddLightningNode(LightningConnectionType.CLightning, false); s.GoToLightningSettings(); // LNURL is true by default @@ -1558,7 +1557,6 @@ namespace BTCPayServer.Tests //ensure ln address is not available as Lightning is not enable s.Driver.AssertElementNotFound(By.Id("StoreNav-LightningAddress")); - s.GoToStore(s.StoreId, StoreNavPages.Payment); s.AddLightningNode(LightningConnectionType.LndREST, false); s.Driver.FindElement(By.Id("StoreNav-LightningAddress")).Click(); diff --git a/BTCPayServer.Tests/TestAccount.cs b/BTCPayServer.Tests/TestAccount.cs index 49466193b..25b37de54 100644 --- a/BTCPayServer.Tests/TestAccount.cs +++ b/BTCPayServer.Tests/TestAccount.cs @@ -133,13 +133,13 @@ namespace BTCPayServer.Tests }); } - public async Task ModifyPayment(Action modify) + public async Task ModifyPayment(Action modify) { var storeController = GetController(); - var response = storeController.Payment(); - PaymentViewModel payment = (PaymentViewModel)((ViewResult)response).Model; - modify(payment); - await storeController.Payment(payment); + var response = storeController.GeneralSettings(); + GeneralSettingsViewModel settings = (GeneralSettingsViewModel)((ViewResult)response).Model; + modify(settings); + await storeController.GeneralSettings(settings); } public async Task ModifyWalletSettings(Action modify) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index 871834fe6..69fe3471d 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -275,13 +275,13 @@ namespace BTCPayServer.Tests // Set tolerance to 50% var stores = user.GetController(); - var response = stores.Payment(); - var vm = Assert.IsType(Assert.IsType(response).Model); + var response = stores.GeneralSettings(); + var vm = Assert.IsType(Assert.IsType(response).Model); Assert.Equal(0.0, vm.PaymentTolerance); vm.PaymentTolerance = 50.0; - Assert.IsType(stores.Payment(vm).Result); + Assert.IsType(stores.GeneralSettings(vm).Result); - var invoice = user.BitPay.CreateInvoice( + var invoice = await user.BitPay.CreateInvoiceAsync( new Invoice() { Buyer = new Buyer() { email = "test@fwf.com" }, @@ -295,7 +295,7 @@ namespace BTCPayServer.Tests // Pays 75% var invoiceAddress = BitcoinAddress.Create(invoice.CryptoInfo[0].Address, tester.ExplorerNode.Network); - tester.ExplorerNode.SendToAddress(invoiceAddress, + await tester.ExplorerNode.SendToAddressAsync(invoiceAddress, Money.Satoshis(invoice.BtcDue.Satoshi * 0.75m)); TestUtils.Eventually(() => @@ -415,13 +415,13 @@ namespace BTCPayServer.Tests await tester.StartAsync(); await tester.EnsureChannelsSetup(); var user = tester.NewAccount(); - user.GrantAccess(true); + await user.GrantAccessAsync(true); var storeController = user.GetController(); - var storeResponse = storeController.Payment(); + var storeResponse = storeController.GeneralSettings(); Assert.IsType(storeResponse); Assert.IsType(await storeController.SetupLightningNode(user.StoreId, "BTC")); - var testResult = storeController.SetupLightningNode(user.StoreId, new LightningNodeViewModel + storeController.SetupLightningNode(user.StoreId, new LightningNodeViewModel { ConnectionString = $"type=charge;server={tester.MerchantCharge.Client.Uri.AbsoluteUri};allowinsecure=true", SkipPortTest = true // We can't test this as the IP can't be resolved by the test host :( diff --git a/BTCPayServer/Components/MainNav/Default.cshtml b/BTCPayServer/Components/MainNav/Default.cshtml index eb5edd86c..9ff22cd33 100644 --- a/BTCPayServer/Components/MainNav/Default.cshtml +++ b/BTCPayServer/Components/MainNav/Default.cshtml @@ -35,7 +35,7 @@
  • @@ -30,7 +31,7 @@ { if (!isLightningEnabled) { - + You need to setup Lightning first } diff --git a/BTCPayServer/Views/UIApps/ListApps.cshtml b/BTCPayServer/Views/UIApps/ListApps.cshtml index dd3db9c0d..255cd58c7 100644 --- a/BTCPayServer/Views/UIApps/ListApps.cshtml +++ b/BTCPayServer/Views/UIApps/ListApps.cshtml @@ -79,7 +79,7 @@ @if (app.IsOwner) { - @app.StoreName + @app.StoreName } else { diff --git a/BTCPayServer/Views/UIAppsPublic/PointOfSale/Print.cshtml b/BTCPayServer/Views/UIAppsPublic/PointOfSale/Print.cshtml index bb1a401ac..c38f13731 100644 --- a/BTCPayServer/Views/UIAppsPublic/PointOfSale/Print.cshtml +++ b/BTCPayServer/Views/UIAppsPublic/PointOfSale/Print.cshtml @@ -24,14 +24,13 @@ { supported = null; } - } @if (supported is null) { diff --git a/BTCPayServer/Views/UIStores/Dashboard.cshtml b/BTCPayServer/Views/UIStores/Dashboard.cshtml index 433a540d5..64d96b997 100644 --- a/BTCPayServer/Views/UIStores/Dashboard.cshtml +++ b/BTCPayServer/Views/UIStores/Dashboard.cshtml @@ -63,7 +63,7 @@ else } else { - +
    Set up a wallet
    @@ -95,7 +95,7 @@ else } else { -
    +
    Set up a Lightning node
    diff --git a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml index c28da1b6e..bbbf671fe 100644 --- a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml +++ b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml @@ -5,7 +5,7 @@ }
    -
    +
    @if (!ViewContext.ModelState.IsValid) {
    @@ -27,8 +27,64 @@
    +

    Payment

    +
    + + + +
    +
    +
    + + + + + +
    +
    + + + + +
    + + minutes +
    + +
    +
    + + + + +
    + + percent +
    + +
    +
    + +
    + + days +
    + +
    + +

    Services

    diff --git a/BTCPayServer/Views/UIStores/Payment.cshtml b/BTCPayServer/Views/UIStores/Payment.cshtml deleted file mode 100644 index 7d77d8706..000000000 --- a/BTCPayServer/Views/UIStores/Payment.cshtml +++ /dev/null @@ -1,75 +0,0 @@ -@model PaymentViewModel -@{ - Layout = "../Shared/_NavLayout.cshtml"; - ViewData.SetActivePage(StoreNavPages.Payment, "Wallets", Context.GetStoreData().Id); -} - -
    -
    - @if (!ViewContext.ModelState.IsValid) - { -
    - } -
    -

    Payment

    -
    - - - -
    -
    - - - - - -
    -
    - - - - - -
    -
    - - - - -
    - - minutes -
    - -
    -
    - - - - -
    - - percent -
    - -
    -
    - -
    - - days -
    - -
    - - -
    -
    - -@section PageFootContent { - -} diff --git a/BTCPayServer/Views/UIStores/StoreNavPages.cs b/BTCPayServer/Views/UIStores/StoreNavPages.cs index 9ca06d326..8d1f5395e 100644 --- a/BTCPayServer/Views/UIStores/StoreNavPages.cs +++ b/BTCPayServer/Views/UIStores/StoreNavPages.cs @@ -2,6 +2,6 @@ namespace BTCPayServer.Views.Stores { public enum StoreNavPages { - Create, Dashboard, Rates, Payment, OnchainSettings, LightningSettings, Lightning, CheckoutAppearance, General, Tokens, Users, PayButton, Integrations, Webhooks, PullPayments, Payouts + Create, Dashboard, General, Rates, OnchainSettings, LightningSettings, Lightning, CheckoutAppearance, Tokens, Users, PayButton, Integrations, Webhooks, PullPayments, Payouts } } diff --git a/BTCPayServer/Views/UIStores/_LayoutWalletSetup.cshtml b/BTCPayServer/Views/UIStores/_LayoutWalletSetup.cshtml index f1df710bb..ca00311fb 100644 --- a/BTCPayServer/Views/UIStores/_LayoutWalletSetup.cshtml +++ b/BTCPayServer/Views/UIStores/_LayoutWalletSetup.cshtml @@ -13,7 +13,7 @@ @section Navbar { @await RenderSectionAsync("Navbar", false) - + } diff --git a/BTCPayServer/Views/UIStores/_Nav.cshtml b/BTCPayServer/Views/UIStores/_Nav.cshtml index f7b5f8693..a9208bc6f 100644 --- a/BTCPayServer/Views/UIStores/_Nav.cshtml +++ b/BTCPayServer/Views/UIStores/_Nav.cshtml @@ -3,7 +3,6 @@ @if (wallet.IsOwner) { - + } else { From c2fc09943927c77789ac73d37fcf85f821139546 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Thu, 20 Jan 2022 17:35:25 +0100 Subject: [PATCH 2/4] Create store: Add default currency and rate provider fields --- BTCPayServer.Rating/AvailableRateProvider.cs | 10 +++++ .../Controllers/UIStoresController.cs | 1 - .../Controllers/UIUserStoresController.cs | 40 ++++++++++++++----- BTCPayServer/Data/StoreBlob.cs | 7 ++-- .../StoreViewModels/CreateStoreViewModel.cs | 17 ++++++-- .../Models/StoreViewModels/RatesViewModel.cs | 32 +++------------ .../Services/Stores/StoreRepository.cs | 10 +++-- .../Views/UIUserStores/CreateStore.cshtml | 10 +++++ 8 files changed, 80 insertions(+), 47 deletions(-) diff --git a/BTCPayServer.Rating/AvailableRateProvider.cs b/BTCPayServer.Rating/AvailableRateProvider.cs index 884da39ac..b21e0189f 100644 --- a/BTCPayServer.Rating/AvailableRateProvider.cs +++ b/BTCPayServer.Rating/AvailableRateProvider.cs @@ -1,3 +1,5 @@ +using System; + namespace BTCPayServer.Rating { public enum RateSource @@ -25,5 +27,13 @@ namespace BTCPayServer.Rating Url = url; Source = source; } + + public string DisplayName => + Source switch + { + RateSource.Direct => Name, + RateSource.Coingecko => $"{Name} (via CoinGecko)", + _ => throw new NotSupportedException(Source.ToString()) + }; } } diff --git a/BTCPayServer/Controllers/UIStoresController.cs b/BTCPayServer/Controllers/UIStoresController.cs index 408a051e9..99a36b4a5 100644 --- a/BTCPayServer/Controllers/UIStoresController.cs +++ b/BTCPayServer/Controllers/UIStoresController.cs @@ -104,7 +104,6 @@ namespace BTCPayServer.Controllers private readonly EventAggregator _EventAggregator; private readonly NBXplorerDashboard _Dashboard; private readonly IOptions _externalServiceOptions; - public string CreatedStoreId { get; set; } [TempData] public bool StoreNotConfigured diff --git a/BTCPayServer/Controllers/UIUserStoresController.cs b/BTCPayServer/Controllers/UIUserStoresController.cs index 188580751..94e711492 100644 --- a/BTCPayServer/Controllers/UIUserStoresController.cs +++ b/BTCPayServer/Controllers/UIUserStoresController.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using BTCPayServer.Abstractions.Constants; @@ -5,12 +7,13 @@ using BTCPayServer.Client; using BTCPayServer.Data; using BTCPayServer.Models; using BTCPayServer.Models.StoreViewModels; -using BTCPayServer.Security; +using BTCPayServer.Rating; +using BTCPayServer.Services.Rates; using BTCPayServer.Services.Stores; -using ExchangeSharp; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; namespace BTCPayServer.Controllers { @@ -20,20 +23,30 @@ namespace BTCPayServer.Controllers { private readonly StoreRepository _repo; private readonly UserManager _userManager; + private readonly RateFetcher _rateFactory; + public string CreatedStoreId { get; set; } public UIUserStoresController( UserManager userManager, - StoreRepository storeRepository) + StoreRepository storeRepository, + RateFetcher rateFactory) { _repo = storeRepository; _userManager = userManager; + _rateFactory = rateFactory; } [HttpGet("create")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettingsUnscoped)] public IActionResult CreateStore() { - return View(); + var vm = new CreateStoreViewModel + { + DefaultCurrency = StoreBlob.StandardDefaultCurrency, + Exchanges = GetExchangesSelectList(CoinGeckoRateProvider.CoinGeckoName) + }; + + return View(vm); } [HttpPost("create")] @@ -42,10 +55,13 @@ namespace BTCPayServer.Controllers { if (!ModelState.IsValid) { + vm.Exchanges = GetExchangesSelectList(vm.PreferredExchange); return View(vm); } - var store = await _repo.CreateStore(GetUserId(), vm.Name); + + var store = await _repo.CreateStore(GetUserId(), vm.Name, vm.DefaultCurrency, vm.PreferredExchange); CreatedStoreId = store.Id; + TempData[WellKnownTempData.SuccessMessage] = "Store successfully created"; return RedirectToAction(nameof(UIStoresController.Dashboard), "UIStores", new { @@ -53,11 +69,6 @@ namespace BTCPayServer.Controllers }); } - public string CreatedStoreId - { - get; set; - } - [HttpGet("{storeId}/me/delete")] [Authorize(AuthenticationSchemes = AuthenticationSchemes.Cookie, Policy = Policies.CanModifyStoreSettings)] public IActionResult DeleteStore(string storeId) @@ -82,5 +93,14 @@ namespace BTCPayServer.Controllers } private string GetUserId() => _userManager.GetUserId(User); + + private SelectList GetExchangesSelectList(string selected) { + var exchanges = _rateFactory.RateProviderFactory + .GetSupportedExchanges() + .Where(r => !string.IsNullOrWhiteSpace(r.Name)) + .OrderBy(s => s.Id, StringComparer.OrdinalIgnoreCase); + var chosen = exchanges.FirstOrDefault(f => f.Id == selected) ?? exchanges.First(); + return new SelectList(exchanges, nameof(chosen.Id), nameof(chosen.Name), chosen.Id); + } } } diff --git a/BTCPayServer/Data/StoreBlob.cs b/BTCPayServer/Data/StoreBlob.cs index 3f96564b3..ffe3dd792 100644 --- a/BTCPayServer/Data/StoreBlob.cs +++ b/BTCPayServer/Data/StoreBlob.cs @@ -18,6 +18,8 @@ namespace BTCPayServer.Data { public class StoreBlob { + public static string StandardDefaultCurrency = "USD"; + public StoreBlob() { InvoiceExpiration = TimeSpan.FromMinutes(15); @@ -27,8 +29,7 @@ namespace BTCPayServer.Data RecommendedFeeBlockTarget = 1; PaymentMethodCriteria = new List(); } - - + [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] public NetworkFeeMode NetworkFeeMode { get; set; } @@ -45,7 +46,7 @@ namespace BTCPayServer.Data { get { - return string.IsNullOrEmpty(_DefaultCurrency) ? "USD" : _DefaultCurrency; + return string.IsNullOrEmpty(_DefaultCurrency) ? StandardDefaultCurrency : _DefaultCurrency; } set { diff --git a/BTCPayServer/Models/StoreViewModels/CreateStoreViewModel.cs b/BTCPayServer/Models/StoreViewModels/CreateStoreViewModel.cs index b465f63fe..17b61d0ec 100644 --- a/BTCPayServer/Models/StoreViewModels/CreateStoreViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/CreateStoreViewModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Mvc.Rendering; namespace BTCPayServer.Models.StoreViewModels { @@ -7,9 +8,17 @@ namespace BTCPayServer.Models.StoreViewModels [Required] [MaxLength(50)] [MinLength(1)] - public string Name - { - get; set; - } + public string Name { get; set; } + + [Required] + [MaxLength(10)] + [Display(Name = "Default currency")] + public string DefaultCurrency { get; set; } + + [Required] + [Display(Name = "Preferred Price Source")] + public string PreferredExchange { get; set; } + + public SelectList Exchanges { get; set; } } } diff --git a/BTCPayServer/Models/StoreViewModels/RatesViewModel.cs b/BTCPayServer/Models/StoreViewModels/RatesViewModel.cs index 34a978270..6ee96f1e6 100644 --- a/BTCPayServer/Models/StoreViewModels/RatesViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/RatesViewModel.cs @@ -16,27 +16,15 @@ namespace BTCPayServer.Models.StoreViewModels public string Rule { get; set; } public bool Error { get; set; } } + public void SetExchangeRates(IEnumerable supportedList, string preferredExchange) { var defaultStore = preferredExchange ?? CoinGeckoRateProvider.CoinGeckoName; - supportedList = supportedList.Select(a => new AvailableRateProvider(a.Id, a.SourceId, GetName(a), a.Url, a.Source)).ToArray(); + supportedList = supportedList.Select(a => new AvailableRateProvider(a.Id, a.SourceId, a.DisplayName, a.Url, a.Source)).ToArray(); var chosen = supportedList.FirstOrDefault(f => f.Id == defaultStore) ?? supportedList.FirstOrDefault(); Exchanges = new SelectList(supportedList, nameof(chosen.Id), nameof(chosen.Name), chosen); - PreferredExchange = chosen.Id; - RateSource = chosen.Url; - } - - private string GetName(AvailableRateProvider a) - { - switch (a.Source) - { - case Rating.RateSource.Direct: - return a.Name; - case Rating.RateSource.Coingecko: - return $"{a.Name} (via CoinGecko)"; - default: - throw new NotSupportedException(a.Source.ToString()); - } + PreferredExchange = chosen?.Id; + RateSource = chosen?.Url; } public List TestRateRules { get; set; } @@ -56,19 +44,11 @@ namespace BTCPayServer.Models.StoreViewModels [Display(Name = "Add Exchange Rate Spread")] [Range(0.0, 100.0)] - public double Spread - { - get; - set; - } + public double Spread { get; set; } [Display(Name = "Preferred Price Source")] public string PreferredExchange { get; set; } - public string RateSource - { - get; - set; - } + public string RateSource { get; set; } } } diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index b1b96c694..d19dd1c21 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -186,10 +186,14 @@ namespace BTCPayServer.Services.Stores await ctx.SaveChangesAsync(); } - public async Task CreateStore(string ownerId, string name) + public async Task CreateStore(string ownerId, string name, string defaultCurrency, string preferredExchange) { - var store = new StoreData() { StoreName = name }; - SetNewStoreHints(ref store); + var store = new StoreData { StoreName = name }; + var blob = store.GetStoreBlob(); + blob.DefaultCurrency = defaultCurrency; + blob.PreferredExchange = preferredExchange; + store.SetStoreBlob(blob); + await CreateStore(ownerId, store); return store; } diff --git a/BTCPayServer/Views/UIUserStores/CreateStore.cshtml b/BTCPayServer/Views/UIUserStores/CreateStore.cshtml index e46cba62d..95ab70072 100644 --- a/BTCPayServer/Views/UIUserStores/CreateStore.cshtml +++ b/BTCPayServer/Views/UIUserStores/CreateStore.cshtml @@ -19,6 +19,16 @@ +
    + + + +
    +
    + + + +
    From 10adb23e715473faca9431b9081d1d5124a59261 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Thu, 20 Jan 2022 17:39:23 +0100 Subject: [PATCH 3/4] Remove obsolete store hints --- .../Controllers/UIStoresController.LightningLike.cs | 4 ---- .../Controllers/UIStoresController.Onchain.cs | 1 - BTCPayServer/Data/StoreBlob.cs | 8 -------- BTCPayServer/Data/StoreDataExtensions.cs | 3 --- BTCPayServer/Services/Stores/StoreRepository.cs | 13 ------------- 5 files changed, 29 deletions(-) diff --git a/BTCPayServer/Controllers/UIStoresController.LightningLike.cs b/BTCPayServer/Controllers/UIStoresController.LightningLike.cs index a48f539a8..ad5db449b 100644 --- a/BTCPayServer/Controllers/UIStoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/UIStoresController.LightningLike.cs @@ -158,11 +158,7 @@ namespace BTCPayServer.Controllers switch (command) { case "save": - var storeBlob = store.GetStoreBlob(); - storeBlob.Hints.Lightning = false; - var lnurl = new PaymentMethodId(vm.CryptoCode, PaymentTypes.LNURLPay); - store.SetStoreBlob(storeBlob); store.SetSupportedPaymentMethod(paymentMethodId, paymentMethod); store.SetSupportedPaymentMethod(lnurl, new LNURLPaySupportedPaymentMethod() { diff --git a/BTCPayServer/Controllers/UIStoresController.Onchain.cs b/BTCPayServer/Controllers/UIStoresController.Onchain.cs index 5d6dd6f1c..aabd56b9f 100644 --- a/BTCPayServer/Controllers/UIStoresController.Onchain.cs +++ b/BTCPayServer/Controllers/UIStoresController.Onchain.cs @@ -163,7 +163,6 @@ namespace BTCPayServer.Controllers await wallet.TrackAsync(strategy.AccountDerivation); store.SetSupportedPaymentMethod(paymentMethodId, strategy); storeBlob.SetExcluded(paymentMethodId, false); - storeBlob.Hints.Wallet = false; storeBlob.PayJoinEnabled = strategy.IsHotWallet && !(vm.SetupRequest?.PayJoinEnabled is false); store.SetStoreBlob(storeBlob); } diff --git a/BTCPayServer/Data/StoreBlob.cs b/BTCPayServer/Data/StoreBlob.cs index ffe3dd792..61b782c5e 100644 --- a/BTCPayServer/Data/StoreBlob.cs +++ b/BTCPayServer/Data/StoreBlob.cs @@ -170,8 +170,6 @@ namespace BTCPayServer.Data public EmailSettings EmailSettings { get; set; } public bool PayJoinEnabled { get; set; } - public StoreHints Hints { get; set; } - [JsonExtensionData] public IDictionary AdditionalData { get; set; } = new Dictionary(); @@ -180,12 +178,6 @@ namespace BTCPayServer.Data [JsonConverter(typeof(TimeSpanJsonConverter.Days))] public TimeSpan RefundBOLT11Expiration { get; set; } - public class StoreHints - { - public bool Wallet { get; set; } - public bool Lightning { get; set; } - } - public IPaymentFilter GetExcludedPaymentMethods() { #pragma warning disable CS0618 // Type or member is obsolete diff --git a/BTCPayServer/Data/StoreDataExtensions.cs b/BTCPayServer/Data/StoreDataExtensions.cs index 35a4e320b..6ae6281a8 100644 --- a/BTCPayServer/Data/StoreDataExtensions.cs +++ b/BTCPayServer/Data/StoreDataExtensions.cs @@ -50,9 +50,6 @@ namespace BTCPayServer.Data var result = storeData.StoreBlob == null ? new StoreBlob() : new Serializer(null).ToObject(Encoding.UTF8.GetString(storeData.StoreBlob)); if (result.PreferredExchange == null) result.PreferredExchange = CoinGeckoRateProvider.CoinGeckoName; - - if (result.Hints == null) - result.Hints = new StoreBlob.StoreHints(); return result; } diff --git a/BTCPayServer/Services/Stores/StoreRepository.cs b/BTCPayServer/Services/Stores/StoreRepository.cs index d19dd1c21..e37a26950 100644 --- a/BTCPayServer/Services/Stores/StoreRepository.cs +++ b/BTCPayServer/Services/Stores/StoreRepository.cs @@ -152,17 +152,6 @@ namespace BTCPayServer.Services.Stores } } - private void SetNewStoreHints(ref StoreData storeData) - { - var blob = storeData.GetStoreBlob(); - blob.Hints = new Data.StoreBlob.StoreHints - { - Wallet = true, - Lightning = true - }; - storeData.SetStoreBlob(blob); - } - public async Task CreateStore(string ownerId, StoreData storeData) { if (!string.IsNullOrEmpty(storeData.Id)) @@ -179,8 +168,6 @@ namespace BTCPayServer.Services.Stores Role = StoreRoles.Owner, }; - SetNewStoreHints(ref storeData); - ctx.Add(storeData); ctx.Add(userStore); await ctx.SaveChangesAsync(); From 240ad49a43c50a01e64881f20d304c409322a426 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Mon, 24 Jan 2022 18:04:17 +0100 Subject: [PATCH 4/4] Add currency selection attributes --- BTCPayServer/Views/UIStores/GeneralSettings.cshtml | 2 +- BTCPayServer/Views/UIUserStores/CreateStore.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml index bbbf671fe..b5d480dd9 100644 --- a/BTCPayServer/Views/UIStores/GeneralSettings.cshtml +++ b/BTCPayServer/Views/UIStores/GeneralSettings.cshtml @@ -30,7 +30,7 @@

    Payment

    - +
    diff --git a/BTCPayServer/Views/UIUserStores/CreateStore.cshtml b/BTCPayServer/Views/UIUserStores/CreateStore.cshtml index 95ab70072..2a57cabeb 100644 --- a/BTCPayServer/Views/UIUserStores/CreateStore.cshtml +++ b/BTCPayServer/Views/UIUserStores/CreateStore.cshtml @@ -21,7 +21,7 @@
    - +
    @wallet.StoreName@wallet.StoreName