Add network switch
MODIFY
HiddenWallet.Daemon/Config.cs
HiddenWallet.Daemon/Config.cs
@@ -38,6 +38,8 @@ namespace HiddenWallet.Daemon
[JsonProperty(PropertyName = "ChaumianTumblerMainNotificationAddress", Order = 7)]
public string ChaumianTumblerMainNotificationAddress { get; private set; }
+ private string ConfigPath { get; set; }
+
public Config()
{
@@ -45,7 +47,7 @@ namespace HiddenWallet.Daemon
public async Task ToFileAsync(string path, CancellationToken cancel)
{
- if (path == null) throw new ArgumentNullException(nameof(path));
+ ConfigPath = string.IsNullOrWhiteSpace(path) ? throw new ArgumentNullException(nameof(path)) : path;
string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);
await File.WriteAllTextAsync(path,
@@ -58,6 +60,7 @@ namespace HiddenWallet.Daemon
{
if (path == null) throw new ArgumentNullException(nameof(path));
+
WalletFilePath = Path.Combine(FullSpvWallet.Global.DataDir, "Wallets", "Wallet.json");
Network = Network.Main;
CanSpendUnconfirmed = true;
@@ -86,5 +89,17 @@ namespace HiddenWallet.Daemon
await ToFileAsync(path, cancel);
}
+
+ public async Task SetNetworkAsync(Network network)
+ {
+ if (network == null) throw new ArgumentNullException(nameof(network));
+ if (network == Network)
+ {
+ return;
+ }
+
+ Network = network;
+ await ToFileAsync(ConfigPath, CancellationToken.None);
+ }
}
}

MODIFY
HiddenWallet.Daemon/Controllers/WalletController.cs
HiddenWallet.Daemon/Controllers/WalletController.cs
@@ -65,7 +65,7 @@ namespace HiddenWallet.Daemon.Controllers
[Route("load")]
[HttpPost]
- public async Task<IActionResult> LoadAsync([FromBody]PasswordModel request)
+ public async Task<IActionResult> LoadAsync([FromBody]LoadModel request)
{
if (request == null || request.Password == null)
{
@@ -74,7 +74,14 @@ namespace HiddenWallet.Daemon.Controllers
try
{
- await Global.WalletWrapper.LoadAsync(request.Password, Global.Config.Network);
+ Network network = Global.Config.Network;
+ if(!string.IsNullOrWhiteSpace(request.Network))
+ {
+ network = Network.GetNetwork(request.Network);
+ await Global.Config.SetNetworkAsync(network);
+ }
+
+ await Global.WalletWrapper.LoadAsync(request.Password, network);
return new ObjectResult(new SuccessResponse());
}
@@ -84,6 +91,24 @@ namespace HiddenWallet.Daemon.Controllers
}
}
+ [Route("is-mainnet")]
+ [HttpGet]
+ public IActionResult IsMainnet()
+ {
+ try
+ {
+ if (Global.Config.Network == Network.Main)
+ {
+ return new ObjectResult(new YesNoResponse { Value = true });
+ }
+ return new ObjectResult(new YesNoResponse { Value = false });
+ }
+ catch (Exception ex)
+ {
+ return new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() });
+ }
+ }
+
[Route("wallet-exists")]
[HttpGet]
public IActionResult WalletExists()

MODIFY
HiddenWallet.Gui/HiddenWallet.GUI.njsproj
HiddenWallet.Gui/HiddenWallet.GUI.njsproj
<SubType>Code</SubType>
</Content>
<Content Include="app\css\justified-nav.css" />
+ <Content Include="app\css\slider.css" />
<Content Include="app\html\broadcast-transaction-window.html" />
<Content Include="app\html\decryption-phase-content.html" />
<Content Include="app\html\decryption-phase-menu.html" />

