import Clipboard from '@react-native-clipboard/clipboard' import React from 'react' import { Trans, useTranslation } from 'react-i18next' import { StyleSheet, Text, View } from 'react-native' import { useSafeAreaInsets } from 'react-native-safe-area-context' import { nameSelector } from 'src/account/selectors' import { BottomSheetModalRefType } from 'src/components/BottomSheet' import Button from 'src/components/Button' import ExchangesBottomSheet from 'src/components/ExchangesBottomSheet' import InLineNotification, { NotificationVariant } from 'src/components/InLineNotification' import { ExternalExchangeProvider } from 'src/fiatExchanges/ExternalExchanges' import CopyIcon from 'src/icons/CopyIcon' import StyledQRCode from 'src/qrcode/StyledQRCode' import { useSelector } from 'src/redux/hooks' import { SVG } from 'src/send/actions' import { NETWORK_NAMES } from 'src/shared/conts' import { getMultichainFeatures } from 'src/statsig' 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 variables from 'src/styles/variables' import { NetworkId } from 'src/transactions/types' import Logger from 'src/utils/Logger' import { walletAddressSelector } from 'src/web3/selectors' interface Props { qrSvgRef: React.MutableRefObject exchanges?: ExternalExchangeProvider[] onCloseBottomSheet?: () => void onPressCopy?: () => void onPressInfo?: () => void onPressExchange?: (exchange: ExternalExchangeProvider) => void } export default function QRCodeDisplay(props: Props) { const exchangesBottomSheetRef = React.createRef() const { t } = useTranslation() const { exchanges, qrSvgRef } = props const address = useSelector(walletAddressSelector) const displayName = useSelector(nameSelector) const insets = useSafeAreaInsets() const onCloseBottomSheet = () => { props.onCloseBottomSheet?.() exchangesBottomSheetRef.current?.close() } const onPressCopy = () => { props.onPressCopy?.() Clipboard.setString(address || '') Logger.showMessage(t('addressCopied')) vibrateInformative() } const onPressInfo = () => { props.onPressInfo?.() exchangesBottomSheetRef.current?.snapToIndex(0) } const onPressExchange = (exchange: ExternalExchangeProvider) => { props.onPressExchange?.(exchange) } const getSupportedNetworks = () => { const supportedNetworkIds = getMultichainFeatures().showBalances const networks = supportedNetworkIds.map((networkId: NetworkId) => { return NETWORK_NAMES[networkId] }) return networks.join(', ') } const description = () => ( ) return ( {!!displayName && ( {displayName} )} {address} } iconMargin={12} iconPositionLeft={false} testID="copyButton" /> {exchanges && exchanges.length > 0 ? ( <> ) : ( )} ) } const styles = StyleSheet.create({ bottomContent: { position: 'absolute', bottom: 0, paddingHorizontal: Spacing.Regular16, width: '100%', }, bold: { ...typeScale.labelSemiBoldXSmall, }, description: { ...typeScale.bodyXSmall, }, container: { flex: 1, flexDirection: 'column', alignItems: 'center', backgroundColor: colors.backgroundPrimary, }, link: { ...typeScale.labelSemiBoldMedium, textDecorationLine: 'underline', color: colors.accent, flexWrap: 'wrap', }, qrContainer: { marginTop: '35%', marginBottom: Spacing.Thick24, }, name: { ...typeScale.labelSemiBoldMedium, marginHorizontal: variables.width / 5, marginBottom: 8, }, address: { ...typeScale.bodyMedium, color: colors.contentSecondary, marginHorizontal: variables.width / 5, marginBottom: 8, textAlign: 'center', }, exchangeText: { ...typeScale.bodyMedium, color: colors.contentSecondary, textAlign: 'center', }, })