Merge pull request #5763 from BlueWallet/plsback

REF: PleaseBackup to TSX
This commit is contained in:
GLaDOS 2023-10-23 16:38:58 +01:00 committed by GitHub
commit 1ff5905b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 39 deletions

View File

@ -23,6 +23,9 @@ type NavigationOptions = {
fontWeight: string;
color: string;
};
gestureEnabled?: boolean;
swipeEnabled?: boolean;
headerHideBackButton?: boolean;
headerLeft?: (() => React.ReactElement) | null;
headerRight?: (() => React.ReactElement) | null;
headerBackTitleVisible?: false;

View File

@ -7,35 +7,38 @@ import navigationStyle from '../../components/navigationStyle';
import Privacy from '../../blue_modules/Privacy';
import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import { AbstractWallet } from '../../class';
const PleaseBackup = () => {
const PleaseBackup: React.FC = () => {
const { wallets } = useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(true);
const { walletID } = useRoute().params;
const wallet = wallets.find(w => w.getID() === walletID);
const { walletID } = useRoute().params as { walletID: string };
const wallet = wallets.find((w: AbstractWallet) => w.getID() === walletID);
const navigation = useNavigation();
const { colors } = useTheme();
const stylesHook = StyleSheet.create({
flex: {
// @ts-ignore: Ignore
backgroundColor: colors.elevated,
},
word: {
// @ts-ignore: Ignore
backgroundColor: colors.inputBackgroundColor,
},
wortText: {
// @ts-ignore: Ignore
color: colors.labelText,
},
successText: {
color: colors.foregroundColor,
},
pleaseText: {
// @ts-ignore: Ignore
color: colors.foregroundColor,
},
});
const handleBackButton = useCallback(() => {
navigation.dangerouslyGetParent().pop();
// @ts-ignore: Ignore
navigation.dangerouslyGetParent()?.pop();
return true;
}, [navigation]);
@ -51,41 +54,47 @@ const PleaseBackup = () => {
}, []);
const renderSecret = () => {
const component = [];
for (const [index, secret] of wallet.getSecret().split(/\s/).entries()) {
const text = `${index + 1}. ${secret} `;
component.push(
<View style={[styles.word, stylesHook.word]} key={index}>
<Text style={[styles.wortText, stylesHook.wortText]} textBreakStrategy="simple">
{text}
</Text>
</View>,
);
const component: JSX.Element[] = [];
const entries = wallet?.getSecret().split(/\s/).entries();
if (entries) {
for (const [index, secret] of entries) {
if (secret) {
const text = `${index + 1}. ${secret} `;
component.push(
<View style={[styles.word, stylesHook.word]} key={index}>
<Text style={[styles.wortText, stylesHook.wortText]} textBreakStrategy="simple">
{text}
</Text>
</View>,
);
}
}
}
return component;
};
return isLoading ? (
<View style={[styles.loading, stylesHook.flex]}>
<ActivityIndicator />
</View>
) : (
<SafeBlueArea style={stylesHook.flex}>
<ScrollView contentContainerStyle={styles.flex} testID="PleaseBackupScrollView">
<View style={styles.please}>
<Text style={[styles.pleaseText, stylesHook.pleaseText]}>{loc.pleasebackup.text}</Text>
</View>
<View style={styles.list}>
<View style={styles.secret}>{renderSecret()}</View>
</View>
<View style={styles.bottom}>
<BlueButton testID="PleasebackupOk" onPress={handleBackButton} title={loc.pleasebackup.ok} />
</View>
</ScrollView>
return (
<SafeBlueArea style={[isLoading ? styles.loading : {}, stylesHook.flex]}>
{isLoading ? (
<ActivityIndicator />
) : (
<ScrollView contentContainerStyle={styles.flex} testID="PleaseBackupScrollView">
<View style={styles.please}>
<Text style={[styles.pleaseText, stylesHook.pleaseText]}>{loc.pleasebackup.text}</Text>
</View>
<View style={styles.list}>
<View style={styles.secret}>{renderSecret()}</View>
</View>
<View style={styles.bottom}>
<BlueButton testID="PleasebackupOk" onPress={handleBackButton} title={loc.pleasebackup.ok} />
</View>
</ScrollView>
)}
</SafeBlueArea>
);
};
// @ts-ignore: Ignore
PleaseBackup.navigationOptions = navigationStyle(
{
gestureEnabled: false,
@ -131,10 +140,6 @@ const styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
successText: {
textAlign: 'center',
fontWeight: 'bold',
},
pleaseText: {
marginVertical: 16,
fontSize: 16,