public decimal WithdrawalTotalThisPeriod(KycSettings settings) { DateTime startDate; switch (settings.WithdrawalPeriod) { case WithdrawalPeriod.Daily: startDate = DateTime.Today; break; case WithdrawalPeriod.Weekly: startDate = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); break; case WithdrawalPeriod.Monthly: var now = DateTime.Now; startDate = new DateTime(now.Year, now.Month, 1); break; default: throw new Exception("invalid withdrawal period"); } var timestamp = ((DateTimeOffset)startDate).ToUnixTimeSeconds(); var withdrawalsThisPeriod = this.Withdrawals.Where(w => w.ApplicationUserId == this.Id && w.Date >= timestamp); decimal total = 0; foreach (var withdrawal in withdrawalsThisPeriod) { total += decimal.Parse(withdrawal.WithdrawalAssetEquivalent); } return(total); }
public BaseWalletController( ILogger logger, UserManager <ApplicationUser> userManager, ApplicationDbContext context, IOptions <ExchangeSettings> settings, IWalletProvider walletProvider, IOptions <KycSettings> kycSettings) : base(logger, userManager, context, settings) { _walletProvider = walletProvider; _kycSettings = kycSettings.Value; }
public ManageController( UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, IEmailSender emailSender, ILogger <ManageController> logger, UrlEncoder urlEncoder, ApplicationDbContext context, IOptions <ExchangeSettings> settings, IOptions <GeneralSettings> gen, IOptions <KycSettings> kyc, IWalletProvider walletProvider) : base(logger, userManager, context, settings) { _signInManager = signInManager; _emailSender = emailSender; _urlEncoder = urlEncoder; _genSettings = gen.Value; _kycSettings = kyc.Value; _walletProvider = walletProvider; }
public AccountController( ILogger <AccountController> logger, UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ApplicationDbContext context, IEmailSender emailSender, IOptions <ExchangeSettings> settings, RoleManager <IdentityRole> roleManager, IOptions <KycSettings> kycSettings, ITripwire tripwire, IOptions <ApiSettings> apiSettings) : base(logger, userManager, context, settings) { _signInManager = signInManager; _emailSender = emailSender; _roleManager = roleManager; _kycSettings = kycSettings.Value; _tripwire = tripwire; _apiSettings = apiSettings.Value; }
public void UpdateKyc(ILogger logger, ApplicationDbContext context, KycSettings kyc, int level) { if (level >= kyc.Levels.Count()) { logger.LogError($"Tried to set kyc level to a level that does not exist '{level}'"); return; } if (this.Kyc == null) { context.Kycs.Add(new Kyc { ApplicationUserId = this.Id, Level = level }); } else if (this.Kyc.Level < level) { this.Kyc.Level = level; context.Kycs.Update(this.Kyc); } }
protected decimal CalculateWithdrawalAssetEquivalent(ILogger logger, KycSettings kyc, string asset, decimal amount) { if (asset == kyc.WithdrawalAsset) { return(amount); } foreach (var market in _settings.Markets.Keys) { if (market.StartsWith(asset) && market.EndsWith(kyc.WithdrawalAsset)) { try { //TODO: move this to a ViaRpcProvider in /Services (like IWalletProvider) var via = new ViaJsonRpc(_settings.AccessHttpUrl); var price = via.MarketPriceQuery(market); var priceDec = decimal.Parse(price); if (priceDec <= 0) { continue; } return(amount * priceDec); } catch (ViaJsonException ex) { _logger.LogError(ex, $"Error getting market price for asset '{market}'"); } } } ; if (kyc.WithdrawalAssetBaseRates.ContainsKey(asset)) { return(amount * kyc.WithdrawalAssetBaseRates[asset]); } logger.LogError($"no price found for asset {asset}"); throw new Exception($"no price found for asset {asset}"); }
protected async Task PostUserEmailConfirmed(RoleManager <IdentityRole> roleManager, SignInManager <ApplicationUser> signInManager, KycSettings kycSettings, ApplicationUser user) { // add email confirmed role var role = await roleManager.FindByNameAsync(Utils.EmailConfirmedRole); System.Diagnostics.Debug.Assert(role != null); if (!await _userManager.IsInRoleAsync(user, role.Name)) { await _userManager.AddToRoleAsync(user, role.Name); } // refresh users cookie (so they dont have to log out/ log in) await signInManager.RefreshSignInAsync(user); // grant email kyc for (var i = 0; i < kycSettings.Levels.Count(); i++) { if (kycSettings.Levels[i].Name == "Email Confirmed") { user.UpdateKyc(_logger, _context, kycSettings, i); _context.SaveChanges(); break; } } }