From 46dca8c0952ee08cd32d3dc4045b59834b7ff5c3 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 9 Oct 2025 07:27:57 +0300 Subject: [PATCH] Revert "Fix referral bonus display and layout spacing" --- app/config.py | 12 +- app/webapi/routes/miniapp.py | 122 ----- app/webapi/schemas/miniapp.py | 68 --- miniapp/index.html | 831 ---------------------------------- 4 files changed, 2 insertions(+), 1031 deletions(-) diff --git a/app/config.py b/app/config.py index 032cdf5e..23b62e0c 100644 --- a/app/config.py +++ b/app/config.py @@ -13,9 +13,8 @@ from pathlib import Path class Settings(BaseSettings): - + BOT_TOKEN: str - BOT_USERNAME: Optional[str] = None ADMIN_IDS: str = "" SUPPORT_USERNAME: str = "@support" SUPPORT_MENU_ENABLED: bool = True @@ -528,14 +527,7 @@ class Settings(BaseSettings): def get_trial_warning_hours(self) -> int: return self.TRIAL_WARNING_HOURS - - def get_bot_username(self) -> Optional[str]: - username = getattr(self, "BOT_USERNAME", None) - if not username: - return None - normalized = str(username).strip().lstrip("@") - return normalized or None - + def is_notifications_enabled(self) -> bool: return self.ENABLE_NOTIFICATIONS diff --git a/app/webapi/routes/miniapp.py b/app/webapi/routes/miniapp.py index 3683d0df..864c1fee 100644 --- a/app/webapi/routes/miniapp.py +++ b/app/webapi/routes/miniapp.py @@ -46,10 +46,6 @@ from app.utils.telegram_webapp import ( TelegramWebAppAuthError, parse_webapp_init_data, ) -from app.utils.user_utils import ( - get_detailed_referral_list, - get_user_referral_summary, -) from ..dependencies import get_db_session from ..schemas.miniapp import ( @@ -66,12 +62,6 @@ from ..schemas.miniapp import ( MiniAppPromoOffer, MiniAppPromoOfferClaimRequest, MiniAppPromoOfferClaimResponse, - MiniAppReferralInfo, - MiniAppReferralItem, - MiniAppReferralList, - MiniAppReferralRecentEarning, - MiniAppReferralStats, - MiniAppReferralTerms, MiniAppRichTextDocument, MiniAppSubscriptionRequest, MiniAppSubscriptionResponse, @@ -732,115 +722,6 @@ async def _load_subscription_links( return payload -async def _build_referral_info( - db: AsyncSession, - user: User, -) -> Optional[MiniAppReferralInfo]: - referral_code = getattr(user, "referral_code", None) - referral_settings = settings.get_referral_settings() or {} - - bot_username = settings.get_bot_username() - referral_link = None - if referral_code and bot_username: - referral_link = f"https://t.me/{bot_username}?start={referral_code}" - - terms = MiniAppReferralTerms( - minimum_topup_kopeks=int(referral_settings.get("minimum_topup_kopeks") or 0), - minimum_topup_label=settings.format_price(int(referral_settings.get("minimum_topup_kopeks") or 0)), - first_topup_bonus_kopeks=int(referral_settings.get("first_topup_bonus_kopeks") or 0), - first_topup_bonus_label=settings.format_price(int(referral_settings.get("first_topup_bonus_kopeks") or 0)), - inviter_bonus_kopeks=int(referral_settings.get("inviter_bonus_kopeks") or 0), - inviter_bonus_label=settings.format_price(int(referral_settings.get("inviter_bonus_kopeks") or 0)), - commission_percent=float(referral_settings.get("commission_percent") or 0), - referred_user_reward_kopeks=int(referral_settings.get("referred_user_reward") or 0), - referred_user_reward_label=settings.format_price(int(referral_settings.get("referred_user_reward") or 0)), - ) - - summary = await get_user_referral_summary(db, user.id) - stats: Optional[MiniAppReferralStats] = None - recent_earnings: List[MiniAppReferralRecentEarning] = [] - - if summary: - total_earned_kopeks = int(summary.get("total_earned_kopeks") or 0) - month_earned_kopeks = int(summary.get("month_earned_kopeks") or 0) - - stats = MiniAppReferralStats( - invited_count=int(summary.get("invited_count") or 0), - paid_referrals_count=int(summary.get("paid_referrals_count") or 0), - active_referrals_count=int(summary.get("active_referrals_count") or 0), - total_earned_kopeks=total_earned_kopeks, - total_earned_label=settings.format_price(total_earned_kopeks), - month_earned_kopeks=month_earned_kopeks, - month_earned_label=settings.format_price(month_earned_kopeks), - conversion_rate=float(summary.get("conversion_rate") or 0.0), - ) - - for earning in summary.get("recent_earnings", []) or []: - amount = int(earning.get("amount_kopeks") or 0) - recent_earnings.append( - MiniAppReferralRecentEarning( - amount_kopeks=amount, - amount_label=settings.format_price(amount), - reason=earning.get("reason"), - referral_name=earning.get("referral_name"), - created_at=earning.get("created_at"), - ) - ) - - detailed = await get_detailed_referral_list(db, user.id, limit=50, offset=0) - referral_items: List[MiniAppReferralItem] = [] - if detailed: - for item in detailed.get("referrals", []) or []: - total_earned = int(item.get("total_earned_kopeks") or 0) - balance = int(item.get("balance_kopeks") or 0) - referral_items.append( - MiniAppReferralItem( - id=int(item.get("id") or 0), - telegram_id=item.get("telegram_id"), - full_name=item.get("full_name"), - username=item.get("username"), - created_at=item.get("created_at"), - last_activity=item.get("last_activity"), - has_made_first_topup=bool(item.get("has_made_first_topup")), - balance_kopeks=balance, - balance_label=settings.format_price(balance), - total_earned_kopeks=total_earned, - total_earned_label=settings.format_price(total_earned), - topups_count=int(item.get("topups_count") or 0), - days_since_registration=item.get("days_since_registration"), - days_since_activity=item.get("days_since_activity"), - status=item.get("status"), - ) - ) - - referral_list = MiniAppReferralList( - total_count=int(detailed.get("total_count") or 0) if detailed else 0, - has_next=bool(detailed.get("has_next")) if detailed else False, - has_prev=bool(detailed.get("has_prev")) if detailed else False, - current_page=int(detailed.get("current_page") or 1) if detailed else 1, - total_pages=int(detailed.get("total_pages") or 1) if detailed else 1, - items=referral_items, - ) - - if ( - not referral_code - and not referral_link - and not referral_items - and not recent_earnings - and (not stats or (stats.invited_count == 0 and stats.total_earned_kopeks == 0)) - ): - return None - - return MiniAppReferralInfo( - referral_code=referral_code, - referral_link=referral_link, - terms=terms, - stats=stats, - recent_earnings=recent_earnings, - referrals=referral_list, - ) - - @router.post("/subscription", response_model=MiniAppSubscriptionResponse) async def get_subscription_details( payload: MiniAppSubscriptionRequest, @@ -1129,8 +1010,6 @@ async def get_subscription_details( promo_offer_discount_source=promo_offer_source, ) - referral_info = await _build_referral_info(db, user) - return MiniAppSubscriptionResponse( subscription_id=subscription.id, remnawave_short_uuid=subscription.remnawave_short_uuid, @@ -1171,7 +1050,6 @@ async def get_subscription_details( branding=settings.get_miniapp_branding(), faq=faq_payload, legal_documents=legal_documents_payload, - referral=referral_info, ) diff --git a/app/webapi/schemas/miniapp.py b/app/webapi/schemas/miniapp.py index 60181a7c..1988e34b 100644 --- a/app/webapi/schemas/miniapp.py +++ b/app/webapi/schemas/miniapp.py @@ -175,73 +175,6 @@ class MiniAppLegalDocuments(BaseModel): privacy_policy: Optional[MiniAppRichTextDocument] = None -class MiniAppReferralTerms(BaseModel): - minimum_topup_kopeks: int = 0 - minimum_topup_label: Optional[str] = None - first_topup_bonus_kopeks: int = 0 - first_topup_bonus_label: Optional[str] = None - inviter_bonus_kopeks: int = 0 - inviter_bonus_label: Optional[str] = None - commission_percent: float = 0.0 - referred_user_reward_kopeks: int = 0 - referred_user_reward_label: Optional[str] = None - - -class MiniAppReferralStats(BaseModel): - invited_count: int = 0 - paid_referrals_count: int = 0 - active_referrals_count: int = 0 - total_earned_kopeks: int = 0 - total_earned_label: Optional[str] = None - month_earned_kopeks: int = 0 - month_earned_label: Optional[str] = None - conversion_rate: float = 0.0 - - -class MiniAppReferralRecentEarning(BaseModel): - amount_kopeks: int = 0 - amount_label: Optional[str] = None - reason: Optional[str] = None - referral_name: Optional[str] = None - created_at: Optional[datetime] = None - - -class MiniAppReferralItem(BaseModel): - id: int - telegram_id: Optional[int] = None - full_name: Optional[str] = None - username: Optional[str] = None - created_at: Optional[datetime] = None - last_activity: Optional[datetime] = None - has_made_first_topup: bool = False - balance_kopeks: int = 0 - balance_label: Optional[str] = None - total_earned_kopeks: int = 0 - total_earned_label: Optional[str] = None - topups_count: int = 0 - days_since_registration: Optional[int] = None - days_since_activity: Optional[int] = None - status: Optional[str] = None - - -class MiniAppReferralList(BaseModel): - total_count: int = 0 - has_next: bool = False - has_prev: bool = False - current_page: int = 1 - total_pages: int = 1 - items: List[MiniAppReferralItem] = Field(default_factory=list) - - -class MiniAppReferralInfo(BaseModel): - referral_code: Optional[str] = None - referral_link: Optional[str] = None - terms: Optional[MiniAppReferralTerms] = None - stats: Optional[MiniAppReferralStats] = None - recent_earnings: List[MiniAppReferralRecentEarning] = Field(default_factory=list) - referrals: Optional[MiniAppReferralList] = None - - class MiniAppSubscriptionResponse(BaseModel): success: bool = True subscription_id: int @@ -275,5 +208,4 @@ class MiniAppSubscriptionResponse(BaseModel): branding: Optional[MiniAppBranding] = None faq: Optional[MiniAppFaq] = None legal_documents: Optional[MiniAppLegalDocuments] = None - referral: Optional[MiniAppReferralInfo] = None diff --git a/miniapp/index.html b/miniapp/index.html index e5ba33e9..1f07a1c9 100644 --- a/miniapp/index.html +++ b/miniapp/index.html @@ -1243,293 +1243,6 @@ font-size: 18px; } - /* Referral Section */ - .referral-card-summary { - margin-left: auto; - display: flex; - align-items: center; - gap: 12px; - flex-wrap: wrap; - justify-content: flex-end; - } - - .referral-card-summary-item { - display: flex; - flex-direction: column; - gap: 4px; - align-items: flex-end; - padding: 8px 12px; - border-radius: var(--radius-sm); - background: rgba(var(--primary-rgb), 0.08); - } - - .referral-card-summary-label { - font-size: 11px; - font-weight: 600; - text-transform: uppercase; - letter-spacing: 0.5px; - color: var(--text-secondary); - } - - .referral-card-summary-value { - font-size: 15px; - font-weight: 700; - color: var(--text-primary); - } - - .referral-content { - display: flex; - flex-direction: column; - gap: 16px; - margin-top: 12px; - } - - .referral-link-section { - display: flex; - flex-direction: column; - gap: 8px; - padding: 16px; - border: 1px solid var(--border-color); - border-radius: var(--radius); - background: rgba(var(--primary-rgb), 0.04); - } - - .referral-link-header { - display: flex; - align-items: center; - justify-content: space-between; - gap: 12px; - } - - .referral-link-label { - font-size: 13px; - font-weight: 600; - color: var(--text-secondary); - } - - .referral-link-value { - font-size: 15px; - font-weight: 600; - color: var(--primary); - word-break: break-word; - } - - .referral-copy-btn { - border: none; - border-radius: var(--radius-sm); - padding: 8px 12px; - background: var(--primary); - color: var(--tg-theme-button-text-color); - font-size: 13px; - font-weight: 600; - cursor: pointer; - transition: transform 0.2s ease, box-shadow 0.2s ease; - } - - .referral-copy-btn:disabled { - opacity: 0.6; - cursor: not-allowed; - } - - .referral-copy-btn:not(:disabled):active { - transform: scale(0.98); - } - - .referral-stats { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); - gap: 12px; - } - - .referral-stat-card { - border: 1px solid var(--border-color); - border-radius: var(--radius); - padding: 12px; - background: rgba(var(--primary-rgb), 0.03); - } - - .referral-stat-label { - font-size: 12px; - text-transform: uppercase; - color: var(--text-secondary); - letter-spacing: 0.04em; - margin-bottom: 6px; - display: block; - } - - .referral-stat-value { - font-size: 18px; - font-weight: 700; - } - - .referral-terms { - display: flex; - flex-direction: column; - gap: 8px; - } - - .referral-section-title { - font-size: 13px; - font-weight: 700; - color: var(--text-secondary); - text-transform: uppercase; - letter-spacing: 0.05em; - } - - .referral-terms-list { - list-style: none; - display: flex; - flex-direction: column; - gap: 10px; - margin: 0; - padding: 0; - } - - .referral-term-item { - display: flex; - justify-content: space-between; - gap: 12px; - padding: 12px; - border: 1px solid var(--border-color); - border-radius: var(--radius); - background: rgba(var(--primary-rgb), 0.02); - } - - .referral-term-label { - font-size: 13px; - color: var(--text-secondary); - } - - .referral-term-value { - font-size: 14px; - font-weight: 600; - } - - .referral-toggle-btn { - display: inline-flex; - align-items: center; - justify-content: center; - gap: 8px; - border: 1px solid var(--border-color); - border-radius: var(--radius); - padding: 10px 14px; - background: transparent; - font-size: 14px; - font-weight: 600; - color: var(--text-primary); - cursor: pointer; - transition: background 0.2s ease, transform 0.2s ease; - } - - .referral-toggle-btn:hover { - background: rgba(var(--primary-rgb), 0.06); - } - - .referral-toggle-btn:active { - transform: scale(0.98); - } - - .referral-list { - list-style: none; - display: flex; - flex-direction: column; - gap: 12px; - margin: 0; - padding: 0; - } - - .referral-item { - border: 1px solid var(--border-color); - border-radius: var(--radius); - padding: 14px; - display: flex; - flex-direction: column; - gap: 10px; - background: rgba(var(--primary-rgb), 0.02); - } - - .referral-item-header { - display: flex; - justify-content: space-between; - align-items: center; - gap: 12px; - } - - .referral-item-name { - font-size: 15px; - font-weight: 600; - } - - .referral-item-username { - font-size: 13px; - color: var(--text-secondary); - margin-top: 2px; - } - - .referral-status { - font-size: 12px; - font-weight: 600; - padding: 4px 8px; - border-radius: 999px; - text-transform: uppercase; - letter-spacing: 0.04em; - } - - .referral-status.active { - background: rgba(16, 185, 129, 0.12); - color: #047857; - } - - .referral-status.inactive { - background: rgba(148, 163, 184, 0.12); - color: #475569; - } - - .referral-status.new { - background: rgba(59, 130, 246, 0.12); - color: #1d4ed8; - } - - .referral-item-grid { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); - gap: 10px; - } - - .referral-item-metric { - display: flex; - flex-direction: column; - gap: 4px; - } - - .referral-item-label { - font-size: 12px; - color: var(--text-secondary); - text-transform: uppercase; - letter-spacing: 0.05em; - } - - .referral-item-value { - font-size: 14px; - font-weight: 600; - } - - .referral-item-dates { - display: flex; - flex-direction: column; - gap: 4px; - } - - .referral-item-date { - font-size: 12px; - color: var(--text-secondary); - } - - .referral-item-date strong { - color: var(--text-primary); - font-weight: 600; - } - /* Transaction History */ .history-list { list-style: none; @@ -2342,11 +2055,6 @@ grid-template-columns: repeat(2, 1fr); } - .referral-card-summary { - margin-left: 0; - justify-content: space-between; - } - .user-header { padding: 16px; } @@ -2451,10 +2159,6 @@ color: rgba(226, 232, 240, 0.75); } - :root[data-theme="dark"] .referral-card-summary-item { - background: rgba(var(--primary-rgb), 0.2); - } - :root[data-theme="dark"] .promo-discount-badge.muted .promo-discount-value { color: rgba(226, 232, 240, 0.75); } @@ -2749,52 +2453,6 @@ - - -