Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/navigation/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import styled from 'styled-components/native';
import {Caution, Slate30, SlateDark, White} from '../styles/colors';
import {isAndroidStoragePermissionGranted} from '../utils/helper-methods';
import RNFS from 'react-native-fs';
import Share, {ShareOptions} from 'react-native-share';
import {ShareOptions} from 'react-native-share';
import {shareFile as shareFileUtil} from '../utils/share';
import DeviceInfo from 'react-native-device-info';
const IS_DESKTOP = DeviceInfo.getDeviceType();

Expand Down Expand Up @@ -99,7 +100,7 @@ const DebugScreen: React.FC<
};

await RNFS.writeFile(filePath, data, 'utf8');
await Share.open(opts);
await dispatch(shareFileUtil(opts));
} catch (error: any) {
Alert.alert(
'Error',
Expand Down
5 changes: 3 additions & 2 deletions src/navigation/tabs/settings/about/screens/SessionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import {ListHeader} from '../../general/screens/customize-home/Shared';
import {storage} from '../../../../../store';
import {TouchableOpacity} from '@components/base/TouchableOpacity';
import {isAndroidStoragePermissionGranted} from '../../../../../utils/helper-methods';
import Share, {ShareOptions} from 'react-native-share';
import {ShareOptions} from 'react-native-share';
import {shareFile as shareFileUtil} from '../../../../../utils/share';
import RNFS from 'react-native-fs';
import {logManager} from '../../../../../managers/LogManager';
import {useLogContext} from '../../../../../contexts/LogContext';
Expand Down Expand Up @@ -210,7 +211,7 @@ const SessionLogs = ({}: SessionLogsScreenProps) => {
};

await RNFS.writeFile(filePath, data, 'utf8');
await Share.open(opts);
await dispatch(shareFileUtil(opts));
} catch (err: any) {
logManager.debug(`[shareFile]: ${err.message}`);
if (err && err.message === 'User did not share') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, {useEffect, useLayoutEffect, useState} from 'react';
import {
ScrollView,
Linking,
Share,
RefreshControl,
Image,
DeviceEventEmitter,
Platform,
} from 'react-native';
import {shareNative} from '../../../../../utils/share';
import {TouchableOpacity} from '@components/base/TouchableOpacity';
import RNPrint from 'react-native-print';
import RenderHtml from 'react-native-render-html';
Expand Down Expand Up @@ -351,7 +351,7 @@ const GiftCardDetails = ({
Platform.OS === 'ios' && giftCard.claimLink
? {url: giftCard.claimLink}
: {message: giftCard.claimLink || giftCard.claimCode};
Share.share(dataToShare);
dispatch(shareNative(dataToShare));
},
},
...(defaultClaimCodeType !== 'link'
Expand Down
5 changes: 3 additions & 2 deletions src/navigation/wallet/screens/BackupOnboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {getMnemonic, sleep} from '../../../utils/helper-methods';
import {AppActions} from '../../../store/app';
import {RouteProp} from '@react-navigation/core';
import {WalletGroupParamList} from '../WalletGroup';
import Share, {ShareOptions} from 'react-native-share';
import {ShareOptions} from 'react-native-share';
import {shareFile} from '../../../utils/share';
import {showBottomNotificationModal} from '../../../store/app/app.actions';
import {BottomNotificationConfig} from '../../../components/modal/bottom-notification/BottomNotification';
import {CustomErrorMessage} from '../components/ErrorMessages';
Expand Down Expand Up @@ -128,7 +129,7 @@ const BackupOnboarding: React.FC = () => {
};

logger.debug('Trying to execute Share.open');
Share.open(opts);
dispatch(shareFile(opts));
} catch (err) {
let errMsg = '';
if (err instanceof Error) {
Expand Down
9 changes: 5 additions & 4 deletions src/navigation/wallet/screens/Copayers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Clipboard from '@react-native-clipboard/clipboard';
import {RouteProp, useRoute} from '@react-navigation/native';
import QRCode from 'react-native-qrcode-svg';
import styled, {useTheme} from 'styled-components/native';
import {Image, ScrollView, RefreshControl, Share} from 'react-native';
import {Image, ScrollView, RefreshControl} from 'react-native';
import {TouchableOpacity} from '@components/base/TouchableOpacity';
import {
Paragraph,
Expand All @@ -26,6 +26,8 @@ import {useNavigation} from '@react-navigation/native';
import Button from '../../../components/button/Button';
import {useTranslation} from 'react-i18next';
import {useLogger} from '../../../utils/hooks';
import {useAppDispatch} from '../../../utils/hooks';
import {shareNative} from '../../../utils/share';

const CircleCheckIcon = require('../../../../assets/img/circle-check.png');
interface CopayersProps {
Expand Down Expand Up @@ -69,6 +71,7 @@ const CopayersContainer = styled(RowContainer)`
const Copayers: React.FC<CopayersProps> = props => {
const {t} = useTranslation();
const logger = useLogger();
const dispatch = useAppDispatch();
const route = useRoute<RouteProp<WalletGroupParamList, 'Copayers'>>();
const {wallet, status} = route.params || {};
const [walletStatus, setWalletStatus] = useState(status);
Expand Down Expand Up @@ -151,9 +154,7 @@ const Copayers: React.FC<CopayersProps> = props => {
};

const shareInvitation = async () => {
await Share.share({
message: walletStatus.secret,
});
await dispatch(shareNative({message: walletStatus.secret}));
};

return (
Expand Down
7 changes: 3 additions & 4 deletions src/navigation/wallet/screens/InviteCosigners.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useState, useEffect} from 'react';
import {ScrollView, Modal, Share, useWindowDimensions} from 'react-native';
import {ScrollView, Modal, useWindowDimensions} from 'react-native';
import {shareNative} from '../../../utils/share';
import styled from 'styled-components/native';
import {NativeStackScreenProps} from '@react-navigation/native-stack';
import {useTranslation} from 'react-i18next';
Expand Down Expand Up @@ -417,9 +418,7 @@ const InviteCosigners: React.FC<Props> = ({route}) => {
const handleShare = async () => {
if (!pendingJoinCode) return;
try {
await Share.share({
message: pendingJoinCode,
});
await dispatch(shareNative({message: pendingJoinCode}));
} catch (err: any) {
logger.error(`Share error: ${err.message}`);
}
Expand Down
6 changes: 2 additions & 4 deletions src/navigation/wallet/screens/JoinTSSWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useEffect, useLayoutEffect, useRef} from 'react';
import {Share} from 'react-native';
import {shareNative} from '../../../utils/share';
import styled from 'styled-components/native';
import {NativeStackScreenProps} from '@react-navigation/native-stack';
import {useTranslation} from 'react-i18next';
Expand Down Expand Up @@ -285,9 +285,7 @@ const JoinTSSWallet: React.FC<Props> = ({navigation, route}) => {

const handleShare = async () => {
try {
await Share.share({
message: sessionId,
});
await dispatch(shareNative({message: sessionId}));
} catch (err: any) {
logger.error(`Share error: ${err.message}`);
}
Expand Down
39 changes: 19 additions & 20 deletions src/navigation/wallet/screens/WalletDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
DeviceEventEmitter,
Linking,
RefreshControl,
Share,
Text,
View,
useWindowDimensions,
} from 'react-native';
import {shareNative} from '../../../utils/share';
import {useStore} from 'react-redux';
import {TouchableOpacity} from '@components/base/TouchableOpacity';
import styled from 'styled-components/native';
Expand Down Expand Up @@ -441,25 +441,24 @@ const WalletDetails: React.FC<WalletDetailsScreenProps> = ({route}) => {
createWalletAddress({wallet: fullWalletObj, newAddress: false}),
)) as string;

Share.share(
{
message: address,
title: t('Share Address'),
},
{
dialogTitle: t('Share Address'),
subject: t('Share Address'),
excludedActivityTypes: [
'print',
'addToReadingList',
'markupAsPDF',
'openInIbooks',
'postToFacebook',
'postToTwitter',
'saveToCameraRoll',
'sharePlay',
],
},
dispatch(
shareNative(
{message: address, title: t('Share Address')},
{
dialogTitle: t('Share Address'),
subject: t('Share Address'),
excludedActivityTypes: [
'print',
'addToReadingList',
'markupAsPDF',
'openInIbooks',
'postToFacebook',
'postToTwitter',
'saveToCameraRoll',
'sharePlay',
],
},
),
);
} catch (e) {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Clipboard from '@react-native-clipboard/clipboard';
import QRCode from 'react-native-qrcode-svg';
import {LightBlack, LightBlue, White} from '../../../../styles/colors';
import ShareIcon from '../../../../components/icons/share/Share';
import {Share} from 'react-native';
import {shareNative} from '../../../../utils/share';
import GhostSvg from '../../../../../assets/img/ghost-straight-face.svg';
import {createWalletAddress} from '../../../../store/wallet/effects/address/address';
import {
Expand Down Expand Up @@ -121,9 +121,7 @@ const RequestSpecificAmountQR = () => {
useLayoutEffect(() => {
const onPressShare = async () => {
if (qrValue) {
await Share.share({
message: qrValue,
});
await dispatch(shareNative({message: qrValue}));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
ScreenGutter,
SettingTitle,
} from '../../../../components/styled/Containers';
import {Share, View} from 'react-native';
import {View} from 'react-native';
import {shareNative} from '../../../../utils/share';
import {RouteProp} from '@react-navigation/core';
import {WalletGroupParamList} from '../../WalletGroup';
import {SlateDark, White} from '../../../../styles/colors';
Expand Down Expand Up @@ -137,7 +138,7 @@ const AllAddresses = () => {
.join('\n');

const subject = appName + ' Addresses';
await Share.share({title: subject, message: body});
await dispatch(shareNative({title: subject, message: body}));
setButtonState('success');
await sleep(200);
setButtonState(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import ChevronUpSvg from '../../../../../assets/img/chevron-up.svg';
import ChevronDownSvg from '../../../../../assets/img/chevron-down.svg';
import Checkbox from '../../../../components/checkbox/Checkbox';
import {TouchableOpacity} from '@components/base/TouchableOpacity';
import Share, {ShareOptions} from 'react-native-share';
import {ShareOptions} from 'react-native-share';
import {shareFile} from '../../../../utils/share';
import RNFS from 'react-native-fs';
import {APP_NAME_UPPERCASE} from '../../../../constants/config';
import {logManager} from '../../../../managers/LogManager';
Expand Down Expand Up @@ -291,7 +292,7 @@ const ExportTSSWallet = () => {
type: 'text/plain',
};

await Share.open(opts);
await dispatch(shareFile(opts));

RNFS.unlink(filePath).catch(() => {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {APP_NAME_UPPERCASE} from '../../../../constants/config';
import {GetPrecision} from '../../../../store/wallet/utils/currency';
import RNFS from 'react-native-fs';
import {PermissionsAndroid, Platform} from 'react-native';
import Share, {ShareOptions} from 'react-native-share';
import {ShareOptions} from 'react-native-share';
import {shareFile as shareFileUtil} from '../../../../utils/share';
import Papa from 'papaparse';
import {BottomNotificationConfig} from '../../../../components/modal/bottom-notification/BottomNotification';
import {
Expand Down Expand Up @@ -237,7 +238,7 @@ const ExportTransactionHistory = () => {
await RNFS.writeFile(filePath, csv, 'utf8');

if (option === 'download') {
await Share.open(opts);
await dispatch(shareFileUtil(opts));
} else {
handleEmail(opts.subject!, filePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import Mailer from 'react-native-mail';
import {TouchableOpacity} from '@components/base/TouchableOpacity';
import {IS_DESKTOP} from '../../../../constants';
import {Platform} from 'react-native';
import Share, {ShareOptions} from 'react-native-share';
import {ShareOptions} from 'react-native-share';
import {shareFile as shareFileUtil} from '../../../../utils/share';
import RNFS from 'react-native-fs';
import {APP_NAME_UPPERCASE} from '../../../../constants/config';
import {logManager} from '../../../../managers/LogManager';
Expand Down Expand Up @@ -226,7 +227,7 @@ const ExportWallet = () => {
};

await RNFS.writeFile(filePath, txt, 'utf8');
await Share.open(opts);
await dispatch(shareFileUtil(opts));
} catch (err: any) {
logManager.debug(`[shareFile]: ${err.message}`);
if (err && err.message === 'User did not share') {
Expand Down
4 changes: 2 additions & 2 deletions src/store/app/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
EmitterSubscription,
Linking,
Platform,
Share,
} from 'react-native';
import {shareNative} from '../../utils/share';
import Braze from '@braze/react-native-sdk';
import RNBootSplash from 'react-native-bootsplash';
import InAppReview from 'react-native-in-app-review';
Expand Down Expand Up @@ -1305,7 +1305,7 @@ export const shareApp = (): Effect<Promise<void>> => async dispatch => {
if (Platform.OS !== 'ios') {
message = `${message} ${DOWNLOAD_BITPAY_URL}`;
}
await Share.share({message, url: DOWNLOAD_BITPAY_URL});
await dispatch(shareNative({message, url: DOWNLOAD_BITPAY_URL}));
} catch (err) {
let errorStr;
if (err instanceof Error) {
Expand Down
37 changes: 37 additions & 0 deletions src/utils/share.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
NativeModules,
Platform,
Share,
ShareContent,
ShareOptions as RNShareOptions,
} from 'react-native';
import RNShare, {ShareOptions} from 'react-native-share';
import {AppActions} from '../store/app';
import {LOCK_AUTHORIZED_TIME} from '../constants/Lock';
import {AppDispatch} from './hooks/useAppDispatch';

const {Timer} = NativeModules;

const extendLockIfAndroid = async (dispatch: AppDispatch) => {
if (Platform.OS === 'android') {
const timeSinceBoot = await Timer.getRelativeTime();
dispatch(
AppActions.lockAuthorizedUntil(
Number(timeSinceBoot) + LOCK_AUTHORIZED_TIME,
),
);
}
};

export const shareNative =
(content: ShareContent, options?: RNShareOptions) =>
async (dispatch: AppDispatch) => {
await extendLockIfAndroid(dispatch);
return Share.share(content, options);
};

export const shareFile =
(options: ShareOptions) => async (dispatch: AppDispatch) => {
await extendLockIfAndroid(dispatch);
return RNShare.open(options);
};
Loading