コード例 #1
0
        private void OnSyncedWallet()
        {
            var txSet    = _wallet.RecentTransactions;
            var recentTx = txSet.UnminedTransactions
                           .Select(x => new TransactionViewModel(_wallet, x.Value, BlockIdentity.Unmined))
                           .Concat(txSet.MinedTransactions.ReverseList().SelectMany(b => b.Transactions.Select(tx => new TransactionViewModel(_wallet, tx, b.Identity))))
                           .Take(10);
            var recentAccounts = _wallet.EnumrateAccounts()
                                 .Select(a => new RecentAccountViewModel(this, a.Key, a.Value));

            Application.Current.Dispatcher.Invoke(() =>
            {
                foreach (var tx in recentTx)
                {
                    _recentActivityViewModel.RecentTransactions.Add(tx);
                }
                foreach (var account in recentAccounts)
                {
                    RecentAccounts.Add(account);
                }
            });
            SyncedBlockHeight = _wallet.ChainTip.Height;
            NotifyRecalculatedBalances();
            StartupWizardVisible = false;
            ShowRecentActivity();
        }
コード例 #2
0
        private void _wallet_ChangesProcessed(object sender, Wallet.ChangesProcessedEventArgs e)
        {
            var currentHeight = e.NewChainTip?.Height ?? SyncedBlockHeight;

            var movedTxViewModels = _recentActivityViewModel.RecentTransactions
                                    .Where(txvm => e.MovedTransactions.ContainsKey(txvm.TxHash))
                                    .Select(txvm => Tuple.Create(txvm, e.MovedTransactions[txvm.TxHash]));

            var newTxViewModels = e.AddedTransactions.Select(tx => new TransactionViewModel(_wallet, tx.Item1, tx.Item2)).ToList();

            foreach (var kvp in e.ModifiedAccountProperties)
            {
                var account         = kvp.Key;
                var state           = kvp.Value;
                var recentAccountVM = RecentAccounts.FirstOrDefault(vm => vm.Account == account);
                if (recentAccountVM != null)
                {
                    recentAccountVM.AccountName = state.AccountName;
                    recentAccountVM.Balance     = state.TotalBalance;
                }
                else
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        RecentAccounts.Add(new RecentAccountViewModel(this, account, state));
                    });
                }
            }

            RaisePropertyChanged(nameof(TotalBalance));

            if (VisibleContent is AccountViewModel)
            {
                var accountViewModel = (AccountViewModel)VisibleContent;
                AccountProperties accountProperties;
                if (e.ModifiedAccountProperties.TryGetValue(accountViewModel.Account, out accountProperties))
                {
                    accountViewModel.UpdateAccountProperties(1, accountProperties);
                }
            }

            foreach (var movedTx in movedTxViewModels)
            {
                var txvm     = movedTx.Item1;
                var location = movedTx.Item2;

                txvm.Location      = location;
                txvm.Confirmations = BlockChain.Confirmations(currentHeight, location);
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                foreach (var txvm in newTxViewModels)
                {
                    _recentActivityViewModel.RecentTransactions.Insert(0, txvm);
                }
            });

            if (e.NewChainTip != null)
            {
                SyncedBlockHeight = ((BlockIdentity)(e.NewChainTip)).Height;
            }
        }