public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            return(View(new FavouriteIndexViewModel
            {
                FavouriteAddresses = await _userQuery.GetFavouriteAddressesAsync(user.Id)
            }));
        }
Beispiel #2
0
        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));
        }