private void OnSchedulesLoaded(object obj) { switch (ScheduleType) { case ScheduleTypes.AC: Schedules = _schedulesRepository.ACSchedules; break; case ScheduleTypes.Heat: Schedules = _schedulesRepository.HeatSchedules; break; case ScheduleTypes.Light: Schedules = _schedulesRepository.LightSchedules; break; case ScheduleTypes.SKUD: Schedules = _schedulesRepository.SKUDSchedules; break; case ScheduleTypes.Ventilation: Schedules = _schedulesRepository.VentilationSchedules; break; } _changedByServer = true; if (AddressList.Any()) { var currentSchedule = Schedules.FirstOrDefault(s => s.ControlledObjects.Contains(new Property())); CurrentSchedule = currentSchedule ?? Schedules[0]; } }
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; }