Exemple #1
0
        public async Task <IActionResult> Kyc()
        {
            var user = await GetUser(required : true);

            // get kyc request url and check the status
            string kycRequestUrl    = null;
            string kycRequestStatus = null;
            var    kycRequest       = _context.KycRequests.Where(r => r.ApplicationUserId == user.Id).OrderByDescending(r => r.Date).FirstOrDefault();

            if (kycRequest != null)
            {
                kycRequestUrl = $"{_kycSettings.KycServerUrl}/request/{kycRequest.Token}";
                var _model = await RestUtils.CheckKycRequest(_logger, _context, _userManager, _kycSettings, user.Id, kycRequest.Token);

                if (_model != null)
                {
                    kycRequestStatus = _model.Status;
                }
            }
            // get users kyc level
            var      levelNum = user.Kyc != null ? user.Kyc.Level : 0;
            KycLevel level    = null;

            if (_kycSettings.Levels.Count > levelNum)
            {
                level = _kycSettings.Levels[levelNum];
            }
            var withdrawalTotalThisPeriod = user.WithdrawalTotalThisPeriod(_kycSettings);
            // convert withdrawal amount to string
            var withdrawalTotalThisPeriodString = _walletProvider.AmountToString(_kycSettings.WithdrawalAsset, withdrawalTotalThisPeriod);

            if (withdrawalTotalThisPeriodString == null)
            {
                withdrawalTotalThisPeriodString = withdrawalTotalThisPeriod.ToString();
            }

            var model = new KycViewModel
            {
                User     = user,
                LevelNum = levelNum,
                Level    = level,
                WithdrawalTotalThisPeriod = withdrawalTotalThisPeriodString,
                KycSettings      = _kycSettings,
                KycRequestUrl    = kycRequestUrl,
                KycRequestStatus = kycRequestStatus,
            };

            return(View(model));
        }
Exemple #2
0
        protected (bool success, decimal withdrawalAssetAmount, string error) ValidateWithdrawlLimit(ApplicationUser user, string asset, decimal amount)
        {
            var withdrawalTotalThisPeriod = user.WithdrawalTotalThisPeriod(_kycSettings);
            var withdrawalAssetAmount     = CalculateWithdrawalAssetEquivalent(_logger, _kycSettings, asset, amount);
            var newWithdrawalTotal        = withdrawalTotalThisPeriod + withdrawalAssetAmount;
            var kycLevel = _kycSettings.Levels[0];

            if (user.Kyc != null && user.Kyc.Level < _kycSettings.Levels.Count)
            {
                kycLevel = _kycSettings.Levels[user.Kyc.Level];
            }
            if (decimal.Parse(kycLevel.WithdrawalLimit) <= newWithdrawalTotal)
            {
                var withdrawalTotalThisPeriodString = _walletProvider.AmountToString(_kycSettings.WithdrawalAsset, withdrawalTotalThisPeriod);
                if (withdrawalTotalThisPeriodString == null)
                {
                    withdrawalTotalThisPeriodString = withdrawalTotalThisPeriod.ToString();
                }
                return(false, 0,
                       $"Your withdrawal limit is {kycLevel.WithdrawalLimit} {_kycSettings.WithdrawalAsset} equivalent, your current withdrawal total this period ({_kycSettings.WithdrawalPeriod}) is {withdrawalTotalThisPeriodString} {_kycSettings.WithdrawalAsset}");
            }
            return(true, withdrawalAssetAmount, null);
        }