コード例 #1
0
        public ReceiveTabViewModel(Wallet wallet)
            : base("Receive")
        {
            Global = Locator.Current.GetService <Global>();
            Wallet = wallet;

            LabelSuggestion       = new SuggestLabelViewModel(Wallet);
            _addresses            = new ObservableCollection <AddressViewModel>();
            LabelSuggestion.Label = "";

            InitializeAddresses();

            GenerateCommand = ReactiveCommand.Create(() =>
            {
                var label             = new SmartLabel(LabelSuggestion.Label);
                LabelSuggestion.Label = label;
                if (label.IsEmpty)
                {
                    NotificationHelpers.Warning("Observers are required.");
                    return;
                }

                AvaloniaThreadingExtensions.PostLogException(Dispatcher.UIThread, () =>
                {
                    var newKey = Wallet.KeyManager.GetNextReceiveKey(label, out bool minGapLimitIncreased);
                    if (minGapLimitIncreased)
                    {
                        int minGapLimit     = Wallet.KeyManager.MinGapLimit.Value;
                        int prevMinGapLimit = minGapLimit - 1;
                        NotificationHelpers.Warning($"{nameof(KeyManager.MinGapLimit)} increased from {prevMinGapLimit} to {minGapLimit}.");
                    }

                    var newAddress = new AddressViewModel(newKey, Wallet.KeyManager, this);
                    Addresses.Insert(0, newAddress);
                    SelectedAddress       = newAddress;
                    LabelSuggestion.Label = "";
                });
            });

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

                await address.TryCopyToClipboardAsync();
            });

            Observable
            .Merge(GenerateCommand.ThrownExceptions)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Subscribe(ex =>
            {
                Logger.LogError(ex);
                NotificationHelpers.Error(ex.ToUserFriendlyString());
            });
        }
コード例 #2
0
        public ReceiveTabViewModel(WalletViewModel walletViewModel)
            : base("Receive", walletViewModel)
        {
            _labelSuggestion       = new SuggestLabelViewModel(Global);
            _addresses             = new ObservableCollection <AddressViewModel>();
            _labelSuggestion.Label = "";

            InitializeAddresses();

            GenerateCommand = ReactiveCommand.Create(() =>
            {
                var label = new SmartLabel(_labelSuggestion.Label);
                _labelSuggestion.Label = label;
                if (label.IsEmpty)
                {
                    NotificationHelpers.Warning("Label is required.");
                    return;
                }

                AvaloniaThreadingExtensions.PostLogException(Dispatcher.UIThread, () =>
                {
                    var newKey = KeyManager.GetNextReceiveKey(label, out bool minGapLimitIncreased);
                    if (minGapLimitIncreased)
                    {
                        int minGapLimit     = KeyManager.MinGapLimit.Value;
                        int prevMinGapLimit = minGapLimit - 1;
                        NotificationHelpers.Warning($"{nameof(KeyManager.MinGapLimit)} increased from {prevMinGapLimit} to {minGapLimit}.");
                    }

                    var newAddress = new AddressViewModel(newKey, Global);
                    Addresses.Insert(0, newAddress);
                    SelectedAddress        = newAddress;
                    _labelSuggestion.Label = "";
                });
            });

            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 is { });