Skip to content

Commit 9a909e7

Browse files
author
Kristifor
committed
Hot wallet support
1 parent 85cd00a commit 9a909e7

File tree

9 files changed

+402
-143
lines changed

9 files changed

+402
-143
lines changed

Models/Enums.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace SYNCWallet.Models
2+
{
3+
public class Enums
4+
{
5+
public enum ConfigMode
6+
{
7+
HotWallet,
8+
ColdWallet
9+
}
10+
}
11+
}

Models/HardwareWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace SYNCWallet.Models
88
{
9-
internal class HardwareWallet
9+
public class HardwareWallet
1010
{
1111
public string Cmd { get; set; }
1212
public string PrivateKey { get; set; }

Pages/Create.razor

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
var getWords = await JS.InvokeAsync<List<string>>("GetImportWords");
245245
var words = new List<Word>();
246246

247-
247+
248248

249249
getWords.ForEach(x =>
250250
{
@@ -302,20 +302,37 @@
302302
private void CreateWallet()
303303
{
304304

305-
try
305+
try
306306
{
307307
var passwrod = HardwareService.Encrypt(PassCode, "iV1z@$H8");
308308
var PK = HardwareService.Encrypt(Wallet.PrivateKey, PassCode);
309309

310-
Communication.WriteState(JsonConvert.SerializeObject(new HardwareWallet
310+
switch (Communication.SoftwareType)
311311
{
312-
Cmd = "NEW",
313-
Password = passwrod,
314-
PrivateKey = PK
315-
}));
312+
case Enums.ConfigMode.ColdWallet:
313+
Communication.WriteState(JsonConvert.SerializeObject(new HardwareWallet
314+
{
315+
Cmd = "NEW",
316+
Password = passwrod,
317+
PrivateKey = PK
318+
}));
319+
320+
break;
321+
case Enums.ConfigMode.HotWallet:
322+
323+
Communication.WriteInternalStorage(new HardwareWallet
324+
{
325+
Cmd = "NEW",
326+
Password = passwrod,
327+
PrivateKey = PK
328+
});
329+
break;
330+
}
331+
316332
Communication.IsConfigured = true;
317333
Communication.ConfigResponse = true;
318334
NavigationManager.NavigateTo("/LoginPanel");
335+
319336
}
320337
catch (Exception e)
321338
{

Pages/HardwareSelect.razor

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
@page "/HardwareSelect"
2+
@using System.Net
3+
@using System.Timers
4+
@using System.Numerics
5+
@using ArduinoUploader.Hardware
6+
@using NFTLock.Data
7+
@using System.IO.Ports
8+
@using System.Diagnostics
9+
@using SYNCWallet.Services
10+
@using SYNCWallet.Services.Definitions
11+
@using static SYNCWallet.Models.Enums
12+
13+
@inject NavigationManager NavigationManager
14+
@inject IJSRuntime JS
15+
16+
17+
18+
<div class="container FixCenter" id="LoginPanel" style="height:100vh; display:flex;">
19+
<div class="row" style="width: 100%;display: flex;justify-content: center;align-items: center; padding:0; margin:0;">
20+
<div class="col-md-4 col-sm-12 " style=" min-width: 500px;">
21+
<div class="row" style="display: flex;flex-direction: row;align-items: center;justify-content: center;">
22+
<img src="/logo.png" style="width: 250px;height: 200px;" alt="homepage" class="light-logo" />
23+
24+
</div>
25+
<div class="row" style="margin-top: 50px;">
26+
<h2 style="color:#EA7080; text-align:center; font-size:25pt;padding: 50px;">
27+
Connect and select ATmega328 compatable device.
28+
</h2>
29+
</div>
30+
<a class="nav-link dropdown-toggle waves-effect waves-dark" href="#" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="color: black;font-weight: 400; text-align:center;">
31+
<i class="me-2 mdi mdi-access-point-network"></i>
32+
<span id="network" style="text-align:center; width:100%;">@DeviceModel.ToString()</span>
33+
34+
</a>
35+
<div id="dropdownNetworks" class="dropdown-menu dropdown-menu-end user-dd animated flipInY" style="left: 68%;top: 4%; position:absolute !important; height:150px; overflow-y:scroll;background: #282931;">
36+
@if (Devices != null)
37+
{
38+
@foreach (var device in Devices)
39+
{
40+
<a class="dropdown-item" @onclick="(() => DeviceChanged(device))">
41+
<i class="me-2 mdi mdi-access-point-network"></i>
42+
@device.ToString()
43+
</a>
44+
}
45+
46+
}
47+
</div>
48+
</div>
49+
</div>
50+
</div>
51+
52+
@code {
53+
private ICommunication Communication { get; set; }
54+
private IAuthenicationService AuthenicationHandler { get; set; }
55+
private IHardwareService HardwareService { get; set; }
56+
private string Address { get; set; }
57+
private string Port{ get; set; }
58+
59+
public ArduinoModel DeviceModel { get; set; }
60+
public List<ArduinoModel> Devices { get; set; }
61+
62+
System.Timers.Timer aTimer { get; set; }
63+
64+
protected override Task OnAfterRenderAsync(bool firstRender)
65+
{
66+
67+
return base.OnAfterRenderAsync(firstRender);
68+
}
69+
70+
protected override async Task OnInitializedAsync()
71+
{
72+
73+
AuthenicationHandler = ServiceHelper.GetService<IAuthenicationService>();
74+
HardwareService = ServiceHelper.GetService<IHardwareService>();
75+
Communication = ServiceHelper.GetService<ICommunication>();
76+
77+
78+
Communication.Init();
79+
//Get Supported Devices
80+
Devices = HardwareService.GetSupportedDevices();
81+
82+
Port = HardwareService.DeviceConnected();
83+
aTimer = new System.Timers.Timer();
84+
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
85+
aTimer.Interval = 5000;
86+
aTimer.Start();
87+
88+
}
89+
90+
// Specify what you want to happen when the Elapsed event is raised.
91+
private void OnTimedEvent(object source, ElapsedEventArgs e)
92+
{
93+
94+
Port = HardwareService.DeviceConnected();
95+
if(!string.IsNullOrEmpty(Port))
96+
{
97+
aTimer.Stop();
98+
aTimer.Dispose();
99+
}
100+
}
101+
102+
private async Task<bool> CheckDeviceConnected(string port)
103+
{
104+
105+
try
106+
{
107+
if (!string.IsNullOrEmpty(port))
108+
{
109+
var firmwareUpdated = HardwareService.CreateNewDevice(port);
110+
111+
var configStatus = Communication.CheckConfigured(ConfigMode.ColdWallet);
112+
113+
if (configStatus && firmwareUpdated)
114+
{
115+
116+
KillTimer();
117+
NavigationManager.NavigateTo("LoginPanel");
118+
}
119+
else
120+
{
121+
KillTimer();
122+
NavigationManager.NavigateTo("Create");
123+
124+
}
125+
}
126+
127+
}
128+
catch (Exception e)
129+
{
130+
131+
throw;
132+
}
133+
134+
return true;
135+
}
136+
137+
138+
private void KillTimer()
139+
{
140+
if (aTimer != null)
141+
{
142+
aTimer.Stop();
143+
aTimer.Dispose();
144+
}
145+
}
146+
147+
private void DeviceChanged(ArduinoModel deviceType)
148+
{
149+
InvokeAsync(async () =>
150+
{
151+
DeviceModel = deviceType;
152+
Communication.DeviceType = deviceType;
153+
await CheckDeviceConnected(Port);
154+
StateHasChanged();
155+
156+
});
157+
158+
159+
160+
}
161+
}

0 commit comments

Comments
 (0)