Refactoring

This commit is contained in:
nicolas.dorier
2019-11-22 19:19:05 +09:00
parent 98276bcb3d
commit 1b58058796

View File

@@ -67,8 +67,13 @@ namespace BTCPayServer.Controllers
int? pin = null; int? pin = null;
var websocketHelper = new WebSocketHelper(websocket); var websocketHelper = new WebSocketHelper(websocket);
async Task<bool> RequireMoreInformation() async Task<bool> RequireDeviceUnlocking()
{ {
if (deviceEntry == null)
{
await websocketHelper.Send("{ \"error\": \"need-device\"}", cancellationToken);
return true;
}
if (deviceEntry.NeedsPinSent is true && pin is null) if (deviceEntry.NeedsPinSent is true && pin is null)
{ {
await websocketHelper.Send("{ \"error\": \"need-pin\"}", cancellationToken); await websocketHelper.Send("{ \"error\": \"need-pin\"}", cancellationToken);
@@ -95,12 +100,7 @@ namespace BTCPayServer.Controllers
password = device.Password; password = device.Password;
break; break;
case "ask-sign": case "ask-sign":
if (device == null) if (await RequireDeviceUnlocking())
{
await websocketHelper.Send("{ \"error\": \"need-device\"}", cancellationToken);
continue;
}
if (await RequireMoreInformation())
{ {
continue; continue;
} }
@@ -163,12 +163,7 @@ namespace BTCPayServer.Controllers
} }
break; break;
case "ask-xpubs": case "ask-xpubs":
if (device == null) if (await RequireDeviceUnlocking())
{
await websocketHelper.Send("{ \"error\": \"need-device\"}", cancellationToken);
continue;
}
if (await RequireMoreInformation())
{ {
continue; continue;
} }