public async Task <ActionResult> WithdrawCancel(string userid, string code, int withdrawid)
        {
            if (!await VerifyUserTwoFactorTokenAsync(TwoFactorTokenType.WithdrawCancel, userid, code))
            {
                ViewBag.SubTitle = "Invalid Security Token";
                ViewBag.Message  = $"Security token for cancellation of withdraw #{withdrawid} is invalid or has expired.";
                return(View("Error"));
            }

            var result = await WithdrawWriter.CancelWithdraw(User.Identity.GetUserId(), new CancelWithdrawModel
            {
                WithdrawId = withdrawid
            });

            if (!result.Success)
            {
                ViewBag.SubTitle = "Withdraw Cancel Failed.";
                ViewBag.Message  = result.Message;
                return(View("Error"));
            }

            ViewBag.SubTitle = "Withdrawal Canceled";
            ViewBag.Message  = $"Withdrawal #{withdrawid} has been successfully canceled.";
            return(View("Success"));
        }
        public async Task <ActionResult> WithdrawConfirm(string userId, string code, int withdrawid)
        {
            if (!await VerifyUserTwoFactorTokenAsync(TwoFactorTokenType.WithdrawConfirm, userId, code))
            {
                ViewBag.SubTitle = "Invalid Security Token";
                ViewBag.Message  = $"Security token for withdraw #{withdrawid} is invalid or has expired, You can send a new one from the <a href='/WithdrawHistory'>Withdraw History</a> section in your account page.";
                return(View("Error"));
            }

            var result = await WithdrawWriter.ConfirmWithdraw(userId, new ConfirmWithdrawModel
            {
                WithdrawId     = withdrawid,
                TwoFactorToken = code
            });

            if (!result.Success)
            {
                ViewBag.SubTitle = "Invalid Security Token";
                ViewBag.Message  = $"Security token for withdraw #{withdrawid} is invalid or has expired, You can send a new one from the <a href='/WithdrawHistory'>Withdraw History</a> section in your account page.";
                return(View("Error"));
            }

            ViewBag.SubTitle = "Withdrawal Confirmed";
            ViewBag.Message  = $"Your withdrawal has been confirmed and will be processed in a few minutes.";
            return(View("Success"));
        }
        public async Task <ActionResult> ResendWithdrawConfirmation(int withdrawid)
        {
            var user = await UserManager.FindValidByIdAsync(User.Identity.GetUserId());

            if (user == null)
            {
                return(JsonError("Unauthorized"));
            }

            var twoFactortoken = await GenerateUserTwoFactorTokenAsync(TwoFactorTokenType.WithdrawConfirm, user.Id);

            var model = new UpdateTwoFactorTokenModel
            {
                WithdrawId     = withdrawid,
                TwoFactorToken = twoFactortoken
            };

            var response = await WithdrawWriter.UpdateTwoFactorToken(User.Identity.GetUserId(), model);

            if (!response.Success)
            {
                return(JsonError(response.Message));
            }

            if (!await SendConfirmationEmail(user, model.Symbol, model.Amount, model.Address, withdrawid, twoFactortoken, model.AddressType))
            {
                return(JsonError("Failed to send email, if problem persists please contact Cryptopia support."));
            }

            return(JsonSuccess($"Successfully sent. Please check {user.Email} for a secure link to confirm this withdrawal."));
        }
        public async Task <ActionResult> CancelWithdraw(int withdrawid)
        {
            var result = await WithdrawWriter.CancelWithdraw(User.Identity.GetUserId(), new CancelWithdrawModel
            {
                WithdrawId = withdrawid
            });

            if (!result.Success)
            {
                return(JsonError(result.Message));
            }

            return(JsonSuccess(string.Format("Withdrawal #{0} has been successfully canceled.", withdrawid)));
        }
