Skip to content

Commit

Permalink
Checking storage permission before downloading pem
Browse files Browse the repository at this point in the history
  • Loading branch information
ignaciosantise committed Nov 14, 2022
1 parent 37eff93 commit 53f76a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

<application
android:name=".MainApplication"
Expand Down
16 changes: 15 additions & 1 deletion src/screens/tabs/Profile/modals/ExportPem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import useCustomToast from '@/hooks/useCustomToast';
import { Wallet } from '@/interfaces/redux';
import { useAppDispatch, useAppSelector } from '@/redux/hooks';
import { getPemFile, validatePassword } from '@/redux/slices/keyring';
import { requestStoragePermissions } from '@/utils/filesystem';
import shortAddress from '@/utils/shortAddress';

import styles from './styles';
Expand Down Expand Up @@ -64,7 +65,7 @@ function ExportPem({ modalRef }: Props) {
);
};

const handleExportPem = () => {
const downloadPem = () => {
dispatch(
getPemFile({
walletId: selectedWallet.walletId,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/translations/en/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
) => {
Expand Down

0 comments on commit 53f76a3

Please sign in to comment.