CW-315-Add-a-toast-message-to-enable-denied-permissions-in-device-settings (#1157)

* add permission handler

* localization

* minor fixes

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii 2023-11-02 19:19:39 +02:00 committed by GitHub
parent e5d99313eb
commit d997ee81a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 82 additions and 3 deletions

View file

@ -69,7 +69,7 @@ class NodeCreateOrEditPage extends BasePage {
@override
Widget trailing(BuildContext context) => IconButton(
onPressed: () async {
await nodeCreateOrEditViewModel.scanQRCodeForNewNode();
await nodeCreateOrEditViewModel.scanQRCodeForNewNode(context);
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,

View file

@ -69,7 +69,7 @@ class PowNodeCreateOrEditPage extends BasePage {
@override
Widget trailing(BuildContext context) => IconButton(
onPressed: () async {
await nodeCreateOrEditViewModel.scanQRCodeForNewNode();
await nodeCreateOrEditViewModel.scanQRCodeForNewNode(context);
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,

View file

@ -12,6 +12,8 @@ import 'package:cake_wallet/routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:cake_wallet/utils/permission_handler.dart';
class RestoreOptionsPage extends BasePage {
RestoreOptionsPage({required this.isNewInstall});
@ -55,6 +57,9 @@ class RestoreOptionsPage extends BasePage {
padding: EdgeInsets.only(top: 24),
child: OptionTile(
onPressed: () async {
bool isCameraPermissionGranted =
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
bool isPinSet = false;
if (isNewInstall) {
await Navigator.pushNamed(context, Routes.setupPin,

View file

@ -8,10 +8,12 @@ import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:cake_wallet/entities/qr_scanner.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/utils/permission_handler.dart';
import 'widgets/pairing_item_widget.dart';
import 'wc_pairing_detail_page.dart';
@ -58,6 +60,9 @@ class WCPairingsWidget extends BasePage {
final String? uri;
if (DeviceInfo.instance.isMobile) {
bool isCameraPermissionGranted =
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
uri = await presentQRScanner();
} else {
uri = await _showEnterWalletConnectURIPopUp(context);

View file

@ -9,6 +9,8 @@ import 'package:cake_wallet/entities/qr_scanner.dart';
import 'package:cake_wallet/entities/contact_base.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cake_wallet/themes/extensions/send_page_theme.dart';
import 'package:cake_wallet/utils/permission_handler.dart';
import 'package:permission_handler/permission_handler.dart';
enum AddressTextFieldOption { paste, qrCode, addressBook }
@ -188,6 +190,9 @@ class AddressTextField extends StatelessWidget {
}
Future<void> _presentQRScanner(BuildContext context) async {
bool isCameraPermissionGranted =
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
final code = await presentQRScanner();
if (code.isEmpty) {
return;

View file

@ -0,0 +1,32 @@
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:flutter/cupertino.dart';
import 'package:permission_handler/permission_handler.dart';
class PermissionHandler {
static Future<bool> checkPermission(Permission permission, BuildContext context) async {
final Map<Permission, String> _permissionMessages = {
Permission.camera: S.of(context).camera_permission_is_required,
};
var status = await permission.status;
if (status.isDenied) {
status = await permission.request();
}
if (status.isPermanentlyDenied || status.isDenied) {
String? message = _permissionMessages[permission];
if (message != null) {
showBar<void>(context, message);
}
return false;
}
if (status.isGranted) {
return true;
}
return false;
}
}

View file

@ -1,11 +1,14 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/entities/qr_scanner.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:flutter/cupertino.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/node.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:collection/collection.dart';
import 'package:cake_wallet/utils/permission_handler.dart';
import 'package:permission_handler/permission_handler.dart';
part 'node_create_or_edit_view_model.g.dart';
@ -175,8 +178,11 @@ abstract class NodeCreateOrEditViewModelBase with Store {
void setAsCurrent(Node node) => _settingsStore.nodes[_walletType] = node;
@action
Future<void> scanQRCodeForNewNode() async {
Future<void> scanQRCodeForNewNode(BuildContext context) async {
try {
bool isCameraPermissionGranted =
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
String code = await presentQRScanner();
if (code.isEmpty) {

View file

@ -723,5 +723,6 @@
"enter_seed_phrase": "أدخل عبارة البذور الخاصة بك",
"add_contact": "ﻝﺎﺼﺗﺍ ﺔﻬﺟ ﺔﻓﺎﺿﺇ",
"exchange_provider_unsupported": "${providerName} لم يعد مدعومًا!",
"camera_permission_is_required": ".ﺍﺮﻴﻣﺎﻜﻟﺍ ﻥﺫﺇ ﺏﻮﻠﻄﻣ",
"switchToETHWallet": "ﻯﺮﺧﺃ ﺓﺮﻣ ﺔﻟﻭﺎﺤﻤﻟﺍﻭ Ethereum ﺔﻈﻔﺤﻣ ﻰﻟﺇ ﻞﻳﺪﺒﺘﻟﺍ ﻰﺟﺮﻳ"
}

View file

@ -719,5 +719,6 @@
"enter_seed_phrase": "Въведете вашата фраза за семена",
"add_contact": "Добави контакт",
"exchange_provider_unsupported": "${providerName} вече не се поддържа!",
"camera_permission_is_required": "Изисква се разрешение за камерата.\nМоля, активирайте го от настройките на приложението.",
"switchToETHWallet": "Моля, преминете към портфейл Ethereum и опитайте отново"
}

View file

@ -719,5 +719,6 @@
"enter_seed_phrase": "Zadejte svou frázi semen",
"add_contact": "Přidat kontakt",
"exchange_provider_unsupported": "${providerName} již není podporováno!",
"camera_permission_is_required": "Vyžaduje se povolení fotoaparátu.\nPovolte jej v nastavení aplikace.",
"switchToETHWallet": "Přejděte na peněženku Ethereum a zkuste to znovu"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Geben Sie Ihre Seed-Phrase ein",
"add_contact": "Kontakt hinzufügen",
"exchange_provider_unsupported": "${providerName} wird nicht mehr unterstützt!",
"camera_permission_is_required": "Eine Kameraerlaubnis ist erforderlich.\nBitte aktivieren Sie es in den App-Einstellungen.",
"switchToETHWallet": "Bitte wechseln Sie zu einem Ethereum-Wallet und versuchen Sie es erneut"
}

View file

@ -728,5 +728,6 @@
"enter_seed_phrase": "Enter your seed phrase",
"add_contact": "Add contact",
"exchange_provider_unsupported": "${providerName} is no longer supported!",
"camera_permission_is_required": "Camera permission is required. \nPlease enable it from app settings.",
"switchToETHWallet": "Please switch to an Ethereum wallet and try again"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Ingrese su frase de semillas",
"add_contact": "Agregar contacto",
"exchange_provider_unsupported": "¡${providerName} ya no es compatible!",
"camera_permission_is_required": "Se requiere permiso de la cámara.\nHabilítelo desde la configuración de la aplicación.",
"switchToETHWallet": "Cambie a una billetera Ethereum e inténtelo nuevamente."
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Entrez votre phrase de semence",
"add_contact": "Ajouter le contact",
"exchange_provider_unsupported": "${providerName} n'est plus pris en charge!",
"camera_permission_is_required": "L'autorisation de la caméra est requise.\nVeuillez l'activer à partir des paramètres de l'application.",
"switchToETHWallet": "Veuillez passer à un portefeuille Ethereum et réessayer"
}

View file

@ -705,5 +705,6 @@
"enter_seed_phrase": "Shigar da Sert Sentarku",
"add_contact": "Ƙara lamba",
"exchange_provider_unsupported": "${providerName}",
"camera_permission_is_required": "Ana buƙatar izinin kyamara.\nDa fatan za a kunna shi daga saitunan app.",
"switchToETHWallet": "Da fatan za a canza zuwa walat ɗin Ethereum kuma a sake gwadawa"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "अपना बीज वाक्यांश दर्ज करें",
"add_contact": "संपर्क जोड़ें",
"exchange_provider_unsupported": "${providerName} अब समर्थित नहीं है!",
"camera_permission_is_required": "कैमरे की अनुमति आवश्यक है.\nकृपया इसे ऐप सेटिंग से सक्षम करें।",
"switchToETHWallet": "कृपया एथेरियम वॉलेट पर स्विच करें और पुनः प्रयास करें"
}

View file

@ -725,5 +725,6 @@
"enter_seed_phrase": "Unesite svoju sjemensku frazu",
"add_contact": "Dodaj kontakt",
"exchange_provider_unsupported": "${providerName} više nije podržan!",
"camera_permission_is_required": "Potrebno je dopuštenje kamere.\nOmogućite ga u postavkama aplikacije.",
"switchToETHWallet": "Prijeđite na Ethereum novčanik i pokušajte ponovno"
}

View file

@ -715,5 +715,6 @@
"enter_seed_phrase": "Masukkan frasa benih Anda",
"add_contact": "Tambah kontak",
"exchange_provider_unsupported": "${providerName} tidak lagi didukung!",
"camera_permission_is_required": "Izin kamera diperlukan.\nSilakan aktifkan dari pengaturan aplikasi.",
"switchToETHWallet": "Silakan beralih ke dompet Ethereum dan coba lagi"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Inserisci la tua frase di semi",
"add_contact": "Aggiungi contatto",
"exchange_provider_unsupported": "${providerName} non è più supportato!",
"camera_permission_is_required": "È richiesta l'autorizzazione della fotocamera.\nAbilitalo dalle impostazioni dell'app.",
"switchToETHWallet": "Passa a un portafoglio Ethereum e riprova"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "シードフレーズを入力してください",
"add_contact": "連絡先を追加",
"exchange_provider_unsupported": "${providerName}はサポートされなくなりました!",
"camera_permission_is_required": "カメラの許可が必要です。\nアプリの設定から有効にしてください。",
"switchToETHWallet": "イーサリアムウォレットに切り替えてもう一度お試しください"
}

View file

@ -725,5 +725,6 @@
"enter_seed_phrase": "시드 문구를 입력하십시오",
"add_contact": "주소록에 추가",
"exchange_provider_unsupported": "${providerName}은 더 이상 지원되지 않습니다!",
"camera_permission_is_required": "카메라 권한이 필요합니다.\n앱 설정에서 활성화해 주세요.",
"switchToETHWallet": "이더리움 지갑으로 전환한 후 다시 시도해 주세요."
}

View file

@ -725,5 +725,6 @@
"enter_seed_phrase": "သင့်ရဲ့မျိုးစေ့စကားစုကိုရိုက်ထည့်ပါ",
"add_contact": "အဆက်အသွယ်ထည့်ပါ။",
"exchange_provider_unsupported": "${providerName} မရှိတော့ပါ!",
"camera_permission_is_required": "ကင်မရာခွင့်ပြုချက် လိုအပ်ပါသည်။\nအက်ပ်ဆက်တင်များမှ ၎င်းကိုဖွင့်ပါ။",
"switchToETHWallet": "ကျေးဇူးပြု၍ Ethereum ပိုက်ဆံအိတ်သို့ ပြောင်းပြီး ထပ်စမ်းကြည့်ပါ။"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Voer uw zaadzin in",
"add_contact": "Contactpersoon toevoegen",
"exchange_provider_unsupported": "${providerName} wordt niet langer ondersteund!",
"camera_permission_is_required": "Cameratoestemming is vereist.\nSchakel dit in via de app-instellingen.",
"switchToETHWallet": "Schakel over naar een Ethereum-portemonnee en probeer het opnieuw"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Wprowadź swoją frazę nasienną",
"add_contact": "Dodaj kontakt",
"exchange_provider_unsupported": "${providerName} nie jest już obsługiwany!",
"camera_permission_is_required": "Wymagane jest pozwolenie na korzystanie z aparatu.\nWłącz tę funkcję w ustawieniach aplikacji.",
"switchToETHWallet": "Przejdź na portfel Ethereum i spróbuj ponownie"
}

View file

@ -726,5 +726,6 @@
"enter_seed_phrase": "Digite sua frase de semente",
"add_contact": "Adicionar contato",
"exchange_provider_unsupported": "${providerName} não é mais suportado!",
"camera_permission_is_required": "É necessária permissão da câmera.\nAtive-o nas configurações do aplicativo.",
"switchToETHWallet": "Mude para uma carteira Ethereum e tente novamente"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Введите свою семенную фразу",
"add_contact": "Добавить контакт",
"exchange_provider_unsupported": "${providerName} больше не поддерживается!",
"camera_permission_is_required": "Требуется разрешение камеры.\nПожалуйста, включите его в настройках приложения.",
"switchToETHWallet": "Пожалуйста, переключитесь на кошелек Ethereum и повторите попытку."
}

View file

@ -725,5 +725,6 @@
"enter_seed_phrase": "ป้อนวลีเมล็ดพันธุ์ของคุณ",
"add_contact": "เพิ่มผู้ติดต่อ",
"exchange_provider_unsupported": "${providerName} ไม่ได้รับการสนับสนุนอีกต่อไป!",
"camera_permission_is_required": "ต้องได้รับอนุญาตจากกล้อง\nโปรดเปิดใช้งานจากการตั้งค่าแอป",
"switchToETHWallet": "โปรดเปลี่ยนไปใช้กระเป๋าเงิน Ethereum แล้วลองอีกครั้ง"
}

View file

@ -722,5 +722,6 @@
"enter_seed_phrase": "Ipasok ang iyong pariralang binhi",
"add_contact": "Magdagdag ng contact",
"exchange_provider_unsupported": "Ang ${providerName} ay hindi na suportado!",
"camera_permission_is_required": "Kinakailangan ang pahintulot sa camera.\nMangyaring paganahin ito mula sa mga setting ng app.",
"switchToETHWallet": "Mangyaring lumipat sa isang Ethereum wallet at subukang muli"
}

View file

@ -725,5 +725,6 @@
"enter_seed_phrase": "Tohum ifadenizi girin",
"add_contact": "Kişi ekle",
"exchange_provider_unsupported": "${providerName} artık desteklenmiyor!",
"camera_permission_is_required": "Kamera izni gereklidir.\nLütfen uygulama ayarlarından etkinleştirin.",
"switchToETHWallet": "Lütfen bir Ethereum cüzdanına geçin ve tekrar deneyin"
}

View file

@ -727,5 +727,6 @@
"enter_seed_phrase": "Введіть свою насіннєву фразу",
"add_contact": "Додати контакт",
"exchange_provider_unsupported": "${providerName} більше не підтримується!",
"camera_permission_is_required": "Потрібен дозвіл камери.\nУвімкніть його в налаштуваннях програми.",
"switchToETHWallet": "Перейдіть на гаманець Ethereum і повторіть спробу"
}

View file

@ -719,5 +719,6 @@
"enter_seed_phrase": "اپنے بیج کا جملہ درج کریں",
"add_contact": "۔ﮟﯾﺮﮐ ﻞﻣﺎﺷ ﮧﻄﺑﺍﺭ",
"exchange_provider_unsupported": "${providerName} اب تعاون نہیں کیا جاتا ہے!",
"camera_permission_is_required": "۔ﮯﮨ ﺭﺎﮐﺭﺩ ﺕﺯﺎﺟﺍ ﯽﮐ ﮮﺮﻤﯿﮐ",
"switchToETHWallet": "۔ﮟﯾﺮﮐ ﺶﺷﻮﮐ ﮦﺭﺎﺑﻭﺩ ﺭﻭﺍ ﮟﯾﺮﮐ ﭻﺋﻮﺳ ﺮﭘ ﭧﯿﻟﺍﻭ Ethereum ﻡﺮﮐ ﮦﺍﺮﺑ"
}

View file

@ -721,5 +721,6 @@
"enter_seed_phrase": "Tẹ ọrọ-iru irugbin rẹ",
"add_contact": "Fi olubasọrọ kun",
"exchange_provider_unsupported": "${providerName} ko ni atilẹyin mọ!",
"camera_permission_is_required": "A nilo igbanilaaye kamẹra.\nJọwọ jeki o lati app eto.",
"switchToETHWallet": "Jọwọ yipada si apamọwọ Ethereum ki o tun gbiyanju lẹẹkansi"
}

View file

@ -726,5 +726,6 @@
"enter_seed_phrase": "输入您的种子短语",
"add_contact": "增加联系人",
"exchange_provider_unsupported": "${providerName}不再支持!",
"camera_permission_is_required": "需要相机许可。\n请从应用程序设置中启用它。",
"switchToETHWallet": "请切换到以太坊钱包并重试"
}