protected void WithdrawCryptocurrencyButton_Click(object sender, EventArgs e) { if (Page.IsValid) { CryptocurrencySuccessMessagePanel.Visible = false; CryptocurrencyErrorMessagePanel.Visible = false; try { var Cryptocurrency = CryptocurrencyFactory.Get(SelectedCryptocurrency); User.ValidatePIN(CryptoPINTextBox.Text); string address = TryGetWithdrawalAddress(Cryptocurrency); Money moneyAmount = Money.Zero; Money moneyFee = Money.Zero; Money totalAmount = Money.Zero; decimal amountInCryptocurrency = Decimal.Zero; if (Cryptocurrency.WithdrawalFeePolicy == WithdrawalFeePolicy.Packs) { WithdrawalPacksPlaceHolder.Visible = true; WithdrawalPacksLiteral.Text = BitcoinWithdrawalFeePacks.GetPacksText(User.Id); } moneyAmount = new Money(Convert.ToDecimal(WithdrawCryptocurrencyAmountTextBox.Text)).FromMulticurrency(); moneyFee = Cryptocurrency.EstimatedWithdrawalFee(amountInCryptocurrency, address, User.Id, Cryptocurrency.WithdrawalSource); totalAmount = moneyAmount - moneyFee; amountInCryptocurrency = Cryptocurrency.ConvertFromMoney(moneyAmount); if (Cryptocurrency.WithdrawalSource == WithdrawalSourceBalance.Wallet) { amountInCryptocurrency = Convert.ToDecimal(WithdrawCryptocurrencyAmountTextBox.Text); moneyAmount = new CryptocurrencyMoney(Cryptocurrency.Type, amountInCryptocurrency); moneyFee = Cryptocurrency.EstimatedWithdrawalFee(amountInCryptocurrency, address, User.Id, Cryptocurrency.WithdrawalSource); totalAmount = new CryptocurrencyMoney(SelectedCryptocurrency, moneyAmount.ToDecimal() - moneyFee.ToDecimal()); } TryValidateCryptocurrencyWithdrawalByEmailOrPhone(); CryptocurrencyFeeLiteral.Visible = WithdrawTotalCryptocurrencyLiteral.Visible = true; CryptocurrencyFeeLiteral.Text = "</br>" + U3500.CASHOUT_FEES + ": " + moneyFee.ToString() + "</br>"; WithdrawTotalCryptocurrencyLiteral.Text = "<b>" + U5001.TOTAL + ": " + totalAmount + "</b>"; WithdrawCryptocurrencyButton.Visible = false; WithdrawCryptocurrencyConfirmButton.Visible = true; WithdrawCryptocurrencyAmountTextBox.Enabled = false; CryptoPINTextBox.Enabled = false; } catch (Exception ex) { CryptocurrencyErrorMessagePanel.Visible = true; CryptocurrencyErrorMessageLiteral.Text = ex.Message; } } }
private decimal EstimatedWithdrawalFee(decimal cryptocurrencyAmount, string userAddress, int userId) { decimal ProcessorFee = CryptocurrencyApiFactory.GetWithdrawalApi(this).GetEstimatedWithdrawalFee(cryptocurrencyAmount, userAddress); if (this.WithdrawalFeePolicy == WithdrawalFeePolicy.Packs) { var fee = BitcoinWithdrawalFeePacks.GetFeePackForUser(userId).Fee; return(ProcessorFee + this.ConvertFromMoney(Money.MultiplyPercent(this.ConvertToMoney(cryptocurrencyAmount), fee))); } return(ProcessorFee + this.ConvertFromMoney(GetAdminWithdrawalFee(this.ConvertToMoney(cryptocurrencyAmount)))); }