@using BTCPayServer.Hwi
@using NBitcoin
@inherits VaultElement
@implements IDisposable
@if (ConfirmedOnDevice)
{
}
else
{
}
@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 _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 WaitConfirmed()
{
ui.ShowFeedback(FeedbackType.Loading,
ui.ViewLocalizer["Please verify that the address displayed on your device is {0}...", 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(TaskCreationOptions.RunContinuationsAsynchronously);
return await _cts.Task;
}
public void Dispose() => _cts?.TrySetCanceled();
}