2020-12-03 02:36:48 +01:00
|
|
|
import React, { useState, useCallback, useContext, useRef } from 'react';
|
2020-08-05 02:03:00 +02:00
|
|
|
import { useWindowDimensions, InteractionManager, ScrollView, ActivityIndicator, StatusBar, View, StyleSheet } from 'react-native';
|
2019-02-14 06:15:56 +01:00
|
|
|
import QRCode from 'react-native-qrcode-svg';
|
2020-12-25 17:09:53 +01:00
|
|
|
import { useTheme, useNavigation, useFocusEffect, useRoute } from '@react-navigation/native';
|
|
|
|
|
|
|
|
import { BlueSpacing20, SafeBlueArea, BlueText, BlueCopyTextToClipboard, BlueCard } from '../../BlueComponents';
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2021-01-19 04:44:55 +01:00
|
|
|
import Privacy from '../../blue_modules/Privacy';
|
2019-09-25 05:42:21 +02:00
|
|
|
import Biometric from '../../class/biometrics';
|
2020-04-04 19:14:17 +02:00
|
|
|
import { LegacyWallet, LightningCustodianWallet, SegwitBech32Wallet, SegwitP2SHWallet, WatchOnlyWallet } from '../../class';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
loading: {
|
|
|
|
flex: 1,
|
2020-12-11 03:57:11 +01:00
|
|
|
justifyContent: 'center',
|
2020-05-24 11:17:26 +02:00
|
|
|
},
|
|
|
|
scrollViewContent: {
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
flexGrow: 1,
|
|
|
|
},
|
2020-08-03 19:26:16 +02:00
|
|
|
activeQrcode: { borderWidth: 6, borderRadius: 8, borderColor: '#FFFFFF' },
|
2020-05-24 11:17:26 +02:00
|
|
|
type: {
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '700',
|
|
|
|
},
|
|
|
|
secret: {
|
|
|
|
alignItems: 'center',
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
fontSize: 16,
|
|
|
|
lineHeight: 24,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-08-05 02:03:00 +02:00
|
|
|
const WalletExport = () => {
|
2020-10-24 19:20:59 +02:00
|
|
|
const { wallets, saveToDisk } = useContext(BlueStorageContext);
|
|
|
|
const { walletID } = useRoute().params;
|
2020-12-03 02:36:48 +01:00
|
|
|
const wallet = useRef(wallets.find(w => w.getID() === walletID));
|
2020-08-05 02:03:00 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
const { goBack } = useNavigation();
|
|
|
|
const { colors } = useTheme();
|
|
|
|
const { width, height } = useWindowDimensions();
|
|
|
|
const stylesHook = {
|
|
|
|
...styles,
|
|
|
|
loading: {
|
|
|
|
...styles.loading,
|
|
|
|
backgroundColor: colors.elevated,
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
backgroundColor: colors.elevated,
|
|
|
|
},
|
|
|
|
type: { ...styles.type, color: colors.foregroundColor },
|
|
|
|
secret: { ...styles.secret, color: colors.foregroundColor },
|
2020-12-03 16:15:05 +01:00
|
|
|
warning: { ...styles.secret, color: colors.failedColor },
|
2020-08-05 02:03:00 +02:00
|
|
|
};
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2020-08-05 02:03:00 +02:00
|
|
|
useFocusEffect(
|
|
|
|
useCallback(() => {
|
|
|
|
Privacy.enableBlur();
|
|
|
|
const task = InteractionManager.runAfterInteractions(async () => {
|
|
|
|
if (wallet) {
|
|
|
|
const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled();
|
2019-09-25 05:42:21 +02:00
|
|
|
|
2020-08-05 02:03:00 +02:00
|
|
|
if (isBiometricsEnabled) {
|
|
|
|
if (!(await Biometric.unlockWithBiometrics())) {
|
|
|
|
return goBack();
|
|
|
|
}
|
|
|
|
}
|
2020-12-15 04:41:19 +01:00
|
|
|
if (!wallet.current.getUserHasSavedExport()) {
|
|
|
|
wallet.current.setUserHasSavedExport(true);
|
|
|
|
saveToDisk();
|
|
|
|
}
|
2020-08-05 02:03:00 +02:00
|
|
|
setIsLoading(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return () => {
|
|
|
|
task.cancel();
|
|
|
|
Privacy.disableBlur();
|
|
|
|
};
|
2020-10-24 19:20:59 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-12-03 02:36:48 +01:00
|
|
|
}, [goBack, walletID]),
|
2020-08-05 02:03:00 +02:00
|
|
|
);
|
2019-02-28 02:29:13 +01:00
|
|
|
|
2020-12-03 02:36:48 +01:00
|
|
|
return isLoading && wallet ? (
|
2020-08-05 02:03:00 +02:00
|
|
|
<View style={stylesHook.loading}>
|
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
) : (
|
|
|
|
<SafeBlueArea style={stylesHook.root}>
|
|
|
|
<StatusBar barStyle="light-content" />
|
2021-03-02 14:38:02 +01:00
|
|
|
<ScrollView contentContainerStyle={styles.scrollViewContent} testID="WalletExportScroll">
|
2020-08-05 02:03:00 +02:00
|
|
|
<View>
|
2020-12-03 02:36:48 +01:00
|
|
|
<BlueText style={stylesHook.type}>{wallet.current.typeReadable}</BlueText>
|
2018-01-30 23:42:38 +01:00
|
|
|
</View>
|
2018-12-11 23:52:46 +01:00
|
|
|
|
2020-08-05 02:03:00 +02:00
|
|
|
{(() => {
|
2020-12-03 02:36:48 +01:00
|
|
|
if ([LegacyWallet.type, SegwitBech32Wallet.type, SegwitP2SHWallet.type].includes(wallet.current.type)) {
|
2020-08-05 02:03:00 +02:00
|
|
|
return (
|
|
|
|
<BlueCard>
|
2020-12-03 02:36:48 +01:00
|
|
|
<BlueText>{wallet.current.getAddress()}</BlueText>
|
2020-08-05 02:03:00 +02:00
|
|
|
</BlueCard>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})()}
|
|
|
|
<BlueSpacing20 />
|
|
|
|
<View style={styles.activeQrcode}>
|
|
|
|
<QRCode
|
2020-12-03 02:36:48 +01:00
|
|
|
value={wallet.current.getSecret()}
|
2020-08-05 02:03:00 +02:00
|
|
|
logo={require('../../img/qr-code.png')}
|
|
|
|
size={height > width ? width - 40 : width / 2}
|
|
|
|
logoSize={70}
|
|
|
|
color="#000000"
|
|
|
|
logoBackgroundColor={colors.brandingColor}
|
|
|
|
backgroundColor="#FFFFFF"
|
|
|
|
ecl="H"
|
|
|
|
/>
|
|
|
|
</View>
|
2020-12-03 16:15:05 +01:00
|
|
|
{wallet.type !== WatchOnlyWallet.type && <BlueText style={stylesHook.warning}>{loc.wallets.warning_do_not_disclose}</BlueText>}
|
2020-08-05 02:03:00 +02:00
|
|
|
<BlueSpacing20 />
|
2020-12-03 02:36:48 +01:00
|
|
|
{wallet.current.type === LightningCustodianWallet.type || wallet.current.type === WatchOnlyWallet.type ? (
|
|
|
|
<BlueCopyTextToClipboard text={wallet.current.getSecret()} />
|
2020-08-05 02:03:00 +02:00
|
|
|
) : (
|
2021-03-02 14:38:02 +01:00
|
|
|
<BlueText style={stylesHook.secret} testID="Secret">
|
|
|
|
{wallet.current.getSecret()}
|
|
|
|
</BlueText>
|
2020-08-05 02:03:00 +02:00
|
|
|
)}
|
|
|
|
</ScrollView>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
2018-03-18 03:48:23 +01:00
|
|
|
};
|
2020-08-05 02:03:00 +02:00
|
|
|
|
2021-02-15 09:03:54 +01:00
|
|
|
WalletExport.navigationOptions = navigationStyle(
|
|
|
|
{
|
|
|
|
closeButton: true,
|
|
|
|
headerLeft: null,
|
|
|
|
},
|
|
|
|
opts => ({ ...opts, title: loc.wallets.export_title }),
|
|
|
|
);
|
2020-08-05 02:03:00 +02:00
|
|
|
|
|
|
|
export default WalletExport;
|