diff --git a/prediqo_mobile/lib/features/prediction/bloc/prediction_bloc.dart b/prediqo_mobile/lib/features/prediction/bloc/prediction_bloc.dart index ede5fba3..1e11eb68 100644 --- a/prediqo_mobile/lib/features/prediction/bloc/prediction_bloc.dart +++ b/prediqo_mobile/lib/features/prediction/bloc/prediction_bloc.dart @@ -344,6 +344,9 @@ class PredictionBloc extends Bloc { add(const PredictionRefreshTick(forceGameState: true)); add(const PredictionBalancesRefreshRequested()); add(const PredictionHistoryPageRequested(1)); + // Missed candle.append frames leave price cliffs until a full reload; + // replace the local series from HTTP after every reconnect. + add(const PredictionCandlesReloadRequested()); } } @@ -1212,6 +1215,7 @@ class PredictionBloc extends Bloc { add(const PredictionBalancesRefreshRequested()); add(const PredictionHistoryPageRequested(1)); add(const PredictionRefreshTick(forceGameState: true)); + add(const PredictionCandlesReloadRequested()); } break; case 'multi.updated': @@ -1246,7 +1250,18 @@ class PredictionBloc extends Bloc { final candle = msg['candle']; if (candle is Map) { final c = OhlcCandleModel.fromJson(candle); - emit(state.copyWith(candles: _mergeCandles(state.candles, [c]))); + final existing = state.candles; + if (existing.isNotEmpty) { + final last = existing.last; + final intervalMs = + state.selectedIntervalMinutes * 60 * 1000; + // More than ~1.5 intervals between bars ⇒ we missed WS frames. + if (c.openMs - last.openMs > (intervalMs * 3) ~/ 2) { + add(const PredictionCandlesReloadRequested()); + break; + } + } + emit(state.copyWith(candles: _mergeCandles(existing, [c]))); } break; case 'bet.accepted': @@ -1439,7 +1454,7 @@ class PredictionBloc extends Bloc { Emitter emit, ) async { emit(state.copyWith( - isLoadingOlderCandles: state.candles.isEmpty, + isLoadingOlderCandles: true, clearCandlesError: true, )); try { diff --git a/prediqo_mobile/lib/features/prediction/presentation/prediction_screen.dart b/prediqo_mobile/lib/features/prediction/presentation/prediction_screen.dart index f82e3a3f..12e96c8b 100644 --- a/prediqo_mobile/lib/features/prediction/presentation/prediction_screen.dart +++ b/prediqo_mobile/lib/features/prediction/presentation/prediction_screen.dart @@ -291,6 +291,9 @@ class _PredictionScreenState extends State with WidgetsBinding hasMoreOlder: state.hasMoreOlderCandles, instrument: gs?.config.instrument ?? defaultCandlePredictInstrument, + onRefresh: () => context + .read() + .add(const PredictionCandlesReloadRequested()), ), ), if (context.watch().state.isAdmin && diff --git a/prediqo_mobile/lib/features/prediction/presentation/widgets/candle_chart_widget.dart b/prediqo_mobile/lib/features/prediction/presentation/widgets/candle_chart_widget.dart index 072728dd..ee62fb30 100644 --- a/prediqo_mobile/lib/features/prediction/presentation/widgets/candle_chart_widget.dart +++ b/prediqo_mobile/lib/features/prediction/presentation/widgets/candle_chart_widget.dart @@ -16,12 +16,15 @@ class CandleChartWidget extends StatefulWidget { this.isLoadingOlder = false, this.hasMoreOlder = true, this.instrument = defaultCandlePredictInstrument, + this.onRefresh, }); final List candles; final bool isLoadingOlder; final bool hasMoreOlder; final CandlePredictInstrument instrument; + /// Targeted reload of candle history (avoids full page refresh). + final VoidCallback? onRefresh; static const double candleSlot = 14; static const double chartHeight = 240; @@ -152,6 +155,35 @@ class _CandleChartWidgetState extends State { return (start, end); } + Widget _refreshControl(BuildContext context) { + final onRefresh = widget.onRefresh; + if (onRefresh == null) return const SizedBox.shrink(); + if (widget.isLoadingOlder) { + return const SizedBox( + width: 36, + height: 36, + child: Padding( + padding: EdgeInsets.all(8), + child: CircularProgressIndicator(strokeWidth: 2), + ), + ); + } + return IconButton( + key: const Key('candle_chart_refresh'), + tooltip: context.strings.refreshCandles, + visualDensity: VisualDensity.compact, + padding: EdgeInsets.zero, + constraints: const BoxConstraints(minWidth: 36, minHeight: 36), + onPressed: onRefresh, + icon: Icon( + Icons.refresh_rounded, + size: 22, + color: Colors.white.withValues(alpha: 0.92), + shadows: const [Shadow(blurRadius: 8, color: Colors.black54)], + ), + ); + } + @override Widget build(BuildContext context) { final s = context.strings; @@ -165,7 +197,17 @@ class _CandleChartWidgetState extends State { height: CandleChartWidget.chartHeight, borderRadius: 12, ) - : Center(child: Text(s.chartNoData)), + : Stack( + children: [ + Center(child: Text(s.chartNoData)), + if (widget.onRefresh != null) + Positioned( + right: 0, + top: 0, + child: _refreshControl(context), + ), + ], + ), ); } @@ -217,7 +259,13 @@ class _CandleChartWidgetState extends State { ), ), ), - if (widget.isLoadingOlder) + if (widget.onRefresh != null) + Positioned( + right: 4, + top: 2, + child: _refreshControl(context), + ) + else if (widget.isLoadingOlder) const Positioned( right: 8, top: 8, diff --git a/prediqo_mobile/lib/l10n/app_strings.dart b/prediqo_mobile/lib/l10n/app_strings.dart index ef12e019..315d0f2f 100644 --- a/prediqo_mobile/lib/l10n/app_strings.dart +++ b/prediqo_mobile/lib/l10n/app_strings.dart @@ -463,6 +463,7 @@ class AppStrings { String get walletBonus => t('Bonus', 'Bonus'); String get walletTest => t('Test', 'Test'); String get chartNoData => t('No chart data', 'Pas de données de graphique'); + String get refreshCandles => t('Refresh candles', 'Actualiser les bougies'); String get chartScrollHint => t( 'Swipe horizontally to browse candle history', 'Faites glisser horizontalement pour parcourir l’historique', diff --git a/prediqo_mobile/pubspec.yaml b/prediqo_mobile/pubspec.yaml index 186313d7..359a2831 100644 --- a/prediqo_mobile/pubspec.yaml +++ b/prediqo_mobile/pubspec.yaml @@ -1,7 +1,7 @@ name: prediqo_mobile description: "Tloto mobile app - prediction games and crypto wallet." publish_to: 'none' -version: 2.0.2+12 +version: 2.0.2+13 environment: sdk: ^3.9.2