More user friendly Update Store screen

This commit is contained in:
nicolas.dorier 2018-08-01 15:59:29 +09:00
parent 4dddc539f6
commit 5c8e03dcbf
2 changed files with 71 additions and 35 deletions

View File

@ -79,6 +79,11 @@ namespace BTCPayServer.Controllers
}
PaymentMethodId paymentMethodId = new PaymentMethodId(network.CryptoCode, PaymentTypes.BTCLike);
var exisingStrategy = store.GetSupportedPaymentMethods(_NetworkProvider)
.Where(c => c.PaymentId == paymentMethodId)
.OfType<DerivationStrategy>()
.Select(c => c.DerivationStrategyBase.ToString())
.FirstOrDefault();
DerivationStrategy strategy = null;
try
{
@ -94,9 +99,33 @@ namespace BTCPayServer.Controllers
vm.Confirmation = false;
return View(vm);
}
if (!vm.Confirmation && strategy != null)
return ShowAddresses(vm, strategy);
if (vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress))
var showAddress = (vm.Confirmation && !string.IsNullOrWhiteSpace(vm.HintAddress)) || // Testing hint address
(!vm.Confirmation && strategy != null && exisingStrategy != strategy.DerivationStrategyBase.ToString()); // Checking addresses after setting xpub
if (!showAddress)
{
try
{
if (strategy != null)
await wallet.TrackAsync(strategy.DerivationStrategyBase);
store.SetSupportedPaymentMethod(paymentMethodId, strategy);
var storeBlob = store.GetStoreBlob();
storeBlob.SetExcluded(paymentMethodId, !vm.Enabled);
store.SetStoreBlob(storeBlob);
}
catch
{
ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid Derivation Scheme");
return View(vm);
}
await _Repo.UpdateStore(store);
StatusMessage = $"Derivation scheme for {network.CryptoCode} has been modified.";
return RedirectToAction(nameof(UpdateStore), new { storeId = storeId });
}
else if (!string.IsNullOrEmpty(vm.HintAddress))
{
BitcoinAddress address = null;
try
@ -122,30 +151,8 @@ namespace BTCPayServer.Controllers
vm.StatusMessage = "Address successfully found, please verify that the rest is correct and click on \"Confirm\"";
ModelState.Remove(nameof(vm.HintAddress));
ModelState.Remove(nameof(vm.DerivationScheme));
return ShowAddresses(vm, strategy);
}
else
{
try
{
if (strategy != null)
await wallet.TrackAsync(strategy.DerivationStrategyBase);
store.SetSupportedPaymentMethod(paymentMethodId, strategy);
var storeBlob = store.GetStoreBlob();
storeBlob.SetExcluded(paymentMethodId, !vm.Enabled);
store.SetStoreBlob(storeBlob);
}
catch
{
ModelState.AddModelError(nameof(vm.DerivationScheme), "Invalid Derivation Scheme");
return View(vm);
}
await _Repo.UpdateStore(store);
StatusMessage = $"Derivation scheme for {network.CryptoCode} has been modified.";
return RedirectToAction(nameof(UpdateStore), new { storeId = storeId });
}
return ShowAddresses(vm, strategy);
}
private IActionResult ShowAddresses(DerivationSchemeViewModel vm, DerivationStrategy strategy)

View File

@ -5,6 +5,21 @@
ViewData.AddActivePage(BTCPayServer.Views.Stores.StoreNavPages.Index);
}
<style type="text/css">
.smMaxWidth {
max-width: 150px;
}
@@media (min-width: 768px) {
.smMaxWidth {
max-width: 300px;
}
}
</style>
<h4>@ViewData["Title"]</h4>
<partial name="_StatusMessage" for="@TempData["TempDataProperty-StatusMessage"]" />
@ -70,8 +85,8 @@
<tr>
<th>Crypto</th>
<th>Derivation Scheme</th>
<th>Enabled</th>
<th style="text-align:right">Actions</th>
<th style="text-align:center;">Enabled</th>
<th style="text-align:right;">Actions</th>
</tr>
</thead>
<tbody>
@ -79,9 +94,16 @@
{
<tr>
<td>@scheme.Crypto</td>
<td style="max-width:300px;overflow:hidden;">@scheme.Value</td>
<td>
@(scheme.Enabled ? "Yes" : "No")
<td class="smMaxWidth text-truncate">@scheme.Value</td>
<td style="text-align:center;">
@if(scheme.Enabled)
{
<span class="fa fa-check"></span>
}
else
{
<span class="fa fa-times"></span>
}
</td>
<td style="text-align:right">
@if(!string.IsNullOrWhiteSpace(scheme.Value))
@ -110,7 +132,7 @@
<tr>
<th>Crypto</th>
<th>Address</th>
<th>Enabled</th>
<th style="text-align:center;">Enabled</th>
<th style="text-align:right">Actions</th>
</tr>
</thead>
@ -119,9 +141,16 @@
{
<tr>
<td>@scheme.CryptoCode</td>
<td>@scheme.Address</td>
<td>
@(scheme.Enabled ? "Yes" : "No")
<td class="smMaxWidth text-truncate">@scheme.Address</td>
<td style="text-align:center;">
@if(scheme.Enabled)
{
<span class="fa fa-check"></span>
}
else
{
<span class="fa fa-times"></span>
}
</td>
<td style="text-align:right"><a asp-action="AddLightningNode" asp-route-cryptoCode="@scheme.CryptoCode">Modify</a></td>
</tr>