Skip to content

Commit

Permalink
FIX: Pause QRCode during Export
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosrdz authored and Overtorment committed Sep 13, 2021
1 parent 9c07e45 commit d88bb5b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 37 deletions.
39 changes: 7 additions & 32 deletions blue_modules/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const writeFileAndExport = async function (filename, contents) {
if (Platform.OS === 'ios') {
const filePath = RNFS.TemporaryDirectoryPath + `/${filename}`;
await RNFS.writeFile(filePath, contents);
Share.open({
await Share.open({
url: 'file://' + filePath,
saveToFiles: isDesktop,
})
Expand All @@ -58,37 +58,12 @@ const writeFileAndExport = async function (filename, contents) {
RNFS.unlink(filePath);
});
} else if (Platform.OS === 'android') {
Alert.alert(
loc._.file_save_title,

loc.formatString(loc._.file_save_location, { filePath: filename }),
[
{ text: loc._.cancel, onPress: () => {}, style: 'cancel' },
{
text: loc._.downloads_folder,
onPress: () => {
writeFileAndExportToAndroidDestionation({
filename,
contents,
destinationLocalizedString: loc._.downloads_folder,
destination: RNFS.DownloadDirectoryPath,
});
},
},
{
text: loc._.external_storage,
onPress: async () => {
writeFileAndExportToAndroidDestionation({
filename,
contents,
destination: RNFS.ExternalStorageDirectoryPath,
destinationLocalizedString: loc._.external_storage,
});
},
},
],
{ cancelable: true },
);
await writeFileAndExportToAndroidDestionation({
filename,
contents,
destinationLocalizedString: loc._.downloads_folder,
destination: RNFS.DownloadDirectoryPath,
});
}
};

Expand Down
13 changes: 11 additions & 2 deletions screen/send/psbtMultisigQRCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const PsbtMultisigQRCode = () => {
const openScannerButton = useRef();
const { psbtBase64, isShowOpenScanner } = useRoute().params;
const [isLoading, setIsLoading] = useState(false);
const dynamicQRCode = useRef();

const psbt = bitcoin.Psbt.fromBase64(psbtBase64);
const stylesHook = StyleSheet.create({
Expand Down Expand Up @@ -64,15 +65,23 @@ const PsbtMultisigQRCode = () => {
};

const exportPSBT = () => {
dynamicQRCode.current?.stopAutoMove();
setIsLoading(true);
setTimeout(() => fs.writeFileAndExport(fileName, psbt.toBase64()).finally(() => setIsLoading(false)), 10);
setTimeout(
() =>
fs.writeFileAndExport(fileName, psbt.toBase64()).finally(() => {
setIsLoading(false);
dynamicQRCode.current?.startAutoMove();
}),
10,
);
};

return (
<SafeBlueArea style={stylesHook.root}>
<ScrollView centerContent contentContainerStyle={styles.scrollViewContent}>
<View style={[styles.modalContentShort, stylesHook.modalContentShort]}>
<DynamicQRCode value={psbt.toHex()} />
<DynamicQRCode value={psbt.toHex()} ref={dynamicQRCode} />
{!isShowOpenScanner && (
<>
<BlueSpacing20 />
Expand Down
8 changes: 6 additions & 2 deletions screen/send/psbtWithHardwareWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const PsbtWithHardwareWallet = () => {
const [isLoading, setIsLoading] = useState(false);
const [txHex, setTxHex] = useState(route.params.txhex);
const openScannerButton = useRef();
const dynamicQRCode = useRef();

const stylesHook = StyleSheet.create({
root: {
Expand Down Expand Up @@ -185,7 +186,10 @@ const PsbtWithHardwareWallet = () => {

const exportPSBT = () => {
const fileName = `${Date.now()}.psbt`;
fs.writeFileAndExport(fileName, typeof psbt === 'string' ? psbt : psbt.toBase64());
dynamicQRCode.current?.stopAutoMove();
fs.writeFileAndExport(fileName, typeof psbt === 'string' ? psbt : psbt.toBase64()).finally(() => {
dynamicQRCode.current?.startAutoMove();
});
};

const openSignedTransaction = async () => {
Expand Down Expand Up @@ -237,7 +241,7 @@ const PsbtWithHardwareWallet = () => {
<Text testID="PSBTHex" style={styles.hidden}>
{psbt.toHex()}
</Text>
<DynamicQRCode value={psbt.toHex()} />
<DynamicQRCode value={psbt.toHex()} ref={dynamicQRCode} />
<BlueSpacing20 />
<SecondButton
testID="PsbtTxScanButton"
Expand Down
5 changes: 4 additions & 1 deletion screen/wallets/exportMultisigCoordinationSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ExportMultisigCoordinationSetup = () => {
const { wallets } = useContext(BlueStorageContext);
const wallet = wallets.find(w => w.getID() === walletId);
const qrCodeContents = useRef();
const dynamicQRCode = useRef();
const [isLoading, setIsLoading] = useState(true);
const [isShareButtonTapped, setIsShareButtonTapped] = useState(false);
const { goBack } = useNavigation();
Expand All @@ -37,9 +38,11 @@ const ExportMultisigCoordinationSetup = () => {

const exportTxtFile = async () => {
setIsShareButtonTapped(true);
dynamicQRCode.current?.stopAutoMove();
setTimeout(() => {
fs.writeFileAndExport(wallet.getLabel() + '.txt', wallet.getXpub()).finally(() => {
setIsShareButtonTapped(false);
dynamicQRCode.current?.startAutoMove();
});
}, 10);
};
Expand Down Expand Up @@ -79,7 +82,7 @@ const ExportMultisigCoordinationSetup = () => {
<BlueText style={[styles.type, stylesHook.type]}>{wallet.getLabel()}</BlueText>
</View>
<BlueSpacing20 />
<DynamicQRCode value={qrCodeContents.current} />
<DynamicQRCode value={qrCodeContents.current} ref={dynamicQRCode} />
<BlueSpacing20 />
{isShareButtonTapped ? (
<ActivityIndicator />
Expand Down

0 comments on commit d88bb5b

Please sign in to comment.