/// <summary>
        /// Handle the transaction we're mining having it's properties updated.
        /// </summary>
        /// <param name="sender">
        /// The event sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void OnTransactionToMinePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            // Only process changes indicating completion
            EnqueuedTransaction transaction = sender as EnqueuedTransaction;

            if (transaction == null || TransactionToMine == null)
            {
                return;
            }
            if (!transaction.Completed)
            {
                return;
            }

            // Clear out the transaction to mine
            TransactionToMine = null;
            SiftDialogViewModel viewModel = _miningTransactionDialogViewModel;

            // Display a message accordingly
            viewModel.IsReturnButtonVisible = true;
            if (transaction.WasSuccessful)
            {
                Logger.ApplicationInstance.Info("Purchase of SIFT added to block " + transaction.Receipt.BlockNumber.Value.ToString() + " for " + transaction.Receipt.TransactionHash + " at index " + transaction.Receipt.TransactionIndex.Value.ToString());
                viewModel.Title                         = "SIFT Purchase Successful";
                viewModel.Message                       = "Congratulations!  Your transaction for the purchase of SIFT has gone onto the Ethereum network.  Your new balance will be updated shortly and will be reflected in your Ethereum wallet.";
                viewModel.IsSiftLogoVisible             = true;
                viewModel.IsEthereumAnimatedLogoVisible = false;
            }
            else
            {
                Logger.ApplicationInstance.Error("TransactionToMine failed with message.  " + transaction.ErrorDetails);
                viewModel.Title   = "Problem Purchasing SIFT";
                viewModel.Message = "There was a problem processing your transaction for SIFT.  " + transaction.ErrorDetails;
            }
        }
Example #2
0
        /// <summary>
        /// Shows a SIFT dialog without any buttons in non-modal mode.
        /// </summary>
        /// <param name="title">
        /// The title of the message.
        /// </param>
        /// <param name="message">
        /// The message to show.
        /// </param>
        /// <param name="isEthereum">
        /// If this dialog is related to the ethereum network (true) and as such the ethereum logo should be displayed, otherwise false.
        /// </param>
        /// <returns>
        /// The dialog that was shown.
        /// </returns>
        public static SiftDialog ShowButtonless(string title, string message, bool isEthereum = false)
        {
            Func <SiftDialog> uiCallback = () =>
            {
                SiftDialogViewModel viewModel = new SiftDialogViewModel
                {
                    Title   = title,
                    Message = message,
                    IsEthereumAnimatedLogoVisible = isEthereum,
                    IsSiftLogoVisible             = !isEthereum,
                    IsLogButtonVisible            = true,
                    IsNoButtonVisible             = false,
                    IsReturnButtonVisible         = false,
                    IsYesButtonVisible            = false
                };
                SiftDialog dialog = new SiftDialog
                {
                    DataContext = viewModel,
                    Owner       = Application.Current.MainWindow
                };
                viewModel.CloseRequested += (s, e) => dialog.Close();
                dialog.Show();
                return(dialog);
            };

            if (Application.Current.Dispatcher.CheckAccess())
            {
                return(uiCallback());
            }
            else
            {
                return(Application.Current.Dispatcher.Invoke(uiCallback));
            }
        }
        /// <summary>
        /// Perform an investment in SIFT using the current UI settings.
        /// </summary>
        private async Task Invest()
        {
            // Disable UI
            SiftInvestIsEnabled = false;

            // Check times
            if (DateTime.UtcNow < _ethereumManager.IcoStartDate)
            {
                SiftDialog.ShowDialog("ICO Not Open", "The ICO for SIFT does not open until " + _ethereumManager.IcoStartDate.ToShortDateString() + " (00:00 GMT).  Please wait until this time to invest in SIFT.");
                return;
            }
            else if (DateTime.UtcNow > _ethereumManager.IcoEndDate)
            {
                SiftDialog.ShowDialog("ICO Not Open", "The ICO for SIFT finished at " + _ethereumManager.IcoStartDate.ToShortDateString() + " (00:00 GMT).  As soon as the ICO has been closed you will be able to purchase SIFT via an open marketplace.");
                return;
            }

            // Perform the purchase
            SiftPurchaseResponse response = await _ethereumManager.PurchaseSift(SelectedAccount.Address, SiftAmountToPurchase);

            if (!response.WasSuccessful)
            {
                SiftDialog.ShowDialog("SIFT Investment Problem", "Sorry, there was a problem processing your transaction.  Your SIFT could not be purchased at this time." + Environment.NewLine + Environment.NewLine + response.FailureReason);
            }
            else
            {
                TransactionToMine = _ethereumManager.EnqueueTransactionPendingReceipt(response.TransactionHash);
                if (TransactionToMine == null)
                {
                    SiftDialog.ShowDialog("SIFT Delayed Investment", "Your transaction to buy SIFT was successfully sent with hash " + response.TransactionHash + ", but we could not validate the transaction.  Your balance should update shortly, but if not please retry the transaction after checking your Ethereum wallet.");
                }
                else
                {
                    // Hookup to wait to hear the status, or process it immediately if we have it
                    Action act = () =>
                    {
                        TransactionToMine.PropertyChanged += OnTransactionToMinePropertyChanged;
                        _miningTransactionDialogViewModel  = new SiftDialogViewModel
                        {
                            IsEthereumAnimatedLogoVisible = true,
                            IsLogButtonVisible            = true,
                            Title   = "Confirming SIFT Investment",
                            Message = "Your transaction to invest in SIFT has been sent to the Ethereum network.  Depending on the current network congestion it may take anywhere between a few seconds and minutes for the transaction to confirm.  If the transaction does not confirm within a few minutes you can check your Ethereum wallet for more information." + Environment.NewLine + Environment.NewLine + "Please wait..."
                        };
                        _miningTransactionDialog = new SiftDialog
                        {
                            DataContext = _miningTransactionDialogViewModel,
                            Owner       = Application.Current.MainWindow
                        };
                        _miningTransactionDialogViewModel.CloseRequested += (s, e) =>
                        {
                            _miningTransactionDialog.Close();
                            _miningTransactionDialog          = null;
                            _miningTransactionDialogViewModel = null;
                        };
                        _miningTransactionDialog.ShowDialog();
                    };
                    if (Application.Current.Dispatcher.CheckAccess())
                    {
                        act();
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke(act);
                    }
                }
            }

            // Update the UI
            UpdateSiftPurchaseSettings();
        }