Ejemplo n.º 1
0
        public void LabelEqualityTests()
        {
            var label  = new SmartLabel("foo");
            var label2 = new SmartLabel(label.ToString());

            Assert.Equal(label, label2);

            label  = new SmartLabel("foo, bar, buz");
            label2 = new SmartLabel(label.ToString());
            Assert.Equal(label, label2);

            label2 = new SmartLabel("bar, buz, foo");
            Assert.Equal(label, label2);

            var label3 = new SmartLabel("bar, buz");

            Assert.NotEqual(label, label3);

            SmartLabel label4 = null;
            SmartLabel label5 = null;

            Assert.Equal(label4, label5);
            Assert.NotEqual(label, label4);
            Assert.False(label.Equals(label4));
            Assert.False(label == label4);
        }
Ejemplo n.º 2
0
        public void SpecialLabelTests()
        {
            var label = new SmartLabel("");

            Assert.Equal(label, SmartLabel.Empty);
            Assert.True(label.IsEmpty);

            label = new SmartLabel("foo, bar, buz");
            var label2 = new SmartLabel("qux");

            label = SmartLabel.Merge(label, label2);
            Assert.Equal("bar, buz, foo, qux", label.ToString());

            label2 = new SmartLabel("qux", "bar");
            label  = SmartLabel.Merge(label, label2);
            Assert.Equal(4, label.Labels.Count());
            Assert.Equal("bar, buz, foo, qux", label.ToString());

            label2 = new SmartLabel("Qux", "Bar");
            label  = SmartLabel.Merge(label, label2, null);
            Assert.Equal(4, label.Labels.Count());
            Assert.Equal("bar, buz, foo, qux", label.ToString());
        }
Ejemplo n.º 3
0
        public ReceiveTabViewModel(WalletViewModel walletViewModel)
            : base("Receive", walletViewModel)
        {
            _addresses = new ObservableCollection <AddressViewModel>();
            Label      = "";

            InitializeAddresses();

            GenerateCommand = ReactiveCommand.Create(() =>
            {
                var label = new SmartLabel(Label);
                Label     = label.ToString();
                if (label.IsEmpty)
                {
                    LabelRequiredNotificationVisible = true;
                    LabelRequiredNotificationOpacity = 1;

                    Dispatcher.UIThread.PostLogException(async() =>
                    {
                        await Task.Delay(TimeSpan.FromSeconds(4));
                        LabelRequiredNotificationOpacity = 0;
                    });

                    return;
                }

                Dispatcher.UIThread.PostLogException(() =>
                {
                    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)
                    {
                        Addresses.Remove(found);
                    }

                    var newAddress = new AddressViewModel(newKey, Global);

                    Addresses.Insert(0, newAddress);

                    SelectedAddress = newAddress;

                    Label = "";
                });
            });

            this.WhenAnyValue(x => x.Label).Subscribe(UpdateSuggestions);

            this.WhenAnyValue(x => x.SelectedAddress).Subscribe(async address =>
            {
                if (Global.UiConfig?.Autocopy is false || address is null)
                {
                    return;
                }

                await address.TryCopyToClipboardAsync();
            });

            var isCoinListItemSelected = this.WhenAnyValue(x => x.SelectedAddress).Select(coin => coin != null);

            CopyAddress = ReactiveCommand.CreateFromTask(async() =>
            {
                if (SelectedAddress is null)
                {
                    return;
                }

                await SelectedAddress.TryCopyToClipboardAsync();
            },
                                                         isCoinListItemSelected);

            CopyLabel = ReactiveCommand.CreateFromTask(async() =>
            {
                try
                {
                    await Application.Current.Clipboard.SetTextAsync(SelectedAddress.Label ?? string.Empty);
                }
                catch (Exception)
                { }
            },
                                                       isCoinListItemSelected);

            ToggleQrCode = ReactiveCommand.Create(() =>
            {
                try
                {
                    SelectedAddress.IsExpanded = !SelectedAddress.IsExpanded;
                }
                catch (Exception)
                { }
            },
                                                  isCoinListItemSelected);

#pragma warning disable IDE0053 // Use expression body for lambda expressions
            ChangeLabelCommand = ReactiveCommand.Create(() => { SelectedAddress.InEditMode = true; });
#pragma warning restore IDE0053 // Use expression body for lambda expressions

            DisplayAddressOnHwCommand = ReactiveCommand.CreateFromTask(async() =>
            {
                var client    = new HwiClient(Global.Network);
                using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
                try
                {
                    await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, SelectedAddress.Model.FullKeyPath, cts.Token);
                }
                catch (HwiException)
                {
                    await PinPadViewModel.UnlockAsync(Global);
                    await client.DisplayAddressAsync(KeyManager.MasterFingerprint.Value, SelectedAddress.Model.FullKeyPath, cts.Token);
                }
            });

            _suggestions = new ObservableCollection <SuggestionViewModel>();
        }
