mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 22:14:26 +01:00
Add View seed to wallet settings
This commit is contained in:
@@ -1137,7 +1137,10 @@ namespace BTCPayServer.Controllers
|
|||||||
Label = derivationSchemeSettings.Label,
|
Label = derivationSchemeSettings.Label,
|
||||||
DerivationScheme = derivationSchemeSettings.AccountDerivation.ToString(),
|
DerivationScheme = derivationSchemeSettings.AccountDerivation.ToString(),
|
||||||
DerivationSchemeInput = derivationSchemeSettings.AccountOriginal,
|
DerivationSchemeInput = derivationSchemeSettings.AccountOriginal,
|
||||||
SelectedSigningKey = derivationSchemeSettings.SigningKey.ToString()
|
SelectedSigningKey = derivationSchemeSettings.SigningKey.ToString(),
|
||||||
|
NBXSeedAvailable = await CanUseHotWallet() && !string.IsNullOrEmpty(await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
|
||||||
|
.GetMetadataAsync<string>(GetDerivationSchemeSettings(walletId).AccountDerivation,
|
||||||
|
WellknownMetadataKeys.MasterHDKey))
|
||||||
};
|
};
|
||||||
vm.AccountKeys = derivationSchemeSettings.AccountKeySettings
|
vm.AccountKeys = derivationSchemeSettings.AccountKeySettings
|
||||||
.Select(e => new WalletSettingsAccountKeyViewModel()
|
.Select(e => new WalletSettingsAccountKeyViewModel()
|
||||||
@@ -1152,8 +1155,9 @@ namespace BTCPayServer.Controllers
|
|||||||
[Route("{walletId}/settings")]
|
[Route("{walletId}/settings")]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> WalletSettings(
|
public async Task<IActionResult> WalletSettings(
|
||||||
[ModelBinder(typeof(WalletIdModelBinder))]
|
[ModelBinder(typeof(WalletIdModelBinder))]
|
||||||
WalletId walletId, WalletSettingsViewModel vm, string command = "save", CancellationToken cancellationToken = default)
|
WalletId walletId, WalletSettingsViewModel vm, string command = "save",
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return View(vm);
|
return View(vm);
|
||||||
@@ -1164,14 +1168,21 @@ namespace BTCPayServer.Controllers
|
|||||||
if (command == "save")
|
if (command == "save")
|
||||||
{
|
{
|
||||||
derivationScheme.Label = vm.Label;
|
derivationScheme.Label = vm.Label;
|
||||||
derivationScheme.SigningKey = string.IsNullOrEmpty(vm.SelectedSigningKey) ? null : new BitcoinExtPubKey(vm.SelectedSigningKey, derivationScheme.Network.NBitcoinNetwork);
|
derivationScheme.SigningKey = string.IsNullOrEmpty(vm.SelectedSigningKey)
|
||||||
|
? null
|
||||||
|
: new BitcoinExtPubKey(vm.SelectedSigningKey, derivationScheme.Network.NBitcoinNetwork);
|
||||||
for (int i = 0; i < derivationScheme.AccountKeySettings.Length; i++)
|
for (int i = 0; i < derivationScheme.AccountKeySettings.Length; i++)
|
||||||
{
|
{
|
||||||
derivationScheme.AccountKeySettings[i].AccountKeyPath = string.IsNullOrWhiteSpace(vm.AccountKeys[i].AccountKeyPath) ? null
|
derivationScheme.AccountKeySettings[i].AccountKeyPath =
|
||||||
: new KeyPath(vm.AccountKeys[i].AccountKeyPath);
|
string.IsNullOrWhiteSpace(vm.AccountKeys[i].AccountKeyPath)
|
||||||
derivationScheme.AccountKeySettings[i].RootFingerprint = string.IsNullOrWhiteSpace(vm.AccountKeys[i].MasterFingerprint) ? (HDFingerprint?)null
|
? null
|
||||||
: new HDFingerprint(Encoders.Hex.DecodeData(vm.AccountKeys[i].MasterFingerprint));
|
: new KeyPath(vm.AccountKeys[i].AccountKeyPath);
|
||||||
|
derivationScheme.AccountKeySettings[i].RootFingerprint =
|
||||||
|
string.IsNullOrWhiteSpace(vm.AccountKeys[i].MasterFingerprint)
|
||||||
|
? (HDFingerprint?)null
|
||||||
|
: new HDFingerprint(Encoders.Hex.DecodeData(vm.AccountKeys[i].MasterFingerprint));
|
||||||
}
|
}
|
||||||
|
|
||||||
var store = (await Repository.FindStore(walletId.StoreId, GetUserId()));
|
var store = (await Repository.FindStore(walletId.StoreId, GetUserId()));
|
||||||
store.SetSupportedPaymentMethod(derivationScheme);
|
store.SetSupportedPaymentMethod(derivationScheme);
|
||||||
await Repository.UpdateStore(store);
|
await Repository.UpdateStore(store);
|
||||||
@@ -1180,15 +1191,41 @@ namespace BTCPayServer.Controllers
|
|||||||
}
|
}
|
||||||
else if (command == "prune")
|
else if (command == "prune")
|
||||||
{
|
{
|
||||||
var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode).PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken);
|
var result = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
|
||||||
|
.PruneAsync(derivationScheme.AccountDerivation, new PruneRequest(), cancellationToken);
|
||||||
if (result.TotalPruned == 0)
|
if (result.TotalPruned == 0)
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.SuccessMessage] = $"The wallet is already pruned";
|
TempData[WellKnownTempData.SuccessMessage] = $"The wallet is already pruned";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TempData[WellKnownTempData.SuccessMessage] = $"The wallet has been successfully pruned ({result.TotalPruned} transactions have been removed from the history)";
|
TempData[WellKnownTempData.SuccessMessage] =
|
||||||
|
$"The wallet has been successfully pruned ({result.TotalPruned} transactions have been removed from the history)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(WalletSettings));
|
||||||
|
}
|
||||||
|
else if (command == "view-seed" && await CanUseHotWallet())
|
||||||
|
{
|
||||||
|
var seed = await ExplorerClientProvider.GetExplorerClient(walletId.CryptoCode)
|
||||||
|
.GetMetadataAsync<string>(derivationScheme.AccountDerivation,
|
||||||
|
WellknownMetadataKeys.Mnemonic, cancellationToken);
|
||||||
|
if (string.IsNullOrEmpty(seed))
|
||||||
|
{
|
||||||
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
|
{
|
||||||
|
Severity = StatusMessageModel.StatusSeverity.Error, Message = "The seed was not found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TempData.SetStatusMessageModel(new StatusMessageModel()
|
||||||
|
{
|
||||||
|
Severity = StatusMessageModel.StatusSeverity.Success,
|
||||||
|
Html = $"Please store your seed securely! <br/><code class=\"alert-link\">{seed}</code>"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return RedirectToAction(nameof(WalletSettings));
|
return RedirectToAction(nameof(WalletSettings));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1196,8 +1233,6 @@ namespace BTCPayServer.Controllers
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private string GetImage(PaymentMethodId paymentMethodId, BTCPayNetwork network)
|
private string GetImage(PaymentMethodId paymentMethodId, BTCPayNetwork network)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -16,6 +16,7 @@ namespace BTCPayServer.Models.WalletViewModels
|
|||||||
public bool IsMultiSig => AccountKeys.Count > 1;
|
public bool IsMultiSig => AccountKeys.Count > 1;
|
||||||
|
|
||||||
public List<WalletSettingsAccountKeyViewModel> AccountKeys { get; set; } = new List<WalletSettingsAccountKeyViewModel>();
|
public List<WalletSettingsAccountKeyViewModel> AccountKeys { get; set; } = new List<WalletSettingsAccountKeyViewModel>();
|
||||||
|
public bool NBXSeedAvailable { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WalletSettingsAccountKeyViewModel
|
public class WalletSettingsAccountKeyViewModel
|
||||||
|
|||||||
@@ -76,6 +76,10 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="SendMenu">
|
<div class="dropdown-menu" aria-labelledby="SendMenu">
|
||||||
<button name="command" type="submit" class="dropdown-item" value="prune">Prune old transactions from history</button>
|
<button name="command" type="submit" class="dropdown-item" value="prune">Prune old transactions from history</button>
|
||||||
|
@if (Model.NBXSeedAvailable)
|
||||||
|
{
|
||||||
|
<button name="command" type="submit" class="dropdown-item" value="view-seed">View seed</button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user