mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 06:21:44 +01:00
Reuse same html and handling of commands for PSBT signing/ Wallet Send (#1587)
* Reuse same html and handling of commands for PSBT signing/ Wallet Send * fix ledger
This commit is contained in:
parent
cdf6886c39
commit
9d215ea27d
5 changed files with 77 additions and 74 deletions
|
@ -100,6 +100,12 @@ namespace BTCPayServer.Controllers
|
|||
ModelState.AddModelError(nameof(vm.PSBT), "Invalid PSBT");
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
var res = await TryHandleSigningCommands(walletId, psbt, command, vm.PayJoinEndpointUrl, null);
|
||||
if (res != null)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
switch (command)
|
||||
{
|
||||
case "decode":
|
||||
|
@ -110,10 +116,7 @@ namespace BTCPayServer.Controllers
|
|||
vm.PSBT = psbt.ToBase64();
|
||||
vm.FileName = vm.UploadedPSBTFile?.FileName;
|
||||
return View(vm);
|
||||
case "vault":
|
||||
return ViewVault(walletId, psbt, vm.PayJoinEndpointUrl);
|
||||
case "ledger":
|
||||
return ViewWalletSendLedger(walletId, psbt);
|
||||
|
||||
case "update":
|
||||
var derivationSchemeSettings = GetDerivationSchemeSettings(walletId);
|
||||
psbt = await ExplorerClientProvider.UpdatePSBT(derivationSchemeSettings, psbt);
|
||||
|
@ -124,21 +127,7 @@ namespace BTCPayServer.Controllers
|
|||
}
|
||||
TempData[WellKnownTempData.SuccessMessage] = "PSBT updated!";
|
||||
return RedirectToWalletPSBT(psbt, vm.FileName);
|
||||
case "seed":
|
||||
return SignWithSeed(walletId, psbt.ToBase64(), vm.PayJoinEndpointUrl);
|
||||
case "nbx-seed":
|
||||
if (await CanUseHotWallet())
|
||||
{
|
||||
var derivationScheme = GetDerivationSchemeSettings(walletId);
|
||||
var extKey = await ExplorerClientProvider.GetExplorerClient(network)
|
||||
.GetMetadataAsync<string>(derivationScheme.AccountDerivation,
|
||||
WellknownMetadataKeys.MasterHDKey);
|
||||
|
||||
return SignWithSeed(walletId,
|
||||
new SignWithSeedViewModel() {SeedOrKey = extKey, PSBT = psbt.ToBase64(), PayJoinEndpointUrl = vm.PayJoinEndpointUrl});
|
||||
}
|
||||
|
||||
return View(vm);
|
||||
case "broadcast":
|
||||
{
|
||||
return RedirectToWalletPSBTReady(psbt.ToBase64());
|
||||
|
@ -470,5 +459,38 @@ namespace BTCPayServer.Controllers
|
|||
TempData[WellKnownTempData.SuccessMessage] = "PSBT Successfully combined!";
|
||||
return RedirectToWalletPSBT(sourcePSBT);
|
||||
}
|
||||
|
||||
private async Task<IActionResult> TryHandleSigningCommands(WalletId walletId, PSBT psbt, string command,
|
||||
string payjoinEndpointUrl, BitcoinAddress changeAddress)
|
||||
{
|
||||
switch (command )
|
||||
{
|
||||
case "vault":
|
||||
return ViewVault(walletId, psbt, payjoinEndpointUrl);
|
||||
case "ledger":
|
||||
return ViewWalletSendLedger(walletId, psbt, changeAddress);
|
||||
case "seed":
|
||||
return SignWithSeed(walletId, psbt.ToBase64(), payjoinEndpointUrl);
|
||||
case "nbx-seed":
|
||||
if (await CanUseHotWallet())
|
||||
{
|
||||
var derivationScheme = GetDerivationSchemeSettings(walletId);
|
||||
var extKey = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
|
||||
.GetMetadataAsync<string>(derivationScheme.AccountDerivation,
|
||||
WellknownMetadataKeys.MasterHDKey);
|
||||
|
||||
return SignWithSeed(walletId,
|
||||
new SignWithSeedViewModel() {SeedOrKey = extKey, PSBT = psbt.ToBase64(), PayJoinEndpointUrl = payjoinEndpointUrl});
|
||||
}
|
||||
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||
{
|
||||
Severity = StatusMessageModel.StatusSeverity.Error,
|
||||
Message = "NBX seed functionality is not available"
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -653,24 +653,16 @@ namespace BTCPayServer.Controllers
|
|||
return View(vm);
|
||||
}
|
||||
derivationScheme.RebaseKeyPaths(psbt.PSBT);
|
||||
|
||||
|
||||
var res = await TryHandleSigningCommands(walletId, psbt.PSBT, command, vm.PayJoinEndpointUrl, psbt.ChangeAddress);
|
||||
if (res != null)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case "vault":
|
||||
return ViewVault(walletId, psbt.PSBT, vm.PayJoinEndpointUrl);
|
||||
case "nbx-seed":
|
||||
var extKey = await ExplorerClientProvider.GetExplorerClient(network)
|
||||
.GetMetadataAsync<string>(derivationScheme.AccountDerivation, WellknownMetadataKeys.MasterHDKey, cancellation);
|
||||
|
||||
return SignWithSeed(walletId, new SignWithSeedViewModel()
|
||||
{
|
||||
PayJoinEndpointUrl = vm.PayJoinEndpointUrl,
|
||||
SeedOrKey = extKey,
|
||||
PSBT = psbt.PSBT.ToBase64()
|
||||
});
|
||||
case "ledger":
|
||||
return ViewWalletSendLedger(walletId, psbt.PSBT, psbt.ChangeAddress);
|
||||
case "seed":
|
||||
return SignWithSeed(walletId, psbt.PSBT.ToBase64(), vm.PayJoinEndpointUrl);
|
||||
case "analyze-psbt":
|
||||
var name =
|
||||
$"Send-{string.Join('_', vm.Outputs.Select(output => $"{output.Amount}->{output.DestinationAddress}{(output.SubtractFeesFromOutput ? "-Fees" : string.Empty)}"))}.psbt";
|
||||
|
|
|
@ -29,28 +29,13 @@
|
|||
<h3>Decoded PSBT</h3>
|
||||
<div class="form-group">
|
||||
<form method="post" asp-action="WalletPSBT" asp-route-walletId="@this.Context.GetRouteValue("walletId")">
|
||||
<input type="hidden" asp-for="CryptoCode" />
|
||||
<input type="hidden" asp-for="PayJoinEndpointUrl" />
|
||||
<input type="hidden" asp-for="NBXSeedAvailable" />
|
||||
<input type="hidden" asp-for="PSBT" />
|
||||
<input type="hidden" asp-for="FileName" />
|
||||
<div class="dropdown d-inline-block" style="margin-top:16px;">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" id="SendMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Sign with...
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="SendMenu">
|
||||
<button name="command" type="submit" class="dropdown-item" value="ledger">... your Ledger Wallet device</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="seed">... an HD private key or mnemonic seed</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="save-psbt">... a wallet supporting PSBT (save as file)</button>
|
||||
@if (Model.CryptoCode == "BTC") {
|
||||
<button name="command" type="submit" class="dropdown-item" value="vault">... the vault (preview)</button>
|
||||
}
|
||||
@if (Model.NBXSeedAvailable)
|
||||
{
|
||||
<button name="command" type="submit" class="dropdown-item" value="nbx-seed">... the seed saved in NBXplorer</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" asp-for="CryptoCode"/>
|
||||
<input type="hidden" asp-for="PayJoinEndpointUrl"/>
|
||||
<input type="hidden" asp-for="NBXSeedAvailable"/>
|
||||
<input type="hidden" asp-for="PSBT"/>
|
||||
<input type="hidden" asp-for="FileName"/>
|
||||
|
||||
<partial name="WalletSigningMenu" model="@((Model.CryptoCode, Model.NBXSeedAvailable))"/>
|
||||
<div class="dropdown d-inline-block">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="OtherActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Other actions...
|
||||
|
|
|
@ -203,24 +203,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group d-flex mt-2">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" id="SendMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Sign with...
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="SendMenu">
|
||||
<button name="command" type="submit" class="dropdown-item" value="ledger">... your Ledger Wallet device</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="seed">... an HD private key or mnemonic seed</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="analyze-psbt">... a wallet supporting PSBT</button>
|
||||
@if (Model.CryptoCode == "BTC")
|
||||
{
|
||||
<button name="command" type="submit" class="dropdown-item" value="vault">... the vault (preview)</button>
|
||||
}
|
||||
@if (Model.NBXSeedAvailable)
|
||||
{
|
||||
<button id="spendWithNBxplorer" name="command" type="submit" class="dropdown-item" value="nbx-seed">... the seed saved in NBXplorer</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<partial name="WalletSigningMenu" model="@((Model.CryptoCode, Model.NBXSeedAvailable))"/>
|
||||
<button type="submit" name="command" value="add-output" class="ml-1 btn btn-secondary">Add another destination</button>
|
||||
<button type="button" id="bip21parse" class="ml-1 btn btn-secondary" title="Paste BIP21/Address"><i class="fa fa-paste"></i></button>
|
||||
<button type="button" id="scanqrcode" class="ml-1 btn btn-secondary only-for-js" data-toggle="modal" data-target="#scanModal" title="Scan BIP21/Address with camera"><i class="fa fa-camera"></i></button>
|
||||
|
|
21
BTCPayServer/Views/Wallets/WalletSigningMenu.cshtml
Normal file
21
BTCPayServer/Views/Wallets/WalletSigningMenu.cshtml
Normal file
|
@ -0,0 +1,21 @@
|
|||
@model (string CryptoCode, bool NBXSeedAvailable)
|
||||
|
||||
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" id="SendMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Sign with...
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="SendMenu">
|
||||
<button name="command" type="submit" class="dropdown-item" value="ledger">... your Ledger Wallet device</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="seed">... an HD private key or mnemonic seed</button>
|
||||
<button name="command" type="submit" class="dropdown-item" value="analyze-psbt">... a wallet supporting PSBT</button>
|
||||
@if (Model.CryptoCode == "BTC")
|
||||
{
|
||||
<button name="command" type="submit" class="dropdown-item" value="vault">... the vault (preview)</button>
|
||||
}
|
||||
@if (Model.NBXSeedAvailable)
|
||||
{
|
||||
<button id="spendWithNBxplorer" name="command" type="submit" class="dropdown-item" value="nbx-seed">... the seed saved in NBXplorer</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Reference in a new issue