ADD
HiddenWallet.Gui/app/css/slider.css
+.switch {
+ position: relative;
+ display: inline-block;
+ width: 160px;
+ height: 34px;
+}
+
+ .switch input {
+ display: none;
+ }
+
+.slider {
+ position: absolute;
+ cursor: pointer;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background-color: #ccc;
+ -webkit-transition: .4s;
+ -moz-transition: .4s;
+ -o-transition: .4s;
+ transition: .4s;
+}
+
+ .slider:before {
+ position: absolute;
+ content: "";
+ height: 26px;
+ width: 26px;
+ left: 4px;
+ bottom: 4px;
+ background-color: white;
+ -webkit-transition: .4s;
+ -moz-transition: .4s;
+ -o-transition: .4s;
+ transition: .4s;
+ }
+
+input:checked + .slider {
+ background-color: #2196F3;
+}
+
+input:focus + .slider {
+ box-shadow: 0 0 1px #2196F3;
+}
+
+input:checked + .slider:before {
+ -webkit-transform: translateX(55px);
+ -moz-transform: translateX(55px);
+ -o-transform: translateX(55px);
+ -ms-transform: translateX(55px);
+ transform: translateX(126px);
+}
+
+/*------ ADDED CSS ---------*/
+.on {
+ display: none;
+}
+
+.on, .off {
+ color: white;
+ position: absolute;
+ transform: translate(-50%,-50%);
+ top: 50%;
+ left: 50%;
+ font-size: 10px;
+ font-family: Verdana, sans-serif;
+}
+
+input:checked + .slider .on {
+ display: block;
+}
+
+input:checked + .slider .off {
+ display: none;
+}
+
+/*--------- END --------*/
+
+/* Rounded sliders */
+.slider.round {
+ border-radius: 34px;
+}
+
+ .slider.round:before {
+ border-radius: 50%;
+ }

MODIFY
HiddenWallet.Gui/app/html/decryption-phase-content.html
HiddenWallet.Gui/app/html/decryption-phase-content.html
<div class="jumbotron" id="decrypt-content">
+ <div align="right">
+ <label class="switch">
+ <input type="checkbox" id="network-toggle-button">
+ <span class="slider">
+ <span class="on">Main Network</span>
+ <span class="off">Test Network</span>
+ </span>
+ </label>
+ </div>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" />
<br />
<button id="decrypt-wallet-button" disabled class="btn btn-lg btn-primary btn-block" onclick="decryptWallet()">Decrypt</button>

MODIFY
HiddenWallet.Gui/app/js/decryption-phase.ts
HiddenWallet.Gui/app/js/decryption-phase.ts
@@ -61,6 +61,16 @@ function decryptionPhaseShow(menuItem: string = "") {
else {
content.innerHTML = '<div class="alert alert-warning" role="alert"><strong>No wallet found!</strong> Generate or recover your wallet before decrypting it!</div>';
}
+
+ let isMainnet: boolean = httpGetWallet("is-mainnet").Value;
+ let networkToggleButton: HTMLInputElement = document.getElementById("network-toggle-button") as HTMLInputElement;
+ if (isMainnet === true)
+ {
+ networkToggleButton.checked = true;
+ }
+ else {
+ networkToggleButton.checked = false;
+ }
}
else if (menuItem === "generate") {
menu.innerHTML = decPhaseMenuFrame.contentWindow.document.getElementById("generate-active").innerHTML;
@@ -178,6 +188,7 @@ function recoverWallet() {
interface DecryptWallet {
Password: string;
+ Network: string
}
function decryptWallet() {
@@ -187,7 +198,18 @@ function decryptWallet() {
let containerElement: Element = document.getElementsByClassName("container").item(0);
- var obj: DecryptWallet = { Password: password };
+ let networkToggleButton: HTMLInputElement = document.getElementById("network-toggle-button") as HTMLInputElement;
+
+ let network: string;
+ if (networkToggleButton.checked)
+ {
+ network = "Main";
+ }
+ else {
+ network = "TestNet";
+ }
+
+ var obj: DecryptWallet = { Password: password, Network: network };
containerElement.setAttribute("style", "pointer-events:none;");
decWalletButton.innerHTML = '<span class="glyphicon glyphicon-cog spinning"></span> Initializing...';

MODIFY
HiddenWallet.Gui/index.html
HiddenWallet.Gui/index.html
<link rel="stylesheet" href="app/css/justified-nav.css">
<link rel="stylesheet" href="app/css/default.css" />
+ <link rel="stylesheet" href="app/css/slider.css" />
<link rel="stylesheet" media="all" href="node_modules/mdi/css/materialdesignicons.min.css" />
</head>
<body onload="decryptionPhaseShow(); periodicUpdate();">

Add network switch