public async Task <decimal> GetBalance(Storage.WalletType convertFrom, decimal convertValue, Storage.WalletType convertTo, CancellationToken cancellationToken) { if (convertValue == 0) { return(0); } if (convertFrom != Storage.WalletType.Iota) { throw new ArgumentException($"Currency type '{convertFrom}' not supported"); } if (convertTo != Storage.WalletType.Eur) { throw new ArgumentException($"Currency type '{convertTo}' not supported"); } var url = $"https://api.coinmarketcap.com/v1/ticker/{convertFrom.ToString()}/?convert={convertTo.ToString()}"; var marketCapArray = await RequestGetAsync <CoinMarketCapEur[]>(url, cancellationToken); var marketCap = marketCapArray.FirstOrDefault(); if (marketCap == null) { return(0); } decimal rate = 0; decimal.TryParse(marketCap.price_eur.Replace('.', ','), out rate); decimal value = convertValue * rate / 1000000; // todo change that divide hardcode return(value); }
public async Task RefreshBalances(Storage.WalletType originalCurrency, CancellationToken cancellationToken) { var originalBalanceModel = Balances.FirstOrDefault(b => b.WalletType == originalCurrency); if (originalBalanceModel == null) { throw new ArgumentException($"Balance item model for '{originalCurrency}' not found"); } BalanceConverter converter = new BalanceConverter(); foreach (var balanceItemModel in Balances) { if (balanceItemModel.WalletType != originalCurrency) { var balance = await converter.GetBalance(originalCurrency, originalBalanceModel.Value, balanceItemModel.WalletType, cancellationToken); balanceItemModel.Value = balance; } } }
public async Task RefreshBalances(Storage.WalletType originalCurrency) { await RefreshBalances(originalCurrency, CancellationToken.None); }