Esempio n. 1
0
    public static String GetName(BalanceType balanceType)
    {
        switch (balanceType)
        {
        case BalanceType.MainBalance:
            if (TitanFeatures.IsTrafficThunder)
            {
                return(String.Format(U6012.WALLET, String.Format("{0} {1}", AppSettings.Site.CurrencyCode, U5004.MAIN)));
            }
            return(L1.MAINBALANCE);

        case BalanceType.PurchaseBalance:
            if (TitanFeatures.IsTrafficThunder)
            {
                return(String.Format(U6012.WALLET, AppSettings.Site.CurrencyCode));
            }
            return(U6012.PURCHASEBALANCE);

        case BalanceType.TrafficBalance:
            return(U4200.TRAFFICBALANCE);

        case BalanceType.PointsBalance:
            return(String.Format("{0}", AppSettings.PointsName));

        case BalanceType.CommissionBalance:
            return(U5004.COMMISSIONBALANCE);

        case BalanceType.PTCCredits:
            return(String.Format("{0} {1}", U6003.PTC, U6012.CREDITS));

        case BalanceType.CashBalance:
            return(U5008.CASHBALANCE);

        case BalanceType.InvestmentBalance:
            return(U6006.INVESTMENTBALANCE);

        case BalanceType.MarketplaceBalance:
            return(U6008.MARKETPLACEBALANCE);

        case BalanceType.BTC:
        case BalanceType.ETH:
        case BalanceType.XRP:
            return(String.Format(U6012.WALLET, balanceType.ToString()));

        case BalanceType.Token:
            return(String.Format(U6012.WALLET, CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token).Code));

        case BalanceType.FreezedToken:
            return(String.Format(U6012.WALLET, CryptocurrencyFactory.Get(CryptocurrencyType.ERCFreezed).Code));

        case BalanceType.LoginAdsCredits:
            return(U5008.LOGINADSCREDITS);

        default:
            return(String.Empty);
        }
    }
Esempio n. 2
0
        public void Buy(Member buyer, int quantity, string deliveryAddress, string email, BalanceType targetBalance)
        {
            Money totalAmount = this.Price * quantity;

            if (totalAmount <= Money.Zero)
            {
                throw new MsgException(U5006.AMOUNTEQUALZERO);
            }

            if (targetBalance == BalanceType.PurchaseBalance)
            {
                if (totalAmount > buyer.PurchaseBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                //Take money and save the user
                buyer.SubtractFromPurchaseBalance(totalAmount, "Marketplace purchase", BalanceLogType.MarketplacePurchase);
            }
            else if (targetBalance == BalanceType.MarketplaceBalance)
            {
                if (totalAmount > buyer.MarketplaceBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                //Take money and save the user
                buyer.SubtractFromMarketplaceBalance(totalAmount, "Marketplace purchase", BalanceLogType.MarketplacePurchase);
            }
            else
            {
                throw new ArgumentException("Invalid argument: " + targetBalance.ToString(), "targetBalance");
            }
            buyer.SaveBalances();

            //Add history entry
            History.AddPurchase(buyer.Name, totalAmount, "Marketplace purchase");

            MarketplaceMember mBuyer = new MarketplaceMember(email, deliveryAddress, buyer.Name, buyer.Id);

            MarketplaceIPN.Create(mBuyer, quantity, this);

            this.Quantity -= Quantity;
            this.Sold     += Quantity;
            this.Save();
        }
Esempio n. 3
0
        public static void TryPurchaseTokens(Member user, ICOStage stage, int numberOfTokens, BalanceType targetBalance)
        {
            var TokenCryprocurrency = CryptocurrencyFactory.Get(CryptocurrencyType.ERC20Token);

            if (numberOfTokens <= 0)
            {
                throw new MsgException(U5006.AMOUNTEQUALZERO);
            }

            if (numberOfTokens > stage.GetAvailableTokens())
            {
                throw new MsgException(U6012.NOTOKENSLEFT);
            }

            int userPurchasesInLast15min = ICOPurchase.GetUserPurchasesInLast15Min(stage.Id, user.Id);

            if (userPurchasesInLast15min + numberOfTokens > AppSettings.ICO.ICOPurchaseLimitPerUserPer15mins)
            {
                throw new MsgException(String.Format(U6012.COINSEXCEED15MIN, "<b>" + userPurchasesInLast15min + "</b>", TokenCryprocurrency.Code));
            }

            //All OK, let's charge the balance
            //If freeze system is enabled, purchased tokens are freezed
            CryptocurrencyType TypeOfPurchasedCoins = AppSettings.Ethereum.ERC20TokensFreezeSystemEnabled ? CryptocurrencyType.ERCFreezed : CryptocurrencyType.ERC20Token;
            Money totalAmount = numberOfTokens * stage.TokenPrice;

            if (targetBalance == BalanceType.PurchaseBalance)
            {
                if (totalAmount > user.PurchaseBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromPurchaseBalance(totalAmount, TokenCryprocurrency.Code + " purchase", BalanceLogType.CoinPurchase);
                user.SaveBalances();
            }
            else if (targetBalance == BalanceType.BTC)
            {
                decimal amountInBTC = (totalAmount.ToDecimal() /
                                       CryptocurrencyFactory.Get(CryptocurrencyType.BTC).GetValue().ToDecimal()).TruncateDecimals(8);

                if (amountInBTC > user.GetCryptocurrencyBalance(CryptocurrencyType.BTC).ToDecimal())
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                user.SubtractFromCryptocurrencyBalance(CryptocurrencyType.BTC, amountInBTC,
                                                       TokenCryprocurrency.Code + " purchase", BalanceLogType.CoinPurchase);
            }
            else
            {
                throw new ArgumentException("Invalid argument: " + targetBalance.ToString(), "targetBalance");
            }

            //Add history entry
            History.AddPurchase(user.Name, totalAmount, TokenCryprocurrency.Code);

            //Credit coins to Referrer
            decimal tokensCreditedToReferrer = 0;

            if (user.HasReferer)
            {
                var Referer = new Member(user.ReferrerId);
                tokensCreditedToReferrer = (Referer.Membership.ICOPurchasePercent / 100) * numberOfTokens;

                if (tokensCreditedToReferrer > 0)
                {
                    Referer.AddToCryptocurrencyBalance(TypeOfPurchasedCoins, tokensCreditedToReferrer, TokenCryprocurrency.Code + " purchase /ref/"
                                                       + user.Name, BalanceLogType.CoinPurchase);

                    if (TypeOfPurchasedCoins == CryptocurrencyType.ERCFreezed)
                    {
                        UserFreezedToken.Add(Referer.Id, tokensCreditedToReferrer);
                    }

                    user.IncreaseERC20TokensEarningsForDRef(tokensCreditedToReferrer);
                    user.SaveStatistics();
                }
            }

            //Add purchase entry
            ICOPurchase.Add(user.Id, numberOfTokens, tokensCreditedToReferrer + (decimal)numberOfTokens, stage.Id);

            //Add coins to balance
            user.AddToCryptocurrencyBalance(TypeOfPurchasedCoins, numberOfTokens, TokenCryprocurrency.Code + " purchase", BalanceLogType.CoinPurchase);
            if (TypeOfPurchasedCoins == CryptocurrencyType.ERCFreezed)
            {
                UserFreezedToken.Add(user.Id, Decimal.Parse(numberOfTokens.ToString()));
            }
        }