From 72d93d20ecf09843f89af057c359f5d9efcd2fd1 Mon Sep 17 00:00:00 2001 From: vjrj <vjrj@comunes.org> Date: Sun, 9 Apr 2023 13:17:56 +0200 Subject: [PATCH] Detect unnsupported browsers --- assets/translations/en.json | 3 ++- assets/translations/es.json | 3 ++- lib/data/models/app_cubit.dart | 6 ++++++ lib/data/models/app_state.dart | 7 ++++++- lib/data/models/app_state.g.dart | 2 ++ lib/ui/screens/first_screen.dart | 23 +++++++++++++++++++++++ 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/assets/translations/en.json b/assets/translations/en.json index 3e701c9c..89f85cee 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -136,5 +136,6 @@ "notification_new_sent_title": "New payment sent", "notification_new_sent_desc": "You have sent a {amount} to {to}", "contact_already_exists": "Contact already exists", - "wrong_public_key": "Wrong public key" + "wrong_public_key": "Wrong public key", + "browser_warning": "You are using a browser we didn't test. Please use Chrome, Firefox or Brave." } diff --git a/assets/translations/es.json b/assets/translations/es.json index 87a746e1..7f2ca419 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -136,5 +136,6 @@ "notification_new_sent_title": "Nuevo pago enviado", "notification_new_sent_desc": "Has enviado un nuevo pago de {amount} a {to}", "contact_already_exists": "Contacto ya existente", - "wrong_public_key": "Clave pública incorrecta" + "wrong_public_key": "Clave pública incorrecta", + "browser_warning": "Estas usando un navegador que no hemos testeado. Por favor, usa Chrome, Firefox o Brave." } diff --git a/lib/data/models/app_cubit.dart b/lib/data/models/app_cubit.dart index f811d083..edeb8c3c 100644 --- a/lib/data/models/app_cubit.dart +++ b/lib/data/models/app_cubit.dart @@ -9,6 +9,8 @@ class AppCubit extends HydratedCubit<AppState> { bool get isWarningViewed => state.warningViewed; + bool get isWarningBrowserViewed => state.warningBrowserViewed; + bool get isExpertMode => state.expertMode; void introViewed() { @@ -19,6 +21,10 @@ class AppCubit extends HydratedCubit<AppState> { emit(state.copyWith(warningViewed: true)); } + void warningBrowserViewed() { + emit(state.copyWith(warningBrowserViewed: true)); + } + @override AppState fromJson(Map<String, dynamic> json) { return AppState.fromJson(json); diff --git a/lib/data/models/app_state.dart b/lib/data/models/app_state.dart index f6a6a4b9..ce04851e 100644 --- a/lib/data/models/app_state.dart +++ b/lib/data/models/app_state.dart @@ -10,6 +10,7 @@ class AppState extends Equatable implements IsJsonSerializable<AppState> { const AppState({ this.introViewed = false, this.warningViewed = false, + this.warningBrowserViewed = false, this.expertMode = false, }); @@ -18,17 +19,20 @@ class AppState extends Equatable implements IsJsonSerializable<AppState> { final bool introViewed; final bool warningViewed; + final bool warningBrowserViewed; final bool expertMode; AppState copyWith({ bool? introViewed, bool? warningViewed, + bool? warningBrowserViewed, bool? expertMode, String? locale, }) { return AppState( introViewed: introViewed ?? this.introViewed, warningViewed: warningViewed ?? this.warningViewed, + warningBrowserViewed: warningBrowserViewed ?? this.warningBrowserViewed, expertMode: expertMode ?? this.expertMode); } @@ -39,5 +43,6 @@ class AppState extends Equatable implements IsJsonSerializable<AppState> { Map<String, dynamic> toJson() => _$AppStateToJson(this); @override - List<Object?> get props => <Object>[introViewed, warningViewed, expertMode]; + List<Object?> get props => + <Object>[introViewed, warningViewed, expertMode, warningBrowserViewed]; } diff --git a/lib/data/models/app_state.g.dart b/lib/data/models/app_state.g.dart index dca06c2f..1ae258e7 100644 --- a/lib/data/models/app_state.g.dart +++ b/lib/data/models/app_state.g.dart @@ -9,11 +9,13 @@ part of 'app_state.dart'; AppState _$AppStateFromJson(Map<String, dynamic> json) => AppState( introViewed: json['introViewed'] as bool? ?? false, warningViewed: json['warningViewed'] as bool? ?? false, + warningBrowserViewed: json['warningBrowserViewed'] as bool? ?? false, expertMode: json['expertMode'] as bool? ?? false, ); Map<String, dynamic> _$AppStateToJson(AppState instance) => <String, dynamic>{ 'introViewed': instance.introViewed, 'warningViewed': instance.warningViewed, + 'warningBrowserViewed': instance.warningBrowserViewed, 'expertMode': instance.expertMode, }; diff --git a/lib/ui/screens/first_screen.dart b/lib/ui/screens/first_screen.dart index 85f05a73..e949e4d4 100644 --- a/lib/ui/screens/first_screen.dart +++ b/lib/ui/screens/first_screen.dart @@ -1,6 +1,8 @@ import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:web_browser_detect/web_browser_detect.dart'; import '../../data/models/app_cubit.dart'; import '../../data/models/app_state.dart'; @@ -38,7 +40,28 @@ class _FirstScreenState extends State<FirstScreen> { ), ); } + if (kIsWeb) { + final Browser? browser = Browser.detectOrNull(); + if (browser == null || + (browser.browserAgent != BrowserAgent.Chrome || + browser.browserAgent != BrowserAgent.Firefox)) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(tr('browser_warning')), + action: SnackBarAction( + label: 'OK', + onPressed: () { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); + context.read<AppCubit>().warningBrowserViewed(); + }, + ), + ), + ); + } + } }); + + // FIXME context.read<PaymentCubit>().notSent(); return BlocBuilder<PaymentCubit, PaymentState>( builder: (BuildContext context, PaymentState state) => -- GitLab