示例#1
0
        public TransactionViewModel(Wallet wallet, WalletTransaction transaction, BlockIdentity transactionLocation)
        {
            _transaction = transaction;
            _location    = transactionLocation;

            var groupedOutputs = _transaction.NonChangeOutputs.Select(o =>
            {
                var destination = wallet.OutputDestination(o);
                return(new GroupedOutput(o.Amount, destination));
            }).Aggregate(new List <GroupedOutput>(), (items, next) =>
            {
                var item = items.Find(a => a.Destination == next.Destination);
                if (item == null)
                {
                    items.Add(next);
                }
                else
                {
                    item.Amount += next.Amount;
                }

                return(items);
            });

            Confirmations  = BlockChain.Confirmations(wallet.ChainTip.Height, transactionLocation);
            Inputs         = _transaction.Inputs.Select(input => new Input(-input.Amount, wallet.AccountName(input.PreviousAccount))).ToArray();
            Outputs        = _transaction.Outputs.Select(output => new Output(output.Amount, wallet.OutputDestination(output))).ToArray();
            GroupedOutputs = groupedOutputs;
        }
示例#2
0
        private void OnWalletChangesProcessed(object sender, Wallet.ChangesProcessedEventArgs e)
        {
            // TODO: The OverviewViewModel should probably connect to this event.  This could be
            // done after the wallet is synced.
            var overviewViewModel = ViewModelLocator.OverviewViewModel as OverviewViewModel;

            if (overviewViewModel != null)
            {
                var currentHeight = e.NewChainTip?.Height ?? SyncedBlockHeight;

                var movedTxViewModels = overviewViewModel.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 movedTx in movedTxViewModels)
                {
                    var txvm     = movedTx.Item1;
                    var location = movedTx.Item2;

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

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

            foreach (var modifiedAccount in e.ModifiedAccountProperties)
            {
                var accountNumber     = checked ((int)modifiedAccount.Key.AccountNumber);
                var accountProperties = modifiedAccount.Value;

                if (accountNumber < Accounts.Count)
                {
                    Accounts[accountNumber].AccountProperties = accountProperties;
                }
            }

            if (e.NewChainTip != null)
            {
                SyncedBlockHeight = e.NewChainTip.Value.Height;
            }
            if (e.AddedTransactions.Count != 0 || e.RemovedTransactions.Count != 0)
            {
                RaisePropertyChanged(nameof(TotalBalance));
            }
        }
示例#3
0
        private void _wallet_ChangesProcessed(object sender, Wallet.ChangesProcessedEventArgs e)
        {
            // TODO: The OverviewViewModel should probably connect to this event.  This could be
            // done after the wallet is synced.
            var overviewViewModel = ViewModelLocator.OverviewViewModel as OverviewViewModel;

            if (overviewViewModel != null)
            {
                var currentHeight = e.NewChainTip?.Height ?? SyncedBlockHeight;

                var movedTxViewModels = overviewViewModel.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 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)
                    {
                        overviewViewModel.RecentTransactions.Insert(0, txvm);
                    }
                });
            }

#if false
            if (VisibleContent is AccountViewModel)
            {
                var accountViewModel = (AccountViewModel)VisibleContent;
                AccountProperties accountProperties;
                if (e.ModifiedAccountProperties.TryGetValue(accountViewModel.Account, out accountProperties))
                {
                    accountViewModel.UpdateAccountProperties(1, accountProperties);
                }
            }
#endif
            RaisePropertyChanged(nameof(TotalBalance));

            if (e.NewChainTip != null)
            {
                SyncedBlockHeight = ((BlockIdentity)(e.NewChainTip)).Height;
            }
        }
示例#4
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;
            }
        }