Add balances label
MODIFY
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
@@ -136,17 +136,19 @@ namespace HiddenWallet.API.Controllers
}
}
- [Route("balances")]
+ [Route("balances/{account}")]
[HttpGet]
- public IActionResult Balances([FromBody]AccountModel request)
+ public IActionResult Balances(string account)
{
try
{
+ if (account == null)
+ return new ObjectResult(new FailureResponse { Message = "No request body specified" });
+
if (!Global.WalletWrapper.IsDecrypted)
- {
return new ObjectResult(new FailureResponse { Message = "Wallet isn't decrypted" });
- }
- var trimmed = request.Account;
+
+ var trimmed = account;
if (String.Equals(trimmed, "alice", StringComparison.OrdinalIgnoreCase))
{
return new ObjectResult(new BalancesResponse { Available = 32.1m, Incoming = 0.23534219m });

MODIFY
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
@@ -71,11 +71,11 @@ namespace HiddenWallet.API.Wrappers
_walletJob = new WalletJob(safe, trackDefaultSafe: false, accountsToTrack: new SafeAccount[] { _aliceAccount, _bobAccount });
- _walletJobTask = _walletJob.StartAsync(_cts.Token);
-
_walletJob.BestHeightChanged += _walletJob_BestHeightChanged;
_walletJob.StateChanged += _walletJob_StateChanged;
_walletJob.Tracker.TrackedTransactions.CollectionChanged += TrackedTransactions_CollectionChanged;
+
+ _walletJobTask = _walletJob.StartAsync(_cts.Token);
}
}
@@ -120,10 +120,13 @@ namespace HiddenWallet.API.Wrappers
#endregion
public async Task EndAsync()
+ {
+ if (_walletJob != null)
{
_walletJob.BestHeightChanged -= _walletJob_BestHeightChanged;
_walletJob.StateChanged -= _walletJob_StateChanged;
_walletJob.Tracker.TrackedTransactions.CollectionChanged -= TrackedTransactions_CollectionChanged;
+ }
_cts.Cancel();
await Task.WhenAll(_walletJobTask).ConfigureAwait(false);

MODIFY
HiddenWallet/HiddenWallet.GUI/HiddenWallet.GUI.njsproj
HiddenWallet/HiddenWallet.GUI/HiddenWallet.GUI.njsproj
<Compile Include="app\js\default.js">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="app\js\hw-client.js" />
<Compile Include="app\js\settings.js" />
<Compile Include="app\js\status.js" />
<Compile Include="app\js\wallet-phase.js" />

MODIFY
HiddenWallet/HiddenWallet.GUI/app/js/decryption-phase.js
HiddenWallet/HiddenWallet.GUI/app/js/decryption-phase.js
@@ -45,23 +45,6 @@ function decryptionPhaseShow(menuItem = "") {
}
}
-function httpGetWallet(path) {
- var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.open("GET", theUrl, false); // false for synchronous request
- xmlHttp.send(null);
- return JSON.parse(xmlHttp.responseText);
-}
-
-function httpPostWallet(path, data) {
- var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
- var xmlHttp = new XMLHttpRequest();
- xmlHttp.open("POST", theUrl, false); // false for synchronous request
- xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
- xmlHttp.send(JSON.stringify(data));
- return JSON.parse(xmlHttp.responseText);
-}
-
function generateWallet() {
var password = document.getElementById("inputPassword").value;
if (password !== document.getElementById("confirmPassword").value) {

ADD
HiddenWallet/HiddenWallet.GUI/app/js/hw-client.js
+function httpGetWallet(path) {
+ var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open("GET", theUrl, false); // false for synchronous request
+ xmlHttp.send(null);
+ return JSON.parse(xmlHttp.responseText);
+}
+
+function httpPostWallet(path, data) {
+ var theUrl = "http://localhost:5000/api/v1/wallet/" + path;
+ var xmlHttp = new XMLHttpRequest();
+ xmlHttp.open("POST", theUrl, false); // false for synchronous request
+ xmlHttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
+ xmlHttp.send(JSON.stringify(data));
+ return JSON.parse(xmlHttp.responseText);
+}
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
@@ -2,14 +2,14 @@ function walletPhaseShow(tabItem = "") {
document.getElementById("hide-btn").hidden = false;
if (tabItem === "alice") {
- document.getElementById("tabs").innerHTML = document.getElementById("wallet-phase-tabs-frame").contentWindow.document.getElementById("alice-active").innerHTML;
+ document.getElementById("tabs").innerHTML = document.getElementById("wallet-phase-tabs-frame").contentWindow.document.getElementById("alice-active").outerHTML;
storage.set('lastAccount', { lastAccount: 'alice' }, function (error) {
if (error) throw error;
});
}
else if (tabItem === "bob") {
- document.getElementById("tabs").innerHTML = document.getElementById("wallet-phase-tabs-frame").contentWindow.document.getElementById("bob-active").innerHTML;
+ document.getElementById("tabs").innerHTML = document.getElementById("wallet-phase-tabs-frame").contentWindow.document.getElementById("bob-active").outerHTML;
storage.set('lastAccount', { lastAccount: 'bob' }, function (error) {
if (error) throw error;
});
@@ -28,7 +28,6 @@ function walletPhaseShow(tabItem = "") {
walletShow('receive');
document.getElementById("before-menu-br").outerHTML = "";
- document.getElementById("balances").innerHTML = '<h4><span class="label label-default" style="display:block;">Available: 3.123213123 BTC, Incoming: 2023.321323 BTC </span></h4>';
document.getElementById("content").innerHTML = "content not imlemented";
}
@@ -44,4 +43,23 @@ function walletShow(menuItem) {
document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("history-active").innerHTML;
writeHint('HiddenWallet? Easy Peasy Lemon Squeezey!');
}
+
+ updateWalletContent();
+}
+
+function updateWalletContent() {
+ var bobOrAlice = document.getElementById("tabs").firstElementChild.id;
+ if (bobOrAlice == "alice-active") {
+ var obj = new Object();
+ obj.account = "alice";
+ var resp = httpGetWallet("balances/alice", obj);
+ document.getElementById("balances").innerHTML = '<h4><span class="label label-default" style="display:block;">Available: ' + resp.Available + ' BTC, Incoming: ' + resp.Incoming +' BTC </span></h4>';
+ }
+ else if (bobOrAlice == "bob-active") {
+ var obj = new Object();
+ obj.account = "bob";
+ var resp = httpGetWallet("balances/bob", obj);
+ document.getElementById("balances").innerHTML = '<h4><span class="label label-default" style="display:block;">Available: ' + resp.Available + ' BTC, Incoming: ' + resp.Incoming + ' BTC </span></h4>';
+ }
+
}
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/index.html
HiddenWallet/HiddenWallet.GUI/index.html
</div>
<div id="status" style="position:absolute; bottom:1px; width: 100%;"></div>
+ <script src="app/js/hw-client.js"></script>
<script src="app/js/default.js"></script>
<script src="app/js/settings.js"></script>
<script src="app/js/status.js"></script>

Add balances label