2020-12-11 03:57:11 +01:00
|
|
|
import React, { useCallback, useContext, useRef, useState } from 'react';
|
2023-10-20 16:25:40 +02:00
|
|
|
import { ActivityIndicator, InteractionManager, ScrollView, StyleSheet, View } from 'react-native';
|
2023-10-24 03:28:44 +02:00
|
|
|
import { useFocusEffect, useNavigation, useRoute } from '@react-navigation/native';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
import { BlueSpacing20, BlueText, SafeBlueArea } from '../../BlueComponents';
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2020-10-29 22:13:54 +01:00
|
|
|
import { DynamicQRCode } from '../../components/DynamicQRCode';
|
2021-01-19 04:44:55 +01:00
|
|
|
import Privacy from '../../blue_modules/Privacy';
|
2020-10-05 23:25:14 +02:00
|
|
|
import Biometric from '../../class/biometrics';
|
|
|
|
import loc from '../../loc';
|
|
|
|
import { SquareButton } from '../../components/SquareButton';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2023-10-24 03:28:44 +02:00
|
|
|
import { useTheme } from '../../components/themes';
|
2020-10-05 23:25:14 +02:00
|
|
|
const fs = require('../../blue_modules/fs');
|
|
|
|
|
|
|
|
const ExportMultisigCoordinationSetup = () => {
|
|
|
|
const walletId = useRoute().params.walletId;
|
2020-10-24 19:20:59 +02:00
|
|
|
const { wallets } = useContext(BlueStorageContext);
|
|
|
|
const wallet = wallets.find(w => w.getID() === walletId);
|
2020-12-11 03:57:11 +01:00
|
|
|
const qrCodeContents = useRef();
|
2021-09-11 19:46:01 +02:00
|
|
|
const dynamicQRCode = useRef();
|
2020-10-05 23:25:14 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
2020-12-11 03:57:11 +01:00
|
|
|
const [isShareButtonTapped, setIsShareButtonTapped] = useState(false);
|
2020-10-05 23:25:14 +02:00
|
|
|
const { goBack } = useNavigation();
|
|
|
|
const { colors } = useTheme();
|
2020-12-11 03:57:11 +01:00
|
|
|
const stylesHook = StyleSheet.create({
|
2020-10-05 23:25:14 +02:00
|
|
|
loading: {
|
|
|
|
backgroundColor: colors.elevated,
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
backgroundColor: colors.elevated,
|
|
|
|
},
|
2020-12-11 03:57:11 +01:00
|
|
|
type: { color: colors.foregroundColor },
|
|
|
|
secret: { color: colors.foregroundColor },
|
2020-10-14 10:43:56 +02:00
|
|
|
exportButton: {
|
|
|
|
backgroundColor: colors.buttonDisabledBackgroundColor,
|
|
|
|
},
|
2020-12-11 03:57:11 +01:00
|
|
|
});
|
2020-10-05 23:25:14 +02:00
|
|
|
|
|
|
|
const exportTxtFile = async () => {
|
2020-12-11 03:57:11 +01:00
|
|
|
setIsShareButtonTapped(true);
|
2021-09-11 19:46:01 +02:00
|
|
|
dynamicQRCode.current?.stopAutoMove();
|
2020-12-11 03:57:11 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
fs.writeFileAndExport(wallet.getLabel() + '.txt', wallet.getXpub()).finally(() => {
|
|
|
|
setIsShareButtonTapped(false);
|
2021-09-11 19:46:01 +02:00
|
|
|
dynamicQRCode.current?.startAutoMove();
|
2020-12-11 03:57:11 +01:00
|
|
|
});
|
|
|
|
}, 10);
|
2020-10-05 23:25:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
useFocusEffect(
|
|
|
|
useCallback(() => {
|
|
|
|
Privacy.enableBlur();
|
|
|
|
const task = InteractionManager.runAfterInteractions(async () => {
|
|
|
|
if (wallet) {
|
|
|
|
const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled();
|
|
|
|
|
|
|
|
if (isBiometricsEnabled) {
|
|
|
|
if (!(await Biometric.unlockWithBiometrics())) {
|
|
|
|
return goBack();
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 03:57:11 +01:00
|
|
|
qrCodeContents.current = Buffer.from(wallet.getXpub(), 'ascii').toString('hex');
|
2020-10-05 23:25:14 +02:00
|
|
|
setIsLoading(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return () => {
|
|
|
|
task.cancel();
|
|
|
|
Privacy.disableBlur();
|
|
|
|
};
|
|
|
|
}, [goBack, wallet]),
|
|
|
|
);
|
|
|
|
|
|
|
|
return isLoading ? (
|
2020-12-11 03:57:11 +01:00
|
|
|
<View style={[styles.loading, stylesHook.loading]}>
|
2020-10-05 23:25:14 +02:00
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
) : (
|
2021-03-22 12:54:17 +01:00
|
|
|
<SafeBlueArea style={stylesHook.root}>
|
2020-10-05 23:25:14 +02:00
|
|
|
<ScrollView contentContainerStyle={styles.scrollViewContent}>
|
|
|
|
<View>
|
2020-12-11 03:57:11 +01:00
|
|
|
<BlueText style={[styles.type, stylesHook.type]}>{wallet.getLabel()}</BlueText>
|
2020-10-05 23:25:14 +02:00
|
|
|
</View>
|
|
|
|
<BlueSpacing20 />
|
2021-09-11 19:46:01 +02:00
|
|
|
<DynamicQRCode value={qrCodeContents.current} ref={dynamicQRCode} />
|
2020-10-14 10:43:56 +02:00
|
|
|
<BlueSpacing20 />
|
2020-12-11 03:57:11 +01:00
|
|
|
{isShareButtonTapped ? (
|
|
|
|
<ActivityIndicator />
|
|
|
|
) : (
|
|
|
|
<SquareButton style={[styles.exportButton, stylesHook.exportButton]} onPress={exportTxtFile} title={loc.multisig.share} />
|
|
|
|
)}
|
2020-10-05 23:25:14 +02:00
|
|
|
<BlueSpacing20 />
|
2020-12-11 03:57:11 +01:00
|
|
|
<BlueText style={[styles.secret, stylesHook.secret]}>{wallet.getXpub()}</BlueText>
|
2020-10-05 23:25:14 +02:00
|
|
|
</ScrollView>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
loading: {
|
|
|
|
flex: 1,
|
2020-12-11 03:57:11 +01:00
|
|
|
justifyContent: 'center',
|
2020-10-05 23:25:14 +02:00
|
|
|
},
|
|
|
|
scrollViewContent: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
flexGrow: 1,
|
|
|
|
},
|
|
|
|
type: {
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '700',
|
|
|
|
},
|
|
|
|
secret: {
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
fontSize: 16,
|
|
|
|
lineHeight: 24,
|
|
|
|
},
|
2020-10-24 19:20:59 +02:00
|
|
|
exportButton: {
|
2020-10-14 10:43:56 +02:00
|
|
|
height: 48,
|
|
|
|
borderRadius: 8,
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
width: '80%',
|
|
|
|
maxWidth: 300,
|
|
|
|
},
|
2020-10-05 23:25:14 +02:00
|
|
|
});
|
|
|
|
|
2021-02-15 09:03:54 +01:00
|
|
|
ExportMultisigCoordinationSetup.navigationOptions = navigationStyle(
|
|
|
|
{
|
|
|
|
closeButton: true,
|
2023-11-11 12:33:50 +01:00
|
|
|
headerBackVisible: false,
|
2023-10-20 16:25:40 +02:00
|
|
|
statusBarStyle: 'light',
|
2021-02-15 09:03:54 +01:00
|
|
|
},
|
|
|
|
opts => ({ ...opts, title: loc.multisig.export_coordination_setup }),
|
|
|
|
);
|
2020-10-05 23:25:14 +02:00
|
|
|
|
|
|
|
export default ExportMultisigCoordinationSetup;
|