From 53f76a3310e1c6d7b5fa5252d52002d024f97341 Mon Sep 17 00:00:00 2001 From: nachosan Date: Mon, 14 Nov 2022 13:16:06 -0300 Subject: [PATCH] Checking storage permission before downloading pem --- android/app/src/main/AndroidManifest.xml | 2 +- .../tabs/Profile/modals/ExportPem/index.tsx | 16 +++++++++++++++- src/translations/en/index.js | 4 ++++ src/utils/filesystem.ts | 2 +- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 35257cc3..a0e634b1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -5,7 +5,7 @@ - + { + const downloadPem = () => { dispatch( getPemFile({ walletId: selectedWallet.walletId, @@ -111,6 +112,19 @@ function ExportPem({ modalRef }: Props) { ); }; + const handleExportPem = async () => { + if (isIos) { + downloadPem(); + } else { + await requestStoragePermissions(() => { + toast.showError( + t('exportPem.permissionError.title'), + t('exportPem.permissionError.message') + ); + }, downloadPem); + } + }; + const renderAccount = (account: Wallet) => { const { name, walletId, icon, principal } = account; const selected = selectedWallet.walletId === walletId; diff --git a/src/translations/en/index.js b/src/translations/en/index.js index 3809a2f5..ef8581bc 100644 --- a/src/translations/en/index.js +++ b/src/translations/en/index.js @@ -353,6 +353,10 @@ const translations = { message: 'There was an error while exporting the account. Please try again.', }, + permissionError: { + title: 'Error Exporting Account', + message: 'You need to allow the app to access storage to save the file.', + }, success: { title: 'Account Successfully Exported', messageIos: 'Your .pem file should be located at the choosen directory.', diff --git a/src/utils/filesystem.ts b/src/utils/filesystem.ts index b24369ca..39ef19d8 100644 --- a/src/utils/filesystem.ts +++ b/src/utils/filesystem.ts @@ -6,7 +6,7 @@ import { isAndroid, isIos } from '@/constants/platform'; import { getExtension } from './fileTypes'; -const requestStoragePermissions = async ( +export const requestStoragePermissions = async ( onError?: () => void, onSuccess?: () => void ) => {