From bee805f5454de194e69f8ad56a59778f2a75b7b4 Mon Sep 17 00:00:00 2001 From: Kukks Date: Tue, 23 May 2023 12:12:44 +0200 Subject: [PATCH] update ff --- .../BTCPayServer.Plugins.FixedFloat.csproj | 8 +-- .../FixedFloatController.cs | 33 ++------- .../FixedFloatPlugin.cs | 4 +- .../FixedFloatSettings.cs | 67 +++++++++++++++++++ .../UpdateFixedFloatSettingsViewModel.cs | 8 --- .../UpdateFixedFloatSettings.cshtml | 32 +++++++-- .../CheckoutContentExtension.cshtml | 6 +- .../CheckoutPaymentExtension.cshtml | 45 +++++++++++-- .../CheckoutPaymentMethodExtension.cshtml | 24 +++++-- .../FixedFloat/CheckoutTabExtension.cshtml | 7 +- .../StoreIntegrationFixedFloatOption.cshtml | 58 ---------------- submodules/btcpayserver | 2 +- 12 files changed, 172 insertions(+), 122 deletions(-) delete mode 100644 Plugins/BTCPayServer.Plugins.FixedFloat/UpdateFixedFloatSettingsViewModel.cs delete mode 100644 Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/StoreIntegrationFixedFloatOption.cshtml diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj b/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj index 95a2b5e..044a9c5 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/BTCPayServer.Plugins.FixedFloat.csproj @@ -9,7 +9,7 @@ FixedFloat Allows you to embed a FixedFloat conversion screen to allow customers to pay with altcoins. - 1.0.6 + 1.1.0 @@ -29,11 +29,11 @@ - - + + - + diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatController.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatController.cs index 5e37eda..2ddce75 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatController.cs +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatController.cs @@ -12,45 +12,31 @@ namespace BTCPayServer.Plugins.FixedFloat [Route("plugins/{storeId}/FixedFloat")] public class FixedFloatController : Controller { - private readonly BTCPayServerClient _btcPayServerClient; private readonly FixedFloatService _FixedFloatService; - public FixedFloatController(BTCPayServerClient btcPayServerClient, FixedFloatService FixedFloatService) + public FixedFloatController(FixedFloatService FixedFloatService) { - _btcPayServerClient = btcPayServerClient; _FixedFloatService = FixedFloatService; } [HttpGet("")] public async Task UpdateFixedFloatSettings(string storeId) { - var store = await _btcPayServerClient.GetStore(storeId); - - UpdateFixedFloatSettingsViewModel vm = new UpdateFixedFloatSettingsViewModel(); - vm.StoreName = store.Name; - FixedFloatSettings FixedFloat = null; + FixedFloatSettings settings = null; try { - FixedFloat = await _FixedFloatService.GetFixedFloatForStore(storeId); + settings = await _FixedFloatService.GetFixedFloatForStore(storeId); } catch (Exception) { // ignored } - SetExistingValues(FixedFloat, vm); - return View(vm); - } - - private void SetExistingValues(FixedFloatSettings existing, UpdateFixedFloatSettingsViewModel vm) - { - if (existing == null) - return; - vm.Enabled = existing.Enabled; + return View(settings); } [HttpPost("")] - public async Task UpdateFixedFloatSettings(string storeId, UpdateFixedFloatSettingsViewModel vm, + public async Task UpdateFixedFloatSettings(string storeId, FixedFloatSettings vm, string command) { if (vm.Enabled) @@ -61,15 +47,10 @@ namespace BTCPayServer.Plugins.FixedFloat } } - var FixedFloatSettings = new FixedFloatSettings() - { - Enabled = vm.Enabled, - }; - switch (command) { case "save": - await _FixedFloatService.SetFixedFloatForStore(storeId, FixedFloatSettings); + await _FixedFloatService.SetFixedFloatForStore(storeId, vm); TempData["SuccessMessage"] = "FixedFloat settings modified"; return RedirectToAction(nameof(UpdateFixedFloatSettings), new {storeId}); @@ -78,4 +59,4 @@ namespace BTCPayServer.Plugins.FixedFloat } } } -} +} \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs index 8c84c6b..c4f36f6 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatPlugin.cs @@ -9,15 +9,13 @@ namespace BTCPayServer.Plugins.FixedFloat { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { - new() { Identifier = nameof(BTCPayServer), Condition = ">=1.7.4" } + new() { Identifier = nameof(BTCPayServer), Condition = ">=1.9.0" } }; public override void Execute(IServiceCollection applicationBuilder) { applicationBuilder.AddSingleton(); applicationBuilder.AddSingleton(new UIExtension("FixedFloat/FixedFloatNav", "store-integrations-nav")); - applicationBuilder.AddSingleton(new UIExtension("FixedFloat/StoreIntegrationFixedFloatOption", - "store-integrations-list")); // Checkout v2 applicationBuilder.AddSingleton(new UIExtension("FixedFloat/CheckoutPaymentMethodExtension", "checkout-payment-method")); diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs index f521771..2df5496 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/FixedFloatSettings.cs @@ -1,8 +1,75 @@ +#nullable enable +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Nodes; +using Microsoft.AspNetCore.Mvc.Rendering; + namespace BTCPayServer.Plugins.FixedFloat { public class FixedFloatSettings { public bool Enabled { get; set; } public decimal AmountMarkupPercentage { get; set; } = 0; + + public string? PreferredTargetPaymentMethodId { get; set; } + + public string[] ExplicitMethods { get; set; } + public bool OnlyShowExplicitMethods { get; set; } = false; + + public static Dictionary AllowedSendingOptions = new() + { + {"AAVEETH", "Aave (ERC20)"}, + {"ADA", "Cardano"}, + {"ATOM", "Cosmos"}, + {"AVAX", "Avalanche (C-Chain)"}, + {"BAT", "Basic Attention (ERC20)"}, + {"BCH", "Bitcoin Cash"}, + {"BNB", "BNB Beacon Chain (BEP2)"}, + {"BSC", "BNB Smart Chain (BEP20)"}, + {"BTC", "Bitcoin"}, + {"BTCLN", "Bitcoin (Lightning)"}, + {"BTT", "BitTorrent"}, + {"BUSD", "Binance USD (BEP2)"}, + {"BUSDBSC", "Binance USD (BEP20)"}, + {"BUSDETH", "Binance USD (ERC20)"}, + {"CAKE", "PancakeSwap (BEP20)"}, + {"DAIETH", "DAI (ERC20)"}, + {"DOGE", "Dogecoin"}, + {"DOT", "Polkadot"}, + {"EOS", "EOS"}, + {"ETC", "Ethereum Classic"}, + {"ETH", "Ethereum"}, + {"FTM", "Fantom"}, + {"LINK", "Chainlink (ERC20)"}, + {"LTC", "Litecoin"}, + {"MANAETH", "Decentraland (ERC20)"}, + {"MATIC", "Polygon"}, + {"MATICETH", "Polygon (ERC20)"}, + {"MKR", "Maker (ERC20)"}, + {"SHIB", "SHIBA INU (ERC20)"}, + {"SOL", "Solana"}, + {"TON", "Toncoin"}, + {"TRX", "Tron"}, + {"TUSD", "TrueUSD (ERC20)"}, + {"TWT", "Trust Wallet Token (BEP2)"}, + {"TWTBSC", "Trust Wallet Token (BEP20)"}, + {"USDCETH", "USD Coin (ERC20)"}, + {"USDCSOL", "USD Coin (Solana)"}, + {"USDCTRC", "USD Coin (TRC20)"}, + {"USDP", "Pax Dollar (ERC20)"}, + {"USDT", "Tether (ERC20)"}, + {"USDTSOL", "Tether (Solana)"}, + {"USDTTRC", "Tether (TRC20)"}, + {"VET", "VeChain"}, + {"XMR", "Monero"}, + {"XRP", "Ripple"}, + {"XTZ", "Tezos"}, + {"ZEC", "Zcash"}, + {"ZRX", "0x (ERC20)"} + }; + + public static List AllowedSendingOptionsList => AllowedSendingOptions.Select(o => new SelectListItem(o.Value, o.Key)).ToList(); + + } } diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/UpdateFixedFloatSettingsViewModel.cs b/Plugins/BTCPayServer.Plugins.FixedFloat/UpdateFixedFloatSettingsViewModel.cs deleted file mode 100644 index d27636a..0000000 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/UpdateFixedFloatSettingsViewModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace BTCPayServer.Plugins.FixedFloat -{ - public class UpdateFixedFloatSettingsViewModel - { - public bool Enabled { get; set; } - public string StoreName { get; set; } - } -} diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml index 85cd6ad..e50658c 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/FixedFloat/UpdateFixedFloatSettings.cshtml @@ -1,11 +1,20 @@ -@using BTCPayServer.Abstractions.Extensions +@using BTCPayServer +@using BTCPayServer.Abstractions.Extensions +@using BTCPayServer.Data +@using BTCPayServer.Plugins.FixedFloat +@using BTCPayServer.Services.Stores @using Microsoft.AspNetCore.Mvc.TagHelpers -@model BTCPayServer.Plugins.FixedFloat.UpdateFixedFloatSettingsViewModel +@model BTCPayServer.Plugins.FixedFloat.FixedFloatSettings +@inject BTCPayNetworkProvider BTCPayNetworkProvider @{ ViewData.SetActivePage("FixedFloat", "FixedFloat", "FixedFloat"); + var store = Context.GetStoreData(); + var allowedPaymentMethods = store.GetEnabledPaymentIds(BTCPayNetworkProvider) + .Select(pmi => new SelectListItem(pmi.ToPrettyString(), pmi.ToString())) + .Prepend(new SelectListItem("Any", "")); } - +

@ViewData["Title"]

@@ -22,7 +31,22 @@ +
+ + +
+
+ + +
+ +
+
+ + +
+
- + \ No newline at end of file diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml index 13f46c3..c315ebf 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutContentExtension.cshtml @@ -1,10 +1,10 @@ @using BTCPayServer.Plugins.FixedFloat -@using Newtonsoft.Json -@using Newtonsoft.Json.Linq +@model BTCPayServer.Models.InvoicingModels.PaymentModel @inject FixedFloatService FixedFloatService @{ - var storeId = ((JObject)JObject.Parse(JsonConvert.SerializeObject(Model)))["StoreId"].Value(); + var storeId = Model.StoreId; var settings = await FixedFloatService.GetFixedFloatForStore(storeId); + if (settings?.Enabled is true) {
diff --git a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml index 2c2e853..4a8822d 100644 --- a/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml +++ b/Plugins/BTCPayServer.Plugins.FixedFloat/Views/Shared/FixedFloat/CheckoutPaymentExtension.cshtml @@ -1,28 +1,58 @@ @using BTCPayServer.Plugins.FixedFloat -@using Newtonsoft.Json -@using Newtonsoft.Json.Linq @inject FixedFloatService FixedFloatService +@model BTCPayServer.Models.InvoicingModels.PaymentModel @{ - var storeId = ((JObject)JObject.Parse(JsonConvert.SerializeObject(Model)))["StoreId"].Value(); + var storeId = Model.StoreId; var settings = await FixedFloatService.GetFixedFloatForStore(storeId); + var preferredTargetPaymentMethodId = string.IsNullOrEmpty(settings.PreferredTargetPaymentMethodId) ? null : Model.AvailableCryptos.Any(crypto => crypto.PaymentMethodId == settings.PreferredTargetPaymentMethodId) ? settings.PreferredTargetPaymentMethodId : null; } @if (settings?.Enabled is true) {