public async Task <SyncPersonalWalletResponse> Handle(SyncPersonalWalletRequest request, CancellationToken cancellationToken) { var result = new SyncPersonalWalletResponse(); var wallet = await _context.Wallets .Where(x => x.WalletID == request.WalletID) .Include(x => x.Blockchain) .SingleOrDefaultAsync(cancellationToken); if (wallet == null) { throw new NotFoundException(nameof(Wallet), request.WalletID); } var cryptoWallet = new CryptoWallet(); var walletDTO = new WalletDTO(); if (wallet.Blockchain.Symbol == CurrencySymbol.BTC) { cryptoWallet = await _bitcoinService.GetBitcoinWalletAsync(wallet.Address); walletDTO = await WalletSynchronizer.ImportBalance(_context, _dateTimeOffset.Now, wallet, cryptoWallet, cancellationToken); } else if (wallet.Blockchain.Symbol == CurrencySymbol.ETH) { if (wallet.IsSynchronized) { walletDTO = await WalletSynchronizer.ImportEthereumTransactions(_context, _ethereumService, wallet, cancellationToken); } else { cryptoWallet = await _ethereumService.GetEthereumWalletAsync(wallet.Address); walletDTO = await WalletSynchronizer.ImportBalance(_context, _dateTimeOffset.Now, wallet, cryptoWallet, cancellationToken); } } else if (wallet.Blockchain.Symbol == CurrencySymbol.DOGE) { cryptoWallet = await _dogecoinService.GetDogecoinWalletAsync(wallet.Address); walletDTO = await WalletSynchronizer.ImportBalance(_context, _dateTimeOffset.Now, wallet, cryptoWallet, cancellationToken); } else if (wallet.Blockchain.Symbol == CurrencySymbol.STEEM) { cryptoWallet = await _steemService.GetSteemWalletAsync(wallet.Address); walletDTO = await WalletSynchronizer.ImportBalance(_context, _dateTimeOffset.Now, wallet, cryptoWallet, cancellationToken); } else if (wallet.Blockchain.Symbol == CurrencySymbol.HIVE) { cryptoWallet = await _hiveService.GetHiveWalletAsync(wallet.Address); walletDTO = await WalletSynchronizer.ImportBalance(_context, _dateTimeOffset.Now, wallet, cryptoWallet, cancellationToken); } result.IsSuccessful = true; result.Wallet = walletDTO; return(result); }
public async Task <SyncAllPersonalWalletsResponse> Handle(SyncAllPersonalWalletsRequest request, CancellationToken cancellationToken) { var result = new SyncAllPersonalWalletsResponse(); var synchronizedWallets = await _context.Wallets .Where(x => x.IsSynchronized) .Include(x => x.Blockchain) .ToListAsync(cancellationToken); foreach (var wallet in synchronizedWallets) { var cryptoWallet = new CryptoWallet(); if (wallet.Blockchain.Symbol == CurrencySymbol.BTC) { cryptoWallet = await _bitcoinService.GetBitcoinWalletAsync(wallet.Address); } else if (wallet.Blockchain.Symbol == CurrencySymbol.ETH) { cryptoWallet = await _ethereumService.GetEthereumWalletAsync(wallet.Address); } else if (wallet.Blockchain.Symbol == CurrencySymbol.DOGE) { cryptoWallet = await _dogecoinService.GetDogecoinWalletAsync(wallet.Address); } else if (wallet.Blockchain.Symbol == CurrencySymbol.STEEM) { cryptoWallet = await _steemService.GetSteemWalletAsync(wallet.Address); } else if (wallet.Blockchain.Symbol == CurrencySymbol.HIVE) { cryptoWallet = await _hiveService.GetHiveWalletAsync(wallet.Address); } var walletDTO = await WalletSynchronizer.ImportBalance(_context, _dateTimeOffset.Now, wallet, cryptoWallet, cancellationToken); result.Wallets.Add(walletDTO); } return(result); }