Skip to content

Commit ca93b88

Browse files
Code cleanup
1 parent 2b4abb4 commit ca93b88

File tree

4 files changed

+79
-105
lines changed

4 files changed

+79
-105
lines changed

SharpPusher/MVVM/DependsOnPropertyAttribute.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ namespace SharpPusher.MVVM
1111
public sealed class DependsOnPropertyAttribute : Attribute
1212
{
1313
/// <summary>
14-
/// Instantiates an instance with only 1 depending properties.
14+
/// Initializes a new instance of <see cref="DependsOnPropertyAttribute"/> using depending properties names.
1515
/// </summary>
16-
/// <param name="dependingPropertyName">Name of the property to depend on.</param>
17-
public DependsOnPropertyAttribute(string dependingPropertyName)
18-
{
19-
DependentProps = new string[] { dependingPropertyName };
20-
}
21-
22-
/// <summary>
23-
/// Instantiates an instance with an array of depending properties.
24-
/// </summary>
25-
/// <param name="dependingPropertyNames">Array of Names of the properties to depend on.</param>
26-
public DependsOnPropertyAttribute(string[] dependingPropertyNames)
16+
/// <param name="dependingPropertyNames">Names of the properties that the property with this attribute depends on.</param>
17+
public DependsOnPropertyAttribute(params string[] dependingPropertyNames)
2718
{
2819
DependentProps = dependingPropertyNames;
2920
}

SharpPusher/Services/Api.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,23 @@ public abstract class Api
3535
/// <returns>Result of broadcasting.</returns>
3636
protected static async Task<Response<string>> PushTx(string txHex, string jKey, string url)
3737
{
38-
Response<string> resp = new Response<string>();
38+
Response<string> resp = new();
3939

40-
using (HttpClient client = new HttpClient())
40+
using HttpClient client = new();
41+
try
4142
{
42-
try
43+
JObject tx = new()
4344
{
44-
JObject tx = new JObject()
45-
{
46-
{jKey, txHex}
47-
};
48-
49-
HttpResponseMessage httpResp = await client.PostAsync(url, new StringContent(tx.ToString()));
50-
resp.Result = await httpResp.Content.ReadAsStringAsync();
51-
}
52-
catch (Exception ex)
53-
{
54-
string errMsg = (ex.InnerException == null) ? ex.Message : ex.Message + " " + ex.InnerException;
55-
resp.Errors.Add(errMsg);
56-
}
45+
{jKey, txHex}
46+
};
47+
48+
HttpResponseMessage httpResp = await client.PostAsync(url, new StringContent(tx.ToString()));
49+
resp.Result = await httpResp.Content.ReadAsStringAsync();
50+
}
51+
catch (Exception ex)
52+
{
53+
string errMsg = (ex.InnerException == null) ? ex.Message : ex.Message + " " + ex.InnerException;
54+
resp.Errors.Add(errMsg);
5755
}
5856

5957
return resp;

SharpPusher/ViewModels/MainWindowViewModel.cs

Lines changed: 62 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ public MainWindowViewModel()
3030

3131
Version ver = Assembly.GetExecutingAssembly().GetName().Version ?? new Version(0, 0, 0);
3232
VersionString = ver.ToString(3);
33-
34-
_rawTx = string.Empty;
3533
}
3634

3735
public string VersionString { get; }
3836

3937

