mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-16 23:24:25 +01:00
Fix Bringin plugin crash (#95)
This commit is contained in:
@@ -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<ApplicationUser> 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<ClaimsPrincipal> 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. <a href=\"{LinkGenerator.GetUriByAction(HttpContextAccessor.HttpContext, "ConfigureStorePayoutProcessors", "UIPayoutProcessors", new {StoreId})}\">Configure now</a>";
|
||||
_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 @@
|
||||
<span class="text-secondary fw-semibold">pending payouts</span>
|
||||
</div>
|
||||
}
|
||||
@if (!_pps.Contains(pmi) && PmiLink is not null)
|
||||
@if (!_pps.Contains(pmi))
|
||||
{
|
||||
<p class="text-warning">@((MarkupString) PmiLink)</p>
|
||||
<p class="text-warning">A payout processor has not been configured for this payment method. Payouts generated by Bringin will not be automatically handled. <a href="@LinkGenerator.GetPathByAction("ConfigureStorePayoutProcessors", "UIPayoutProcessors", new {StoreId}, pathBase: BTCPayServerOptions.RootPath)">Configure now</a></p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user