From 290e5a73b3d5a6f68d565083e13f6abe71f19715 Mon Sep 17 00:00:00 2001 From: Rodrigo <39995243+RodriFS@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:14:56 -0300 Subject: [PATCH] Null pointer exception when invalid metadata from btcpay --- src/Pages/Withdrawals.razor | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index 8cd9c54d..08d49fc1 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -586,23 +586,15 @@ { if (walletWithdrawalRequest.RequestMetadata != null) { - try + var requestMetadata = JsonConvert.DeserializeObject>(walletWithdrawalRequest.RequestMetadata); + if (requestMetadata != null && requestMetadata.TryGetValue("userName", out var userName)) { - var requestMetadata = JsonConvert.DeserializeObject>(walletWithdrawalRequest.RequestMetadata); - - if (requestMetadata.TryGetValue("userName", out var userName)) + if (ValidationHelper.IsValidEmail(userName)) { - if (ValidationHelper.IsValidEmail(userName)) - { - int atIndex = userName.IndexOf('@'); - return atIndex >= 0 ? userName.Substring(0, atIndex) : userName; - } - return userName; + int atIndex = userName.IndexOf('@'); + return atIndex >= 0 ? userName.Substring(0, atIndex) : userName; } - } - catch (JsonReaderException ex) - { - Console.WriteLine("Invalid JSON: " + ex.Message); + return userName; } }