Ejemplo n.º 1
0
        public void UpdateDashboard()
        {
            var barcoin = new Blockchain.Model.Blockchain();

            ObservableCollection <Transaction> transactions = barcoin.GetUserRelevantTransactions(SignedUser.Id);

            CustomTransactions = new ObservableCollection <CustomTransaction>();

            var orderedTransactions = transactions.OrderByDescending(x => x.Timestamp.Date)
                                      .ThenByDescending(x => x.Timestamp.TimeOfDay);

            float balance = 0.0f;

            foreach (Transaction t in orderedTransactions)
            {
                if (t.RecipientId == SignedUser.Id)
                {
                    balance += t.Amount;
                }
                else
                {
                    balance -= t.Amount;
                }

                string sender    = barcoin.GetUsernameById(t.SenderId);
                string recipient = barcoin.GetUsernameById(t.RecipientId);

                CustomTransaction ct = new CustomTransaction()
                {
                    Id        = t.Id,
                    Hash      = t.ComputeHash(),
                    Sender    = t.SenderId == SignedUser.Id ? "You" : sender,
                    Recipient = t.RecipientId == SignedUser.Id ? "You" : recipient,
                    Amount    = t.Amount,
                    Timestamp = t.Timestamp.ToString("yyyy.MM.dd"),
                    Color     = t.RecipientId == SignedUser.Id ? "DeepSkyBlue" : "Transparent"
                };

                CustomTransactions.Add(ct);
            }

            ChartSeriesRepo = new ChartSeriesRepository(
                barcoin.GetTransactions()
                .OrderByDescending(x => x.Timestamp.Date)
                .Take(50),
                CustomTransactions
                );

            Balance = balance.ToString("n4");

            if (barcoin.IsValid())
            {
                ViewModelLocator.Main.SyncState = "up to date";
            }
            else
            {
                ViewModelLocator.Main.SyncState = "out of sync";
            }
        }
Ejemplo n.º 2
0
        private void OnSend(object obj)
        {
            if (string.IsNullOrWhiteSpace(Address))
            {
                Error           = "Enter a receiver's address.";
                ErrorVisibility = Visibility.Visible;
                return;
            }

            if (string.IsNullOrWhiteSpace(Amount))
            {
                Error           = "Enter an amount to be sent.";
                ErrorVisibility = Visibility.Visible;
                return;
            }

            if (!IsLegal)
            {
                Error           = "Accept our terms and conditions.";
                ErrorVisibility = Visibility.Visible;
                return;
            }

            var barcoin = new Blockchain.Model.Blockchain();

            int recipientId = barcoin.GetIdFromAddress(Address);

            if (recipientId != -1)
            {
                string senderBalance = ViewModelLocator.Dashboard.Balance;

                if (float.Parse(Amount) < float.Parse(senderBalance))
                {
                    barcoin.AcceptBlock(
                        barcoin.GenerateBlock(
                            (int)Application.Current.Resources["SID"],
                            recipientId,
                            float.Parse(Amount)
                            )
                        );

                    dialogCoordinator.ShowMessageAsync(
                        this,
                        "Transaction Successful",
                        "Find furthermore information about your transactions in the dashboard tab."
                        );

                    Address = string.Empty;
                    Amount  = string.Empty;
                }
                else
                {
                    dialogCoordinator.ShowMessageAsync(
                        this,
                        "Transaction Failed",
                        "The amount you provided exceeds your current balance. It will be now defaulted to max value."
                        );

                    Amount = senderBalance;
                }
            }
            else
            {
                dialogCoordinator.ShowMessageAsync(
                    this,
                    "Transaction Failed",
                    "The address you provided wasn't found inside the network. Please double check and retry."
                    );
            }
        }