From 9810edcd1ace31e887c8b0b713c4c4a8c3afb439 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Fri, 16 Sep 2022 11:49:44 +0200 Subject: [PATCH] Fix Monero and Zcash nav extensions They failed with an `System.NullReferenceException: Object reference not set to an instance of an object.` when navigating to a LNbank page, because LNbank uses Razor Pages and the controller part wan't defined. Brought up [on Mattermost](https://chat.btcpayserver.org/btcpayserver/pl/x3iohhct97nateyq4y1c4hp9mw). --- .../Views/Shared/Monero/StoreNavMoneroExtension.cshtml | 10 +++++++--- .../Monero/StoreWalletsNavMoneroExtension.cshtml | 10 ++++++---- .../Views/Shared/Zcash/StoreNavZcashExtension.cshtml | 10 +++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/BTCPayServer/Views/Shared/Monero/StoreNavMoneroExtension.cshtml b/BTCPayServer/Views/Shared/Monero/StoreNavMoneroExtension.cshtml index 97f68afd4..fc5ca8bdb 100644 --- a/BTCPayServer/Views/Shared/Monero/StoreNavMoneroExtension.cshtml +++ b/BTCPayServer/Views/Shared/Monero/StoreNavMoneroExtension.cshtml @@ -1,12 +1,16 @@ @using BTCPayServer.Services.Altcoins.Monero.Configuration @using BTCPayServer.Services.Altcoins.Monero.UI +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using BTCPayServer.Abstractions.Contracts @inject SignInManager SignInManager; @inject MoneroLikeConfiguration MoneroLikeConfiguration; +@inject IScopeProvider ScopeProvider @{ - var controller = ViewContext.RouteData.Values["Controller"].ToString(); - var isMonero = controller.Equals(nameof(UIMoneroLikeStoreController), StringComparison.InvariantCultureIgnoreCase); + var storeId = ScopeProvider.GetCurrentStoreId(); + var isActive = !string.IsNullOrEmpty(storeId) && ViewContext.RouteData.Values.TryGetValue("Controller", out var controller) && controller is not null && + nameof(UIMoneroLikeStoreController).StartsWith(controller.ToString() ?? string.Empty, StringComparison.InvariantCultureIgnoreCase); } @if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.ServerAdmin) && MoneroLikeConfiguration.MoneroLikeConfigurationItems.Any()) { - Monero + Monero } diff --git a/BTCPayServer/Views/Shared/Monero/StoreWalletsNavMoneroExtension.cshtml b/BTCPayServer/Views/Shared/Monero/StoreWalletsNavMoneroExtension.cshtml index 38ffd4c42..2160f8ef7 100644 --- a/BTCPayServer/Views/Shared/Monero/StoreWalletsNavMoneroExtension.cshtml +++ b/BTCPayServer/Views/Shared/Monero/StoreWalletsNavMoneroExtension.cshtml @@ -3,18 +3,20 @@ @using Microsoft.AspNetCore.Mvc.TagHelpers @using BTCPayServer.Client @using BTCPayServer.Abstractions.TagHelpers +@using BTCPayServer.Abstractions.Contracts @inject MoneroLikeConfiguration MoneroLikeConfiguration; +@inject IScopeProvider ScopeProvider @{ - var controller = ViewContext.RouteData.Values["Controller"].ToString(); - var isMonero = nameof(UIMoneroLikeStoreController).StartsWith(controller, StringComparison.InvariantCultureIgnoreCase); + var storeId = ScopeProvider.GetCurrentStoreId(); + var isActive = !string.IsNullOrEmpty(storeId) && ViewContext.RouteData.Values.TryGetValue("Controller", out var controller) && controller is not null && + nameof(UIMoneroLikeStoreController).StartsWith(controller.ToString() ?? string.Empty, StringComparison.InvariantCultureIgnoreCase); } @if (MoneroLikeConfiguration.MoneroLikeConfigurationItems.Any()) { } diff --git a/BTCPayServer/Views/Shared/Zcash/StoreNavZcashExtension.cshtml b/BTCPayServer/Views/Shared/Zcash/StoreNavZcashExtension.cshtml index 2a025c707..9761c1b73 100644 --- a/BTCPayServer/Views/Shared/Zcash/StoreNavZcashExtension.cshtml +++ b/BTCPayServer/Views/Shared/Zcash/StoreNavZcashExtension.cshtml @@ -1,12 +1,16 @@ @using BTCPayServer.Services.Altcoins.Zcash.Configuration @using BTCPayServer.Services.Altcoins.Zcash.UI +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using BTCPayServer.Abstractions.Contracts @inject SignInManager SignInManager; @inject ZcashLikeConfiguration ZcashLikeConfiguration; +@inject IScopeProvider ScopeProvider @{ - var controller = ViewContext.RouteData.Values["Controller"].ToString(); - var isZcash = controller.Equals(nameof(UIZcashLikeStoreController), StringComparison.InvariantCultureIgnoreCase); + var storeId = ScopeProvider.GetCurrentStoreId(); + var isActive = !string.IsNullOrEmpty(storeId) && ViewContext.RouteData.Values.TryGetValue("Controller", out var controller) && controller is not null && + nameof(UIZcashLikeStoreController).StartsWith(controller.ToString() ?? string.Empty, StringComparison.InvariantCultureIgnoreCase); } @if (SignInManager.IsSignedIn(User) && User.IsInRole(Roles.ServerAdmin) && ZcashLikeConfiguration.ZcashLikeConfigurationItems.Any()) { - Zcash + Zcash }