2020-10-24 19:20:59 +02:00
|
|
|
import React, { useCallback, useContext, useState } from 'react';
|
2020-08-05 01:50:32 +02:00
|
|
|
import { InteractionManager, useWindowDimensions, ActivityIndicator, View, StatusBar, StyleSheet } from 'react-native';
|
2019-02-14 06:15:56 +01:00
|
|
|
import QRCode from 'react-native-qrcode-svg';
|
2020-12-04 14:39:47 +01:00
|
|
|
import { BlueSpacing20, SafeBlueArea, BlueText, BlueNavigationStyle, BlueCopyTextToClipboard } from '../../BlueComponents';
|
2019-02-28 02:29:13 +01:00
|
|
|
import Privacy from '../../Privacy';
|
2019-09-25 05:42:21 +02:00
|
|
|
import Biometric from '../../class/biometrics';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-12-04 14:39:47 +01:00
|
|
|
import { useFocusEffect, useRoute, useNavigation, useTheme } from '@react-navigation/native';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 20,
|
|
|
|
},
|
|
|
|
container: {
|
|
|
|
alignItems: 'center',
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
},
|
2020-08-03 19:26:16 +02:00
|
|
|
qrCodeContainer: { borderWidth: 6, borderRadius: 8, borderColor: '#FFFFFF' },
|
2020-05-24 11:17:26 +02:00
|
|
|
});
|
|
|
|
|
2020-08-05 01:50:32 +02:00
|
|
|
const WalletXpub = () => {
|
|
|
|
const { secret } = useRoute().params;
|
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
const [xPub, setXPub] = useState();
|
|
|
|
const [xPubText, setXPubText] = useState();
|
|
|
|
const [wallet, setWallet] = useState();
|
|
|
|
const { goBack } = useNavigation();
|
|
|
|
const { colors } = useTheme();
|
|
|
|
const { width, height } = useWindowDimensions();
|
2020-09-08 18:06:41 +02:00
|
|
|
const stylesHook = StyleSheet.create({ root: { backgroundColor: colors.elevated } });
|
2020-10-24 19:20:59 +02:00
|
|
|
const { wallets } = useContext(BlueStorageContext);
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2020-08-05 01:50:32 +02:00
|
|
|
useFocusEffect(
|
|
|
|
useCallback(() => {
|
|
|
|
Privacy.enableBlur();
|
|
|
|
const task = InteractionManager.runAfterInteractions(async () => {
|
2020-10-24 19:20:59 +02:00
|
|
|
for (const w of wallets) {
|
2020-08-05 01:50:32 +02:00
|
|
|
if (w.getSecret() === secret) {
|
|
|
|
// found our wallet
|
|
|
|
setWallet(w);
|
|
|
|
}
|
|
|
|
}
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2020-08-05 01:50:32 +02:00
|
|
|
if (wallet) {
|
|
|
|
const isBiometricsEnabled = await Biometric.isBiometricUseCapableAndEnabled();
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2020-08-05 01:50:32 +02:00
|
|
|
if (isBiometricsEnabled) {
|
|
|
|
if (!(await Biometric.unlockWithBiometrics())) {
|
|
|
|
return goBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setXPub(wallet.getXpub());
|
|
|
|
setXPubText(wallet.getXpub());
|
|
|
|
setIsLoading(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return () => {
|
|
|
|
task.cancel();
|
|
|
|
Privacy.disableBlur();
|
|
|
|
};
|
2020-10-24 19:20:59 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-08-05 01:50:32 +02:00
|
|
|
}, [goBack, secret, wallet]),
|
|
|
|
);
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2020-08-05 01:50:32 +02:00
|
|
|
return isLoading ? (
|
2020-09-08 18:06:41 +02:00
|
|
|
<View style={[styles.root, stylesHook.root]}>
|
2020-08-05 01:50:32 +02:00
|
|
|
<ActivityIndicator />
|
|
|
|
</View>
|
|
|
|
) : (
|
2020-09-08 18:06:41 +02:00
|
|
|
<SafeBlueArea style={[styles.root, stylesHook.root]}>
|
2020-08-05 01:50:32 +02:00
|
|
|
<StatusBar barStyle="light-content" />
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View>
|
|
|
|
<BlueText>{wallet.typeReadable}</BlueText>
|
2018-12-27 16:37:12 +01:00
|
|
|
</View>
|
2020-08-05 01:50:32 +02:00
|
|
|
<BlueSpacing20 />
|
|
|
|
<View style={styles.qrCodeContainer}>
|
|
|
|
<QRCode
|
|
|
|
value={xPub}
|
|
|
|
logo={require('../../img/qr-code.png')}
|
|
|
|
size={height > width ? width - 40 : width / 2}
|
|
|
|
logoSize={90}
|
|
|
|
color="#000000"
|
|
|
|
logoBackgroundColor={colors.brandingColor}
|
|
|
|
backgroundColor="#FFFFFF"
|
|
|
|
ecl="H"
|
|
|
|
/>
|
2019-01-06 20:28:02 +01:00
|
|
|
</View>
|
2018-12-27 16:37:12 +01:00
|
|
|
|
2020-08-05 01:50:32 +02:00
|
|
|
<BlueSpacing20 />
|
|
|
|
<BlueCopyTextToClipboard text={xPubText} />
|
|
|
|
</View>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
2018-12-27 16:37:12 +01:00
|
|
|
};
|
2020-07-15 19:32:59 +02:00
|
|
|
|
2020-12-04 14:39:47 +01:00
|
|
|
WalletXpub.navigationOptions = ({ navigation }) => ({
|
|
|
|
...BlueNavigationStyle(navigation, true),
|
2020-07-20 15:38:46 +02:00
|
|
|
title: loc.wallets.xpub_title,
|
2020-07-15 19:32:59 +02:00
|
|
|
headerLeft: null,
|
|
|
|
});
|
2020-08-05 01:50:32 +02:00
|
|
|
|
|
|
|
export default WalletXpub;
|