Example #1
0
        private void New_Restore_Click(object sender, RoutedEventArgs e)
        {
            var walletWizard = new walletWizard();

            walletWizard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            walletWizard.Show();
            Close();
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();

            if (walletPasswordCancel)
            {
                Model = null;
                Backup_Wallet.Visibility = Visibility.Collapsed;
                Delete.Visibility        = Visibility.Collapsed;
                Tools.Visibility         = Visibility.Collapsed;
                Wallet.Visibility        = Visibility.Collapsed;
            }

            else
            {
                if (Model != null)
                {
                    MainFrame.NavigationService.Navigate(new overview(Model));
                    explorer = new BlockExplorer();

                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;

                        if (CheckForInternetConnection())
                        {
                            walletData.Serialize(Model.Wallet);
                            Model.Update();
                        }

                        while (true)
                        {
                            if (CheckForInternetConnection())
                            {
                                var Addresses = explorer.GetMultiAddressAsync(Model.Addresses).Result.Addresses;
                                var TxsCount  = Model.TxRecords == null ? 0 : Model.TxRecords.Count;
                                if (explorer.GetMultiAddressAsync(Model.Addresses).Result.Transactions.Count() >
                                    TxsCount)
                                {
                                    walletData.Serialize(Model.Wallet);
                                    Model.Update();
                                }

                                foreach (var tx in Model.TxRecords)
                                {
                                    if (tx.lockTime < 0)
                                    {
                                        var txAsync = explorer.GetTransactionByHashAsync(tx.hash).Result;
                                        if (txAsync.BlockHeight > 0)
                                        {
                                            var data = JsonConvert.DeserializeObject <Data>(
                                                File.ReadAllText(walletFileSerializer
                                                                 .Deserialize(Model.Wallet.WalletFilePath).walletTransactionsPath));
                                            data.txData[tx.hash].lockTime = txAsync.BlockHeight;
                                            File.WriteAllText(
                                                walletFileSerializer.Deserialize(Model.Wallet.WalletFilePath)
                                                .walletTransactionsPath, JsonConvert.SerializeObject(data));
                                            Model.Update();
                                        }
                                    }
                                }

                                using (var client = new HttpClient())
                                {
                                    const string url = @"https://api.blockcypher.com/v1/btc/main";
                                    var result       = client.GetAsync(url, HttpCompletionOption.ResponseContentRead).Result;
                                    var asyncData    = new FileInfo(Model.Wallet.WalletFilePath).Directory.FullName +
                                                       Path.DirectorySeparatorChar + "asyncData.json";
                                    if (result.IsSuccessStatusCode)
                                    {
                                        File.WriteAllText(asyncData, result.Content.ReadAsStringAsync().Result);
                                    }
                                    Model.Update();
                                }
                            }

                            Thread.Sleep(15000);
                        }
                    }).Start();
                }

                else
                {
                    var defaultWallet = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                                        Path.DirectorySeparatorChar + "ArGo" + Path.DirectorySeparatorChar +
                                        "default_wallet.json";
                    if (File.Exists(defaultWallet))
                    {
                        var walletPasswordWindow = new walletPasswordWindow(defaultWallet);
                        walletPasswordWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        walletPasswordWindow.Show();
                        Close();
                    }
                    else
                    {
                        var walletWizard = new walletWizard();
                        walletWizard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        walletWizard.Show();
                        Close();
                    }
                }
            }
        }