Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }
            if (Input.WithdrawAmount < 20)
            {
                TempData["ERROR"] = "Minimum withdrawal is 20 TRTL";
                return(Page());
            }
            if (Input.WithdrawAmount > user.TRTLBalance)
            {
                TempData["ERROR"] = "You tried to withdraw more than you have";
                return(Page());
            }
            var adminModel  = _db.AdminModel.FirstOrDefault();
            var GameBalance = TRTLService.GetTRTLBalance(adminModel.PaymentAddress);

            /*amount to withdraw would exceed balance*/
            if ((GameBalance.availableBalance) < Input.WithdrawAmount)
            {
                TempData["ERROR"] = "Internal error 1";
                return(Page());
            }

            string WithdrawAddress  = Input.WithdrawAddress;
            float  WithdrawalFeeDev = (5f / 100f);
            float  WithdrawAmount   = Input.WithdrawAmount - ((float)Input.WithdrawAmount * WithdrawalFeeDev);
            int    WithdrawAmountForFeeCalculation = (int)Math.Ceiling(WithdrawAmount);
            float  feeCalculated = TRTLService.GetTRTLFee(float.Parse(WithdrawAmountForFeeCalculation.ToString()));
            var    transfer      = TRTLService.TransferTRTL(
                from: _db.AdminModel.FirstOrDefault().PaymentAddress,
                to: WithdrawAddress,
                amount: float.Parse((WithdrawAmount + feeCalculated).ToString("n2")),
                fee: (float)0.1
                );

            if (transfer != null && transfer.transactionHash != null && transfer.transactionHash.Length > 0)
            {
                if (_db.Withdrawals.Where(w => w.transactionHash == transfer.transactionHash).FirstOrDefault() == null)
                {
                    _db.Withdrawals.Add(new Withdrawal()
                    {
                        transactionHash = transfer.transactionHash
                    });
                }
                user.TRTLBalance        -= Input.WithdrawAmount;
                user.TRTLWithdrawnTotal += Input.WithdrawAmount;
                _db.Users.Update(user);
                _db.SaveChanges();
                TempData["SUCCESS"] = "Withdrawal of " + WithdrawAmount + " TRTL successfull. Withdrawal hash is: " + transfer.transactionHash;
            }
            else
            {
                TempData["ERROR"] = "Internal error. Please contact admin or try different amount.";
            }
            return(Page());
        }
Esempio n. 2
0
 public float getAmountFee(decimal amount)
 {
     return(TRTLService.GetTRTLFee(float.Parse(amount.ToString())));
 }