import React, { useEffect, useRef, useState } from 'react'; import { useRoute } from '@react-navigation/native'; import LottieView from 'lottie-react-native'; import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { Icon } from '@rneui/themed'; import { BlueSpacing20 } from '../../BlueComponents'; import { MultisigHDWallet } from '../../class'; import BottomModal from '../../components/BottomModal'; import Button from '../../components/Button'; import ListItem from '../../components/ListItem'; import SafeArea from '../../components/SafeArea'; import { useTheme } from '../../components/themes'; import loc from '../../loc'; import { useSettings } from '../../hooks/context/useSettings'; import { useExtendedNavigation } from '../../hooks/useExtendedNavigation'; const WalletsAddMultisig = () => { const { colors } = useTheme(); const { navigate } = useExtendedNavigation(); const loadingAnimation = useRef(); const bottomModalRef = useRef(); const { walletLabel } = useRoute().params; const [m, setM] = useState(2); const [n, setN] = useState(3); const [format, setFormat] = useState(MultisigHDWallet.FORMAT_P2WSH); const { isAdvancedModeEnabled } = useSettings(); const stylesHook = StyleSheet.create({ root: { backgroundColor: colors.elevated, justifyContent: 'space-between', flex: 1, }, textdesc: { color: colors.alternativeTextColor, }, textSubtitle: { color: colors.alternativeTextColor, }, selectedItem: { paddingHorizontal: 8, backgroundColor: colors.elevated, }, deSelectedItem: { paddingHorizontal: 8, backgroundColor: 'transparent', }, textHeader: { color: colors.outputValue, }, }); useEffect(() => { if (loadingAnimation.current) { /* https://github.com/lottie-react-native/lottie-react-native/issues/832#issuecomment-1008209732 Temporary workaround until Lottie is fixed. */ setTimeout(() => { loadingAnimation.current?.reset(); loadingAnimation.current?.play(); }, 100); } }, []); const onLetsStartPress = () => { bottomModalRef.current?.dismiss(); navigate('WalletsAddMultisigStep2', { m, n, format, walletLabel }); }; const setFormatP2wsh = () => setFormat(MultisigHDWallet.FORMAT_P2WSH); const setFormatP2shP2wsh = () => setFormat(MultisigHDWallet.FORMAT_P2SH_P2WSH); const setFormatP2sh = () => setFormat(MultisigHDWallet.FORMAT_P2SH); const isP2wsh = () => format === MultisigHDWallet.FORMAT_P2WSH; const isP2shP2wsh = () => format === MultisigHDWallet.FORMAT_P2SH_P2WSH || format === MultisigHDWallet.FORMAT_P2SH_P2WSH_ALT; const isP2sh = () => format === MultisigHDWallet.FORMAT_P2SH; const increaseM = () => { if (n === m) return; if (m === 7) return; setM(m + 1); }; const decreaseM = () => { if (m === 2) return; setM(m - 1); }; const increaseN = () => { if (n === 7) return; setN(n + 1); }; const decreaseN = () => { if (n === m) return; setN(n - 1); }; const renderModal = () => { return ( {loc.multisig.quorum_header} {loc.multisig.required_keys_out_of_total} {m} {loc.multisig.of} {n} {loc.multisig.wallet_type} ); }; const showAdvancedOptionsModal = () => { bottomModalRef.current.present(); }; const getCurrentlySelectedFormat = code => { switch (code) { case 'format': return WalletsAddMultisig.getCurrentFormatReadable(format); case 'quorum': return loc.formatString(loc.multisig.quorum, { m, n }); default: throw new Error('This should never happen'); } }; return ( {loc.multisig.what_is_vault} {loc.formatString(loc.multisig.what_is_vault_numberOfWallets, { m, n })} {loc.multisig.what_is_vault_wallet} {loc.multisig.needs} {loc.formatString(loc.multisig.what_is_vault_description_number_of_vault_keys, { m })} {m === 2 && n === 3 ? loc.multisig.what_is_vault_description_to_spend : loc.multisig.what_is_vault_description_to_spend_other} {isAdvancedModeEnabled && ( )}