After refonte for the options of Profile
This commit is contained in:
parent
c65def01fe
commit
22e86a76dc
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../core/di/injection.dart';
|
||||
import '../../../core/errors/app_exception.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
@ -58,6 +59,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Future<void>? _gamesInFlight;
|
||||
Future<void>? _referralInFlight;
|
||||
|
||||
/// Privacy-first: amount hidden until the user reveals it (synced with Wallet).
|
||||
bool _hideBalance = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -66,20 +70,40 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
_games = cachedGames;
|
||||
_gamesLoading = false;
|
||||
}
|
||||
final cachedAds = sl<AdvertisementRepository>().peekLast(placement: 'home_hero');
|
||||
final cachedAds = sl<AdvertisementRepository>().peekLast(
|
||||
placement: 'home_hero',
|
||||
);
|
||||
if (cachedAds != null && cachedAds.isNotEmpty) {
|
||||
_heroAds = cachedAds;
|
||||
_adsLoading = false;
|
||||
}
|
||||
_loadHideBalancePreference();
|
||||
_load();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
context.read<PredictionBloc>().add(const PredictionLoadRequested(ifStale: true));
|
||||
context.read<PredictionBloc>().add(
|
||||
const PredictionLoadRequested(ifStale: true),
|
||||
);
|
||||
context.read<WalletBloc>().add(const WalletLoadRequested(ifStale: true));
|
||||
_checkAppUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadHideBalancePreference() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_hideBalance = prefs.getBool(kHideBalancePrefsKey) ?? true;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _toggleHideBalance() async {
|
||||
final next = !_hideBalance;
|
||||
setState(() => _hideBalance = next);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(kHideBalancePrefsKey, next);
|
||||
}
|
||||
|
||||
Future<void> _checkAppUpdate() async {
|
||||
final available = await checkAppUpdateAvailable();
|
||||
if (!mounted) return;
|
||||
@ -182,7 +206,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
_referralRetrying = force || _referral == null;
|
||||
});
|
||||
try {
|
||||
final referral = await sl<ReferralRepository>().getDashboard(maxDepth: 1);
|
||||
final referral = await sl<ReferralRepository>().getDashboard(
|
||||
maxDepth: 1,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_referral = referral;
|
||||
@ -233,10 +259,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> _onUpdateTap() => handleAppUpdateTap(
|
||||
context,
|
||||
updateAvailable: _updateAvailable,
|
||||
);
|
||||
Future<void> _onUpdateTap() =>
|
||||
handleAppUpdateTap(context, updateAvailable: _updateAvailable);
|
||||
|
||||
void _openHelp() => context.push('/faq?category=predictions');
|
||||
|
||||
@ -314,8 +338,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
icon: Icons.notifications_none_rounded,
|
||||
foregroundColor: Colors.white,
|
||||
showBadge: _unreadNotifications > 0,
|
||||
badgeLabel:
|
||||
_unreadNotifications > 9 ? '9+' : '$_unreadNotifications',
|
||||
badgeLabel: _unreadNotifications > 9
|
||||
? '9+'
|
||||
: '$_unreadNotifications',
|
||||
onPressed: () async {
|
||||
await context.push('/notifications');
|
||||
if (mounted) _refreshUnread();
|
||||
@ -345,45 +370,24 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
final loading =
|
||||
wallet.isLoading && wallet.balances.isEmpty;
|
||||
if (loading) {
|
||||
return const PredSkeletonCard(height: 132);
|
||||
return const PredSkeletonCard(height: 64);
|
||||
}
|
||||
final code = balance?.walletType.code ?? 'USDT';
|
||||
//final code = balance?.walletType.code ?? 'USDT';
|
||||
final code = 'USDT';
|
||||
final decimals = balance?.walletType.decimals ?? 6;
|
||||
final amountLabel = balance == null
|
||||
final amountLabel = _hideBalance
|
||||
? '****** $code'
|
||||
: balance == null
|
||||
? '— $code'
|
||||
: '${rawAmountToHuman(balance.available, decimals)} $code';
|
||||
final subtitle = balance == null
|
||||
? s.navWallet
|
||||
: code.toUpperCase().contains('USDT')
|
||||
? 'USDT'
|
||||
: code;
|
||||
return BalanceHeroCard(
|
||||
key: const Key('home_balance_hero'),
|
||||
amountLabel: amountLabel,
|
||||
subtitle: subtitle,
|
||||
trailing: TextButton(
|
||||
onPressed: () => context.push('/deposit'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.primary,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
backgroundColor:
|
||||
AppColors.primary.withValues(alpha: 0.14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
s.deposit,
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
),
|
||||
obscured: _hideBalance,
|
||||
onVisibilityToggle: _toggleHideBalance,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 12),
|
||||
HomeAdCarousel(
|
||||
ads: _heroAds,
|
||||
loading: _adsLoading && _heroAds.isEmpty,
|
||||
@ -401,7 +405,9 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
onRetry: () => _loadGames(force: true),
|
||||
)
|
||||
else if (_games.isNotEmpty)
|
||||
..._games.take(4).map(
|
||||
..._games
|
||||
.take(4)
|
||||
.map(
|
||||
(g) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _GameCard(
|
||||
@ -422,39 +428,45 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
_FeaturedPredictCard(
|
||||
onTap: () => context.go('/predict'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_SectionTitle(
|
||||
title: s.shortcuts,
|
||||
subtitle: s.shortcutsSubtitle,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_ShortcutGrid(
|
||||
items: [
|
||||
_Shortcut(
|
||||
icon: predictionGamesNavIcon,
|
||||
label: s.navPredict,
|
||||
color: AppColors.primary,
|
||||
onTap: () => context.go('/predict'),
|
||||
),
|
||||
_Shortcut(
|
||||
icon: Icons.add_rounded,
|
||||
label: s.deposit,
|
||||
color: AppColors.info,
|
||||
onTap: () => context.push('/deposit'),
|
||||
),
|
||||
_Shortcut(
|
||||
icon: Icons.groups_rounded,
|
||||
label: s.referralTitle,
|
||||
color: AppColors.accentGold,
|
||||
onTap: () => context.push('/referral'),
|
||||
),
|
||||
_Shortcut(
|
||||
icon: Icons.help_outline_rounded,
|
||||
label: s.helpCenter,
|
||||
color: AppColors.walletBonus,
|
||||
onTap: _openHelp,
|
||||
),
|
||||
],
|
||||
// Single quick action — Predict / Referral / Help live in
|
||||
// Play Now, Your Network, How it Works (and bottom nav).
|
||||
PredCard(
|
||||
key: const Key('home_deposit_shortcut'),
|
||||
onTap: () => context.push('/deposit'),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 14,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.info.withValues(alpha: 0.16),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.add_rounded,
|
||||
color: AppColors.info,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.deposit,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
color: AppColors.textMuted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_totpKnown && !_totpEnabled) ...[
|
||||
const SizedBox(height: 22),
|
||||
@ -500,6 +512,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
const SizedBox(height: 12),
|
||||
_ReferralTeaser(
|
||||
dashboard: _referral!,
|
||||
obscured: _hideBalance,
|
||||
onTap: () => context.push('/referral'),
|
||||
),
|
||||
],
|
||||
@ -591,19 +604,17 @@ class _SectionTitle extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w800),
|
||||
),
|
||||
if (subtitle != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle!,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textMuted
|
||||
: const Color(0xFF64748B),
|
||||
),
|
||||
color: isDark ? AppColors.textMuted : const Color(0xFF64748B),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
@ -645,15 +656,18 @@ class _FeaturedPredictCard extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(s.predictionGamesTitle, style: const TextStyle(fontWeight: FontWeight.w800)),
|
||||
Text(
|
||||
s.predictionGamesTitle,
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
s.predictionGamesSubtitle,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -698,9 +712,12 @@ class _GameCard extends StatelessWidget {
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: game.thumbnailUrl != null && game.thumbnailUrl!.isNotEmpty
|
||||
? Image.network(game.thumbnailUrl!, fit: BoxFit.cover,
|
||||
? Image.network(
|
||||
game.thumbnailUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) =>
|
||||
Icon(gameCatalogIcon(game), color: Colors.white))
|
||||
Icon(gameCatalogIcon(game), color: Colors.white),
|
||||
)
|
||||
: Icon(gameCatalogIcon(game), color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
@ -708,16 +725,20 @@ class _GameCard extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(game.title, style: const TextStyle(fontWeight: FontWeight.w800)),
|
||||
if (game.description != null && game.description!.isNotEmpty) ...[
|
||||
Text(
|
||||
game.title,
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
if (game.description != null &&
|
||||
game.description!.isNotEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
game.description!,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
@ -738,51 +759,6 @@ class _GameCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _Shortcut {
|
||||
const _Shortcut({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
}
|
||||
|
||||
class _ShortcutGrid extends StatelessWidget {
|
||||
const _ShortcutGrid({required this.items});
|
||||
final List<_Shortcut> items;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
childAspectRatio: 1.55,
|
||||
children: [
|
||||
for (final item in items)
|
||||
PredCard(
|
||||
onTap: item.onTap,
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(item.icon, color: item.color),
|
||||
const Spacer(),
|
||||
Text(item.label, style: const TextStyle(fontWeight: FontWeight.w700)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TwoFaPromptCard extends StatelessWidget {
|
||||
const _TwoFaPromptCard({required this.onTap});
|
||||
final VoidCallback onTap;
|
||||
@ -824,10 +800,10 @@ class _TwoFaPromptCard extends StatelessWidget {
|
||||
Text(
|
||||
s.homeTwoFaSubtitle,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
@ -852,9 +828,14 @@ class _TwoFaPromptCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _ReferralTeaser extends StatelessWidget {
|
||||
const _ReferralTeaser({required this.dashboard, required this.onTap});
|
||||
const _ReferralTeaser({
|
||||
required this.dashboard,
|
||||
required this.onTap,
|
||||
this.obscured = true,
|
||||
});
|
||||
final ReferralDashboardModel dashboard;
|
||||
final VoidCallback onTap;
|
||||
final bool obscured;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -867,19 +848,24 @@ class _ReferralTeaser extends StatelessWidget {
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.directReferrals,
|
||||
value: '${dashboard.directReferrals}',
|
||||
value: obscured ? '*****' : '${dashboard.directReferrals}',
|
||||
obscured: obscured,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.networkSize,
|
||||
value: '${dashboard.networkSize}',
|
||||
value: obscured ? '*****' : '${dashboard.networkSize}',
|
||||
obscured: obscured,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _MiniStat(
|
||||
label: s.totalEarned,
|
||||
value: rawAmountToHuman(dashboard.totalEarnedRaw, 6),
|
||||
value: obscured
|
||||
? '*****'
|
||||
: rawAmountToHuman(dashboard.totalEarnedRaw, 6),
|
||||
obscured: obscured,
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -889,22 +875,34 @@ class _ReferralTeaser extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _MiniStat extends StatelessWidget {
|
||||
const _MiniStat({required this.label, required this.value});
|
||||
const _MiniStat({
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.obscured = false,
|
||||
});
|
||||
final String label;
|
||||
final String value;
|
||||
final bool obscured;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.w900, fontSize: 16)),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 16,
|
||||
letterSpacing: obscured ? 1.5 : 0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
label,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: AppColors.textMuted,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.labelSmall?.copyWith(color: AppColors.textMuted),
|
||||
),
|
||||
],
|
||||
);
|
||||
@ -923,19 +921,25 @@ class _HowItWorksCard extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.lightbulb_outline_rounded, color: AppColors.accentGold),
|
||||
const Icon(
|
||||
Icons.lightbulb_outline_rounded,
|
||||
color: AppColors.accentGold,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(s.howItWorks, style: const TextStyle(fontWeight: FontWeight.w800)),
|
||||
Text(
|
||||
s.howItWorks,
|
||||
style: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
s.howItWorksSubtitle,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/di/injection.dart';
|
||||
@ -11,6 +11,7 @@ import '../../../l10n/app_strings.dart';
|
||||
import '../../../shared/widgets/app_snackbar.dart';
|
||||
import '../../../shared/widgets/pred_card.dart';
|
||||
import '../../../shared/widgets/pred_skeleton.dart';
|
||||
import '../../../shared/widgets/prediqo_logo.dart';
|
||||
import '../../../shared/widgets/section_error.dart';
|
||||
import '../../home/utils/home_navigation.dart';
|
||||
import '../bloc/prediction_bloc.dart';
|
||||
@ -102,79 +103,124 @@ class _PredictionGamesScreenState extends State<PredictionGamesScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
return Scaffold(
|
||||
key: const Key('prediction_games_screen'),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _load(force: true),
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
floating: true,
|
||||
pinned: false,
|
||||
centerTitle: false,
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
s.predictionGamesTitle,
|
||||
style: const TextStyle(fontWeight: FontWeight.w900),
|
||||
),
|
||||
Text(
|
||||
s.predictionGamesSubtitle,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: AppColors.textMuted,
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
||||
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
key: const Key('prediction_games_screen'),
|
||||
body: Column(
|
||||
children: [
|
||||
DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF059669),
|
||||
Color(0xFF047857),
|
||||
Color(0xFF0F172A),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: SizedBox(
|
||||
height: kToolbarHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
const PrediqoLogo(size: 28, showWordmark: false),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.predictionGamesTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.3,
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 32),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
if (_error != null && _games.isEmpty)
|
||||
SectionError(
|
||||
message: _error!,
|
||||
retrying: _retrying,
|
||||
onRetry: () => _load(force: true),
|
||||
)
|
||||
else if (_loading && _games.isEmpty)
|
||||
const Column(
|
||||
children: [
|
||||
PredSkeletonCard(height: 96),
|
||||
SizedBox(height: 12),
|
||||
PredSkeletonCard(height: 96),
|
||||
SizedBox(height: 12),
|
||||
PredSkeletonCard(height: 96),
|
||||
],
|
||||
)
|
||||
else if (_games.isEmpty)
|
||||
PredCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
s.predictionGamesEmpty,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => _load(force: true),
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.fromLTRB(20, 12, 20, 24 + bottomInset),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
Text(
|
||||
s.predictionGamesSubtitle,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textMuted
|
||||
: const Color(0xFF64748B),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_error != null && _games.isEmpty)
|
||||
SectionError(
|
||||
message: _error!,
|
||||
retrying: _retrying,
|
||||
onRetry: () => _load(force: true),
|
||||
)
|
||||
else if (_loading && _games.isEmpty)
|
||||
const Column(
|
||||
children: [
|
||||
PredSkeletonCard(height: 96),
|
||||
SizedBox(height: 12),
|
||||
PredSkeletonCard(height: 96),
|
||||
SizedBox(height: 12),
|
||||
PredSkeletonCard(height: 96),
|
||||
],
|
||||
)
|
||||
else if (_games.isEmpty)
|
||||
PredCard(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(
|
||||
s.predictionGamesEmpty,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
..._games.map(
|
||||
(g) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: _PredictionGameCard(
|
||||
game: g,
|
||||
onTap: () => _openGame(g),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
..._games.map(
|
||||
(g) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: _PredictionGameCard(
|
||||
game: g,
|
||||
onTap: () => _openGame(g),
|
||||
)
|
||||
.animate()
|
||||
.fadeIn(duration: 280.ms)
|
||||
.slideY(begin: 0.03, end: 0),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -193,9 +239,13 @@ class _PredictionGameCard extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final accent = parseHexColor(game.accentColor);
|
||||
final status = gameStatusLabel(game, isFr: s.isFr);
|
||||
final icon = gameCatalogIcon(game);
|
||||
final endColor = isDark ? AppColors.surfaceCard : Colors.white;
|
||||
final muted = isDark ? AppColors.textMuted : const Color(0xFF94A3B8);
|
||||
final secondary = isDark ? AppColors.textSecondary : const Color(0xFF475569);
|
||||
|
||||
return PredCard(
|
||||
key: Key('game_card_${game.slug}'),
|
||||
@ -203,8 +253,8 @@ class _PredictionGameCard extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(16),
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
accent.withValues(alpha: 0.2),
|
||||
AppColors.surfaceCard,
|
||||
accent.withValues(alpha: isDark ? 0.2 : 0.12),
|
||||
endColor,
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
@ -217,7 +267,14 @@ class _PredictionGameCard extends StatelessWidget {
|
||||
color: accent.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(icon, color: accent, size: 30),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: game.thumbnailUrl != null && game.thumbnailUrl!.isNotEmpty
|
||||
? Image.network(
|
||||
game.thumbnailUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => Icon(icon, color: accent, size: 30),
|
||||
)
|
||||
: Icon(icon, color: accent, size: 30),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
@ -237,7 +294,7 @@ class _PredictionGameCard extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: game.isPlayable
|
||||
? AppColors.primary.withValues(alpha: 0.15)
|
||||
: AppColors.textMuted.withValues(alpha: 0.15),
|
||||
: muted.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
@ -245,7 +302,7 @@ class _PredictionGameCard extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: game.isPlayable ? AppColors.primary : AppColors.textMuted,
|
||||
color: game.isPlayable ? AppColors.primary : muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -258,7 +315,7 @@ class _PredictionGameCard extends StatelessWidget {
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
color: secondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../../core/di/injection.dart';
|
||||
import '../../../core/errors/app_exception.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
@ -7,6 +8,7 @@ import '../../../domain/repositories/referral_repository.dart';
|
||||
import '../../../l10n/app_strings.dart';
|
||||
import '../../../shared/widgets/pred_skeleton.dart';
|
||||
import '../../../shared/widgets/section_error.dart';
|
||||
import '../../../shared/widgets/tloto_gradient_app_bar.dart';
|
||||
import 'widgets/referral_member_card.dart';
|
||||
|
||||
const _pageSize = 15;
|
||||
@ -53,7 +55,8 @@ class _ReferralDirectsScreenState extends State<ReferralDirectsScreen> {
|
||||
});
|
||||
}
|
||||
try {
|
||||
final dashboard = await _repo.getDashboard(maxDepth: 1, force: force || !keep);
|
||||
final dashboard =
|
||||
await _repo.getDashboard(maxDepth: 1, force: force || !keep);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_members = dashboard.directMembers;
|
||||
@ -79,29 +82,50 @@ class _ReferralDirectsScreenState extends State<ReferralDirectsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
||||
final visible = _members.take(_visibleCount).toList();
|
||||
final remaining = _members.length - visible.length;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(s.directReferrals)),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _load(force: true),
|
||||
child: _buildBody(s, visible, remaining),
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: TlotoGradientAppBar.overlayStyle,
|
||||
child: Scaffold(
|
||||
key: const Key('referral_directs_screen'),
|
||||
body: Column(
|
||||
children: [
|
||||
TlotoGradientAppBar(
|
||||
title: s.directReferrals,
|
||||
showBack: true,
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => _load(force: true),
|
||||
child: _buildBody(s, isDark, visible, remaining, bottomInset),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(
|
||||
AppStrings s,
|
||||
bool isDark,
|
||||
List<ReferralNetworkMember> visible,
|
||||
int remaining,
|
||||
double bottomInset,
|
||||
) {
|
||||
final muted = isDark ? AppColors.textMuted : const Color(0xFF94A3B8);
|
||||
final secondary =
|
||||
isDark ? AppColors.textSecondary : const Color(0xFF475569);
|
||||
|
||||
if (_loading && _members.isEmpty) {
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 28),
|
||||
padding: EdgeInsets.fromLTRB(20, 16, 20, 24 + bottomInset),
|
||||
children: const [
|
||||
PredSkeletonCard(height: 88),
|
||||
SizedBox(height: 10),
|
||||
@ -116,7 +140,7 @@ class _ReferralDirectsScreenState extends State<ReferralDirectsScreen> {
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 28),
|
||||
padding: EdgeInsets.fromLTRB(20, 16, 20, 24 + bottomInset),
|
||||
children: [
|
||||
SectionError(
|
||||
message: _error!,
|
||||
@ -131,15 +155,15 @@ class _ReferralDirectsScreenState extends State<ReferralDirectsScreen> {
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.all(40),
|
||||
padding: EdgeInsets.fromLTRB(40, 40, 40, 40 + bottomInset),
|
||||
children: [
|
||||
const Icon(Icons.groups_outlined, size: 48, color: AppColors.textMuted),
|
||||
Icon(Icons.groups_outlined, size: 48, color: muted),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
s.noDirectReferrals,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
color: secondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -149,7 +173,7 @@ class _ReferralDirectsScreenState extends State<ReferralDirectsScreen> {
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 28),
|
||||
padding: EdgeInsets.fromLTRB(20, 16, 20, 24 + bottomInset),
|
||||
itemCount: visible.length + (remaining > 0 ? 1 : 0),
|
||||
separatorBuilder: (_, __) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, index) {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../../core/di/injection.dart';
|
||||
import '../../../core/errors/app_exception.dart';
|
||||
import '../../../core/network/api_client.dart';
|
||||
@ -8,7 +9,9 @@ import '../../../domain/repositories/referral_repository.dart';
|
||||
import '../../../l10n/app_strings.dart';
|
||||
import '../../../shared/widgets/pred_skeleton.dart';
|
||||
import '../../../shared/widgets/section_error.dart';
|
||||
import '../../../shared/widgets/tloto_gradient_app_bar.dart';
|
||||
import 'widgets/referral_network_tree.dart';
|
||||
import 'widgets/referral_tree_toolbar.dart';
|
||||
|
||||
/// Expandable tree of commission-eligible referral levels.
|
||||
class ReferralNetworkScreen extends StatefulWidget {
|
||||
@ -20,15 +23,21 @@ class ReferralNetworkScreen extends StatefulWidget {
|
||||
|
||||
class _ReferralNetworkScreenState extends State<ReferralNetworkScreen> {
|
||||
final _repo = sl<ReferralRepository>();
|
||||
final _treeKey = GlobalKey<ReferralNetworkTreeState>();
|
||||
final _transform = TransformationController();
|
||||
|
||||
bool _loading = true;
|
||||
bool _retrying = false;
|
||||
String? _error;
|
||||
ReferralDashboardModel? _dashboard;
|
||||
String? _rootUserId;
|
||||
String? _selectedUserId;
|
||||
double _scale = 1;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_transform.addListener(_onTransformChanged);
|
||||
final cached = _repo.peekLastDashboard(maxDepth: 10);
|
||||
if (cached != null) {
|
||||
_dashboard = cached;
|
||||
@ -37,6 +46,20 @@ class _ReferralNetworkScreenState extends State<ReferralNetworkScreen> {
|
||||
_load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_transform.removeListener(_onTransformChanged);
|
||||
_transform.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onTransformChanged() {
|
||||
final next = _transform.value.getMaxScaleOnAxis();
|
||||
if ((next - _scale).abs() > 0.001) {
|
||||
setState(() => _scale = next);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _load({bool force = false}) async {
|
||||
final keep = _dashboard != null && !force;
|
||||
if (!keep) {
|
||||
@ -82,7 +105,9 @@ class _ReferralNetworkScreenState extends State<ReferralNetworkScreen> {
|
||||
String _resolvedRootUserId(ReferralDashboardModel dashboard) {
|
||||
if (_rootUserId != null && _rootUserId!.isNotEmpty) return _rootUserId!;
|
||||
for (final m in dashboard.network) {
|
||||
if (m.levelNumber == 1 && m.parentUserId.isNotEmpty) return m.parentUserId;
|
||||
if (m.levelNumber == 1 && m.parentUserId.isNotEmpty) {
|
||||
return m.parentUserId;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@ -90,39 +115,83 @@ class _ReferralNetworkScreenState extends State<ReferralNetworkScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
||||
final depth = _dashboard?.maxNetworkDepth;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(s.referralNetworkTree),
|
||||
actions: [
|
||||
if (depth != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Center(
|
||||
child: Text(
|
||||
s.referralLevelLabel(depth),
|
||||
style: Theme.of(context).textTheme.labelLarge?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: TlotoGradientAppBar.overlayStyle,
|
||||
child: Scaffold(
|
||||
key: const Key('referral_network_screen'),
|
||||
body: Column(
|
||||
children: [
|
||||
TlotoGradientAppBar(
|
||||
title: s.referralNetworkTree,
|
||||
showBack: true,
|
||||
actions: [
|
||||
if (depth != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.14),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.22),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
s.referralLevelLabel(depth),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: s.retry,
|
||||
onPressed: _retrying ? null : () => _load(force: true),
|
||||
icon: _retrying
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.refresh_rounded, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _load(force: true),
|
||||
child: _buildBody(s),
|
||||
Expanded(
|
||||
child: _buildBody(s, isDark, bottomInset),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(AppStrings s) {
|
||||
Widget _buildBody(AppStrings s, bool isDark, double bottomInset) {
|
||||
final muted = isDark ? AppColors.textMuted : const Color(0xFF94A3B8);
|
||||
final secondary =
|
||||
isDark ? AppColors.textSecondary : const Color(0xFF475569);
|
||||
|
||||
if (_loading && _dashboard == null) {
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||
padding: EdgeInsets.fromLTRB(16, 12, 16, 24 + bottomInset),
|
||||
children: const [
|
||||
PredSkeletonLine(width: 180, height: 14),
|
||||
SizedBox(height: 16),
|
||||
@ -139,7 +208,7 @@ class _ReferralNetworkScreenState extends State<ReferralNetworkScreen> {
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||
padding: EdgeInsets.fromLTRB(16, 12, 16, 24 + bottomInset),
|
||||
children: [
|
||||
SectionError(
|
||||
message: _error!,
|
||||
@ -149,36 +218,76 @@ class _ReferralNetworkScreenState extends State<ReferralNetworkScreen> {
|
||||
],
|
||||
);
|
||||
}
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||
children: [
|
||||
Text(
|
||||
s.tapToExpand,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textMuted,
|
||||
|
||||
final dashboard = _dashboard;
|
||||
if (dashboard == null || dashboard.network.isEmpty) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 40, 24, 24 + bottomInset),
|
||||
child: Text(
|
||||
s.noNetworkMembers,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: secondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (_dashboard != null)
|
||||
ReferralNetworkTree(
|
||||
members: _dashboard!.network,
|
||||
rootUserId: _resolvedRootUserId(_dashboard!),
|
||||
referrer: _dashboard!.referrer,
|
||||
)
|
||||
else
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 40),
|
||||
);
|
||||
}
|
||||
|
||||
final rootId = _resolvedRootUserId(dashboard);
|
||||
if (rootId.isEmpty) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 40, 24, 24 + bottomInset),
|
||||
child: Text(
|
||||
s.noNetworkMembers,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: secondary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: ReferralNetworkTree(
|
||||
key: _treeKey,
|
||||
members: dashboard.network,
|
||||
rootUserId: rootId,
|
||||
rootLabel: s.networkYou,
|
||||
referrer: dashboard.referrer,
|
||||
transformationController: _transform,
|
||||
onSelectionChanged: (id) {
|
||||
setState(() => _selectedUserId = id);
|
||||
},
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 12,
|
||||
right: 12,
|
||||
top: 8,
|
||||
child: IgnorePointer(
|
||||
child: Text(
|
||||
s.noNetworkMembers,
|
||||
s.tapToExpand,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 12 + bottomInset,
|
||||
child: Center(
|
||||
child: ReferralTreeToolbar(
|
||||
treeKey: _treeKey,
|
||||
scale: _scale,
|
||||
hasSelection: _selectedUserId != null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../core/di/injection.dart';
|
||||
import '../../../core/errors/app_exception.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
@ -9,8 +10,10 @@ import '../../../data/models/referral_models.dart';
|
||||
import '../../../domain/repositories/referral_repository.dart';
|
||||
import '../../../l10n/app_strings.dart';
|
||||
import '../../../shared/widgets/app_snackbar.dart';
|
||||
import '../../../shared/widgets/balance_hero_card.dart';
|
||||
import '../../../shared/widgets/pred_card.dart';
|
||||
import '../../../shared/widgets/pred_skeleton.dart';
|
||||
import '../../../shared/widgets/prediqo_logo.dart';
|
||||
import '../../../shared/widgets/section_error.dart';
|
||||
|
||||
class ReferralScreen extends StatefulWidget {
|
||||
@ -41,6 +44,9 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
Future<void>? _dashboardInFlight;
|
||||
Future<void>? _commissionsInFlight;
|
||||
|
||||
/// Privacy-first — synced with Home/Wallet hide preference.
|
||||
bool _hideSensitive = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -54,10 +60,31 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
_commissions = cachedCommissions.items;
|
||||
_commissionsLoading = false;
|
||||
}
|
||||
_loadHidePreference();
|
||||
_loadDashboard();
|
||||
_loadCommissions();
|
||||
}
|
||||
|
||||
Future<void> _loadHidePreference() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_hideSensitive = prefs.getBool(kHideBalancePrefsKey) ?? true;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _toggleHideSensitive() async {
|
||||
final next = !_hideSensitive;
|
||||
setState(() => _hideSensitive = next);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(kHideBalancePrefsKey, next);
|
||||
}
|
||||
|
||||
String _maskCount(int value) => _hideSensitive ? '*****' : '$value';
|
||||
|
||||
String _maskAmount(String raw) =>
|
||||
_hideSensitive ? '*****' : '${rawAmountToHuman(raw, 6)} USDT';
|
||||
|
||||
Future<void> _loadDashboard({bool force = false}) {
|
||||
if (_dashboardInFlight != null) return _dashboardInFlight!;
|
||||
final keep = _dashboard != null && !force;
|
||||
@ -168,21 +195,101 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(s.referralTitle)),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: _refreshAll,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: const EdgeInsets.all(20),
|
||||
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
key: const Key('referral_screen'),
|
||||
body: Column(
|
||||
children: [
|
||||
..._dashboardSection(s),
|
||||
const SizedBox(height: 20),
|
||||
Text(s.recentCommissions, style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
..._commissionsSection(s),
|
||||
DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF059669),
|
||||
Color(0xFF047857),
|
||||
Color(0xFF0F172A),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: SizedBox(
|
||||
height: kToolbarHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: MaterialLocalizations.of(context)
|
||||
.backButtonTooltip,
|
||||
onPressed: () => context.pop(),
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_rounded,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const PrediqoLogo(size: 26, showWordmark: false),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.referralTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.3,
|
||||
color: Colors.white,
|
||||
fontSize: 17,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('referral_privacy_toggle'),
|
||||
tooltip: _hideSensitive
|
||||
? s.showBalance
|
||||
: s.hideBalance,
|
||||
onPressed: _toggleHideSensitive,
|
||||
icon: Icon(
|
||||
_hideSensitive
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: _refreshAll,
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
padding: EdgeInsets.fromLTRB(20, 16, 20, 24 + bottomInset),
|
||||
children: [
|
||||
..._dashboardSection(s),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
s.recentCommissions,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
..._commissionsSection(s),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -274,7 +381,8 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
Expanded(
|
||||
child: _StatCard(
|
||||
label: s.directReferrals,
|
||||
value: '${d.directReferrals}',
|
||||
value: _maskCount(d.directReferrals),
|
||||
obscured: _hideSensitive,
|
||||
icon: Icons.person_add_alt_1_rounded,
|
||||
onTap: () => _openRoute('/referral/directs'),
|
||||
),
|
||||
@ -283,49 +391,15 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
Expanded(
|
||||
child: _StatCard(
|
||||
label: s.networkSize,
|
||||
value: '${d.networkSize}',
|
||||
value: _maskCount(d.networkSize),
|
||||
obscured: _hideSensitive,
|
||||
icon: Icons.account_tree_rounded,
|
||||
onTap: () => _openRoute('/referral/network'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
PredCard(
|
||||
onTap: () => _openRoute('/referral/directs'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.groups_rounded, color: AppColors.primary),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.viewDirectReferrals,
|
||||
style: const TextStyle(fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right_rounded, color: AppColors.textMuted),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
PredCard(
|
||||
onTap: () => _openRoute('/referral/network'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.lan_rounded, color: AppColors.accentGold),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.viewNetworkTree,
|
||||
style: const TextStyle(fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right_rounded, color: AppColors.textMuted),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Direct / network stats are tappable — no separate "View …" tiles.
|
||||
if (d.referrer != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
PredCard(
|
||||
@ -356,9 +430,21 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
children: [
|
||||
Text(s.earnings, style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 12),
|
||||
_EarningRow(label: s.totalEarned, raw: d.totalEarnedRaw),
|
||||
_EarningRow(label: s.paid, raw: d.paidRaw),
|
||||
_EarningRow(label: s.pending, raw: d.pendingRaw),
|
||||
_EarningRow(
|
||||
label: s.totalEarned,
|
||||
display: _maskAmount(d.totalEarnedRaw),
|
||||
obscured: _hideSensitive,
|
||||
),
|
||||
_EarningRow(
|
||||
label: s.paid,
|
||||
display: _maskAmount(d.paidRaw),
|
||||
obscured: _hideSensitive,
|
||||
),
|
||||
_EarningRow(
|
||||
label: s.pending,
|
||||
display: _maskAmount(d.pendingRaw),
|
||||
obscured: _hideSensitive,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -431,8 +517,11 @@ class _ReferralScreenState extends State<ReferralScreen> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${rawAmountToHuman(c.amountRaw, 6)} USDT',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
_maskAmount(c.amountRaw),
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: _hideSensitive ? 1.2 : 0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -470,30 +559,46 @@ class _StatCard extends StatelessWidget {
|
||||
required this.value,
|
||||
required this.icon,
|
||||
required this.onTap,
|
||||
this.obscured = false,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
final IconData icon;
|
||||
final VoidCallback onTap;
|
||||
final bool obscured;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
return PredCard(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, color: AppColors.primary, size: 22),
|
||||
const SizedBox(height: 8),
|
||||
Text(value, style: Theme.of(context).textTheme.headlineSmall),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
letterSpacing: obscured ? 1.5 : 0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
label,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Icon(Icons.chevron_right_rounded, size: 18, color: AppColors.textMuted),
|
||||
Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
size: 18,
|
||||
color: isDark ? AppColors.textMuted : const Color(0xFF94A3B8),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -501,9 +606,14 @@ class _StatCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _EarningRow extends StatelessWidget {
|
||||
const _EarningRow({required this.label, required this.raw});
|
||||
const _EarningRow({
|
||||
required this.label,
|
||||
required this.display,
|
||||
this.obscured = false,
|
||||
});
|
||||
final String label;
|
||||
final String raw;
|
||||
final String display;
|
||||
final bool obscured;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -514,8 +624,11 @@ class _EarningRow extends StatelessWidget {
|
||||
children: [
|
||||
Text(label),
|
||||
Text(
|
||||
'${rawAmountToHuman(raw, 6)} USDT',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
display,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: obscured ? 1.2 : 0,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -1,89 +1,655 @@
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../../../../data/models/referral_models.dart';
|
||||
import '../../../../l10n/app_strings.dart';
|
||||
import '../../utils/referral_display.dart';
|
||||
import 'referral_tree_layout.dart';
|
||||
|
||||
/// Expandable tree of commission-eligible referral levels.
|
||||
/// Interactive top-down referral org chart (pan / pinch / expand / select).
|
||||
class ReferralNetworkTree extends StatefulWidget {
|
||||
const ReferralNetworkTree({
|
||||
super.key,
|
||||
required this.members,
|
||||
required this.rootUserId,
|
||||
required this.rootLabel,
|
||||
this.referrer,
|
||||
this.transformationController,
|
||||
this.onSelectionChanged,
|
||||
});
|
||||
|
||||
final List<ReferralNetworkMember> members;
|
||||
final String rootUserId;
|
||||
final String rootLabel;
|
||||
final ReferralReferrerModel? referrer;
|
||||
final TransformationController? transformationController;
|
||||
final ValueChanged<String?>? onSelectionChanged;
|
||||
|
||||
@override
|
||||
State<ReferralNetworkTree> createState() => _ReferralNetworkTreeState();
|
||||
State<ReferralNetworkTree> createState() => ReferralNetworkTreeState();
|
||||
}
|
||||
|
||||
class _ReferralNetworkTreeState extends State<ReferralNetworkTree> {
|
||||
static const _rootBatch = 12;
|
||||
int _visibleRoots = _rootBatch;
|
||||
class ReferralNetworkTreeState extends State<ReferralNetworkTree>
|
||||
with TickerProviderStateMixin {
|
||||
static const minScale = 0.35;
|
||||
static const maxScale = 2.5;
|
||||
|
||||
late final TransformationController _transform;
|
||||
late Set<String> _expandedIds;
|
||||
String? _selectedUserId;
|
||||
ReferralTreeLayoutResult? _layout;
|
||||
AnimationController? _matrixAnim;
|
||||
Size _viewport = Size.zero;
|
||||
bool _didInitialFit = false;
|
||||
|
||||
TransformationController get transformationController => _transform;
|
||||
String? get selectedUserId => _selectedUserId;
|
||||
ReferralTreeLayoutResult? get layout => _layout;
|
||||
|
||||
Map<String, ReferralNetworkMember> get _byId {
|
||||
final map = <String, ReferralNetworkMember>{};
|
||||
for (final m in widget.members) {
|
||||
map[m.userId] = m;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Map<String, List<ReferralNetworkMember>> get _childMap =>
|
||||
buildReferralChildMap(widget.members);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_transform = widget.transformationController ?? TransformationController();
|
||||
_expandedIds = {widget.rootUserId};
|
||||
_recomputeLayout();
|
||||
_transform.addListener(_onTransformTick);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant ReferralNetworkTree oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.members != widget.members || oldWidget.rootUserId != widget.rootUserId) {
|
||||
_visibleRoots = _rootBatch;
|
||||
if (oldWidget.members != widget.members ||
|
||||
oldWidget.rootUserId != widget.rootUserId) {
|
||||
_expandedIds = {widget.rootUserId};
|
||||
_selectedUserId = null;
|
||||
_didInitialFit = false;
|
||||
widget.onSelectionChanged?.call(null);
|
||||
_recomputeLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_transform.removeListener(_onTransformTick);
|
||||
_matrixAnim?.dispose();
|
||||
if (widget.transformationController == null) {
|
||||
_transform.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onTransformTick() {
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _recomputeLayout() {
|
||||
_layout = layoutReferralTree(
|
||||
rootId: widget.rootUserId,
|
||||
childMap: _childMap,
|
||||
expandedIds: _expandedIds,
|
||||
);
|
||||
}
|
||||
|
||||
bool _canExpand(String userId) {
|
||||
final kids = _childMap[userId] ?? const [];
|
||||
if (kids.isNotEmpty) return true;
|
||||
if (userId == widget.rootUserId) {
|
||||
return (_childMap[userId] ?? const []).isNotEmpty;
|
||||
}
|
||||
final m = _byId[userId];
|
||||
return m != null && m.directReferralsCount > 0;
|
||||
}
|
||||
|
||||
bool _hasPartialChildren(String userId) {
|
||||
final m = _byId[userId];
|
||||
if (m == null) return false;
|
||||
final kids = _childMap[userId] ?? const [];
|
||||
return m.directReferralsCount > kids.length;
|
||||
}
|
||||
|
||||
void toggleExpand(String userId) {
|
||||
if (!_canExpand(userId)) return;
|
||||
setState(() {
|
||||
if (_expandedIds.contains(userId)) {
|
||||
_expandedIds.remove(userId);
|
||||
// Collapse descendants.
|
||||
final childMap = _childMap;
|
||||
void drop(String id) {
|
||||
for (final c in childMap[id] ?? const <ReferralNetworkMember>[]) {
|
||||
_expandedIds.remove(c.userId);
|
||||
drop(c.userId);
|
||||
}
|
||||
}
|
||||
drop(userId);
|
||||
} else {
|
||||
_expandedIds.add(userId);
|
||||
}
|
||||
_recomputeLayout();
|
||||
});
|
||||
}
|
||||
|
||||
void selectUser(String userId) {
|
||||
setState(() => _selectedUserId = userId);
|
||||
widget.onSelectionChanged?.call(userId);
|
||||
}
|
||||
|
||||
void showMemberSheet(String userId) {
|
||||
selectUser(userId);
|
||||
final member = _byId[userId];
|
||||
final s = context.strings;
|
||||
final parentId = member?.parentUserId;
|
||||
final parentName = parentId == null || parentId.isEmpty
|
||||
? null
|
||||
: (parentId == widget.rootUserId
|
||||
? widget.rootLabel
|
||||
: _byId[parentId]?.displayName);
|
||||
final isRoot = userId == widget.rootUserId;
|
||||
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
builder: (ctx) {
|
||||
final isDark = Theme.of(ctx).brightness == Brightness.dark;
|
||||
final muted =
|
||||
isDark ? AppColors.textMuted : const Color(0xFF64748B);
|
||||
final name = isRoot ? widget.rootLabel : (member?.displayName ?? '—');
|
||||
final initials = name.trim().isEmpty
|
||||
? '?'
|
||||
: name.trim().characters.take(2).toString().toUpperCase();
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
s.memberDetails,
|
||||
style: Theme.of(ctx).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 28,
|
||||
backgroundColor: AppColors.primary.withValues(alpha: 0.18),
|
||||
child: Text(
|
||||
initials.characters.first.toUpperCase(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 22,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
if (!isRoot && member != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
[
|
||||
s.referralLevelLabel(member.levelNumber),
|
||||
referralStatusLabel(member.status, s),
|
||||
].join(' · '),
|
||||
style: TextStyle(color: muted, fontSize: 13),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (!isRoot && member != null) ...[
|
||||
_SheetRow(
|
||||
label: s.sponsorLabel,
|
||||
value: parentName ?? '—',
|
||||
),
|
||||
_SheetRow(
|
||||
label: s.directReferrals,
|
||||
value: '${member.directReferralsCount}',
|
||||
),
|
||||
_SheetRow(
|
||||
label: s.memberSince,
|
||||
value: formatReferralDate(member.registeredAt),
|
||||
),
|
||||
if (member.generatesCommissions)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Text(
|
||||
s.generatesCommissions,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.accentGold,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_hasPartialChildren(member.userId)) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
s.networkPartialData,
|
||||
style: TextStyle(color: muted, fontSize: 12),
|
||||
),
|
||||
],
|
||||
] else ...[
|
||||
_SheetRow(
|
||||
label: s.directReferrals,
|
||||
value: '${(_childMap[widget.rootUserId] ?? const []).length}',
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
child: Text(s.closeSheet),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
double get currentScale {
|
||||
final m = _transform.value;
|
||||
return m.getMaxScaleOnAxis().clamp(minScale, maxScale);
|
||||
}
|
||||
|
||||
void zoomBy(double factor, {Offset? focal}) {
|
||||
final next = (currentScale * factor).clamp(minScale, maxScale);
|
||||
_animateToScale(next, focal: focal);
|
||||
}
|
||||
|
||||
void _animateToScale(double targetScale, {Offset? focal}) {
|
||||
final old = _transform.value.clone();
|
||||
final oldScale = old.getMaxScaleOnAxis();
|
||||
if (oldScale == 0) return;
|
||||
final sceneFocal = focal ??
|
||||
(_viewport == Size.zero
|
||||
? Offset.zero
|
||||
: _transform.toScene(
|
||||
Offset(_viewport.width / 2, _viewport.height / 2),
|
||||
));
|
||||
final ratio = targetScale / oldScale;
|
||||
final next = Matrix4.identity()
|
||||
..translateByDouble(sceneFocal.dx, sceneFocal.dy, 0, 1)
|
||||
..scaleByDouble(ratio, ratio, 1, 1)
|
||||
..translateByDouble(-sceneFocal.dx, -sceneFocal.dy, 0, 1)
|
||||
..multiply(old);
|
||||
_animateMatrix(next);
|
||||
}
|
||||
|
||||
void fitToScreen() {
|
||||
final layout = _layout;
|
||||
if (layout == null || _viewport == Size.zero) return;
|
||||
final content = layout.size;
|
||||
if (content.width <= 0 || content.height <= 0) return;
|
||||
final sx = _viewport.width / content.width;
|
||||
final sy = _viewport.height / content.height;
|
||||
final scale = math.min(sx, sy).clamp(minScale, maxScale) * 0.92;
|
||||
final dx = (_viewport.width - content.width * scale) / 2;
|
||||
final dy = (_viewport.height - content.height * scale) / 2;
|
||||
final next = Matrix4.identity()
|
||||
..translateByDouble(dx, dy, 0, 1)
|
||||
..scaleByDouble(scale, scale, 1, 1);
|
||||
_animateMatrix(next);
|
||||
}
|
||||
|
||||
void centerOnUser(String userId, {bool keepScale = true}) {
|
||||
final layout = _layout;
|
||||
final pos = layout?.positions[userId];
|
||||
if (pos == null || _viewport == Size.zero) return;
|
||||
final scale = keepScale ? currentScale : currentScale;
|
||||
final dx = _viewport.width / 2 - pos.dx * scale;
|
||||
final dy = _viewport.height / 2 - pos.dy * scale;
|
||||
final next = Matrix4.identity()
|
||||
..translateByDouble(dx, dy, 0, 1)
|
||||
..scaleByDouble(scale, scale, 1, 1);
|
||||
_animateMatrix(next);
|
||||
}
|
||||
|
||||
void goToRoot() {
|
||||
selectUser(widget.rootUserId);
|
||||
centerOnUser(widget.rootUserId);
|
||||
}
|
||||
|
||||
void _animateMatrix(Matrix4 target) {
|
||||
_matrixAnim?.stop();
|
||||
_matrixAnim?.dispose();
|
||||
final begin = _transform.value.clone();
|
||||
final controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 280),
|
||||
);
|
||||
_matrixAnim = controller;
|
||||
final anim = Matrix4Tween(begin: begin, end: target).animate(
|
||||
CurvedAnimation(parent: controller, curve: Curves.easeOutCubic),
|
||||
);
|
||||
late void Function() listener;
|
||||
listener = () {
|
||||
_transform.value = anim.value;
|
||||
if (controller.status == AnimationStatus.completed ||
|
||||
controller.status == AnimationStatus.dismissed) {
|
||||
controller.removeListener(listener);
|
||||
}
|
||||
};
|
||||
controller.addListener(listener);
|
||||
controller.forward();
|
||||
}
|
||||
|
||||
Color _levelColor(int level, {required bool isRoot}) {
|
||||
if (isRoot) return AppColors.primary;
|
||||
return switch (level % 4) {
|
||||
1 => const Color(0xFF0D9488),
|
||||
2 => AppColors.accentGold,
|
||||
3 => const Color(0xFF64748B),
|
||||
_ => AppColors.primaryDark,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final childMap = buildReferralChildMap(widget.members);
|
||||
final roots = childMap[widget.rootUserId] ?? const <ReferralNetworkMember>[];
|
||||
final visibleRoots = roots.take(_visibleRoots).toList();
|
||||
final remaining = roots.length - visibleRoots.length;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final layout = _layout;
|
||||
if (layout == null) return const SizedBox.shrink();
|
||||
|
||||
final byId = _byId;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.referrer != null) ...[
|
||||
_ReferrerBanner(referrer: widget.referrer!),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
if (roots.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 32),
|
||||
child: Text(
|
||||
s.noNetworkMembers,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
...visibleRoots.map(
|
||||
(m) => _TreeNode(
|
||||
member: m,
|
||||
childMap: childMap,
|
||||
depth: 0,
|
||||
initiallyExpanded: true,
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(12, 8, 12, 0),
|
||||
child: _ReferrerBanner(referrer: widget.referrer!),
|
||||
),
|
||||
if (remaining > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_visibleRoots = (_visibleRoots + _rootBatch).clamp(0, roots.length);
|
||||
});
|
||||
},
|
||||
child: Text(s.loadMoreRemaining(remaining)),
|
||||
),
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
_viewport = Size(constraints.maxWidth, constraints.maxHeight);
|
||||
if (!_didInitialFit && layout.positions.isNotEmpty) {
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || _didInitialFit) return;
|
||||
_didInitialFit = true;
|
||||
fitToScreen();
|
||||
});
|
||||
}
|
||||
return InteractiveViewer(
|
||||
key: const Key('referral_network_viewer'),
|
||||
transformationController: _transform,
|
||||
minScale: minScale,
|
||||
maxScale: maxScale,
|
||||
boundaryMargin: const EdgeInsets.all(800),
|
||||
constrained: false,
|
||||
child: SizedBox(
|
||||
width: math.max(layout.size.width, constraints.maxWidth),
|
||||
height: math.max(layout.size.height, constraints.maxHeight),
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
CustomPaint(
|
||||
size: layout.size,
|
||||
painter: _EdgePainter(
|
||||
layout: layout,
|
||||
isDark: isDark,
|
||||
),
|
||||
),
|
||||
for (final id in layout.visibleIds)
|
||||
_buildNode(
|
||||
context: context,
|
||||
s: s,
|
||||
isDark: isDark,
|
||||
id: id,
|
||||
center: layout.positions[id]!,
|
||||
member: byId[id],
|
||||
isRoot: id == widget.rootUserId,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNode({
|
||||
required BuildContext context,
|
||||
required AppStrings s,
|
||||
required bool isDark,
|
||||
required String id,
|
||||
required Offset center,
|
||||
required ReferralNetworkMember? member,
|
||||
required bool isRoot,
|
||||
}) {
|
||||
final level = isRoot ? 0 : (member?.levelNumber ?? 0);
|
||||
final accent = _levelColor(level, isRoot: isRoot);
|
||||
final selected = _selectedUserId == id;
|
||||
final expanded = _expandedIds.contains(id);
|
||||
final canExpand = _canExpand(id);
|
||||
final name = isRoot ? widget.rootLabel : (member?.displayName ?? '—');
|
||||
final directs = isRoot
|
||||
? (_childMap[id] ?? const []).length
|
||||
: (member?.directReferralsCount ?? 0);
|
||||
final partial = !isRoot && member != null && _hasPartialChildren(id);
|
||||
final left = center.dx - kReferralNodeWidth / 2;
|
||||
final top = center.dy - kReferralNodeHeight / 2;
|
||||
|
||||
return Positioned(
|
||||
left: left,
|
||||
top: top,
|
||||
width: kReferralNodeWidth,
|
||||
height: kReferralNodeHeight,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 56,
|
||||
height: 56,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
key: Key('referral_node_$id'),
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: () => showMemberSheet(id),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
accent.withValues(alpha: 0.35),
|
||||
accent.withValues(alpha: 0.85),
|
||||
],
|
||||
),
|
||||
border: Border.all(
|
||||
color: selected
|
||||
? Colors.white
|
||||
: accent.withValues(alpha: 0.95),
|
||||
width: selected || isRoot ? 3 : 2,
|
||||
),
|
||||
boxShadow: [
|
||||
if (selected)
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withValues(alpha: 0.55),
|
||||
blurRadius: 14,
|
||||
spreadRadius: 1,
|
||||
),
|
||||
BoxShadow(
|
||||
color: accent.withValues(alpha: 0.35),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
name.trim().isEmpty
|
||||
? '?'
|
||||
: name.trim().characters.first.toUpperCase(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (canExpand)
|
||||
Positioned(
|
||||
right: -4,
|
||||
bottom: -4,
|
||||
child: Material(
|
||||
color: isDark ? AppColors.surfaceElevated : Colors.white,
|
||||
shape: const CircleBorder(),
|
||||
elevation: 2,
|
||||
child: InkWell(
|
||||
key: Key('referral_expand_$id'),
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: () => toggleExpand(id),
|
||||
child: Tooltip(
|
||||
message:
|
||||
expanded ? s.collapseBranch : s.expandBranch,
|
||||
child: SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: Icon(
|
||||
expanded ? Icons.remove : Icons.add,
|
||||
size: 14,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: isDark ? AppColors.textPrimary : const Color(0xFF0F172A),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
s.directCountLabel(directs),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: partial
|
||||
? AppColors.warning
|
||||
: (isDark ? AppColors.textMuted : const Color(0xFF64748B)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SheetRow extends StatelessWidget {
|
||||
const _SheetRow({required this.label, required this.value});
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.w700)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EdgePainter extends CustomPainter {
|
||||
_EdgePainter({required this.layout, required this.isDark});
|
||||
final ReferralTreeLayoutResult layout;
|
||||
final bool isDark;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final paint = Paint()
|
||||
..color = (isDark ? AppColors.primary : AppColors.primaryDark)
|
||||
.withValues(alpha: 0.55)
|
||||
..strokeWidth = 1.6
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeCap = StrokeCap.round;
|
||||
|
||||
for (final e in layout.edges) {
|
||||
final a = layout.positions[e.parentId];
|
||||
final b = layout.positions[e.childId];
|
||||
if (a == null || b == null) continue;
|
||||
final start = Offset(a.dx, a.dy + 28);
|
||||
final end = Offset(b.dx, b.dy - 36);
|
||||
final midY = (start.dy + end.dy) / 2;
|
||||
final path = Path()
|
||||
..moveTo(start.dx, start.dy)
|
||||
..cubicTo(start.dx, midY, end.dx, midY, end.dx, end.dy);
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _EdgePainter oldDelegate) =>
|
||||
oldDelegate.layout != layout || oldDelegate.isDark != isDark;
|
||||
}
|
||||
|
||||
class _ReferrerBanner extends StatelessWidget {
|
||||
@ -93,14 +659,15 @@ class _ReferrerBanner extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.info.withValues(alpha: 0.18),
|
||||
AppColors.surfaceCard,
|
||||
AppColors.info.withValues(alpha: isDark ? 0.18 : 0.12),
|
||||
isDark ? AppColors.surfaceCard : Colors.white,
|
||||
],
|
||||
),
|
||||
border: Border.all(color: AppColors.info.withValues(alpha: 0.35)),
|
||||
@ -108,7 +675,7 @@ class _ReferrerBanner extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.arrow_upward_rounded, color: AppColors.info),
|
||||
const SizedBox(width: 12),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -121,14 +688,7 @@ class _ReferrerBanner extends StatelessWidget {
|
||||
),
|
||||
Text(
|
||||
referrer.displayName,
|
||||
style: const TextStyle(fontWeight: FontWeight.w800, fontSize: 16),
|
||||
),
|
||||
Text(
|
||||
'${s.memberSince} ${formatReferralDate(referrer.memberSince)}'
|
||||
'${referrer.referralCode != null ? ' · ${referrer.referralCode}' : ''}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textMuted,
|
||||
),
|
||||
style: const TextStyle(fontWeight: FontWeight.w800, fontSize: 15),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -138,208 +698,3 @@ class _ReferrerBanner extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TreeNode extends StatefulWidget {
|
||||
const _TreeNode({
|
||||
required this.member,
|
||||
required this.childMap,
|
||||
required this.depth,
|
||||
this.initiallyExpanded = false,
|
||||
});
|
||||
|
||||
final ReferralNetworkMember member;
|
||||
final Map<String, List<ReferralNetworkMember>> childMap;
|
||||
final int depth;
|
||||
final bool initiallyExpanded;
|
||||
|
||||
@override
|
||||
State<_TreeNode> createState() => _TreeNodeState();
|
||||
}
|
||||
|
||||
class _TreeNodeState extends State<_TreeNode> {
|
||||
late bool _expanded = widget.initiallyExpanded;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final children = widget.childMap[widget.member.userId] ?? const [];
|
||||
final hasChildren = children.isNotEmpty;
|
||||
final statusColor = referralStatusColor(widget.member.status);
|
||||
final indent = 12.0 + widget.depth * 16.0;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: indent, bottom: 8),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: widget.member.generatesCommissions
|
||||
? AppColors.accentGold.withValues(alpha: 0.45)
|
||||
: AppColors.border,
|
||||
),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
(widget.member.generatesCommissions
|
||||
? AppColors.accentGold
|
||||
: AppColors.primary)
|
||||
.withValues(alpha: 0.10),
|
||||
AppColors.surfaceCard,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 8, 12, 12),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: hasChildren
|
||||
? IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => setState(() => _expanded = !_expanded),
|
||||
icon: Icon(
|
||||
_expanded
|
||||
? Icons.expand_more_rounded
|
||||
: Icons.chevron_right_rounded,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primary.withValues(alpha: 0.16),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(
|
||||
widget.member.generatesCommissions
|
||||
? Icons.payments_rounded
|
||||
: Icons.person_rounded,
|
||||
size: 18,
|
||||
color: widget.member.generatesCommissions
|
||||
? AppColors.accentGold
|
||||
: AppColors.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.member.displayName,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
_MiniChip(
|
||||
label: s.referralLevelLabel(widget.member.levelNumber),
|
||||
color: AppColors.info,
|
||||
),
|
||||
_MiniChip(
|
||||
label: referralStatusLabel(widget.member.status, s),
|
||||
color: statusColor,
|
||||
),
|
||||
if (widget.member.directReferralsCount > 0)
|
||||
_MiniChip(
|
||||
label: s.directCountLabel(
|
||||
widget.member.directReferralsCount,
|
||||
),
|
||||
color: AppColors.primary,
|
||||
),
|
||||
if (widget.member.generatesCommissions)
|
||||
_MiniChip(
|
||||
label: s.generatesCommissions,
|
||||
color: AppColors.accentGold,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
[
|
||||
if (widget.member.email != null &&
|
||||
widget.member.email!.isNotEmpty)
|
||||
widget.member.email!,
|
||||
if (widget.member.countryName != null &&
|
||||
widget.member.countryName!.isNotEmpty)
|
||||
widget.member.countryName!,
|
||||
'${s.paid}: ${formatUsdt(widget.member.commissionsPaidRaw)}',
|
||||
if ((BigInt.tryParse(widget.member.commissionsPendingRaw) ??
|
||||
BigInt.zero) >
|
||||
BigInt.zero)
|
||||
'${s.pending}: ${formatUsdt(widget.member.commissionsPendingRaw)}',
|
||||
].join(' · '),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (hasChildren && _expanded)
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: indent + 28),
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
left: BorderSide(color: AppColors.border, width: 2),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final child in children)
|
||||
_TreeNode(
|
||||
member: child,
|
||||
childMap: widget.childMap,
|
||||
depth: widget.depth + 1,
|
||||
initiallyExpanded: child.levelNumber <= 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MiniChip extends StatelessWidget {
|
||||
const _MiniChip({required this.label, required this.color});
|
||||
final String label;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.14),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w700, color: color),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,104 @@
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../data/models/referral_models.dart';
|
||||
|
||||
/// Visual size of one node (circle + label) in layout units.
|
||||
const kReferralNodeWidth = 96.0;
|
||||
const kReferralNodeHeight = 118.0;
|
||||
const kReferralHGap = 28.0;
|
||||
const kReferralVGap = 64.0;
|
||||
|
||||
class ReferralTreeEdge {
|
||||
const ReferralTreeEdge({required this.parentId, required this.childId});
|
||||
final String parentId;
|
||||
final String childId;
|
||||
}
|
||||
|
||||
class ReferralTreeLayoutResult {
|
||||
const ReferralTreeLayoutResult({
|
||||
required this.positions,
|
||||
required this.size,
|
||||
required this.edges,
|
||||
required this.visibleIds,
|
||||
});
|
||||
|
||||
/// Center of each visible node.
|
||||
final Map<String, Offset> positions;
|
||||
final Size size;
|
||||
final List<ReferralTreeEdge> edges;
|
||||
final Set<String> visibleIds;
|
||||
}
|
||||
|
||||
/// Top-down tidy tree layout (simplified Reingold–Tilford).
|
||||
/// Only includes [rootId] and descendants reachable through [expandedIds].
|
||||
ReferralTreeLayoutResult layoutReferralTree({
|
||||
required String rootId,
|
||||
required Map<String, List<ReferralNetworkMember>> childMap,
|
||||
required Set<String> expandedIds,
|
||||
}) {
|
||||
final positions = <String, Offset>{};
|
||||
final edges = <ReferralTreeEdge>[];
|
||||
final visibleIds = <String>{rootId};
|
||||
|
||||
double subtreeWidth(String id) {
|
||||
final kids = expandedIds.contains(id)
|
||||
? (childMap[id] ?? const <ReferralNetworkMember>[])
|
||||
: const <ReferralNetworkMember>[];
|
||||
if (kids.isEmpty) return kReferralNodeWidth;
|
||||
var sum = 0.0;
|
||||
for (var i = 0; i < kids.length; i++) {
|
||||
if (i > 0) sum += kReferralHGap;
|
||||
sum += subtreeWidth(kids[i].userId);
|
||||
}
|
||||
return math.max(kReferralNodeWidth, sum);
|
||||
}
|
||||
|
||||
void place(String id, double centerX, double topY) {
|
||||
positions[id] = Offset(centerX, topY + kReferralNodeHeight / 2);
|
||||
visibleIds.add(id);
|
||||
if (!expandedIds.contains(id)) return;
|
||||
final kids = childMap[id] ?? const <ReferralNetworkMember>[];
|
||||
if (kids.isEmpty) return;
|
||||
|
||||
final widths = kids.map((k) => subtreeWidth(k.userId)).toList();
|
||||
var total = 0.0;
|
||||
for (var i = 0; i < widths.length; i++) {
|
||||
if (i > 0) total += kReferralHGap;
|
||||
total += widths[i];
|
||||
}
|
||||
var x = centerX - total / 2;
|
||||
final childY = topY + kReferralNodeHeight + kReferralVGap;
|
||||
for (var i = 0; i < kids.length; i++) {
|
||||
final w = widths[i];
|
||||
final childCenter = x + w / 2;
|
||||
final childId = kids[i].userId;
|
||||
edges.add(ReferralTreeEdge(parentId: id, childId: childId));
|
||||
place(childId, childCenter, childY);
|
||||
x += w + kReferralHGap;
|
||||
}
|
||||
}
|
||||
|
||||
final rootW = subtreeWidth(rootId);
|
||||
place(rootId, rootW / 2, 0);
|
||||
|
||||
var maxX = 0.0;
|
||||
var maxY = 0.0;
|
||||
for (final p in positions.values) {
|
||||
maxX = math.max(maxX, p.dx + kReferralNodeWidth / 2);
|
||||
maxY = math.max(maxY, p.dy + kReferralNodeHeight / 2);
|
||||
}
|
||||
|
||||
// Padding around content for comfortable pan/zoom.
|
||||
const pad = 48.0;
|
||||
final shifted = <String, Offset>{};
|
||||
for (final e in positions.entries) {
|
||||
shifted[e.key] = Offset(e.value.dx + pad, e.value.dy + pad);
|
||||
}
|
||||
|
||||
return ReferralTreeLayoutResult(
|
||||
positions: shifted,
|
||||
size: Size(maxX + pad * 2, maxY + pad * 2),
|
||||
edges: edges,
|
||||
visibleIds: visibleIds,
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/theme/app_colors.dart';
|
||||
import '../../../../l10n/app_strings.dart';
|
||||
import 'referral_network_tree.dart';
|
||||
|
||||
/// Compact zoom / navigation bar for the referral org chart.
|
||||
class ReferralTreeToolbar extends StatelessWidget {
|
||||
const ReferralTreeToolbar({
|
||||
super.key,
|
||||
required this.treeKey,
|
||||
required this.scale,
|
||||
required this.hasSelection,
|
||||
});
|
||||
|
||||
final GlobalKey<ReferralNetworkTreeState> treeKey;
|
||||
final double scale;
|
||||
final bool hasSelection;
|
||||
|
||||
ReferralNetworkTreeState? get _state => treeKey.currentState;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final pct = (scale * 100).round();
|
||||
|
||||
return Material(
|
||||
elevation: 4,
|
||||
color: isDark ? AppColors.surfaceElevated : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_IconAction(
|
||||
key: const Key('referral_zoom_out'),
|
||||
tooltip: s.zoomOut,
|
||||
icon: Icons.remove_rounded,
|
||||
onPressed: () => _state?.zoomBy(1 / 1.2),
|
||||
),
|
||||
SizedBox(
|
||||
width: 44,
|
||||
child: Text(
|
||||
'$pct%',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
_IconAction(
|
||||
key: const Key('referral_zoom_in'),
|
||||
tooltip: s.zoomIn,
|
||||
icon: Icons.add_rounded,
|
||||
onPressed: () => _state?.zoomBy(1.2),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
_IconAction(
|
||||
key: const Key('referral_fit'),
|
||||
tooltip: s.fitToScreen,
|
||||
icon: Icons.fit_screen_rounded,
|
||||
onPressed: () => _state?.fitToScreen(),
|
||||
),
|
||||
_IconAction(
|
||||
key: const Key('referral_center_selection'),
|
||||
tooltip: s.centerSelection,
|
||||
icon: Icons.my_location_rounded,
|
||||
onPressed: hasSelection
|
||||
? () {
|
||||
final id = _state?.selectedUserId;
|
||||
if (id != null) _state?.centerOnUser(id);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
_IconAction(
|
||||
key: const Key('referral_go_root'),
|
||||
tooltip: s.goToRoot,
|
||||
icon: Icons.home_rounded,
|
||||
onPressed: () => _state?.goToRoot(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _IconAction extends StatelessWidget {
|
||||
const _IconAction({
|
||||
super.key,
|
||||
required this.tooltip,
|
||||
required this.icon,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final String tooltip;
|
||||
final IconData icon;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IconButton(
|
||||
tooltip: tooltip,
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 20,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(icon),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/errors/app_exception.dart';
|
||||
@ -6,7 +7,9 @@ import '../../../core/theme/app_theme.dart';
|
||||
import '../../../data/repositories/auth_repository_impl.dart';
|
||||
import '../../../domain/repositories/repositories.dart';
|
||||
import '../../../l10n/app_strings.dart';
|
||||
import '../../../shared/widgets/pred_card.dart';
|
||||
import '../../../shared/widgets/pred_skeleton.dart';
|
||||
import '../../../shared/widgets/prediqo_logo.dart';
|
||||
import '../../../shared/widgets/section_error.dart';
|
||||
import '../../auth/bloc/auth_bloc.dart';
|
||||
|
||||
@ -114,6 +117,7 @@ class _AccountScreenState extends State<AccountScreen> {
|
||||
final phone = _profile?.phone?.trim();
|
||||
final country = _profile?.countryOfResidence?.trim();
|
||||
final showHeaderSkeleton = _profileLoading && _profile == null;
|
||||
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
||||
|
||||
return BlocListener<AuthBloc, AuthState>(
|
||||
listenWhen: (prev, curr) => prev.status != curr.status,
|
||||
@ -122,152 +126,229 @@ class _AccountScreenState extends State<AccountScreen> {
|
||||
context.go('/welcome');
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
key: const Key('account_screen'),
|
||||
appBar: AppBar(
|
||||
title: Text(s.accountTitle),
|
||||
flexibleSpace: Container(
|
||||
decoration: const BoxDecoration(gradient: AppTheme.goldGradient),
|
||||
),
|
||||
child: AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _loadProfile(force: true),
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Scaffold(
|
||||
key: const Key('account_screen'),
|
||||
body: Column(
|
||||
children: [
|
||||
if (_profileError != null && _profile == null) ...[
|
||||
SectionError(
|
||||
message: _profileError!,
|
||||
retrying: _profileRetrying,
|
||||
onRetry: () => _loadProfile(force: true),
|
||||
DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF059669),
|
||||
Color(0xFF047857),
|
||||
Color(0xFF0F172A),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
] else ...[
|
||||
Center(
|
||||
child: showHeaderSkeleton
|
||||
? const PredSkeleton(
|
||||
width: 88,
|
||||
height: 88,
|
||||
borderRadius: 44,
|
||||
)
|
||||
: Container(
|
||||
width: 88,
|
||||
height: 88,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppTheme.goldAccentGradient,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.goldPrimary.withValues(alpha: 0.4),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 4),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: SizedBox(
|
||||
height: kToolbarHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
const PrediqoLogo(size: 28, showWordmark: false),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.accountTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.3,
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
_initials(),
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: isDark ? AppColors.navy : Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (showHeaderSkeleton) ...[
|
||||
const Center(child: PredSkeletonLine(width: 160, height: 22)),
|
||||
const SizedBox(height: 8),
|
||||
const Center(child: PredSkeletonLine(width: 200, height: 14)),
|
||||
] else ...[
|
||||
Text(
|
||||
name,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (email != null && email.isNotEmpty && email != name) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
email,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => _loadProfile(force: true),
|
||||
child: ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
],
|
||||
if ((phone != null && phone.isNotEmpty) ||
|
||||
(country != null && country.isNotEmpty) ||
|
||||
_profile?.totpEnabled == true) ...[
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (phone != null && phone.isNotEmpty)
|
||||
_InfoChip(icon: Icons.phone_outlined, label: phone),
|
||||
if (country != null && country.isNotEmpty)
|
||||
_InfoChip(icon: Icons.public_outlined, label: country),
|
||||
if (_profile?.totpEnabled == true)
|
||||
_InfoChip(
|
||||
icon: Icons.verified_user_outlined,
|
||||
label: s.twoFactorEnabledShort,
|
||||
padding: EdgeInsets.fromLTRB(20, 16, 20, 24 + bottomInset),
|
||||
children: [
|
||||
if (_profileError != null && _profile == null) ...[
|
||||
SectionError(
|
||||
message: _profileError!,
|
||||
retrying: _profileRetrying,
|
||||
onRetry: () => _loadProfile(force: true),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
] else ...[
|
||||
Center(
|
||||
child: showHeaderSkeleton
|
||||
? const PredSkeleton(
|
||||
width: 88,
|
||||
height: 88,
|
||||
borderRadius: 44,
|
||||
)
|
||||
: Container(
|
||||
width: 88,
|
||||
height: 88,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppTheme.goldAccentGradient,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.goldPrimary
|
||||
.withValues(alpha: 0.35),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
_initials(),
|
||||
style: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: isDark
|
||||
? AppColors.navy
|
||||
: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (showHeaderSkeleton) ...[
|
||||
const Center(
|
||||
child: PredSkeletonLine(width: 160, height: 22),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Center(
|
||||
child: PredSkeletonLine(width: 200, height: 14),
|
||||
),
|
||||
] else ...[
|
||||
Text(
|
||||
name,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (email != null &&
|
||||
email.isNotEmpty &&
|
||||
email != name) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
email,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
],
|
||||
if ((phone != null && phone.isNotEmpty) ||
|
||||
(country != null && country.isNotEmpty) ||
|
||||
_profile?.totpEnabled == true) ...[
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (phone != null && phone.isNotEmpty)
|
||||
_InfoChip(
|
||||
icon: Icons.phone_outlined,
|
||||
label: phone,
|
||||
),
|
||||
if (country != null && country.isNotEmpty)
|
||||
_InfoChip(
|
||||
icon: Icons.public_outlined,
|
||||
label: country,
|
||||
),
|
||||
if (_profile?.totpEnabled == true)
|
||||
_InfoChip(
|
||||
icon: Icons.verified_user_outlined,
|
||||
label: s.twoFactorEnabledShort,
|
||||
),
|
||||
],
|
||||
),
|
||||
] else if (email == null || email.isEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
s.accountSubtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
const SizedBox(height: 28),
|
||||
],
|
||||
),
|
||||
] else if (email == null || email.isEmpty) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
s.accountSubtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
const SizedBox(height: 28),
|
||||
],
|
||||
_AccountTile(
|
||||
icon: Icons.badge_outlined,
|
||||
title: s.updateProfile,
|
||||
onTap: _openProfileEdit,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.lock_reset_rounded,
|
||||
title: s.changePassword,
|
||||
onTap: () => context.push('/account/change-password'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.security_rounded,
|
||||
title: s.twoFactor,
|
||||
onTap: () => context.push('/totp-setup'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.card_giftcard_rounded,
|
||||
title: s.referralProgram,
|
||||
onTap: () => context.push('/referral'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.help_outline_rounded,
|
||||
title: s.helpFaq,
|
||||
onTap: () => context.push('/faq'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.logout_rounded,
|
||||
title: s.logout,
|
||||
isDestructive: true,
|
||||
onTap: () =>
|
||||
context.read<AuthBloc>().add(const AuthLogoutRequested()),
|
||||
_AccountTile(
|
||||
icon: Icons.badge_outlined,
|
||||
title: s.updateProfile,
|
||||
onTap: _openProfileEdit,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.lock_reset_rounded,
|
||||
title: s.changePassword,
|
||||
onTap: () => context.push('/account/change-password'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.security_rounded,
|
||||
title: s.twoFactor,
|
||||
onTap: () => context.push('/totp-setup'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.card_giftcard_rounded,
|
||||
title: s.referralProgram,
|
||||
onTap: () => context.push('/referral'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.help_outline_rounded,
|
||||
title: s.helpFaq,
|
||||
onTap: () => context.push('/faq'),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
_AccountTile(
|
||||
icon: Icons.logout_rounded,
|
||||
title: s.logout,
|
||||
isDestructive: true,
|
||||
onTap: () => context
|
||||
.read<AuthBloc>()
|
||||
.add(const AuthLogoutRequested()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -326,42 +407,40 @@ class _AccountTile extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final color = isDestructive
|
||||
? Theme.of(context).colorScheme.error
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
return Material(
|
||||
color: Theme.of(context).cardTheme.color ?? Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
elevation: 2,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right_rounded, color: color),
|
||||
],
|
||||
return PredCard(
|
||||
onTap: onTap,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: isDark ? 0.15 : 0.12),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 24),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right_rounded,
|
||||
color: isDestructive
|
||||
? color
|
||||
: (isDark ? AppColors.textMuted : const Color(0xFF94A3B8)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@ -16,15 +17,18 @@ import '../../../data/repositories/wallet_repository_impl.dart';
|
||||
import '../../../domain/repositories/referral_repository.dart';
|
||||
import '../../../l10n/app_strings.dart';
|
||||
import '../../../shared/widgets/app_snackbar.dart';
|
||||
import '../../../shared/widgets/balance_hero_card.dart';
|
||||
import '../../../shared/widgets/pred_card.dart';
|
||||
import '../../../shared/widgets/pred_skeleton.dart';
|
||||
import '../../../shared/widgets/prediqo_logo.dart';
|
||||
import '../../../shared/widgets/section_error.dart';
|
||||
import '../../wallet/bloc/wallet_bloc.dart';
|
||||
import '../utils/transaction_display.dart';
|
||||
import '../utils/withdraw_eligibility.dart';
|
||||
import '../../share_cards/presentation/share_result_widgets.dart';
|
||||
|
||||
const _hideBalanceKey = 'wallet_hide_balance';
|
||||
// Prefer shared key so Home and Wallet stay in sync (see BalanceHeroCard).
|
||||
const _hideBalanceKey = kHideBalancePrefsKey;
|
||||
|
||||
String _friendlyError(Object e) {
|
||||
if (e is DioException) return AppException.fromDio(e).message;
|
||||
@ -41,7 +45,8 @@ class WalletOverviewScreen extends StatefulWidget {
|
||||
class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final TabController _tabController;
|
||||
bool _hideBalance = false;
|
||||
/// Privacy-first: obscured until prefs say otherwise (default hidden).
|
||||
bool _hideBalance = true;
|
||||
bool _prefsLoaded = false;
|
||||
bool _requestingTestCredits = false;
|
||||
bool _transferringBonus = false;
|
||||
@ -75,7 +80,7 @@ class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_hideBalance = prefs.getBool(_hideBalanceKey) ?? false;
|
||||
_hideBalance = prefs.getBool(_hideBalanceKey) ?? true;
|
||||
_prefsLoaded = true;
|
||||
});
|
||||
}
|
||||
@ -154,7 +159,7 @@ class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
}
|
||||
|
||||
String _maskOrAmount(String raw, int decimals, String code) {
|
||||
if (_hideBalance) return '••••••';
|
||||
if (_hideBalance) return '******';
|
||||
final human = rawAmountToHuman(raw, decimals);
|
||||
final symbol = code.toUpperCase().contains('USDT') ? 'USDT' : code;
|
||||
return '$human $symbol';
|
||||
@ -163,6 +168,7 @@ class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final bottomInset = MediaQuery.paddingOf(context).bottom;
|
||||
return BlocBuilder<WalletBloc, WalletState>(
|
||||
builder: (context, state) {
|
||||
final balance = _usdtBalance(state.balances);
|
||||
@ -175,41 +181,90 @@ class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
|
||||
// Single CustomScrollView (no NestedScrollView) — NestedScrollView + TabBarView
|
||||
// triggers a known Android overscroll assertion (`activity!.isScrolling`).
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(s.navWallet),
|
||||
actions: [
|
||||
if (_prefsLoaded)
|
||||
IconButton(
|
||||
tooltip: _hideBalance ? s.showBalance : s.hideBalance,
|
||||
onPressed: _toggleHideBalance,
|
||||
icon: Icon(
|
||||
_hideBalance
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
key: const Key('wallet_overview_screen'),
|
||||
body: Column(
|
||||
children: [
|
||||
DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF059669),
|
||||
Color(0xFF047857),
|
||||
Color(0xFF0F172A),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: SizedBox(
|
||||
height: kToolbarHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
const PrediqoLogo(size: 28, showWordmark: false),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
s.navWallet,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.3,
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_prefsLoaded)
|
||||
IconButton(
|
||||
key: const Key('wallet_balance_visibility'),
|
||||
tooltip:
|
||||
_hideBalance ? s.showBalance : s.hideBalance,
|
||||
onPressed: _toggleHideBalance,
|
||||
icon: Icon(
|
||||
_hideBalance
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: _refreshAll,
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: _refreshAll,
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(
|
||||
parent: BouncingScrollPhysics(),
|
||||
),
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (balancesLoading) ...[
|
||||
const PredSkeletonCard(height: 168),
|
||||
const PredSkeletonCard(height: 148),
|
||||
const SizedBox(height: 12),
|
||||
const PredSkeletonCard(height: 132),
|
||||
const PredSkeletonCard(height: 120),
|
||||
const SizedBox(height: 12),
|
||||
const PredSkeletonCard(height: 132),
|
||||
const PredSkeletonCard(height: 120),
|
||||
] else if (balancesError) ...[
|
||||
SectionError(
|
||||
message: state.errorMessage!,
|
||||
@ -375,6 +430,11 @@ class _WalletOverviewScreenState extends State<WalletOverviewScreen>
|
||||
category: category,
|
||||
balance: balance,
|
||||
),
|
||||
SliverToBoxAdapter(child: SizedBox(height: bottomInset)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -604,7 +664,9 @@ class _WalletTypeCard extends StatelessWidget {
|
||||
Text(
|
||||
subtitle,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -616,7 +678,9 @@ class _WalletTypeCard extends StatelessWidget {
|
||||
Text(
|
||||
context.strings.availableBalance.toUpperCase(),
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: AppColors.textMuted,
|
||||
color: isDark
|
||||
? AppColors.textMuted
|
||||
: const Color(0xFF64748B),
|
||||
letterSpacing: 0.6,
|
||||
),
|
||||
),
|
||||
@ -900,7 +964,7 @@ class _StatusTxTile extends StatelessWidget {
|
||||
final amountRaw = BigInt.tryParse(tx.amount) ?? BigInt.zero;
|
||||
final totalRaw = amountRaw + feeRaw;
|
||||
final amount = hideBalance
|
||||
? '••••'
|
||||
? '****'
|
||||
: showWithdrawalFee
|
||||
? '-${rawAmountToHuman(totalRaw.toString(), decimals)} USDT'
|
||||
: _formatSignedAmount(
|
||||
@ -1223,7 +1287,7 @@ String _formatSignedAmount({
|
||||
required int decimals,
|
||||
required String assetCode,
|
||||
}) {
|
||||
if (hideBalance) return '••••';
|
||||
if (hideBalance) return '****';
|
||||
final human = rawAmountToHuman(tx.amount, decimals);
|
||||
final symbol = assetCode.toUpperCase().contains('USDT') ? 'USDT' : assetCode;
|
||||
final sign = credit ? '+' : '-';
|
||||
|
||||
@ -578,6 +578,21 @@ class AppStrings {
|
||||
String directCountLabel(int count) => t('$count direct', '$count direct${count > 1 ? 's' : ''}');
|
||||
String get memberSince => t('Member since', 'Membre depuis');
|
||||
String get tapToExpand => t('Tap to expand', 'Toucher pour développer');
|
||||
String get zoomIn => t('Zoom in', 'Zoomer');
|
||||
String get zoomOut => t('Zoom out', 'Dézoomer');
|
||||
String get fitToScreen => t('Fit to screen', 'Ajuster à l’écran');
|
||||
String get centerSelection => t('Center selection', 'Centrer la sélection');
|
||||
String get goToRoot => t('Go to root', 'Parrain principal');
|
||||
String get expandBranch => t('Expand branch', 'Développer');
|
||||
String get collapseBranch => t('Collapse branch', 'Réduire');
|
||||
String get closeSheet => t('Close', 'Fermer');
|
||||
String get networkYou => t('You', 'Vous');
|
||||
String get sponsorLabel => t('Sponsor', 'Parrain');
|
||||
String get networkPartialData => t(
|
||||
'Some deeper members are not loaded yet.',
|
||||
'Certains filleuls plus profonds ne sont pas encore chargés.',
|
||||
);
|
||||
String get memberDetails => t('Member details', 'Fiche membre');
|
||||
String get earnings => t('Earnings', 'Gains');
|
||||
String get totalEarned => t('Total earned', 'Total gagné');
|
||||
String get paid => t('Paid', 'Payé');
|
||||
|
||||
@ -3,57 +3,77 @@ import '../../core/theme/app_colors.dart';
|
||||
import '../../l10n/app_strings.dart';
|
||||
import 'pred_card.dart';
|
||||
|
||||
/// Shared with [WalletOverviewScreen] so Home and Wallet stay in sync.
|
||||
const kHideBalancePrefsKey = 'wallet_hide_balance';
|
||||
|
||||
/// Compact available-balance strip for Home (privacy-aware).
|
||||
class BalanceHeroCard extends StatelessWidget {
|
||||
const BalanceHeroCard({
|
||||
super.key,
|
||||
required this.amountLabel,
|
||||
required this.subtitle,
|
||||
this.trailing,
|
||||
required this.obscured,
|
||||
required this.onVisibilityToggle,
|
||||
});
|
||||
|
||||
/// Visible amount text, or a masked placeholder when [obscured].
|
||||
final String amountLabel;
|
||||
final String subtitle;
|
||||
final Widget? trailing;
|
||||
final bool obscured;
|
||||
final VoidCallback onVisibilityToggle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.strings;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
return Container(
|
||||
key: const Key('home_balance_hero'),
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 6, 12),
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.heroGradient(isDark),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.primary.withValues(alpha: 0.25)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
context.strings.availableBalance,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: isDark ? AppColors.textSecondary : const Color(0xFF475569),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
amountLabel,
|
||||
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
|
||||
color: isDark ? AppColors.textPrimary : const Color(0xFF0F172A),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
s.availableBalance,
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: isDark
|
||||
? AppColors.textSecondary
|
||||
: const Color(0xFF475569),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (trailing != null) trailing!,
|
||||
],
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
amountLabel,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: obscured ? 2 : 0,
|
||||
color: isDark
|
||||
? AppColors.textPrimary
|
||||
: const Color(0xFF0F172A),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
subtitle,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
IconButton(
|
||||
key: const Key('home_balance_visibility'),
|
||||
tooltip: obscured ? s.showBalance : s.hideBalance,
|
||||
onPressed: onVisibilityToggle,
|
||||
icon: Icon(
|
||||
obscured
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
color: isDark ? AppColors.textSecondary : const Color(0xFF64748B),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'prediqo_logo.dart';
|
||||
|
||||
/// Edge-to-edge emerald→navy top bar shared by authenticated Tloto screens.
|
||||
class TlotoGradientAppBar extends StatelessWidget {
|
||||
const TlotoGradientAppBar({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.showBack = false,
|
||||
this.showLogo = true,
|
||||
this.actions = const [],
|
||||
});
|
||||
|
||||
final String title;
|
||||
final bool showBack;
|
||||
final bool showLogo;
|
||||
final List<Widget> actions;
|
||||
|
||||
static const gradient = LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF059669),
|
||||
Color(0xFF047857),
|
||||
Color(0xFF0F172A),
|
||||
],
|
||||
);
|
||||
|
||||
static const overlayStyle = SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DecoratedBox(
|
||||
decoration: const BoxDecoration(gradient: gradient),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: SizedBox(
|
||||
height: kToolbarHeight,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: showBack ? 0 : 16,
|
||||
right: actions.isEmpty ? 16 : 4,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (showBack)
|
||||
IconButton(
|
||||
tooltip:
|
||||
MaterialLocalizations.of(context).backButtonTooltip,
|
||||
onPressed: () => Navigator.of(context).maybePop(),
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_rounded,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
if (showLogo) ...[
|
||||
const PrediqoLogo(size: 26, showWordmark: false),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.3,
|
||||
color: Colors.white,
|
||||
fontSize: 17,
|
||||
),
|
||||
),
|
||||
),
|
||||
...actions,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -164,7 +164,7 @@ void main() {
|
||||
expect(sw.elapsedMilliseconds, lessThan(100));
|
||||
});
|
||||
|
||||
testWidgets('Home paints shortcuts while ads still loading', (tester) async {
|
||||
testWidgets('Home paints deposit shortcut while ads still loading', (tester) async {
|
||||
final adsHold = Completer<List<AdvertisementModel>>();
|
||||
final ads = _ControllableAds()..hold = adsHold;
|
||||
final games = _ControllableGames(
|
||||
@ -198,7 +198,7 @@ void main() {
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Shortcuts'), findsOneWidget);
|
||||
expect(find.byKey(const Key('home_deposit_shortcut')), findsOneWidget);
|
||||
expect(find.text('Candle Predict'), findsOneWidget);
|
||||
expect(find.byType(PredSkeletonCarousel), findsOneWidget);
|
||||
|
||||
@ -254,7 +254,7 @@ void main() {
|
||||
// Soft-fail: empty promo placeholder, games remain; no ads SectionError.
|
||||
expect(find.textContaining('promotions coming soon'), findsOneWidget);
|
||||
expect(find.text('Candle Predict'), findsOneWidget);
|
||||
expect(find.text('Shortcuts'), findsOneWidget);
|
||||
expect(find.byKey(const Key('home_deposit_shortcut')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Home ads in-flight dedupes parallel list calls', (tester) async {
|
||||
|
||||
@ -103,7 +103,11 @@ Future<void> _boot(ReferralRepository repo) async {
|
||||
);
|
||||
sl.registerSingleton<ConnectivityController>(ConnectivityController());
|
||||
final locale = LocaleController();
|
||||
SharedPreferences.setMockInitialValues({'app_locale': 'en'});
|
||||
// Reveal stats in tests (product default remains privacy-first / hidden).
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'app_locale': 'en',
|
||||
'wallet_hide_balance': false,
|
||||
});
|
||||
await locale.load();
|
||||
sl.registerSingleton<LocaleController>(locale);
|
||||
sl.registerLazySingleton<ApiClient>(() => ApiClient(config: sl()));
|
||||
|
||||
162
prediqo_mobile/test/referral_network_tree_test.dart
Normal file
162
prediqo_mobile/test/referral_network_tree_test.dart
Normal file
@ -0,0 +1,162 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:prediqo_mobile/core/theme/app_theme.dart';
|
||||
import 'package:prediqo_mobile/data/models/referral_models.dart';
|
||||
import 'package:prediqo_mobile/features/referral/presentation/widgets/referral_network_tree.dart';
|
||||
import 'package:prediqo_mobile/features/referral/presentation/widgets/referral_tree_layout.dart';
|
||||
import 'package:prediqo_mobile/features/referral/presentation/widgets/referral_tree_toolbar.dart';
|
||||
import 'package:prediqo_mobile/features/referral/utils/referral_display.dart';
|
||||
|
||||
ReferralNetworkMember _member({
|
||||
required String id,
|
||||
required String parent,
|
||||
required int level,
|
||||
required String name,
|
||||
int directs = 0,
|
||||
}) {
|
||||
return ReferralNetworkMember(
|
||||
userId: id,
|
||||
parentUserId: parent,
|
||||
levelNumber: level,
|
||||
displayName: name,
|
||||
registeredAt: '2024-01-0${level}T00:00:00.000Z',
|
||||
emailVerified: true,
|
||||
status: ReferralMemberStatus.active,
|
||||
directReferralsCount: directs,
|
||||
realPredictionsCount: 0,
|
||||
commissionsGeneratedRaw: '0',
|
||||
commissionsPaidRaw: '0',
|
||||
commissionsPendingRaw: '0',
|
||||
);
|
||||
}
|
||||
|
||||
final _members = [
|
||||
_member(id: 'a', parent: 'root', level: 1, name: 'Alice', directs: 1),
|
||||
_member(id: 'b', parent: 'a', level: 2, name: 'Bob', directs: 0),
|
||||
_member(id: 'c', parent: 'root', level: 1, name: 'Carol', directs: 0),
|
||||
];
|
||||
|
||||
Widget _harness({
|
||||
GlobalKey<ReferralNetworkTreeState>? treeKey,
|
||||
TransformationController? transform,
|
||||
ValueChanged<String?>? onSelectionChanged,
|
||||
List<ReferralNetworkMember>? members,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
theme: AppTheme.light,
|
||||
locale: const Locale('en'),
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ReferralNetworkTree(
|
||||
key: treeKey,
|
||||
members: members ?? _members,
|
||||
rootUserId: 'root',
|
||||
rootLabel: 'You',
|
||||
transformationController: transform,
|
||||
onSelectionChanged: onSelectionChanged,
|
||||
),
|
||||
),
|
||||
if (treeKey != null)
|
||||
ReferralTreeToolbar(
|
||||
treeKey: treeKey,
|
||||
scale: transform?.value.getMaxScaleOnAxis() ?? 1,
|
||||
hasSelection: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('layoutReferralTree places expanded children below root', () {
|
||||
final childMap = buildReferralChildMap(_members);
|
||||
final collapsed = layoutReferralTree(
|
||||
rootId: 'root',
|
||||
childMap: childMap,
|
||||
expandedIds: {'root'},
|
||||
);
|
||||
expect(collapsed.visibleIds, containsAll(['root', 'a', 'c']));
|
||||
expect(collapsed.visibleIds.contains('b'), isFalse);
|
||||
expect(collapsed.positions['a']!.dy, greaterThan(collapsed.positions['root']!.dy));
|
||||
|
||||
final expanded = layoutReferralTree(
|
||||
rootId: 'root',
|
||||
childMap: childMap,
|
||||
expandedIds: {'root', 'a'},
|
||||
);
|
||||
expect(expanded.visibleIds, contains('b'));
|
||||
expect(expanded.positions['b']!.dy, greaterThan(expanded.positions['a']!.dy));
|
||||
});
|
||||
|
||||
testWidgets('expand/collapse toggles nested child visibility', (tester) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final treeKey = GlobalKey<ReferralNetworkTreeState>();
|
||||
await tester.pumpWidget(_harness(treeKey: treeKey));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
expect(find.text('Alice'), findsOneWidget);
|
||||
expect(find.text('Carol'), findsOneWidget);
|
||||
expect(find.text('Bob'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('referral_expand_a')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(find.text('Bob'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('referral_expand_a')));
|
||||
await tester.pump();
|
||||
expect(find.text('Bob'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('tap node opens member bottom sheet', (tester) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
await tester.pumpWidget(_harness());
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
await tester.tap(find.byKey(const Key('referral_node_a')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Member details'), findsOneWidget);
|
||||
expect(find.text('Alice'), findsWidgets);
|
||||
expect(find.text('Close'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('zoom toolbar changes TransformationController scale', (tester) async {
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
|
||||
final treeKey = GlobalKey<ReferralNetworkTreeState>();
|
||||
final transform = TransformationController();
|
||||
await tester.pumpWidget(
|
||||
_harness(treeKey: treeKey, transform: transform),
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 350));
|
||||
|
||||
final before = transform.value.getMaxScaleOnAxis();
|
||||
await tester.tap(find.byKey(const Key('referral_zoom_in')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(transform.value.getMaxScaleOnAxis(), greaterThan(before));
|
||||
|
||||
await tester.tap(find.byKey(const Key('referral_fit')));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 300));
|
||||
expect(transform.value.getMaxScaleOnAxis(), isPositive);
|
||||
});
|
||||
}
|
||||
@ -147,7 +147,11 @@ Future<void> _boot(_ControllableWallet wallet) async {
|
||||
);
|
||||
sl.registerSingleton<ConnectivityController>(ConnectivityController());
|
||||
final locale = LocaleController();
|
||||
SharedPreferences.setMockInitialValues({'app_locale': 'en'});
|
||||
// Reveal amounts in tests (product default remains privacy-first / hidden).
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'app_locale': 'en',
|
||||
'wallet_hide_balance': false,
|
||||
});
|
||||
await locale.load();
|
||||
sl.registerSingleton<LocaleController>(locale);
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ function StatCard({ label, value, sub }: { label: string; value: string | number
|
||||
export function ReferralPage() {
|
||||
const { t, i18n } = useTranslation();
|
||||
const { auth } = useAuth();
|
||||
const [tab, setTab] = useState(0);
|
||||
const [tab, setTab] = useState(1);
|
||||
const [toast, setToast] = useState<string | null>(null);
|
||||
|
||||
const dashQ = useReferralDashboard();
|
||||
@ -337,7 +337,11 @@ export function ReferralPage() {
|
||||
|
||||
{tab === 0 && <ReferralTableView members={data.network} />}
|
||||
{tab === 1 && auth.userId && (
|
||||
<ReferralTreeView members={data.network} rootUserId={auth.userId} />
|
||||
<ReferralTreeView
|
||||
members={data.network}
|
||||
rootUserId={auth.userId}
|
||||
rootLabel={t('referralPage.tree.you')}
|
||||
/>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@ -1,156 +1,304 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type PointerEvent as ReactPointerEvent,
|
||||
type WheelEvent as ReactWheelEvent,
|
||||
} from 'react';
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Chip,
|
||||
Collapse,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
IconButton,
|
||||
Paper,
|
||||
Stack,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from '@mui/material';
|
||||
import ExpandMoreRoundedIcon from '@mui/icons-material/ExpandMoreRounded';
|
||||
import ChevronRightRoundedIcon from '@mui/icons-material/ChevronRightRounded';
|
||||
import PersonRoundedIcon from '@mui/icons-material/PersonRounded';
|
||||
import AddRoundedIcon from '@mui/icons-material/AddRounded';
|
||||
import RemoveRoundedIcon from '@mui/icons-material/RemoveRounded';
|
||||
import FitScreenRoundedIcon from '@mui/icons-material/FitScreenRounded';
|
||||
import MyLocationRoundedIcon from '@mui/icons-material/MyLocationRounded';
|
||||
import HomeRoundedIcon from '@mui/icons-material/HomeRounded';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { rawToHuman } from '../../wallet/utils/walletFormat';
|
||||
import type { ReferralNetworkMember } from '../types';
|
||||
import {
|
||||
NODE_H,
|
||||
NODE_W,
|
||||
buildReferralChildMap,
|
||||
layoutReferralTree,
|
||||
} from '../utils/referralTreeLayout';
|
||||
|
||||
const USDT_DECIMALS = 6;
|
||||
const ROOT_BATCH_SIZE = 15;
|
||||
const MIN_SCALE = 0.35;
|
||||
const MAX_SCALE = 2.5;
|
||||
|
||||
type TreeNodeProps = {
|
||||
member: ReferralNetworkMember;
|
||||
children: ReferralNetworkMember[];
|
||||
childMap: Map<string, ReferralNetworkMember[]>;
|
||||
defaultExpanded?: boolean;
|
||||
};
|
||||
const LEVEL_COLORS = ['#10B981', '#0D9488', '#D4AF37', '#64748B', '#059669'] as const;
|
||||
|
||||
function TreeNode({ member, children, childMap, defaultExpanded = false }: TreeNodeProps) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(defaultExpanded);
|
||||
const hasChildren = children.length > 0;
|
||||
|
||||
const statusColor =
|
||||
member.status === 'active' ? 'success' : member.status === 'unverified' ? 'warning' : 'default';
|
||||
|
||||
const statusLabel =
|
||||
member.status === 'active'
|
||||
? t('referralPage.table.status.active')
|
||||
: member.status === 'unverified'
|
||||
? t('referralPage.table.status.unverified')
|
||||
: t('referralPage.table.status.registered');
|
||||
|
||||
return (
|
||||
<Box sx={{ pl: { xs: 1, sm: 2 } }}>
|
||||
<Paper
|
||||
variant="outlined"
|
||||
sx={{
|
||||
p: 1.25,
|
||||
mb: 1,
|
||||
borderRadius: 2,
|
||||
borderColor: 'divider',
|
||||
bgcolor: 'background.paper',
|
||||
}}
|
||||
>
|
||||
<Stack direction="row" spacing={1} sx={{ alignItems: 'flex-start' }}>
|
||||
{hasChildren ? (
|
||||
<IconButton size="small" onClick={() => setOpen((v) => !v)} sx={{ mt: -0.25 }}>
|
||||
{open ? <ExpandMoreRoundedIcon fontSize="small" /> : <ChevronRightRoundedIcon fontSize="small" />}
|
||||
</IconButton>
|
||||
) : (
|
||||
<Box sx={{ width: 34 }} />
|
||||
)}
|
||||
<PersonRoundedIcon fontSize="small" color="primary" sx={{ mt: 0.5 }} />
|
||||
<Box sx={{ flex: 1, minWidth: 0 }}>
|
||||
<Stack direction="row" spacing={1} sx={{ flexWrap: 'wrap', alignItems: 'center' }} useFlexGap>
|
||||
<Typography variant="body2" sx={{ fontWeight: 800 }}>
|
||||
{member.displayName}
|
||||
</Typography>
|
||||
<Chip
|
||||
size="small"
|
||||
label={t('referralPage.tree.level', { level: member.levelNumber })}
|
||||
variant="outlined"
|
||||
/>
|
||||
<Chip size="small" label={statusLabel} color={statusColor} variant="outlined" />
|
||||
{member.directReferralsCount > 0 && (
|
||||
<Chip
|
||||
size="small"
|
||||
label={t('referralPage.tree.direct', { count: member.directReferralsCount })}
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', mt: 0.5 }}>
|
||||
{member.email ? `${member.email} · ` : ''}
|
||||
{member.countryName ? `${member.countryName} · ` : ''}
|
||||
{t('referralPage.tree.paid', {
|
||||
amount: rawToHuman(member.commissionsPaidRaw, USDT_DECIMALS),
|
||||
})}
|
||||
{BigInt(member.commissionsPendingRaw) > 0n &&
|
||||
` · ${t('referralPage.tree.pending', {
|
||||
amount: rawToHuman(member.commissionsPendingRaw, USDT_DECIMALS),
|
||||
})}`}
|
||||
{member.referralCode
|
||||
? ` · ${t('referralPage.tree.code', { code: member.referralCode })}`
|
||||
: ''}
|
||||
</Typography>
|
||||
</Box>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
{hasChildren && (
|
||||
<Collapse in={open}>
|
||||
<Box
|
||||
sx={{
|
||||
ml: 2,
|
||||
pl: 1.5,
|
||||
borderLeft: '2px solid',
|
||||
borderColor: 'divider',
|
||||
}}
|
||||
>
|
||||
{children.map((child) => (
|
||||
<TreeNode
|
||||
key={child.userId}
|
||||
member={child}
|
||||
children={childMap.get(child.userId) ?? []}
|
||||
childMap={childMap}
|
||||
defaultExpanded={child.levelNumber <= 2}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
</Collapse>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
type Transform = { x: number; y: number; scale: number };
|
||||
|
||||
type ReferralTreeViewProps = {
|
||||
members: ReferralNetworkMember[];
|
||||
rootUserId: string;
|
||||
rootLabel?: string;
|
||||
};
|
||||
|
||||
export function ReferralTreeView({ members, rootUserId }: ReferralTreeViewProps) {
|
||||
const { t } = useTranslation();
|
||||
const [visibleRoots, setVisibleRoots] = useState(ROOT_BATCH_SIZE);
|
||||
function levelColor(level: number, isRoot: boolean): string {
|
||||
if (isRoot) return LEVEL_COLORS[0]!;
|
||||
return LEVEL_COLORS[((level - 1) % (LEVEL_COLORS.length - 1)) + 1]!;
|
||||
}
|
||||
|
||||
const childMap = useMemo(() => {
|
||||
const map = new Map<string, ReferralNetworkMember[]>();
|
||||
for (const m of members) {
|
||||
const key = m.parentUserId;
|
||||
if (!map.has(key)) map.set(key, []);
|
||||
map.get(key)!.push(m);
|
||||
}
|
||||
for (const list of map.values()) {
|
||||
list.sort((a, b) => a.registeredAt.localeCompare(b.registeredAt));
|
||||
}
|
||||
function initials(name: string): string {
|
||||
const t = name.trim();
|
||||
if (!t) return '?';
|
||||
return t.charAt(0).toUpperCase();
|
||||
}
|
||||
|
||||
export function ReferralTreeView({
|
||||
members,
|
||||
rootUserId,
|
||||
rootLabel,
|
||||
}: ReferralTreeViewProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const youLabel = rootLabel ?? t('referralPage.tree.you');
|
||||
|
||||
const childMap = useMemo(() => buildReferralChildMap(members), [members]);
|
||||
const byId = useMemo(() => {
|
||||
const map = new Map<string, ReferralNetworkMember>();
|
||||
for (const m of members) map.set(m.userId, m);
|
||||
return map;
|
||||
}, [members]);
|
||||
|
||||
const directChildren = childMap.get(rootUserId) ?? [];
|
||||
const visibleChildren = directChildren.slice(0, visibleRoots);
|
||||
const hasMore = directChildren.length > visibleRoots;
|
||||
const [expandedIds, setExpandedIds] = useState(() => new Set<string>([rootUserId]));
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null);
|
||||
const [sheetId, setSheetId] = useState<string | null>(null);
|
||||
const [transform, setTransform] = useState<Transform>({ x: 0, y: 0, scale: 1 });
|
||||
const viewportRef = useRef<HTMLDivElement>(null);
|
||||
const dragRef = useRef<{
|
||||
pointerId: number;
|
||||
startX: number;
|
||||
startY: number;
|
||||
origX: number;
|
||||
origY: number;
|
||||
moved: boolean;
|
||||
} | null>(null);
|
||||
const didInitialFit = useRef(false);
|
||||
const animRef = useRef<number | null>(null);
|
||||
|
||||
if (directChildren.length === 0) {
|
||||
useEffect(() => {
|
||||
setExpandedIds(new Set([rootUserId]));
|
||||
setSelectedId(null);
|
||||
setSheetId(null);
|
||||
didInitialFit.current = false;
|
||||
}, [rootUserId, members]);
|
||||
|
||||
const layout = useMemo(
|
||||
() =>
|
||||
layoutReferralTree({
|
||||
rootId: rootUserId,
|
||||
childMap,
|
||||
expandedIds,
|
||||
}),
|
||||
[rootUserId, childMap, expandedIds],
|
||||
);
|
||||
|
||||
const canExpand = useCallback(
|
||||
(id: string) => {
|
||||
const kids = childMap.get(id) ?? [];
|
||||
if (kids.length > 0) return true;
|
||||
if (id === rootUserId) return false;
|
||||
const m = byId.get(id);
|
||||
return Boolean(m && m.directReferralsCount > 0);
|
||||
},
|
||||
[byId, childMap, rootUserId],
|
||||
);
|
||||
|
||||
const hasPartial = useCallback(
|
||||
(id: string) => {
|
||||
const m = byId.get(id);
|
||||
if (!m) return false;
|
||||
const kids = childMap.get(id) ?? [];
|
||||
return m.directReferralsCount > kids.length;
|
||||
},
|
||||
[byId, childMap],
|
||||
);
|
||||
|
||||
const transformRef = useRef(transform);
|
||||
transformRef.current = transform;
|
||||
|
||||
const animateTo = useCallback((next: Transform, ms = 280) => {
|
||||
if (animRef.current != null) cancelAnimationFrame(animRef.current);
|
||||
const from = { ...transformRef.current };
|
||||
const start = performance.now();
|
||||
const tick = (now: number) => {
|
||||
const t = Math.min(1, (now - start) / ms);
|
||||
const e = 1 - Math.pow(1 - t, 3);
|
||||
setTransform({
|
||||
x: from.x + (next.x - from.x) * e,
|
||||
y: from.y + (next.y - from.y) * e,
|
||||
scale: from.scale + (next.scale - from.scale) * e,
|
||||
});
|
||||
if (t < 1) {
|
||||
animRef.current = requestAnimationFrame(tick);
|
||||
} else {
|
||||
animRef.current = null;
|
||||
}
|
||||
};
|
||||
animRef.current = requestAnimationFrame(tick);
|
||||
}, []);
|
||||
|
||||
const fitToScreen = useCallback(() => {
|
||||
const el = viewportRef.current;
|
||||
if (!el) return;
|
||||
const vw = el.clientWidth;
|
||||
const vh = el.clientHeight;
|
||||
const { width, height } = layout.size;
|
||||
if (width <= 0 || height <= 0 || vw <= 0 || vh <= 0) return;
|
||||
const scale = Math.min(vw / width, vh / height, MAX_SCALE) * 0.92;
|
||||
const clamped = Math.max(MIN_SCALE, Math.min(MAX_SCALE, scale));
|
||||
const x = (vw - width * clamped) / 2;
|
||||
const y = (vh - height * clamped) / 2;
|
||||
animateTo({ x, y, scale: clamped });
|
||||
}, [animateTo, layout.size]);
|
||||
|
||||
useEffect(() => {
|
||||
if (didInitialFit.current) return;
|
||||
if (layout.visibleIds.size === 0) return;
|
||||
const id = requestAnimationFrame(() => {
|
||||
didInitialFit.current = true;
|
||||
fitToScreen();
|
||||
});
|
||||
return () => cancelAnimationFrame(id);
|
||||
}, [fitToScreen, layout.visibleIds.size]);
|
||||
|
||||
const applyZoom = useCallback((factor: number) => {
|
||||
const el = viewportRef.current;
|
||||
if (!el) return;
|
||||
const fx = el.clientWidth / 2;
|
||||
const fy = el.clientHeight / 2;
|
||||
setTransform((prev) => {
|
||||
const nextScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, prev.scale * factor));
|
||||
const sceneX = (fx - prev.x) / prev.scale;
|
||||
const sceneY = (fy - prev.y) / prev.scale;
|
||||
return {
|
||||
scale: nextScale,
|
||||
x: fx - sceneX * nextScale,
|
||||
y: fy - sceneY * nextScale,
|
||||
};
|
||||
});
|
||||
}, []);
|
||||
|
||||
const centerOnUser = useCallback(
|
||||
(userId: string) => {
|
||||
const el = viewportRef.current;
|
||||
const pos = layout.positions.get(userId);
|
||||
if (!el || !pos) return;
|
||||
const scale = transform.scale;
|
||||
animateTo({
|
||||
scale,
|
||||
x: el.clientWidth / 2 - pos.x * scale,
|
||||
y: el.clientHeight / 2 - pos.y * scale,
|
||||
});
|
||||
},
|
||||
[animateTo, layout.positions, transform.scale],
|
||||
);
|
||||
|
||||
const goToRoot = useCallback(() => {
|
||||
setSelectedId(rootUserId);
|
||||
centerOnUser(rootUserId);
|
||||
}, [centerOnUser, rootUserId]);
|
||||
|
||||
const toggleExpand = useCallback(
|
||||
(userId: string) => {
|
||||
if (!canExpand(userId)) return;
|
||||
setExpandedIds((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(userId)) {
|
||||
next.delete(userId);
|
||||
const drop = (id: string) => {
|
||||
for (const c of childMap.get(id) ?? []) {
|
||||
next.delete(c.userId);
|
||||
drop(c.userId);
|
||||
}
|
||||
};
|
||||
drop(userId);
|
||||
} else {
|
||||
next.add(userId);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
},
|
||||
[canExpand, childMap],
|
||||
);
|
||||
|
||||
const openSheet = useCallback((userId: string) => {
|
||||
setSelectedId(userId);
|
||||
setSheetId(userId);
|
||||
}, []);
|
||||
|
||||
const onPointerDown = (e: ReactPointerEvent) => {
|
||||
if (e.button !== 0) return;
|
||||
const target = e.target as HTMLElement;
|
||||
if (target.closest('[data-node-hit]')) return;
|
||||
dragRef.current = {
|
||||
pointerId: e.pointerId,
|
||||
startX: e.clientX,
|
||||
startY: e.clientY,
|
||||
origX: transform.x,
|
||||
origY: transform.y,
|
||||
moved: false,
|
||||
};
|
||||
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
||||
};
|
||||
|
||||
const onPointerMove = (e: ReactPointerEvent) => {
|
||||
const d = dragRef.current;
|
||||
if (!d || d.pointerId !== e.pointerId) return;
|
||||
const dx = e.clientX - d.startX;
|
||||
const dy = e.clientY - d.startY;
|
||||
if (Math.abs(dx) + Math.abs(dy) > 3) d.moved = true;
|
||||
setTransform((prev) => ({
|
||||
...prev,
|
||||
x: d.origX + dx,
|
||||
y: d.origY + dy,
|
||||
}));
|
||||
};
|
||||
|
||||
const onPointerUp = (e: ReactPointerEvent) => {
|
||||
const d = dragRef.current;
|
||||
if (!d || d.pointerId !== e.pointerId) return;
|
||||
dragRef.current = null;
|
||||
};
|
||||
|
||||
const onWheel = (e: ReactWheelEvent) => {
|
||||
e.preventDefault();
|
||||
const el = viewportRef.current;
|
||||
if (!el) return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
const fx = e.clientX - rect.left;
|
||||
const fy = e.clientY - rect.top;
|
||||
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
||||
setTransform((prev) => {
|
||||
const nextScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, prev.scale * factor));
|
||||
const sceneX = (fx - prev.x) / prev.scale;
|
||||
const sceneY = (fy - prev.y) / prev.scale;
|
||||
return {
|
||||
scale: nextScale,
|
||||
x: fx - sceneX * nextScale,
|
||||
y: fy - sceneY * nextScale,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
const directRoots = childMap.get(rootUserId) ?? [];
|
||||
if (directRoots.length === 0 && members.length === 0) {
|
||||
return (
|
||||
<Typography variant="body2" color="text.secondary" sx={{ py: 3, textAlign: 'center' }}>
|
||||
{t('referralPage.tree.empty')}
|
||||
@ -158,39 +306,379 @@ export function ReferralTreeView({ members, rootUserId }: ReferralTreeViewProps)
|
||||
);
|
||||
}
|
||||
|
||||
const sheetMember = sheetId && sheetId !== rootUserId ? byId.get(sheetId) : null;
|
||||
const sheetIsRoot = sheetId === rootUserId;
|
||||
const sheetName = sheetIsRoot ? youLabel : (sheetMember?.displayName ?? '—');
|
||||
const parentName = (() => {
|
||||
if (!sheetMember) return null;
|
||||
if (sheetMember.parentUserId === rootUserId) return youLabel;
|
||||
return byId.get(sheetMember.parentUserId)?.displayName ?? '—';
|
||||
})();
|
||||
|
||||
const statusLabel = (status: ReferralNetworkMember['status']) =>
|
||||
status === 'active'
|
||||
? t('referralPage.table.status.active')
|
||||
: status === 'unverified'
|
||||
? t('referralPage.table.status.unverified')
|
||||
: t('referralPage.table.status.registered');
|
||||
|
||||
const pct = Math.round(transform.scale * 100);
|
||||
|
||||
return (
|
||||
<Box sx={{ py: 1 }}>
|
||||
{visibleChildren.map((member) => (
|
||||
<TreeNode
|
||||
key={member.userId}
|
||||
member={member}
|
||||
children={childMap.get(member.userId) ?? []}
|
||||
childMap={childMap}
|
||||
defaultExpanded
|
||||
/>
|
||||
))}
|
||||
{hasMore && (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 1, mb: 1 }}>
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
onClick={() => setVisibleRoots((n) => n + ROOT_BATCH_SIZE)}
|
||||
<Box sx={{ position: 'relative', height: { xs: 420, sm: 520, md: 560 } }}>
|
||||
<Typography
|
||||
variant="caption"
|
||||
color="text.secondary"
|
||||
sx={{ position: 'absolute', top: 8, left: 0, right: 0, textAlign: 'center', zIndex: 2, pointerEvents: 'none' }}
|
||||
>
|
||||
{t('referralPage.tree.hint')}
|
||||
</Typography>
|
||||
|
||||
<Box
|
||||
ref={viewportRef}
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerMove={onPointerMove}
|
||||
onPointerUp={onPointerUp}
|
||||
onPointerCancel={onPointerUp}
|
||||
onWheel={onWheel}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
inset: 0,
|
||||
overflow: 'hidden',
|
||||
borderRadius: 2,
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
bgcolor: 'rgba(0,0,0,0.25)',
|
||||
cursor: 'grab',
|
||||
touchAction: 'none',
|
||||
userSelect: 'none',
|
||||
'&:active': { cursor: 'grabbing' },
|
||||
}}
|
||||
>
|
||||
<Box
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: Math.max(layout.size.width, 1),
|
||||
height: Math.max(layout.size.height, 1),
|
||||
transform: `translate(${transform.x}px, ${transform.y}px) scale(${transform.scale})`,
|
||||
transformOrigin: '0 0',
|
||||
willChange: 'transform',
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width={layout.size.width}
|
||||
height={layout.size.height}
|
||||
style={{ position: 'absolute', inset: 0, overflow: 'visible' }}
|
||||
>
|
||||
{t('referralPage.network.showMore', {
|
||||
remaining: directChildren.length - visibleRoots,
|
||||
{layout.edges.map((e) => {
|
||||
const a = layout.positions.get(e.parentId);
|
||||
const b = layout.positions.get(e.childId);
|
||||
if (!a || !b) return null;
|
||||
const startX = a.x;
|
||||
const startY = a.y + 28;
|
||||
const endX = b.x;
|
||||
const endY = b.y - 36;
|
||||
const midY = (startY + endY) / 2;
|
||||
return (
|
||||
<path
|
||||
key={`${e.parentId}-${e.childId}`}
|
||||
d={`M ${startX} ${startY} C ${startX} ${midY}, ${endX} ${midY}, ${endX} ${endY}`}
|
||||
fill="none"
|
||||
stroke="rgba(16,185,129,0.55)"
|
||||
strokeWidth={1.6}
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
{directChildren.length > ROOT_BATCH_SIZE && !hasMore && (
|
||||
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', textAlign: 'center', mt: 1 }}>
|
||||
{t('common.pagination', {
|
||||
from: 1,
|
||||
to: directChildren.length,
|
||||
total: directChildren.length,
|
||||
</svg>
|
||||
|
||||
{[...layout.visibleIds].map((id) => {
|
||||
const pos = layout.positions.get(id)!;
|
||||
const isRoot = id === rootUserId;
|
||||
const member = byId.get(id);
|
||||
const level = isRoot ? 0 : (member?.levelNumber ?? 0);
|
||||
const accent = levelColor(level, isRoot);
|
||||
const selected = selectedId === id;
|
||||
const expanded = expandedIds.has(id);
|
||||
const expandable = canExpand(id);
|
||||
const name = isRoot ? youLabel : (member?.displayName ?? '—');
|
||||
const directs = isRoot
|
||||
? (childMap.get(id) ?? []).length
|
||||
: (member?.directReferralsCount ?? 0);
|
||||
const partial = !isRoot && hasPartial(id);
|
||||
|
||||
return (
|
||||
<Box
|
||||
key={id}
|
||||
data-node-hit
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
left: pos.x - NODE_W / 2,
|
||||
top: pos.y - NODE_H / 2,
|
||||
width: NODE_W,
|
||||
height: NODE_H,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
<Box sx={{ position: 'relative', width: 56, height: 56 }}>
|
||||
<Box
|
||||
component="button"
|
||||
type="button"
|
||||
aria-label={name}
|
||||
onClick={() => openSheet(id)}
|
||||
sx={{
|
||||
all: 'unset',
|
||||
boxSizing: 'border-box',
|
||||
width: 56,
|
||||
height: 56,
|
||||
borderRadius: '50%',
|
||||
cursor: 'pointer',
|
||||
display: 'grid',
|
||||
placeItems: 'center',
|
||||
color: '#fff',
|
||||
fontWeight: 900,
|
||||
fontSize: 20,
|
||||
background: `linear-gradient(135deg, ${accent}59, ${accent}d9)`,
|
||||
border: `${selected || isRoot ? 3 : 2}px solid ${
|
||||
selected ? '#fff' : accent
|
||||
}`,
|
||||
boxShadow: selected
|
||||
? `0 0 0 4px rgba(16,185,129,0.35), 0 4px 12px ${accent}59`
|
||||
: `0 3px 8px ${accent}59`,
|
||||
}}
|
||||
>
|
||||
{initials(name)}
|
||||
</Box>
|
||||
{expandable && (
|
||||
<Tooltip
|
||||
title={
|
||||
expanded
|
||||
? t('referralPage.tree.collapseBranch')
|
||||
: t('referralPage.tree.expandBranch')
|
||||
}
|
||||
>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={(ev) => {
|
||||
ev.stopPropagation();
|
||||
toggleExpand(id);
|
||||
}}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
right: -6,
|
||||
bottom: -6,
|
||||
width: 22,
|
||||
height: 22,
|
||||
bgcolor: 'background.paper',
|
||||
border: '1px solid',
|
||||
borderColor: 'divider',
|
||||
'&:hover': { bgcolor: 'background.paper' },
|
||||
}}
|
||||
>
|
||||
{expanded ? (
|
||||
<RemoveRoundedIcon sx={{ fontSize: 14 }} />
|
||||
) : (
|
||||
<AddRoundedIcon sx={{ fontSize: 14 }} />
|
||||
)}
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Box>
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{
|
||||
mt: 0.75,
|
||||
fontWeight: 800,
|
||||
maxWidth: NODE_W,
|
||||
textAlign: 'center',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
lineHeight: 1.2,
|
||||
}}
|
||||
>
|
||||
{name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="caption"
|
||||
sx={{
|
||||
fontWeight: 600,
|
||||
fontSize: 10,
|
||||
color: partial ? 'warning.main' : 'text.secondary',
|
||||
maxWidth: NODE_W,
|
||||
textAlign: 'center',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{t('referralPage.tree.direct', { count: directs })}
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Paper
|
||||
elevation={4}
|
||||
sx={{
|
||||
position: 'absolute',
|
||||
left: '50%',
|
||||
bottom: 12,
|
||||
transform: 'translateX(-50%)',
|
||||
zIndex: 3,
|
||||
borderRadius: 3,
|
||||
px: 0.5,
|
||||
py: 0.25,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: 0.25,
|
||||
}}
|
||||
>
|
||||
<Tooltip title={t('referralPage.tree.zoomOut')}>
|
||||
<IconButton size="small" onClick={() => applyZoom(1 / 1.2)} aria-label={t('referralPage.tree.zoomOut')}>
|
||||
<RemoveRoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Typography variant="caption" sx={{ width: 40, textAlign: 'center', fontWeight: 800 }}>
|
||||
{pct}%
|
||||
</Typography>
|
||||
)}
|
||||
<Tooltip title={t('referralPage.tree.zoomIn')}>
|
||||
<IconButton size="small" onClick={() => applyZoom(1.2)} aria-label={t('referralPage.tree.zoomIn')}>
|
||||
<AddRoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('referralPage.tree.fit')}>
|
||||
<IconButton size="small" onClick={fitToScreen} aria-label={t('referralPage.tree.fit')}>
|
||||
<FitScreenRoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('referralPage.tree.centerSelection')}>
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
disabled={!selectedId}
|
||||
onClick={() => selectedId && centerOnUser(selectedId)}
|
||||
aria-label={t('referralPage.tree.centerSelection')}
|
||||
>
|
||||
<MyLocationRoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('referralPage.tree.goToRoot')}>
|
||||
<IconButton size="small" onClick={goToRoot} aria-label={t('referralPage.tree.goToRoot')}>
|
||||
<HomeRoundedIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Paper>
|
||||
|
||||
<Dialog
|
||||
open={sheetId != null}
|
||||
onClose={() => setSheetId(null)}
|
||||
fullWidth
|
||||
maxWidth="xs"
|
||||
>
|
||||
<DialogTitle sx={{ fontWeight: 800 }}>{t('referralPage.tree.memberDetails')}</DialogTitle>
|
||||
<DialogContent>
|
||||
<Stack direction="row" spacing={2} sx={{ alignItems: 'center', mb: 2 }}>
|
||||
<Box
|
||||
sx={{
|
||||
width: 56,
|
||||
height: 56,
|
||||
borderRadius: '50%',
|
||||
display: 'grid',
|
||||
placeItems: 'center',
|
||||
fontWeight: 900,
|
||||
fontSize: 22,
|
||||
color: 'primary.main',
|
||||
bgcolor: 'rgba(16,185,129,0.18)',
|
||||
}}
|
||||
>
|
||||
{initials(sheetName)}
|
||||
</Box>
|
||||
<Box sx={{ minWidth: 0 }}>
|
||||
<Typography variant="h6" sx={{ fontWeight: 900, lineHeight: 1.2 }}>
|
||||
{sheetName}
|
||||
</Typography>
|
||||
{sheetMember && (
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t('referralPage.tree.level', { level: sheetMember.levelNumber })}
|
||||
{' · '}
|
||||
{statusLabel(sheetMember.status)}
|
||||
</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Stack>
|
||||
|
||||
{sheetMember ? (
|
||||
<Stack spacing={1.25}>
|
||||
<Row label={t('referralPage.tree.sponsor')} value={parentName ?? '—'} />
|
||||
<Row
|
||||
label={t('referralPage.table.directRefs')}
|
||||
value={String(sheetMember.directReferralsCount)}
|
||||
/>
|
||||
<Row
|
||||
label={t('referralPage.tree.memberSince')}
|
||||
value={new Date(sheetMember.registeredAt).toLocaleDateString(i18n.language)}
|
||||
/>
|
||||
<Typography variant="body2" sx={{ fontWeight: 600 }}>
|
||||
{t('referralPage.tree.paid', {
|
||||
amount: rawToHuman(sheetMember.commissionsPaidRaw, USDT_DECIMALS),
|
||||
})}
|
||||
</Typography>
|
||||
{BigInt(sheetMember.commissionsPendingRaw) > 0n && (
|
||||
<Typography variant="body2" color="warning.main" sx={{ fontWeight: 700 }}>
|
||||
{t('referralPage.tree.pending', {
|
||||
amount: rawToHuman(sheetMember.commissionsPendingRaw, USDT_DECIMALS),
|
||||
})}
|
||||
</Typography>
|
||||
)}
|
||||
{sheetMember.referralCode && (
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{t('referralPage.tree.code', { code: sheetMember.referralCode })}
|
||||
</Typography>
|
||||
)}
|
||||
{hasPartial(sheetMember.userId) && (
|
||||
<Chip
|
||||
size="small"
|
||||
color="warning"
|
||||
variant="outlined"
|
||||
label={t('referralPage.tree.partialData')}
|
||||
sx={{ alignSelf: 'flex-start' }}
|
||||
/>
|
||||
)}
|
||||
</Stack>
|
||||
) : (
|
||||
<Row
|
||||
label={t('referralPage.table.directRefs')}
|
||||
value={String((childMap.get(rootUserId) ?? []).length)}
|
||||
/>
|
||||
)}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setSheetId(null)} variant="contained">
|
||||
{t('common.close')}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
function Row({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<Stack direction="row" spacing={1} sx={{ justifyContent: 'space-between', gap: 2 }}>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
{label}
|
||||
</Typography>
|
||||
<Typography variant="body2" sx={{ fontWeight: 700 }}>
|
||||
{value}
|
||||
</Typography>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
101
prediqo_web/src/features/referral/utils/referralTreeLayout.ts
Normal file
101
prediqo_web/src/features/referral/utils/referralTreeLayout.ts
Normal file
@ -0,0 +1,101 @@
|
||||
import type { ReferralNetworkMember } from '../types';
|
||||
|
||||
export const NODE_W = 96;
|
||||
export const NODE_H = 118;
|
||||
export const H_GAP = 28;
|
||||
export const V_GAP = 64;
|
||||
const PAD = 48;
|
||||
|
||||
export type TreeEdge = { parentId: string; childId: string };
|
||||
|
||||
export type TreeLayoutResult = {
|
||||
positions: Map<string, { x: number; y: number }>;
|
||||
size: { width: number; height: number };
|
||||
edges: TreeEdge[];
|
||||
visibleIds: Set<string>;
|
||||
};
|
||||
|
||||
export function buildReferralChildMap(
|
||||
members: ReferralNetworkMember[],
|
||||
): Map<string, ReferralNetworkMember[]> {
|
||||
const map = new Map<string, ReferralNetworkMember[]>();
|
||||
for (const m of members) {
|
||||
const list = map.get(m.parentUserId) ?? [];
|
||||
list.push(m);
|
||||
map.set(m.parentUserId, list);
|
||||
}
|
||||
for (const list of map.values()) {
|
||||
list.sort((a, b) => a.registeredAt.localeCompare(b.registeredAt));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/** Top-down tidy tree layout (simplified Reingold–Tilford). */
|
||||
export function layoutReferralTree(opts: {
|
||||
rootId: string;
|
||||
childMap: Map<string, ReferralNetworkMember[]>;
|
||||
expandedIds: Set<string>;
|
||||
}): TreeLayoutResult {
|
||||
const { rootId, childMap, expandedIds } = opts;
|
||||
const positions = new Map<string, { x: number; y: number }>();
|
||||
const edges: TreeEdge[] = [];
|
||||
const visibleIds = new Set<string>([rootId]);
|
||||
|
||||
function subtreeWidth(id: string): number {
|
||||
const kids = expandedIds.has(id) ? (childMap.get(id) ?? []) : [];
|
||||
if (kids.length === 0) return NODE_W;
|
||||
let sum = 0;
|
||||
for (let i = 0; i < kids.length; i++) {
|
||||
if (i > 0) sum += H_GAP;
|
||||
sum += subtreeWidth(kids[i]!.userId);
|
||||
}
|
||||
return Math.max(NODE_W, sum);
|
||||
}
|
||||
|
||||
function place(id: string, centerX: number, topY: number) {
|
||||
positions.set(id, { x: centerX, y: topY + NODE_H / 2 });
|
||||
visibleIds.add(id);
|
||||
if (!expandedIds.has(id)) return;
|
||||
const kids = childMap.get(id) ?? [];
|
||||
if (kids.length === 0) return;
|
||||
|
||||
const widths = kids.map((k) => subtreeWidth(k.userId));
|
||||
let total = 0;
|
||||
for (let i = 0; i < widths.length; i++) {
|
||||
if (i > 0) total += H_GAP;
|
||||
total += widths[i]!;
|
||||
}
|
||||
let x = centerX - total / 2;
|
||||
const childY = topY + NODE_H + V_GAP;
|
||||
for (let i = 0; i < kids.length; i++) {
|
||||
const w = widths[i]!;
|
||||
const childCenter = x + w / 2;
|
||||
const childId = kids[i]!.userId;
|
||||
edges.push({ parentId: id, childId });
|
||||
place(childId, childCenter, childY);
|
||||
x += w + H_GAP;
|
||||
}
|
||||
}
|
||||
|
||||
const rootW = subtreeWidth(rootId);
|
||||
place(rootId, rootW / 2, 0);
|
||||
|
||||
let maxX = 0;
|
||||
let maxY = 0;
|
||||
for (const p of positions.values()) {
|
||||
maxX = Math.max(maxX, p.x + NODE_W / 2);
|
||||
maxY = Math.max(maxY, p.y + NODE_H / 2);
|
||||
}
|
||||
|
||||
const shifted = new Map<string, { x: number; y: number }>();
|
||||
for (const [id, p] of positions) {
|
||||
shifted.set(id, { x: p.x + PAD, y: p.y + PAD });
|
||||
}
|
||||
|
||||
return {
|
||||
positions: shifted,
|
||||
size: { width: maxX + PAD * 2, height: maxY + PAD * 2 },
|
||||
edges,
|
||||
visibleIds,
|
||||
};
|
||||
}
|
||||
@ -890,6 +890,19 @@ export const en = {
|
||||
paid: 'Paid: {{amount}} USDT',
|
||||
pending: 'Pending: {{amount}} USDT',
|
||||
code: 'Code: {{code}}',
|
||||
you: 'You',
|
||||
hint: 'Drag to pan · scroll to zoom · tap a node for details',
|
||||
zoomIn: 'Zoom in',
|
||||
zoomOut: 'Zoom out',
|
||||
fit: 'Fit to screen',
|
||||
centerSelection: 'Center selection',
|
||||
goToRoot: 'Go to root',
|
||||
expandBranch: 'Expand branch',
|
||||
collapseBranch: 'Collapse branch',
|
||||
memberDetails: 'Member details',
|
||||
sponsor: 'Sponsor',
|
||||
memberSince: 'Member since',
|
||||
partialData: 'Some deeper members are not loaded yet.',
|
||||
},
|
||||
commissions: {
|
||||
empty: 'No commission events yet.',
|
||||
|
||||
@ -904,6 +904,19 @@ export const fr = {
|
||||
paid: 'Versé : {{amount}} USDT',
|
||||
pending: 'En attente : {{amount}} USDT',
|
||||
code: 'Code : {{code}}',
|
||||
you: 'Vous',
|
||||
hint: 'Glisser pour déplacer · molette pour zoomer · toucher un nœud pour les détails',
|
||||
zoomIn: 'Zoomer',
|
||||
zoomOut: 'Dézoomer',
|
||||
fit: 'Ajuster à l’écran',
|
||||
centerSelection: 'Centrer la sélection',
|
||||
goToRoot: 'Parrain principal',
|
||||
expandBranch: 'Développer',
|
||||
collapseBranch: 'Réduire',
|
||||
memberDetails: 'Fiche membre',
|
||||
sponsor: 'Parrain',
|
||||
memberSince: 'Membre depuis',
|
||||
partialData: 'Certains filleuls plus profonds ne sont pas encore chargés.',
|
||||
},
|
||||
commissions: {
|
||||
empty: 'Aucune commission pour le moment.',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user