Skip to content

Commit

Permalink
Fix some more bugs in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dangershony committed Mar 24, 2023
1 parent 3a175cc commit 7f0fb90
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
28 changes: 20 additions & 8 deletions src/Blockcore.AtomicSwaps.Client/Extentions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using Blockcore.AtomicSwaps.Client.Services;
using Blockcore.AtomicSwaps.Shared;
using Blockcore.Consensus.ScriptInfo;
using Blockcore.Consensus.TransactionInfo;
using Blockcore.Networks;
using Blockcore.Utilities;
using NBitcoin;
using NBitcoin.Crypto;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;

namespace Blockcore.AtomicSwaps.Client
{
Expand All @@ -23,5 +17,23 @@ public static void ThorwIfError(this string error)
if (!string.IsNullOrEmpty(error))
throw new Exception(error);
}

public static async Task<TValue?> GetFromJsonNullableAsync<TValue>(this HttpClient client, [StringSyntax(StringSyntaxAttribute.Uri)] string? requestUri, CancellationToken cancellationToken = default)
{
string? res = await client.GetStringAsync(requestUri, cancellationToken);

if (string.IsNullOrEmpty(res))
{
return default(TValue);
}

var ser = JsonSerializer.Deserialize<TValue>(res, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
});

return ser;
}
}
}
4 changes: 2 additions & 2 deletions src/Blockcore.AtomicSwaps.Client/Pages/MySwaps.razor
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ else
{
if (myswap.Status is SwapsDataStatus.Available or SwapsDataStatus.InProgress)
{
var swap = await Http.GetFromJsonAsync<SwapSession>($"api/SwapCoordinator/session/{myswap.SwapSessionId}");
var swap = await Http.GetFromJsonNullableAsync<SwapSession?>($"api/SwapCoordinator/session/{myswap.SwapSessionId}");

if (myswap.Status != swap.Status)
if (swap != null && myswap.Status != swap.Status)
{
myswaps.ToList().Remove(myswap);
myswaps.ToList().Add(swap);
Expand Down
13 changes: 9 additions & 4 deletions src/Blockcore.AtomicSwaps.Client/Pages/ViewSwap.razor
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
*@
@if (swap.SwapMaker.SwapTransactionHash != null)
{
var url = $"{storage.GetExplorerUrl().Result}/{swap.SwapMaker.CoinSymbol}/explorer/transaction/{swap.SwapMaker.SwapTransactionHash}";
var url = $"{GetExplorerUrl()}/{swap.SwapMaker.CoinSymbol}/explorer/transaction/{swap.SwapMaker.SwapTransactionHash}";

<p>Maker on @swap.SwapMaker.CoinSymbol, confirmations - @MakerSwapTransactionConfirmations, trx - <a href="@url" target="_blank">@swap.SwapMaker.SwapTransactionHash</a></p>
@if (swap.SwapMaker.RecoveryLockTime.HasValue)
Expand Down Expand Up @@ -186,7 +186,7 @@
*@
@if (swap.SwapTaker.SwapTransactionHash != null)
{
var url = $"{storage.GetExplorerUrl().Result}/{swap.SwapTaker.CoinSymbol}/explorer/transaction/{swap.SwapTaker.SwapTransactionHash}";
var url = $"{GetExplorerUrl()}/{swap.SwapTaker.CoinSymbol}/explorer/transaction/{swap.SwapTaker.SwapTransactionHash}";

<p>Taker on @swap.SwapTaker.CoinSymbol, confirmations : @TakerSwapTransactionConfirmations, trx - <a href="@url" target="_blank">@swap.SwapTaker.SwapTransactionHash</a></p>
@if (swap.SwapTaker.RecoveryLockTime.HasValue)
Expand Down Expand Up @@ -231,7 +231,7 @@

@if (@swap.SwapTaker.ExchangeTransactionHash != null)
{
var url = $"{storage.GetExplorerUrl().Result}/{swap.SwapTaker.CoinSymbol}/explorer/transaction/{swap.SwapTaker.ExchangeTransactionHash}";
var url = $"{GetExplorerUrl()}/{swap.SwapTaker.CoinSymbol}/explorer/transaction/{swap.SwapTaker.ExchangeTransactionHash}";

<p>Maker on @swap.SwapTaker.CoinSymbol, Confirmations : @MakerExchangeTransactionConfirmations, trx - <a href="@url" target="_blank">@swap.SwapTaker.ExchangeTransactionHash</a></p>
<P class="text-success"><strong>MAKER EXCHANGE SUCCESS</strong></P>
Expand Down Expand Up @@ -278,7 +278,7 @@

@if (swap.SwapMaker.ExchangeTransactionHash != null)
{
var url = $"{storage.GetExplorerUrl().Result}/{swap.SwapMaker.CoinSymbol}/explorer/transaction/{swap.SwapMaker.ExchangeTransactionHash}";
var url = $"{GetExplorerUrl()}/{swap.SwapMaker.CoinSymbol}/explorer/transaction/{swap.SwapMaker.ExchangeTransactionHash}";

<p>Taker on @swap.SwapMaker.CoinSymbol, Confirmations : @TakerExchangeTransactionConfirmations, trx - <a href="@url" target="_blank">@swap.SwapMaker.ExchangeTransactionHash</a></p>
<P class="text-success"><strong>TAKER EXCHANGE SUCCESS</strong></P>
Expand Down Expand Up @@ -403,6 +403,11 @@
await this.RefreshConfirmations();
}

private string GetExplorerUrl()
{
return storage.GetExplorerUrl().Result;
}

private async Task DeleteSwap()
{
// this method is of course problematic because anyone can delete using an api call
Expand Down
11 changes: 10 additions & 1 deletion src/Blockcore.AtomicSwaps.Client/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,16 @@ public void SetExplorerUrl(string address)

public async Task<string>? GetExplorerUrl()
{
return _storage.GetItemAsString("explorer") ?? await GetExplorerUrlFromDDNS();
var res = _storage.GetItemAsString("explorer");

if (string.IsNullOrEmpty(res))
{
res = await GetExplorerUrlFromDDNS();

SetExplorerUrl(res);
}

return res;
}

public async Task<string>? GetExplorerUrlFromDDNS()
Expand Down

0 comments on commit 7f0fb90

Please sign in to comment.