Add balance of the store in the stores page

This commit is contained in:
NicolasDorier 2017-10-06 11:07:22 +09:00
parent f456d62d3c
commit 783132a012
5 changed files with 28 additions and 3 deletions

View File

@ -23,4 +23,10 @@ You can run the tests inside a container by running
```
docker-compose run --rm tests
```
The Bitcoin RPC server is exposed to the host, for example, you can send 0.23111090 BTC to mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf.
```
bitcoin-cli -regtest -rpcport=43782 -rpcuser=ceiwHEbqWI83 -rpcpassword=DwubwWsoo3 sendtoaddress "mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf" 0.23111090
```

View File

@ -86,13 +86,17 @@ namespace BTCPayServer.Controllers
StoresViewModel result = new StoresViewModel();
result.StatusMessage = StatusMessage;
var stores = await _Repo.GetStoresByUserId(GetUserId());
foreach(var store in stores)
var balances = stores.Select(async s => string.IsNullOrEmpty(s.DerivationStrategy) ? Money.Zero : await _Wallet.GetBalance(s.DerivationStrategy)).ToArray();
for(int i = 0; i < stores.Length; i++)
{
var store = stores[i];
result.Stores.Add(new StoresViewModel.StoreViewModel()
{
Id = store.Id,
Name = store.StoreName,
WebSite = store.StoreWebsite
WebSite = store.StoreWebsite,
Balance = await balances[i]
});
}
return View(result);

View File

@ -1,4 +1,5 @@
using System;
using NBitcoin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -31,6 +32,10 @@ namespace BTCPayServer.Models.StoreViewModels
{
get; set;
}
public Money Balance
{
get; set;
}
}
}
}

View File

@ -73,5 +73,13 @@ namespace BTCPayServer.Services.Wallets
var tasks = transactions.Select(t => _Client.BroadcastAsync(t)).ToArray();
return Task.WhenAll(tasks);
}
public async Task<Money> GetBalance(string derivationStrategy)
{
var result = await _Client.SyncAsync(_DerivationStrategyFactory.Parse(derivationStrategy), null, true);
return result.Confirmed.UTXOs.Select(u => u.Output.Value)
.Concat(result.Unconfirmed.UTXOs.Select(u => u.Output.Value))
.Sum();
}
}
}

View File

@ -27,6 +27,7 @@
<tr>
<th>Name</th>
<th>Website</th>
<th>Balance</th>
<th>Actions</th>
</tr>
</thead>
@ -40,6 +41,7 @@
{
<a href="@store.WebSite">@store.WebSite</a>
}</td>
<td>@store.Balance</td>
<td><a asp-action="UpdateStore" asp-route-storeId="@store.Id">Settings</a></td>
</tr>
}