Esempio n. 5
0
        public async Task <ApiResult <ApiSubmitWithdrawResponse> > SubmitWithdraw(string userId, string currency, string address, decimal amount)
        {
            try
            {
                var result = await WithdrawWriter.CreateApiWithdraw(userId, currency, address, amount);

                if (result.HasErrors)
                {
                    return(new ApiResult <ApiSubmitWithdrawResponse>(false, result.FirstError));
                }

                var apiResult = new ApiSubmitWithdrawResponse
                {
                    WithdrawalId = result.Data
                };
                return(new ApiResult <ApiSubmitWithdrawResponse>(true, apiResult));
            }
            catch (Exception ex)
            {
                return(new ApiResult <ApiSubmitWithdrawResponse>(ex));
            }
        }
        public async Task <ActionResult> Create(WithdrawCurrencyModel model)
        {
            var currencyData = await CurrencyReader.GetCurrency(model.Symbol);

            var user = await UserManager.FindValidByIdAsync(User.Identity.GetUserId());

            if (currencyData == null || user == null)
            {
                ViewBag.Message = $"Currency {model.Symbol} not found.";
                return(View("Error"));
            }

            if (currencyData.CurrencyId == Constant.NZDT_ID && !UserVerificationReader.IsVerified(user.VerificationLevel))
            {
                return(View("NotVerified"));
            }

            // Verify Address
            var address = model.AddressData?.Trim();

            if (string.IsNullOrEmpty(address))
            {
                address = model.SelectedAddress;
            }
            else if (currencyData.AddressType != AddressType.Standard)
            {
                if (currencyData.AddressType == AddressType.PaymentId && !CurrencyExtensions.IsValidPaymentId(model.AddressData2?.Trim()))
                {
                    ModelState.AddModelError("AddressData2", $"Please enter a valid Cryptonote PaymentId.");
                    return(View(await CreateWithdrawModel(user, model)));
                }
                address = $"{model.AddressData?.Trim()}:{model.AddressData2?.Trim()}";
                if (currencyData.Type == CurrencyType.Fiat)
                {
                    address = address.TrimEnd(':');
                }
            }
            if (string.IsNullOrEmpty(address))
            {
                ModelState.AddModelError(user.IsUnsafeWithdrawEnabled ? "AddressData" : "AddressBookError", $"Please enter a valid {model.Symbol} address");
                return(View(await CreateWithdrawModel(user, model)));
            }

            // Verify Amount
            var withdrawAmount = decimal.Round(model.Amount, currencyData.CurrencyDecimals);

            if (withdrawAmount < currencyData.WithdrawMin || withdrawAmount >= currencyData.WithdrawMax)
            {
                ModelState.AddModelError("Amount", $"Withdrawal amount must be between {currencyData.WithdrawMin} {currencyData.Symbol} and {currencyData.WithdrawMax} {currencyData.Symbol}");
                return(View(await CreateWithdrawModel(user, model)));
            }

            // Verify Two Factor
            if (!await UserManager.VerifyUserTwoFactorCodeAsync(TwoFactorComponent.Withdraw, user.Id, model.Code1, model.Code2))
            {
                ModelState.AddModelError("TwoFactorError", "The TFA code entered was incorrect or has expired, please try again.");
                return(View(await CreateWithdrawModel(user, model)));
            }

            // Create withdraw

            var twoFactortoken = await GenerateUserTwoFactorTokenAsync(TwoFactorTokenType.WithdrawConfirm, user.Id);

            var result = await WithdrawWriter.CreateWithdraw(User.Identity.GetUserId(), new CreateWithdrawModel
            {
                Address        = address,
                Amount         = withdrawAmount,
                CurrencyId     = model.CurrencyId,
                TwoFactorToken = twoFactortoken,
                Type           = WithdrawType.Normal,
            });

            if (!result.Success)
            {
                ModelState.AddModelError("Error", result.Message);
                return(View(await CreateWithdrawModel(user, model)));
            }

            // Send Confirmation email
            if (!user.DisableWithdrawEmailConfirmation)
            {
                await SendConfirmationEmail(user, model.Symbol, withdrawAmount - model.Fee, address, result.Result, twoFactortoken, currencyData.AddressType);
            }

            return(RedirectToAction("Summary", new { withdrawId = result.Result, returnUrl = GetLocalReturnUrl(model.ReturnUrl) }));
        }