Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/permission for pem file #537

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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