public async Task <IActionResult> Address(string addressHash) { if (addressHash == null) { return(RedirectToAction("index")); } var addressDto = await _addressQuery.GetAddressAsync(addressHash); if (addressDto == null) { return(RedirectToAction("index")); } var txSentFloor = (int)Math.Floor((double)addressDto.SentCount / TransactionsPerPage); var txRecFloor = (int)Math.Floor((double)addressDto.ReceivedCount / TransactionsPerPage); var txSentRecFloor = (int)Math.Floor(((double)addressDto.SentCount + addressDto.ReceivedCount) / TransactionsPerPage); var user = await _userManager.GetUserAsync(User); var faveAddress = (await _userQuery.GetFavouriteAddressesAsync(user?.Id))? .FirstOrDefault(x => x.AddressId == addressDto.AddressId); var currency = user?.Currency ?? Currency.USD; var nxsCurrency = new NxsCurrencyHelper( currency, addressDto.Balance, await _currencyQuery.GetLatestNXSPriceInBTCAsync(), await _currencyQuery.GetLatestBTCPriceInUSDAsync(), (double)await _currencyQuery.ConvertFromUSDAsync(currency)); var viewModel = new AddressViewModel { Address = addressDto, TrustKey = await _addressQuery.GetAddressTrustKey(addressDto.Hash), TxPerPage = TransactionsPerPage, TxSentPageCount = addressDto.SentCount % TransactionsPerPage == 0 ? txSentFloor : txSentFloor + 1, TxReceivedPageCount = addressDto.ReceivedCount % TransactionsPerPage == 0 ? txRecFloor : txRecFloor + 1, TxSentReceivedPageCount = (addressDto.SentCount + addressDto.ReceivedCount) % TransactionsPerPage == 0 ? txSentRecFloor : txSentRecFloor + 1, NxsCurrency = nxsCurrency, LastBlockSeenTimestamp = await _blockQuery.GetBlockTimestamp(addressDto.LastBlockSeen), IsUserFavourite = faveAddress != null, AddressAlias = faveAddress?.Alias }; return(View(viewModel)); }
private async Task AddOrUpdateTrustKeysAsync(IEnumerable <TrustKeyResponseDto> latestKeys, ICollection <TrustKeyDto> keyCache) { var nonExpired = latestKeys.Where(x => !x.Expired).ToList(); foreach (var latestKeyDto in nonExpired) { var trustKey = keyCache.FirstOrDefault(x => x.TrustKey == latestKeyDto.TrustKey); if (trustKey == null) { var address = await _addressQuery.GetAddressAsync(latestKeyDto.AddressHash); var block = await _blockQuery.GetBlockAsync(latestKeyDto.GenesisBlockHash, true); var tx = block?.Transactions.FirstOrDefault(x => x.Hash == latestKeyDto.TransactionHash); if (address == null || block == null || tx == null) { continue; } trustKey = new TrustKeyDto { AddressId = address.AddressId, AddressHash = latestKeyDto.AddressHash, GenesisBlockHeight = block.Height, TransactionId = tx.TransactionId, TransactionHash = tx.Hash, InterestRate = latestKeyDto.InterestRate, TimeSinceLastBlock = TimeSpan.FromSeconds(latestKeyDto.TimeSinceLastBlock), TimeUtc = latestKeyDto.TimeUtc, TrustHash = latestKeyDto.TrustHash, TrustKey = latestKeyDto.TrustKey }; keyCache.Add(trustKey); } else { trustKey.InterestRate = latestKeyDto.InterestRate; trustKey.TimeSinceLastBlock = TimeSpan.FromSeconds(latestKeyDto.TimeSinceLastBlock); } } }