Beispiel #1
0
        public ActionResult Send(string address, string amount)
        {
            decimal amountParsed = 0;

            if (string.IsNullOrEmpty(this.CurrentUser.AccountName))
            {
                TempData["ErrorMessage"] = "Authentication Error!";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            if (string.IsNullOrEmpty(address))
            {
                TempData["ErrorMessage"] = "Did you enter a receiver address?";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            if (string.IsNullOrEmpty(amount))
            {
                TempData["ErrorMessage"] = "Did you enter an amount?";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            if (!decimal.TryParse(amount, out amountParsed))
            {
                amount = amount.Replace(".", ",");
                if (!decimal.TryParse(amount, out amountParsed))
                {
                    TempData["ErrorMessage"] = "Did you enter a correct amount?";
                    return(RedirectToAction("Dancefloor", "Home"));
                }
            }

            OnionHandler handler = new OnionHandler();

            // seems that rpc getbalance delivers wrong amounts.. Check explorer.deeponion.org instead.
            //decimal amountSpendable = handler.GetAccountBalance(this.CurrentUser.AccountName);
            decimal amountSpendable = OnionPriceChecker.GetAddressBalance(this.CurrentUser.OnionAddress);

            // TODO Calculate actual fees
            amountSpendable = (amountSpendable > (decimal)0.001) ? amountSpendable - (decimal)0.001 : 0;

            if (amountParsed > amountSpendable)
            {
                TempData["ErrorMessage"] = "Insufficient funds! You cannot send more than " + amountSpendable + " Onions!";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            try
            {
                string transactionID = handler.SendOnions(this.CurrentUser.AccountName, address, amountParsed);
                TempData["SuccessMessage"] = "Onions successfully sent!";
            }
            catch (Exception ex)
            {
                Logger.Error("OnionController->Send: " + ex.Message);
                TempData["ErrorMessage"] = "Oops, something went wrong! Please try again or contact support.";
            }

            return(RedirectToAction("Dancefloor", "Home"));
        }