import Clipboard from '@react-native-clipboard/clipboard' import * as React from 'react' import { WithTranslation } from 'react-i18next' import { StyleSheet, Text, TextInput, View, ViewStyle, useWindowDimensions } from 'react-native' import { isValidBackupPhrase } from 'src/backup/utils' import Touchable from 'src/components/Touchable' import withTextInputPasteAware from 'src/components/WithTextInputPasteAware' import { withTranslation } from 'src/i18n' import colors from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { vibrateInformative } from 'src/styles/hapticFeedback' import { Spacing } from 'src/styles/styles' import Logger from 'src/utils/Logger' const PhraseInput = withTextInputPasteAware(TextInput, { top: undefined, right: 12, bottom: 12 }) type TwelveWordTableProps = { words: string[] } function TwelveWordTable({ words }: TwelveWordTableProps) { const { fontScale } = useWindowDimensions() return ( {words.map((word, index) => ( 1.5 ? { width: '50%' } : { width: '33%' }]} > {index + 1} {word} ))} ) } export enum BackupPhraseContainerMode { READONLY = 'READONLY', INPUT = 'INPUT', } export enum BackupPhraseType { BACKUP_KEY = 'BACKUP_KEY', } type Props = { value: string | null mode: BackupPhraseContainerMode type: BackupPhraseType index?: number // e.g. index of safeguard phrase showCopy?: boolean style?: ViewStyle onChangeText?: (value: string) => void includeHeader?: boolean testID?: string readOnlyStyle?: ViewStyle } & WithTranslation export class BackupPhraseContainer extends React.Component { onPressCopy = () => { const { value: words, t } = this.props if (!words) { return } Clipboard.setString(words) Logger.showMessage(t('copied')) vibrateInformative() } onPhraseInputChange = (value: string) => { if (this.props.onChangeText) { this.props.onChangeText(value) } } render() { const { t, value: words, showCopy, style, mode, type, includeHeader, testID, readOnlyStyle, } = this.props const wordList = words?.split(' ') const isTwelveWords = wordList?.length === 12 return ( {type === BackupPhraseType.BACKUP_KEY && includeHeader !== false && ( {t('writeDownKeyExperimental')} )} {showCopy && ( {this.props.t('copy')} )} {mode === BackupPhraseContainerMode.READONLY && ( {isTwelveWords ? !!wordList && : !!words && {words}} )} {mode === BackupPhraseContainerMode.INPUT && ( )} ) } } const styles = StyleSheet.create({ headerContainer: { flexDirection: 'row', justifyContent: 'space-between', paddingHorizontal: 2, }, headerButton: { ...typeScale.bodyMedium, }, writeDownKeyContainer: { flexDirection: 'column', }, writeDownKey: { ...typeScale.titleSmall, marginBottom: 16, }, indexText: { ...typeScale.bodyMedium, color: colors.contentSecondary, }, twelveWordTable: { flexDirection: 'row', flexWrap: 'wrap', marginHorizontal: Spacing.Small12, }, wordContainer: { flexDirection: 'row', gap: Spacing.Smallest8, alignItems: 'center', marginVertical: 11, }, wordText: { ...typeScale.labelSemiBoldSmall, }, phraseContainer: { flexWrap: 'wrap', flexDirection: 'row', marginTop: 8, backgroundColor: colors.backgroundSecondary, borderRadius: 8, borderWidth: 1, borderColor: colors.borderPrimary, alignContent: 'center', justifyContent: 'center', padding: 8, }, phraseText: { ...typeScale.bodyMedium, fontSize: 22, lineHeight: 32, }, phraseInputContainer: { marginTop: 10, }, phraseInputText: { ...typeScale.bodyMedium, minHeight: 125, padding: 14, paddingTop: 16, textAlignVertical: 'top', }, }) export default withTranslation()(BackupPhraseContainer)