Files
btcpayserver/BTCPayServer/Blazor/VaultBridge/Elements/VerifyAddress.razor
Nicolas Dorier 2f26979ed7 Refactor vault (#6678)
* Use Blazor for the Vault code

* Put elements in different file

* Controller abstraction

* Break into VaultElement
2025-04-21 17:09:46 +09:00

63 lines
1.9 KiB
Plaintext

@using BTCPayServer.Hwi
@using NBitcoin
@inherits VaultElement
@implements IDisposable
@if (ConfirmedOnDevice)
{
<button id="vault-confirm" class="btn btn-primary mt-4" type="button" @onclick="OnConfirm">@ui.StringLocalizer["Confirm"]</button>
}
else
{
<button id="vault-confirm" class="btn btn-primary mt-4" type="button" disabled="disabled">@ui.StringLocalizer["Please, confirm on the device first..."]</button>
}
@code {
private readonly VaultBridgeUI ui;
public VerifyAddress(VaultBridgeUI ui)
{
this.ui = ui;
}
public BitcoinAddress Address { get; set; }
public KeyPath KeyPath { get; set; }
public ScriptPubKeyType ScriptPubKeyType { get; set; }
public HwiDeviceClient Device { get; set; }
private TaskCompletionSource<bool> _cts;
public void OnConfirm()
{
ui.Elements.Remove(this);
ui.ShowFeedback(FeedbackType.Success, ui.StringLocalizer["Address verified."]);
_cts?.TrySetResult(true);
_cts = null;
}
bool ConfirmedOnDevice { get; set; }
public async Task<bool> WaitConfirmed()
{
ui.ShowFeedback(FeedbackType.Loading,
ui.ViewLocalizer["Please verify that the address displayed on your device is <b>{0}</b>...", Address.ToString()]);
ui.AddElement(this);
var deviceAddress = await Device.DisplayAddressAsync(ScriptPubKeyType, KeyPath, ui.CancellationToken);
// Note that the device returned here may be different from what on screen for Testnet/Regtest
if (deviceAddress != Address)
{
ui.ShowFeedback(FeedbackType.Failed, ui.StringLocalizer["Unexpected address returned by the device..."]);
return false;
}
ConfirmedOnDevice = true;
ui.StateHasChanged();
_cts = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
return await _cts.Task;
}
public void Dispose() => _cts?.TrySetCanceled();
}