diff --git a/app/containers/TwoFactor/index.tsx b/app/containers/TwoFactor/index.tsx index 376f1fc98a..08fe503591 100644 --- a/app/containers/TwoFactor/index.tsx +++ b/app/containers/TwoFactor/index.tsx @@ -4,18 +4,19 @@ import isEmpty from 'lodash/isEmpty'; import { sha256 } from 'js-sha256'; import Modal from 'react-native-modal'; import useDeepCompareEffect from 'use-deep-compare-effect'; -import { connect } from 'react-redux'; import { FormTextInput } from '../TextInput'; import I18n from '../../i18n'; import EventEmitter from '../../lib/methods/helpers/events'; import { useTheme } from '../../theme'; -import { themes } from '../../lib/constants'; import Button from '../Button'; import sharedStyles from '../../views/Styles'; import styles from './styles'; -import { IApplicationState } from '../../definitions'; +import { ICredentials } from '../../definitions'; import { Services } from '../../lib/services'; +import { useAppSelector } from '../../lib/hooks'; +import Toast from '../Toast'; +import { showToast } from '../../lib/methods/helpers/showToast'; export const TWO_FACTOR = 'TWO_FACTOR'; @@ -32,6 +33,7 @@ interface IMethods { } interface EventListenerMethod { + params?: ICredentials; method?: keyof IMethods; submit?: (param: string) => void; cancel?: () => void; @@ -55,15 +57,31 @@ const methods: IMethods = { } }; -const TwoFactor = React.memo(({ isMasterDetail }: { isMasterDetail: boolean }) => { - const { theme } = useTheme(); +const TwoFactor = React.memo(() => { + const { colors } = useTheme(); + const { isMasterDetail } = useAppSelector(state => ({ + isMasterDetail: state.app.isMasterDetail as boolean + })); const [visible, setVisible] = useState(false); const [data, setData] = useState({}); const [code, setCode] = useState(''); const method = data.method ? methods[data.method] : null; const isEmail = data.method === 'email'; - const sendEmail = () => Services.sendEmailCode(); + const params = data?.params; + + const sendEmail = async () => { + try { + if (params?.user) { + const response = await Services.sendEmailCode(params?.user); + if (response.success) { + showToast(I18n.t('Two_Factor_Success_message')); + } + } + } catch (error) { + console.log(error, 'here'); + } + }; useDeepCompareEffect(() => { if (!isEmpty(data)) { @@ -102,7 +120,7 @@ const TwoFactor = React.memo(({ isMasterDetail }: { isMasterDetail: boolean }) = setData({}); }; - const color = themes[theme].fontTitlesLabels; + const color = colors.fontTitlesLabels; return ( @@ -110,7 +128,7 @@ const TwoFactor = React.memo(({ isMasterDetail }: { isMasterDetail: boolean }) = style={[ styles.content, isMasterDetail && [sharedStyles.modalFormSheet, styles.tablet], - { backgroundColor: themes[theme].surfaceTint } + { backgroundColor: colors.surfaceTint } ]}> {I18n.t(method?.title || 'Two_Factor_Authentication')} {method?.text ? {I18n.t(method.text)} : null} @@ -136,13 +154,10 @@ const TwoFactor = React.memo(({ isMasterDetail }: { isMasterDetail: boolean }) =