40-
private string _rawTx;
38+
private string _rawTx = string.Empty;
4139
public string RawTx
4240
{
4341
get => _rawTx;
@@ -79,7 +77,7 @@ public enum Networks
7977
private Networks _selNet;
8078
public Networks SelectedNetwork
8179
{
82-
get { return _selNet; }
80+
get => _selNet;
8381
set
8482
{
8583
if (SetField(ref _selNet, value))
@@ -93,122 +91,122 @@ private void SetApiList()
9391
switch (SelectedNetwork)
9492
{
9593
case Networks.Bitcoin:
96-
ApiList = new ObservableCollection<Api>()
97-
{
94+
ApiList =
95+
[
9896
new Blockchair(Blockchair.Chain.BTC),
9997
new Smartbit(),
10098
new BlockCypher(),
10199
new P2P(true)
102-
};
100+
];
103101
break;
104102
case Networks.BitcoinCash:
105-
ApiList = new ObservableCollection<Api>()
106-
{
103+
ApiList =
104+
[
107105
new Blockchair(Blockchair.Chain.BCH),
108-
};
106+
];
109107
break;
110108
case Networks.Dogecoin:
111-
ApiList = new ObservableCollection<Api>()
112-
{
109+
ApiList =
110+
[
113111
new Blockchair(Blockchair.Chain.DOGE),
114-
};
112+
];
115113
break;
116114
case Networks.Litecoin:
117-
ApiList = new ObservableCollection<Api>()
118-
{
115+
ApiList =
116+
[
119117
new Blockchair(Blockchair.Chain.LTC),
120-
};
118+
];
121119
break;
122120
case Networks.Monero:
123-
ApiList = new ObservableCollection<Api>()
124-
{
121+
ApiList =
122+
[
125123
new Blockchair(Blockchair.Chain.XMR),
126-
};
124+
];
127125
break;
128126
case Networks.BitcoinTestnet:
129-
ApiList = new ObservableCollection<Api>()
130-
{
127+
ApiList =
128+
[
131129
new Blockchair(Blockchair.Chain.TBTC),
132130
new P2P(false)
133-
};
131+
];
134132
break;
135133
case Networks.BitcoinSV:
136-
ApiList = new ObservableCollection<Api>()
137-
{
134+
ApiList =
135+
[
138136
new Blockchair(Blockchair.Chain.BSV),
139-
};
137+
];
140138
break;
141139
case Networks.Zcash:
142-
ApiList = new ObservableCollection<Api>()
143-
{
140+
ApiList =
141+
[
144142
new Blockchair(Blockchair.Chain.ZEC),
145-
};
143+
];
146144
break;
147145
case Networks.Ripple:
148-
ApiList = new ObservableCollection<Api>()
149-
{
146+
ApiList =
147+
[
150148
new Blockchair(Blockchair.Chain.XRP),
151-
};
149+
];
152150
break;
153151
case Networks.Stellar:
154-
ApiList = new ObservableCollection<Api>()
155-
{
152+
ApiList =
153+
[
156154
new Blockchair(Blockchair.Chain.XLM),
157-
};
155+
];
158156
break;
159157
case Networks.Cardano:
160-
ApiList = new ObservableCollection<Api>()
161-
{
158+
ApiList =
159+
[
162160
new Blockchair(Blockchair.Chain.ADA),
163-
};
161+
];
164162
break;
165163
case Networks.Mixin:
166-
ApiList = new ObservableCollection<Api>()
167-
{
164+
ApiList =
165+
[
168166
new Blockchair(Blockchair.Chain.XIN),
169-
};
167+
];
170168
break;
171169
case Networks.Tezos:
172-
ApiList = new ObservableCollection<Api>()
173-
{
170+
ApiList =
171+
[
174172
new Blockchair(Blockchair.Chain.XTZ),
175-
};
173+
];
176174
break;
177175
case Networks.EOS:
178-
ApiList = new ObservableCollection<Api>()
179-
{
176+
ApiList =
177+
[
180178
new Blockchair(Blockchair.Chain.EOS),
181-
};
179+
];
182180
break;
183181
case Networks.Ethereum:
184-
ApiList = new ObservableCollection<Api>()
185-
{
182+
ApiList =
183+
[
186184
new Blockchair(Blockchair.Chain.ETH),
187-
};
185+
];
188186
break;
189187
case Networks.EthereumTestnet:
190-
ApiList = new ObservableCollection<Api>()
191-
{
188+
ApiList =
189+
[
192190
new Blockchair(Blockchair.Chain.ΤETH),
193-
};
191+
];
194192
break;
195193
case Networks.Groestlcoin:
196-
ApiList = new ObservableCollection<Api>()
197-
{
194+
ApiList =
195+
[
198196
new Blockchair(Blockchair.Chain.GRS),
199-
};
197+
];
200198
break;
201199
case Networks.Dash:
202-
ApiList = new ObservableCollection<Api>()
203-
{
200+
ApiList =
201+
[
204202
new Blockchair(Blockchair.Chain.DASH),
205-
};
203+
];
206204
break;
207205
case Networks.BitcoinABC:
208-
ApiList = new ObservableCollection<Api>()
209-
{
206+
ApiList =
207+
[
210208
new Blockchair(Blockchair.Chain.ABC),
211-
};
209+
];
212210
break;
213211
}
214212
}
@@ -282,8 +280,8 @@ private async void BroadcastTx()
282280
if (IsCheckTxVisible && CheckTx)
283281
{
284282
Debug.Assert(result != null);
285-
var stream = new FastStreamReader(result);
286-
var tx = new Transaction();
283+
FastStreamReader stream = new(result);
284+
Transaction tx = new();
287285
if (!tx.TryDeserialize(stream, out Errors error))
288286
{
289287
Status = $"Invalid transaction. Error message: {error.Convert()}";
@@ -325,14 +323,7 @@ private async void BroadcastTx()
325323
}
326324
private bool CanBroadcast()
327325
{
328-
if (!string.IsNullOrWhiteSpace(RawTx) && !IsSending && SelectedApi != null)
329-
{
330-
return true;
331-
}
332-
else
333-
{
334-
return false;
335-
}
326+
return !string.IsNullOrWhiteSpace(RawTx) && !IsSending && SelectedApi != null;
336327
}
337328
}
338329
}

SharpPusher/Views/MainWindow.axaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
55

66
using Avalonia.Controls;
7-
using Avalonia.Markup.Xaml;
87

98
namespace SharpPusher.Views
109
{
@@ -14,10 +13,5 @@ public MainWindow()
1413
{
1514
InitializeComponent();
1615
}
17-
18-
private void InitializeComponent()
19-
{
20-
AvaloniaXamlLoader.Load(this);
21-
}
2216
}
2317
}

0 commit comments

Comments
 (0)