internal static List <CurrencyOperationType> MapLimitationType(LimitationType limitType) { var result = new List <CurrencyOperationType>(); switch (limitType) { case LimitationType.CardCashIn: result.Add(CurrencyOperationType.CardCashIn); break; case LimitationType.CryptoCashOut: result.Add(CurrencyOperationType.CryptoCashOut); break; case LimitationType.CardAndSwiftCashIn: result.Add(CurrencyOperationType.CardCashIn); result.Add(CurrencyOperationType.SwiftTransfer); break; default: throw new NotSupportedException($"Limitation type {limitType} is not supported!"); } return(result); }
public async Task <double> GetAttemptsValueAsync( string clientId, string asset, LimitationType limitType) { var keys = await GetClientAttemptKeysAsync(clientId); if (keys.Length == 0) { return(0); } var attemptJsons = await _db.StringGetAsync(keys); var opTypes = LimitMapHelper.MapLimitationType(limitType); var attempts = attemptJsons .Where(a => a.HasValue) .Select(a => a.ToString().DeserializeJson <CurrencyOperationAttempt>()) .Where(a => opTypes.Contains(a.OperationType)) .ToList(); double result = 0; foreach (var attempt in attempts) { if (_currencyConverter.IsNotConvertible(asset) && attempt.Asset == asset) { result += attempt.Amount; } else if (!_currencyConverter.IsNotConvertible(asset) && !_currencyConverter.IsNotConvertible(attempt.Asset)) { var converted = await _currencyConverter.ConvertAsync(attempt.Asset, asset, attempt.Amount); result += converted.Item2; } } return(result); }