Merge pull request #1410 from Kukks/coin-selection-fix

fix coin selection
This commit is contained in:
Nicolas Dorier 2020-03-26 01:08:53 +09:00 committed by GitHub
commit c633402fe2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -12,6 +12,8 @@ using System.Text.RegularExpressions;
using BTCPayServer.Models;
using NBitcoin.Payment;
using BTCPayServer.Controllers;
using BTCPayServer.Data;
using BTCPayServer.Services.Wallets;
namespace BTCPayServer.Tests
{
@ -442,13 +444,28 @@ namespace BTCPayServer.Tests
var targetTx = await s.Server.ExplorerNode.SendToAddressAsync(address, Money.Coins(1.2m));
var tx = await s.Server.ExplorerNode.GetRawTransactionAsync(targetTx);
var spentOutpoint = new OutPoint(targetTx, tx.Outputs.FindIndex(txout => txout.Value == Money.Coins(1.2m)));
await TestUtils.EventuallyAsync(async () =>
{
var store = await s.Server.PayTester.StoreRepository.FindStore(storeId);
var x = store.GetSupportedPaymentMethods(s.Server.NetworkProvider)
.OfType<DerivationSchemeSettings>()
.Single(settings => settings.PaymentId.CryptoCode == walletId.CryptoCode);
Assert.Contains(
await s.Server.PayTester.GetService<BTCPayWalletProvider>().GetWallet(walletId.CryptoCode)
.GetUnspentCoins(x.AccountDerivation),
coin => coin.OutPoint == spentOutpoint);
});
await s.Server.ExplorerNode.GenerateAsync(1);
s.GoToWalletSend(walletId);
s.Driver.FindElement(By.Id("advancedSettings")).Click();
s.Driver.FindElement(By.Id("toggleInputSelection")).Click();
s.Driver.WaitForElement(By.Id(spentOutpoint.ToString()));
Assert.Equal("true", s.Driver.FindElement(By.Name("InputSelection")).GetAttribute("value").ToLowerInvariant());
var el = s.Driver.FindElement(By.Id(spentOutpoint.ToString()));
s.Driver.FindElement(By.Id(spentOutpoint.ToString())).Click();
var inputSelectionSelect = s.Driver.FindElement(By.Name("SelectedInputs"));
Assert.Single(inputSelectionSelect.FindElements(By.CssSelector("[selected]")));
var bob = new Key().PubKey.Hash.GetAddress(Network.RegTest);
SetTransactionOutput(s, 0, bob, 0.3m);
s.Driver.FindElement(By.Id("SendMenu")).Click();

View file

@ -179,7 +179,11 @@ $(function () {
res.splice(this.selectedInputs.indexOf(item.outpoint),1);
}
$("#SelectedInputs").val(res);
$("select option").each(function(){
var selected = res.indexOf($(this).attr("value")) !== -1;
$(this).attr("selected",selected? "selected": null);
});
this.selectedInputs = res;
$(".crypto-balance-link").text(this.selectedAmount);
}