diff --git a/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor b/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor index 8dea669..bd2f250 100644 --- a/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor +++ b/Plugins/BTCPayServer.Plugins.Bringin/Components/BringinWidget.razor @@ -1,14 +1,17 @@ -@using System.Threading +@using System.Security.Claims +@using System.Threading @using BTCPayServer.Abstractions.Extensions @using BTCPayServer.Client +@using BTCPayServer.Configuration @using BTCPayServer.Data @using BTCPayServer.Payments @using BTCPayServer.PayoutProcessors @using BTCPayServer.Payouts @using BTCPayServer.Services -@using BTCPayServer.Services.Invoices + @using BTCPayServer.Services.Stores @using Microsoft.AspNetCore.Http +@using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.Routing @using NBitcoin @implements IAsyncDisposable; @@ -18,7 +21,10 @@ private bool _isLoaded = false; private CancellationTokenSource _cts = new CancellationTokenSource(); - [Inject] private IHttpContextAccessor HttpContextAccessor { get; set; } + + [Inject] BTCPayServerOptions BTCPayServerOptions { get; set; } + [Inject] private AuthenticationStateProvider AuthenticationStateProvider { get; set; } + [Inject] UserManager UserManager { get; set; } [Inject] private DisplayFormatter DisplayFormatter { get; set; } [Inject] private BringinService BringinService { get; set; } [Inject] private LinkGenerator LinkGenerator { get; set; } @@ -73,14 +79,19 @@ private bool _editMode; private bool _readOnly; + async Task GetUser() + { + var state = await AuthenticationStateProvider.GetAuthenticationStateAsync(); + if (state.User.Identity?.IsAuthenticated is not true) + return null; + return state.User; + } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { - _readOnly = !(await AuthorizationService.AuthorizeAsync(HttpContextAccessor.HttpContext.User, StoreId, Policies.CanModifyStoreSettings)).Succeeded; - OnboardLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "Onboard", "Bringin", new {StoreId}); - PmiLink = $"A payout processor has not been configured for this payment method. Payouts generated by Bringin will not be automatically handled. Configure now"; - _callbackLink = LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "Callback", "Bringin", new {StoreId}); + _readOnly = !(await AuthorizationService.AuthorizeAsync(await GetUser(), StoreId, Policies.CanModifyStoreSettings)).Succeeded; + OnboardLink = LinkGenerator.GetPathByAction("Onboard", "Bringin", new {StoreId}, pathBase: BTCPayServerOptions.RootPath); _settings = BringinService.IsInEditMode(StoreId) ? await BringinService.Update(StoreId) : await BringinService.Get(StoreId); var store = await StoreRepository.FindStore(StoreId); _pms = PayoutMethodHandlerDictionary.GetSupportedPayoutMethods(store); @@ -98,8 +109,6 @@ await base.OnAfterRenderAsync(firstRender); } - private string _callbackLink; - private void EditModeChanged(object sender, (string storeId, bool editMode) e) { if (e.storeId != StoreId) @@ -302,8 +311,6 @@ // private bool ManualOrderPayout = true; - public string PmiLink; - public string OnboardLink; private async void ResetBalance(PaymentMethodId pmi) @@ -521,9 +528,9 @@ pending payouts } - @if (!_pps.Contains(pmi) && PmiLink is not null) + @if (!_pps.Contains(pmi)) { -

@((MarkupString) PmiLink)

+

A payout processor has not been configured for this payment method. Payouts generated by Bringin will not be automatically handled. Configure now

} }