-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create component to display words, use when creating passphrase.
- Loading branch information
1 parent
9bff185
commit b7d649b
Showing
2 changed files
with
155 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import React, { memo, useCallback, useMemo } from 'react' | ||
import { upperCase } from 'lodash' | ||
import { useTranslation } from 'react-i18next' | ||
import Text from '@components/Text' | ||
import Box from '@components/Box' | ||
import ButtonPressable from '@components/ButtonPressable' | ||
import { FlatList } from 'react-native' | ||
import { useColors, useSpacing } from '@theme/themeHooks' | ||
import CopyAddress from '@assets/images/copyAddress.svg' | ||
import TouchableOpacityBox from '@components/TouchableOpacityBox' | ||
import useCopyText from '@hooks/useCopyText' | ||
import useHaptic from '@hooks/useHaptic' | ||
|
||
type Props = { | ||
mnemonic: string[] | ||
onDone: () => void | ||
ListHeaderComponent?: React.JSX.Element | ||
} | ||
const RevealWords = ({ mnemonic, onDone, ListHeaderComponent }: Props) => { | ||
const { t } = useTranslation() | ||
const spacing = useSpacing() | ||
const { secondaryText } = useColors() | ||
const copyText = useCopyText() | ||
const { triggerImpact } = useHaptic() | ||
|
||
const handleCopySeedPhrase = useCallback(() => { | ||
triggerImpact('light') | ||
copyText({ | ||
message: t('generic.copiedSeedPhrase'), | ||
copyText: mnemonic.join(' ') || '', | ||
}) | ||
}, [copyText, triggerImpact, mnemonic, t]) | ||
|
||
const renderItem = useCallback( | ||
// eslint-disable-next-line react/no-unused-prop-types | ||
({ item, index }: { item: string; index: number }) => { | ||
return ( | ||
<Box | ||
borderRadius="round" | ||
padding="s" | ||
marginHorizontal="s" | ||
marginBottom="m" | ||
flex={1} | ||
overflow="hidden" | ||
backgroundColor="surfaceSecondary" | ||
alignItems="center" | ||
justifyContent="center" | ||
flexDirection="row" | ||
> | ||
<Text | ||
fontSize={16} | ||
color="primaryText" | ||
maxFontSizeMultiplier={1} | ||
adjustsFontSizeToFit | ||
>{`${index + 1}. `}</Text> | ||
<Text | ||
fontSize={16} | ||
color="primaryText" | ||
maxFontSizeMultiplier={1} | ||
adjustsFontSizeToFit | ||
> | ||
{upperCase(item)} | ||
</Text> | ||
</Box> | ||
) | ||
}, | ||
[], | ||
) | ||
|
||
const contentContainerStyle = useMemo( | ||
() => ({ | ||
flexGrow: 1, | ||
paddingHorizontal: spacing.l, | ||
}), | ||
[spacing], | ||
) | ||
|
||
const ListFooterComponent = useCallback(() => { | ||
return ( | ||
<Box> | ||
<TouchableOpacityBox | ||
onPress={handleCopySeedPhrase} | ||
justifyContent="center" | ||
alignItems="center" | ||
flexDirection="row" | ||
marginTop="m" | ||
marginBottom="xl" | ||
> | ||
<CopyAddress width={16} height={16} color={secondaryText} /> | ||
<Text | ||
marginStart="s" | ||
variant="body2" | ||
color="secondaryText" | ||
numberOfLines={1} | ||
adjustsFontSizeToFit | ||
maxFontSizeMultiplier={1.2} | ||
textAlign="center" | ||
> | ||
{t('generic.copyToClipboard')} | ||
</Text> | ||
</TouchableOpacityBox> | ||
<Box flex={1} /> | ||
<ButtonPressable | ||
height={60} | ||
borderRadius="round" | ||
backgroundColor="surfaceSecondary" | ||
titleColor="primaryText" | ||
title={t('settings.revealWords.next')} | ||
marginBottom="m" | ||
onPress={onDone} | ||
/> | ||
</Box> | ||
) | ||
}, [handleCopySeedPhrase, secondaryText, t, onDone]) | ||
|
||
return ( | ||
<FlatList | ||
numColumns={2} | ||
columnWrapperStyle={{ | ||
flexDirection: 'row', | ||
}} | ||
data={mnemonic || []} | ||
ListHeaderComponent={ListHeaderComponent} | ||
ListFooterComponent={ListFooterComponent} | ||
ListFooterComponentStyle={{ flexGrow: 1, justifyContent: 'flex-end' }} | ||
renderItem={renderItem} | ||
contentContainerStyle={contentContainerStyle} | ||
scrollEnabled | ||
initialNumToRender={24} | ||
/> | ||
) | ||
} | ||
|
||
export default memo(RevealWords) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters