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)); } }
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; } }
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; } }
private void OnWalletChangesProcessed(object sender, Wallet.ChangesProcessedEventArgs e) { var wallet = (Wallet)sender; var currentHeight = e.NewChainTip?.Height ?? SyncedBlockHeight; // 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 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.Depth = BlockChain.Depth(currentHeight, location); } App.Current.Dispatcher.Invoke(() => { foreach (var txvm in newTxViewModels) { overviewViewModel.RecentTransactions.Insert(0, txvm); } while (overviewViewModel.RecentTransactions.Count > 10) { overviewViewModel.RecentTransactions.RemoveAt(10); } }); } // TODO: same.. in fact these tx viewmodels should be reused so changes don't need to be recalculated. // It would be a good idea for this synchronzier viewmodel to manage these and hand them out to other // viewmodels for sorting and organization. var transactionHistoryViewModel = ViewModelLocator.TransactionHistoryViewModel as TransactionHistoryViewModel; if (transactionHistoryViewModel != null) { foreach (var tx in transactionHistoryViewModel.Transactions) { var txvm = tx.Transaction; BlockIdentity newLocation; if (e.MovedTransactions.TryGetValue(txvm.TxHash, out newLocation)) { txvm.Location = newLocation; } txvm.Depth = BlockChain.Depth(currentHeight, txvm.Location); } transactionHistoryViewModel.AppendNewTransactions(wallet, e.AddedTransactions); } 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; } } // TODO: this would be better if all new accounts were a field in the event message. var newAccounts = e.ModifiedAccountProperties. Where(kvp => kvp.Key.AccountNumber >= Accounts.Count && kvp.Key.AccountNumber != Wallet.ImportedAccountNumber). OrderBy(kvp => kvp.Key.AccountNumber); foreach (var modifiedAccount in newAccounts) { var accountNumber = checked ((int)modifiedAccount.Key.AccountNumber); var accountProperties = modifiedAccount.Value; // TODO: This is very inefficient because it recalculates balances of every account, for each new account. var accountBalance = wallet.CalculateBalances(2)[accountNumber]; var accountViewModel = new AccountViewModel(modifiedAccount.Key, accountProperties, accountBalance); App.Current.Dispatcher.Invoke(() => Accounts.Add(accountViewModel)); } if (e.NewChainTip != null) { SyncedBlockHeight = e.NewChainTip.Value.Height; var oldRetarget = BlocksUntilTicketPriceRetarget; BlocksUntilTicketPriceRetarget = BlockChain.BlocksUntilTicketPriceRetarget(SyncedBlockHeight, wallet.ActiveChain); if (BlocksUntilTicketPriceRetarget > oldRetarget) { Task.Run(async() => { var sdiff = await WalletRpcClient.TicketPriceAsync(); await App.Current.Dispatcher.InvokeAsync(() => TicketPrice = sdiff); }).ContinueWith(t => { if (t.Exception != null) { MessageBox.Show(t.Exception.InnerException.Message, "Error querying ticket price"); } }); } } if (e.AddedTransactions.Count != 0 || e.RemovedTransactions.Count != 0 || e.NewChainTip != null) { TotalBalance = wallet.TotalBalance; TransactionCount += e.AddedTransactions.Count - e.RemovedTransactions.Count; var balances = wallet.CalculateBalances(2); // TODO: don't hardcode confs for (var i = 0; i < balances.Length; i++) { Accounts[i].Balances = balances[i]; } } }