Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to display raw transaction JSON for addresses and amounts #131

Merged
merged 10 commits into from
Nov 4, 2024
2 changes: 0 additions & 2 deletions src/Angor/Client/Pages/Investor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@
}
</div>



</div>

</div>
Expand Down
75 changes: 64 additions & 11 deletions src/Angor/Client/Pages/Wallet.razor
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@page "/wallet"


@using System.Text.Json
@using Angor.Client.Storage
@using Angor.Shared
@using Angor.Shared.Models
@using Blockcore.NBitcoin
@using Blockcore.Networks

@inherits BaseComponent
@inject HttpClient _httpClient;
@inject IClientStorage storage;
@inject ICacheStorage _cacheStorage;
Expand All @@ -19,7 +20,7 @@
@inject NavMenuState NavMenuState
@inject IEncryptionService _encryptionService
@inject IClipboardService ClipboardService
@inherits BaseComponent


<PageTitle>Wallet and balances</PageTitle>
<NotificationComponent @ref="notificationComponent"/>
Expand Down Expand Up @@ -471,8 +472,8 @@ else
var outpointStr = addressUtxoItem.outpoint.ToString();
var outpointLength = outpointStr.Length;
var shortenedOutpoint = outpointLength > 20
? $"{outpointStr.Substring(0, 10)} ... {outpointStr.Substring(outpointLength - 10)}"
: outpointStr;
? $"{outpointStr.Substring(0, 10)} ... {outpointStr.Substring(outpointLength - 10)}"
: outpointStr;

var valueInBTC = Money.Satoshis(addressUtxoItem.value).ToUnit(MoneyUnit.BTC);
var coinTicker = network.CoinTicker;
Expand All @@ -487,7 +488,7 @@ else

</div>
<div class="modal-footer">
<button class="btn btn-warning" @onclick="() => coinControlModal = false" >Submit</button>
<button class="btn btn-warning" @onclick="() => coinControlModal = false">Submit</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -619,6 +620,7 @@ else
<th class="text-uppercase text-xxs font-weight-bolder opacity-7" scope="col">Amount</th>
<th class="text-uppercase text-xxs font-weight-bolder opacity-7" scope="col">Path</th>
<th class="text-uppercase text-xxs font-weight-bolder opacity-7" scope="col">UTXO count</th>
<th class="text-uppercase text-xxs font-weight-bolder opacity-7" scope="col">View Raw Json</th>
</tr>
</thead>
<tbody>
Expand All @@ -631,17 +633,17 @@ else
{
<tr @onclick="() => ToggleCollapse(addressInfo.Address)" class="clickable-row" data-cy="adress-row" aria-expanded="@IsExpanded(addressInfo.Address).ToString().ToLower()" aria-controls="@($"collapse-{addressInfo.Address}")">
<td>@addressInfo.Address</td>
<td>
@Money.Satoshis(total).ToUnit(MoneyUnit.BTC) @network.CoinTicker
</td>
<td>@Money.Satoshis(total).ToUnit(MoneyUnit.BTC) @network.CoinTicker</td>
<td>@addressInfo.HdPath</td>
<td>@count</td>
<td>
<button class="btn btn-border" @onclick="() => ShowRawTransactionJson(addressInfo)">Show</button>
</td>
</tr>

@if (IsExpanded(addressInfo.Address))
{
<tr>
<td colspan="4">
<td colspan="5">
<div class="collapse show" data-cy="expend-amount" id="@($"collapse-{addressInfo.Address}")">
<div class="card card-body">
<!-- Inner table goes here -->
Expand Down Expand Up @@ -721,6 +723,9 @@ else
private int FeePosition = 1;
private SendInfo _sendInfo = new();

private bool showRawTransactionModal;
private string rawTransactionJson = string.Empty;

private readonly AccountBalanceInfo accountBalanceInfo = new();

private readonly FeeEstimations FeeEstimations = new();
Expand Down Expand Up @@ -1243,7 +1248,7 @@ else
}
catch (Exception ex)
{
Logger.LogError(ex, $"Failed to read clipboard contents");
Logger.LogError(ex, "Failed to read clipboard contents");
}
}

Expand Down Expand Up @@ -1289,4 +1294,52 @@ else
}


private void ShowRawTransactionJson(AddressInfo addressInfo)
{
rawTransactionJson = GetRawTransactionJson(addressInfo);
showRawTransactionModal = true;
}

private string GetRawTransactionJson(AddressInfo addressInfo)
{
var options = new JsonSerializerOptions
{
WriteIndented = true
};
return JsonSerializer.Serialize(addressInfo, options);
}

private async Task CopyStringToClipboard(string msg)
{
await _clipboardService.WriteTextAsync(msg);
notificationComponent.ShowNotificationMessage("Copied to clipboard!", 3);
StateHasChanged();
}


}


@if (showRawTransactionModal)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this location for the html by convention?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responding a bit late haha, happy to be back!

I took the convention from here:
https://blog.samferree.dev/basics-in-blazor-modal
if you prefer, I can move it to the top of the file or create a component for the modal (it can be much better if you can think of another place we could use the component) .

{
<div class="modal-wrapper">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could become a component in the next PR.

<div class="modal fade show d-block">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Raw Transaction JSON</h5>
<span type="button" @onclick="() => showRawTransactionModal = false" aria-label="Close">
<Icon IconName="close-circle"/>
<i @onclick="@(async () => await CopyStringToClipboard(rawTransactionJson))" class="ms-auto cursor-pointer user-select-none">
<Icon IconName="copy"></Icon>
</i>
</span>
</div>
<div class="modal-body">
<pre>@rawTransactionJson</pre>
</div>
</div>
</div>
</div>
</div>
}
Loading