Finish balances
MODIFY
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
@@ -151,11 +151,19 @@ namespace HiddenWallet.API.Controllers
var trimmed = account;
if (String.Equals(trimmed, "alice", StringComparison.OrdinalIgnoreCase))
{
- return new ObjectResult(new BalancesResponse { Available = 32.1m, Incoming = 0.23534219m });
+ return new ObjectResult(new BalancesResponse
+ {
+ Available = Global.WalletWrapper.GetAvailable(Global.WalletWrapper.AliceAccount).ToString(false, true),
+ Incoming = Global.WalletWrapper.GetIncoming(Global.WalletWrapper.AliceAccount).ToString(false, true)
+ });
}
else if (String.Equals(trimmed, "bob", StringComparison.OrdinalIgnoreCase))
{
- return new ObjectResult(new BalancesResponse { Available = 0.34342m, Incoming = 5m });
+ return new ObjectResult(new BalancesResponse
+ {
+ Available = Global.WalletWrapper.GetAvailable(Global.WalletWrapper.BobAccount).ToString(false, true),
+ Incoming = Global.WalletWrapper.GetIncoming(Global.WalletWrapper.BobAccount).ToString(false, true)
+ });
}
else return new ObjectResult(new FailureResponse { Message = "Wrong account" });
}

MODIFY
HiddenWallet/HiddenWallet.API/Models/BalancesResponse.cs
HiddenWallet/HiddenWallet.API/Models/BalancesResponse.cs
@@ -8,7 +8,7 @@ namespace HiddenWallet.API.Models
public class BalancesResponse : BaseResponse
{
public BalancesResponse() => Success = true;
- public decimal Available { get; set; }
- public decimal Incoming { get; set; }
+ public string Available { get; set; }
+ public string Incoming { get; set; }
}
}

MODIFY
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
@@ -25,8 +25,8 @@ namespace HiddenWallet.API.Wrappers
private string _password = null;
private WalletJob _walletJob = null;
- private readonly SafeAccount _aliceAccount = new SafeAccount(1);
- private readonly SafeAccount _bobAccount = new SafeAccount(2);
+ public readonly SafeAccount AliceAccount = new SafeAccount(1);
+ public readonly SafeAccount BobAccount = new SafeAccount(2);
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
private Task _walletJobTask = Task.CompletedTask;
@@ -34,6 +34,13 @@ namespace HiddenWallet.API.Wrappers
public bool WalletExists => File.Exists(Config.WalletFilePath);
public bool IsDecrypted => !_walletJobTask.IsCompleted && _password != null;
+ private Money _availableAlice = Money.Zero;
+ private Money _availableBob = Money.Zero;
+ private Money _incomingAlice = Money.Zero;
+ private Money _incomingBob = Money.Zero;
+ public Money GetAvailable(SafeAccount account) => account == AliceAccount ? _availableAlice : _availableBob;
+ public Money GetIncoming(SafeAccount account) => account == AliceAccount ? _incomingAlice : _incomingBob;
+
#endregion
public WalletWrapper()
@@ -69,7 +76,7 @@ namespace HiddenWallet.API.Wrappers
// it's not running yet, let's run it
_password = password;
- _walletJob = new WalletJob(safe, trackDefaultSafe: false, accountsToTrack: new SafeAccount[] { _aliceAccount, _bobAccount });
+ _walletJob = new WalletJob(safe, trackDefaultSafe: false, accountsToTrack: new SafeAccount[] { AliceAccount, BobAccount });
_walletJob.BestHeightChanged += _walletJob_BestHeightChanged;
_walletJob.StateChanged += _walletJob_StateChanged;
@@ -94,6 +101,17 @@ namespace HiddenWallet.API.Wrappers
#region EventSubscriptions
private void TrackedTransactions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
+ var aliceHistory = _walletJob.GetSafeHistory(AliceAccount);
+ var bobHistory = _walletJob.GetSafeHistory(BobAccount);
+
+ CalculateBalances(aliceHistory, out Money aa, out Money ia);
+ _availableAlice = aa;
+ _incomingAlice = ia;
+ CalculateBalances(bobHistory, out Money ab, out Money ib);
+ _availableBob = ab;
+ _incomingBob = ib;
+
+ // bump change
if (_changeBump >= 10000)
{
_changeBump = 0;
@@ -104,6 +122,30 @@ namespace HiddenWallet.API.Wrappers
}
}
+ private static void CalculateBalances(IEnumerable<SafeHistoryRecord> history, out Money available, out Money incoming)
+ {
+ available = Money.Zero;
+ incoming = Money.Zero;
+ foreach (var rec in history)
+ {
+ if (rec.Confirmed)
+ {
+ available += rec.Amount;
+ }
+ else
+ {
+ if (rec.Amount < Money.Zero)
+ {
+ available += rec.Amount;
+ }
+ else
+ {
+ incoming += rec.Amount;
+ }
+ }
+ }
+ }
+
private void _walletJob_StateChanged(object sender, EventArgs e)
{
_walletState = _walletJob.State.ToString();

MODIFY
HiddenWallet/HiddenWallet.GUI/app/js/status.js
HiddenWallet/HiddenWallet.GUI/app/js/status.js
@@ -7,12 +7,13 @@ function statusShow(progress, text, progressType = "") {
}
}
+var changeBump = 0;
var walletState;
var headerHeight;
var trackingHeight;
var connectedNodeCount;
var memPoolTransactionCount;
-function periodicStatusUpdate() {
+function periodicUpdate() {
setInterval(function statusUpdate() {
var response = httpGetWallet("status");
@@ -82,5 +83,10 @@ function periodicStatusUpdate() {
if (progress < 50) statusShow(50, text, progressType); //mincheck
else if (progress > 100) statusShow(100, text, progressType); //maxcheck
else statusShow(progress, text, progressType);
+
+ if (response.ChangeBump != changeBump) {
+ updateWalletContent();
+ changeBump = response.ChangeBump;
+ }
}, 1000);
}
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/index.html
HiddenWallet/HiddenWallet.GUI/index.html
<link rel="stylesheet" href="app/css/justified-nav.css">
<link rel="stylesheet" href="app/css/default.css" />
</head>
-<body onload="decryptionPhaseShow(); periodicStatusUpdate();">
+<body onload="decryptionPhaseShow(); periodicUpdate();">
<iframe id="decryption-phase-menu-frame" src="app/html/decryption-phase-menu.html" style="display:none"></iframe>
<iframe id="wallet-menu-frame" src="app/html/wallet-menu.html" style="display:none"></iframe>
<iframe id="decryption-phase-content-frame" src="app/html/decryption-phase-content.html" style="display:none"></iframe>

Finish balances