Ejemplo n.º 4
0
		public ReceiveTabViewModel(WalletViewModel walletViewModel)
			: base("Receive", walletViewModel)
		{
			_addresses = new ObservableCollection<AddressViewModel>();
			Label = "";

			InitializeAddresses();

			GenerateCommand = ReactiveCommand.Create(() =>
			{
				var label = new SmartLabel(Label);
				Label = label.ToString();
				if (label.IsEmpty)
				{
					LabelRequiredNotificationVisible = true;
					LabelRequiredNotificationOpacity = 1;

					Dispatcher.UIThread.PostLogException(async () =>
					{
						await Task.Delay(TimeSpan.FromSeconds(4));
						LabelRequiredNotificationOpacity = 0;
					});

					return;
				}

				Dispatcher.UIThread.PostLogException(() =>
				{
					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)
					{
						Addresses.Remove(found);
					}

					var newAddress = new AddressViewModel(newKey, Global);

					Addresses.Insert(0, newAddress);

					SelectedAddress = newAddress;

					Label = "";
				});
			});

			this.WhenAnyValue(x => x.Label).Subscribe(UpdateSuggestions);

			this.WhenAnyValue(x => x.SelectedAddress).Subscribe(async address =>
			{
				if (Global.UiConfig?.Autocopy is false || address is null)
				{
					return;
				}

				await address.TryCopyToClipboardAsync();
			});

			var isCoinListItemSelected = this.WhenAnyValue(x => x.SelectedAddress).Select(coin => coin != null);

			CopyAddress = ReactiveCommand.CreateFromTask(async () =>
			{
				if (SelectedAddress is null)
				{
					return;
				}

				await SelectedAddress.TryCopyToClipboardAsync();
			}, isCoinListItemSelected);

			CopyLabel = ReactiveCommand.CreateFromTask(async () =>
			{
				try
				{
					await Application.Current.Clipboard.SetTextAsync(SelectedAddress.Label ?? string.Empty);
				}
				catch (Exception)
				{ }
			}, isCoinListItemSelected);

			ShowQrCode = ReactiveCommand.Create(() =>
			{
				try
				{
					SelectedAddress.IsExpanded = true;
				}
				catch (Exception)
				{ }
			}, isCoinListItemSelected);

			ChangeLabelCommand = ReactiveCommand.Create(() =>
			{
				SelectedAddress.InEditMode = true;
			});

			_suggestions = new ObservableCollection<SuggestionViewModel>();
		}
Ejemplo n.º 5
0
        public void LabelParsingTests()
        {
            var label = new SmartLabel();

            Assert.Equal("", label.ToString());

            label = new SmartLabel("");
            Assert.Equal("", label.ToString());

            label = new SmartLabel(null);
            Assert.Equal("", label.ToString());

            label = new SmartLabel(null, null);
            Assert.Equal("", label.ToString());

            label = new SmartLabel(" ");
            Assert.Equal("", label.ToString());

            label = new SmartLabel(",");
            Assert.Equal("", label.ToString());

            label = new SmartLabel(":");
            Assert.Equal("", label.ToString());

            label = new SmartLabel("foo");
            Assert.Equal("foo", label.ToString());

            label = new SmartLabel("foo", "bar");
            Assert.Equal("bar, foo", label.ToString());

            label = new SmartLabel("foo bar");
            Assert.Equal("foo bar", label.ToString());

            label = new SmartLabel("foo bar", "Buz quX@");
            Assert.Equal("Buz quX@, foo bar", label.ToString());

            label = new SmartLabel(new List <string>()
            {
                "foo", "bar"
            });
            Assert.Equal("bar, foo", label.ToString());

            label = new SmartLabel("  foo    ");
            Assert.Equal("foo", label.ToString());

            label = new SmartLabel("foo      ", "      bar");
            Assert.Equal("bar, foo", label.ToString());

            label = new SmartLabel(new List <string>()
            {
                "   foo   ", "   bar    "
            });
            Assert.Equal("bar, foo", label.ToString());

            label = new SmartLabel(new List <string>()
            {
                "foo:", ":bar", null, ":buz:", ",", ": , :", "qux:quux", "corge,grault", "", "  ", " , garply, waldo,", " : ,  :  ,  fred  , : , :   plugh, : , : ,"
            });
            Assert.Equal("bar, buz, corge, foo, fred, garply, grault, plugh, quux, qux, waldo", label.ToString());

            label = new SmartLabel(",: foo::bar :buz:,: , :qux:quux, corge,grault  , garply, waldo, : ,  :  ,  fred  , : , :   plugh, : , : ,");
            Assert.Equal("bar, buz, corge, foo, fred, garply, grault, plugh, quux, qux, waldo", label.ToString());
        }