Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Label class (MempoolStore Breakdown Part 3) #2201

Merged
merged 16 commits into from Sep 9, 2019
2 changes: 1 addition & 1 deletion WalletWasabi.Gui/Controls/WalletExplorer/CoinViewModel.cs
Expand Up @@ -159,7 +159,7 @@ public string ToolTip

public string AmountBtc => Model.Amount.ToString(false, true);

public string Label => Model.Label;
public string Label => Model.Label.ToString();

public int Height => Model.Height;

Expand Down
Expand Up @@ -177,7 +177,7 @@ private List<(DateTimeOffset dateTime, Height height, Money amount, string label
}
else
{
txRecordList.Add((dateTime, coin.Height, coin.Amount, coin.Label, coin.TransactionId));
txRecordList.Add((dateTime, coin.Height, coin.Amount, coin.Label.ToString(), coin.TransactionId));
}

if (coin.SpenderTransactionId != null)
Expand Down
15 changes: 8 additions & 7 deletions WalletWasabi.Gui/Controls/WalletExplorer/ReceiveTabViewModel.cs
Expand Up @@ -13,6 +13,7 @@
using WalletWasabi.Gui.Tabs.WalletManager;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.KeyManagement;
using WalletWasabi.Models;

namespace WalletWasabi.Gui.Controls.WalletExplorer
{
Expand Down Expand Up @@ -43,8 +44,9 @@ public ReceiveTabViewModel(WalletViewModel walletViewModel)

GenerateCommand = ReactiveCommand.Create(() =>
{
Label = Label.Trim(',', ' ').Trim();
if (string.IsNullOrWhiteSpace(Label))
var label = new SmartLabel(Label);
Label = label.ToString();
if (label.IsEmpty)
{
LabelRequiredNotificationVisible = true;
LabelRequiredNotificationOpacity = 1;
Expand All @@ -60,8 +62,7 @@ public ReceiveTabViewModel(WalletViewModel walletViewModel)

Dispatcher.UIThread.PostLogException(() =>
{
var label = Label;
HdPubKey newKey = Global.WalletService.GetReceiveKey(label, Addresses.Select(x => x.Model).Take(7)); // Never touch the first 7 keys.
HdPubKey newKey = Global.WalletService.GetReceiveKey(new SmartLabel(Label), Addresses.Select(x => x.Model).Take(7)); // Never touch the first 7 keys.

AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
if (found != default)
Expand Down Expand Up @@ -164,7 +165,7 @@ private void InitializeAddresses()
}

foreach (HdPubKey key in walletService.KeyManager.GetKeys(x =>
x.HasLabel
!x.Label.IsEmpty
&& !x.IsInternal
&& x.KeyState == KeyState.Clean)
.Reverse())
Expand Down Expand Up @@ -233,8 +234,8 @@ private void UpdateSuggestions(string words)
}

var labels = Global.WalletService.GetLabels();
IEnumerable<string> suggestedWords = labels.Where(w => w.StartsWith(lastWord, StringComparison.InvariantCultureIgnoreCase))
.Union(labels.Where(w => w.Contains(lastWord, StringComparison.InvariantCultureIgnoreCase)))
IEnumerable<string> suggestedWords = labels.Where(w => w.StartsWith(lastWord, StringComparison.OrdinalIgnoreCase))
.Union(labels.Where(w => w.Contains(lastWord, StringComparison.OrdinalIgnoreCase)))
.Except(enteredWordList)
.Take(3);

Expand Down
11 changes: 6 additions & 5 deletions WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
Expand Up @@ -222,9 +222,10 @@ public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuild

OnAddressPasteCommand = ReactiveCommand.Create((BitcoinUrlBuilder url) =>
{
if (!string.IsNullOrWhiteSpace(url.Label))
var label = new SmartLabel(url.Label);
if (!label.IsEmpty)
{
Label = url.Label;
Label = label.ToString();
}

if (url.Amount != null)
Expand All @@ -241,8 +242,9 @@ public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuild
IsBusy = true;
MainWindowViewModel.Instance.StatusBar.TryAddStatus(StatusBarStatus.BuildingTransaction);

Label = Label.Trim(',', ' ').Trim();
if (!IsMax && string.IsNullOrWhiteSpace(Label))
var label = new SmartLabel(Label);
Label = label.ToString();
if (!IsMax && label.IsEmpty)
{
SetWarningMessage($"{nameof(Label)} is required.");
return;
Expand Down Expand Up @@ -298,7 +300,6 @@ public SendTabViewModel(WalletViewModel walletViewModel, bool isTransactionBuild
bool useCustomFee = !IsSliderFeeUsed;
var feeStrategy = FeeStrategy.CreateFromFeeRate(FeeRate);

var label = Label;
var intent = new PaymentIntent(address, moneyRequest, label);
try
{
Expand Down
5 changes: 3 additions & 2 deletions WalletWasabi.Gui/ViewModels/AddressViewModel.cs
Expand Up @@ -10,6 +10,7 @@
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.KeyManagement;
using WalletWasabi.Models;

namespace WalletWasabi.Gui.ViewModels
{
Expand All @@ -33,7 +34,7 @@ public AddressViewModel(HdPubKey model, Global global)
Model = model;
ClipboardNotificationVisible = false;
ClipboardNotificationOpacity = 0;
_label = model.Label;
_label = model.Label.ToString();

this.WhenAnyValue(x => x.IsExpanded)
.ObserveOn(RxApp.TaskpoolScheduler)
Expand Down Expand Up @@ -70,7 +71,7 @@ public AddressViewModel(HdPubKey model, Global global)

if (hdPubKey != default)
{
hdPubKey.SetLabel(newLabel, kmToFile: keyManager);
hdPubKey.SetLabel(new SmartLabel(newLabel), kmToFile: keyManager);
}
}
});
Expand Down