Files
btcpayserver/BTCPayServer/Components/AppSales/AppSales.cs
Andrew Camilleri f74ea14d8b Plugins can now build apps (#4608)
* Plugins can now build apps

* fix tests

* fixup

* pluginize existing apps

* Test fixes part 1

* Test fixes part 2

* Fix Crowdfund namespace

* Syntax

* More namespace fixes

* Markup

* Test fix

* upstream fixes

* Add plugin icon

* Fix nullable build warnings

* allow pre popualting app creation

* Fixes after merge

* Make link methods async

* Use AppData as parameter for ConfigureLink

* GetApps by AppType

* Use ConfigureLink on dashboard

* Rename method

* Add properties to indicate stats support

* Property updates

* Test fixes

* Clean up imports

* Fixes after merge

---------

Co-authored-by: Dennis Reimann <mail@dennisreimann.de>
2023-03-17 11:56:32 +09:00

50 lines
1.3 KiB
C#

using System;
using System.Security.AccessControl;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Models.AppViewModels;
using BTCPayServer.Services.Apps;
using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
namespace BTCPayServer.Components.AppSales;
public enum AppSalesPeriod
{
Week,
Month
}
public class AppSales : ViewComponent
{
private readonly AppService _appService;
public AppSales(AppService appService)
{
_appService = appService;
}
public async Task<IViewComponentResult> InvokeAsync(string appId, string appType)
{
var vm = new AppSalesViewModel
{
Id = appId,
AppType = appType,
DataUrl = Url.Action("AppSales", "UIApps", new { appId }),
InitialRendering = HttpContext.GetAppData()?.Id != appId
};
if (vm.InitialRendering)
return View(vm);
var app = HttpContext.GetAppData();
var stats = await _appService.GetSalesStats(app);
vm.SalesCount = stats.SalesCount;
vm.Series = stats.Series;
vm.AppType = app.AppType;
vm.AppUrl = await _appService.ConfigureLink(app, app.AppType);
return View(vm);
}
}