private void ChangeKeyLogic() { if (!string.IsNullOrEmpty(SelectedAddress.AddressID)) {//check to see if key is part of the current companylist... Address query = AddressList.Where(company => company.AddressID == SelectedAddress.AddressID && company.AutoID != SelectedAddress.AutoID).FirstOrDefault(); if (query != null) {//revert it back SelectedAddress.AddressID = SelectedAddressMirror.AddressID; //change to the newly selected company... SelectedAddress = query; return; } //it is not part of the existing list try to fetch it from the db... AddressList = GetAddressByID(SelectedAddress.AddressID, XERP.Client.ClientSessionSingleton.Instance.CompanyID); if (AddressList.Count == 0)//it was not found do new record required logic... { NotifyNewRecordNeeded("Record " + SelectedAddress.AddressID + " Does Not Exist. Create A New Record?"); } else { SelectedAddress = AddressList.FirstOrDefault(); } } else { string errorMessage = "ID Is Required."; NotifyMessage(errorMessage); //revert back to the value it was before it was changed... if (SelectedAddress.AddressID != SelectedAddressMirror.AddressID) { SelectedAddress.AddressID = SelectedAddressMirror.AddressID; } } }
private void onAddressListChange(object sender, PropertyChangedEventArgs e) { if (e.PropertyName.Equals("AddressList")) { var deliveryAddressFoundList = AddressList.Where(x => x.ID == Order.DeliveryAddress).ToList(); DeliveryAddress = (deliveryAddressFoundList.Count() > 0) ? deliveryAddressFoundList[0] : new Entity.Address(); var billAddressFoundList = AddressList.Where(x => x.ID == Order.BillAddress).ToList(); BillAddress = (billAddressFoundList.Count() > 0) ? billAddressFoundList[0] : new Entity.Address(); } }
private async void GetTransactions() { Status = "Updating transaction lists..."; Errors = string.Empty; IsReceiving = true; BalanceApi ba = new BlockCypher(); // Bech32 addresses in AddressList should be ignored until the block explorers and forks start supporting it. Response resp = await ba.UpdateTransactionListAsync(AddressList.Where(x => !x.Address.StartsWith("bc1", StringComparison.OrdinalIgnoreCase)).ToList()); Coindesk pa = new Coindesk(); DateTime start = AddressList.Where(x => !x.Address.StartsWith("bc1", StringComparison.OrdinalIgnoreCase)) .Min(x => x.TransactionList.Min(y => y.ConfirmedTime)); DateTime end = AddressList.Where(x => !x.Address.StartsWith("bc1", StringComparison.OrdinalIgnoreCase)).Max(x => x.TransactionList.Max(y => y.ConfirmedTime));; Response <List <PriceHistory> > resp2 = await pa.GetPriceHistoryAsync(start, end); foreach (var adr in AddressList) { if (adr.TransactionList == null) { continue; } foreach (var tx in adr.TransactionList) { PriceHistory ph = resp2.Result.Find(x => x.Time.Date.Equals(tx.ConfirmedTime.Date)); if (ph != null) { tx.UsdValue = ph.Price; } } } if (resp.Errors.Any()) { Errors = resp.Errors.GetErrors(); Status = "Encountered an error!"; } else { Save(); Status = "Transaction Update Success!"; } IsReceiving = false; }
private async void GetBalance() { if (!AddressList.ToList().TrueForAll(x => !x.HasErrors) || AddressList.Any(d => string.IsNullOrEmpty(d.Address))) { Errors = "Fix the errors in addresses first!"; return; } Status = "Updating Balances..."; Errors = string.Empty; IsReceiving = true; BalanceApi api = null; switch (SettingsInstance.SelectedBalanceApi) { case BalanceServiceNames.Chainz: api = new Chainz(); break; case BalanceServiceNames.Insight: api = new Insight(); break; default: api = new Chainz(); break; } // Not all exchanges support Bech32 addresses! // The following "if" is to solve that. bool hasSegWit = AddressList.Any(x => x.Address.StartsWith("grs1", System.StringComparison.InvariantCultureIgnoreCase)); if (hasSegWit) { BalanceApi segApi = new Chainz(); List <GroestlcoinAddress> legacyAddrs = new List <GroestlcoinAddress>(AddressList.Where(x => !x.Address.StartsWith("grs1", System.StringComparison.OrdinalIgnoreCase))); List <GroestlcoinAddress> segWitAddrs = new List <GroestlcoinAddress>(AddressList.Where(x => x.Address.StartsWith("grs1", System.StringComparison.OrdinalIgnoreCase))); Response respSW = await segApi.UpdateBalancesAsync(segWitAddrs); if (respSW.Errors.Any()) { Errors = "SegWit API error: " + respSW.Errors.GetErrors(); Status = "Error in SegWit API! Continue updating legacy balances..."; } Response resp = await api.UpdateBalancesAsync(legacyAddrs); if (resp.Errors.Any()) { Errors = resp.Errors.GetErrors(); Status = "Encountered an error!"; } else { DataManager.WriteFile(AddressList, DataManager.FileType.Wallet); RaisePropertyChanged("GroestlcoinBalance"); LastUpdated = DateTime.Now; Status = "Balance Update Success!"; } } else { Response resp = await api.UpdateBalancesAsync(AddressList.ToList()); if (resp.Errors.Any()) { Errors = resp.Errors.GetErrors(); Status = "Encountered an error!"; } else { DataManager.WriteFile(AddressList, DataManager.FileType.Wallet); RaisePropertyChanged("GroestlcoinBalance"); LastUpdated = DateTime.Now; Status = "Balance Update Success!"; } } Status += $" - Last Updated: {LastUpdated.ToShortDateString()} {LastUpdated.ToShortTimeString()}"; if (SettingsInstance.GroestlcoinPriceInUSD == 0) { Status = "Error: Please open settings and press refresh to get FIAT balances"; } IsReceiving = false; }
private async void GetBalance() { if (!AddressList.ToList().TrueForAll(x => !x.HasErrors)) { Errors = "Fix the errors in addresses first!"; return; } Status = "Updating Balances..."; Errors = string.Empty; IsReceiving = true; BalanceApi api = null; switch (SettingsInstance.SelectedBalanceApi) { case BalanceServiceNames.BlockchainInfo: api = new BlockchainInfo(); break; case BalanceServiceNames.BlockExplorer: api = new BlockExplorer(); break; case BalanceServiceNames.BlockCypher: api = new BlockCypher(); break; case BalanceServiceNames.Blockonomics: api = new Blockonomics(); break; default: api = new BlockchainInfo(); break; } // Not all exchanges support Bech32 addresses! // The following "if" is to solve that. bool hasSegWit = AddressList.Any(x => x.Address.StartsWith("bc1", System.StringComparison.InvariantCultureIgnoreCase)); if (hasSegWit && !SettingsInstance.SelectedBalanceApi.Equals(BalanceServiceNames.Blockonomics)) { BalanceApi segApi = new Blockonomics(); List <BitcoinAddress> legacyAddrs = new List <BitcoinAddress>(AddressList.Where(x => !x.Address.StartsWith("bc1", System.StringComparison.OrdinalIgnoreCase))); List <BitcoinAddress> segWitAddrs = new List <BitcoinAddress>(AddressList.Where(x => x.Address.StartsWith("bc1", System.StringComparison.OrdinalIgnoreCase))); Response respSW = await segApi.UpdateBalancesAsync(segWitAddrs); if (respSW.Errors.Any()) { Errors = "SegWit API error: " + respSW.Errors.GetErrors(); Status = "Error in SegWit API! Continue updating legacy balances..."; } Response resp = await api.UpdateBalancesAsync(legacyAddrs); if (resp.Errors.Any()) { Errors = resp.Errors.GetErrors(); Status = "Encountered an error!"; } else { DataManager.WriteFile(AddressList, DataManager.FileType.Wallet); RaisePropertyChanged("BitcoinBalance"); Status = "Balance Update Success!"; } } else { Response resp = await api.UpdateBalancesAsync(AddressList.ToList()); if (resp.Errors.Any()) { Errors = resp.Errors.GetErrors(); Status = "Encountered an error!"; } else { DataManager.WriteFile(AddressList, DataManager.FileType.Wallet); RaisePropertyChanged("BitcoinBalance"); Status = "Balance Update Success!"; } } IsReceiving = false; }