diff --git a/src/pages/EnablePayments/EnablePaymentsPage.js b/src/pages/EnablePayments/EnablePaymentsPage.js index 064f9371e46a..773dfe8b5df7 100644 --- a/src/pages/EnablePayments/EnablePaymentsPage.js +++ b/src/pages/EnablePayments/EnablePaymentsPage.js @@ -1,5 +1,5 @@ import _ from 'underscore'; -import React from 'react'; +import React, {useEffect} from 'react'; import {withOnyx} from 'react-native-onyx'; import ScreenWrapper from '../../components/ScreenWrapper'; import * as Wallet from '../../libs/actions/Wallet'; @@ -7,8 +7,6 @@ import ONYXKEYS from '../../ONYXKEYS'; import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; import CONST from '../../CONST'; import userWalletPropTypes from './userWalletPropTypes'; -import {withNetwork} from '../../components/OnyxProvider'; -import networkPropTypes from '../../components/networkPropTypes'; // Steps import OnfidoStep from './OnfidoStep'; @@ -17,94 +15,88 @@ import TermsStep from './TermsStep'; import ActivateStep from './ActivateStep'; import HeaderWithBackButton from '../../components/HeaderWithBackButton'; import FailedKYC from './FailedKYC'; -import compose from '../../libs/compose'; -import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; +import useLocalize from '../../hooks/useLocalize'; +import useNetwork from '../../hooks/useNetwork'; const propTypes = { - /** Information about the network from Onyx */ - network: networkPropTypes.isRequired, - /** The user's wallet */ userWallet: userWalletPropTypes, - - ...withLocalizePropTypes, }; const defaultProps = { userWallet: {}, }; -class EnablePaymentsPage extends React.Component { - componentDidMount() { - Wallet.openEnablePaymentsPage(); - } +function EnablePaymentsPage({userWallet}) { + const {translate} = useLocalize(); + const {isOffline} = useNetwork(); - componentDidUpdate(prevProps) { - if (!prevProps.network.isOffline || this.props.network.isOffline) { + useEffect(() => { + if (isOffline) { return; } Wallet.openEnablePaymentsPage(); - } + }, [isOffline]); - render() { - if (_.isEmpty(this.props.userWallet)) { - return ; - } - - return ( - - {() => { - if (this.props.userWallet.errorCode === CONST.WALLET.ERROR.KYC) { - return ( - <> - Navigation.goBack(ROUTES.SETTINGS_WALLET)} - /> - - - ); - } - - if (this.props.userWallet.shouldShowWalletActivationSuccess) { - return ; - } - - const currentStep = this.props.userWallet.currentStep || CONST.WALLET.STEP.ADDITIONAL_DETAILS; + if (_.isEmpty(userWallet)) { + return ; + } + return ( + + {() => { + if (userWallet.errorCode === CONST.WALLET.ERROR.KYC) { return ( <> - {(currentStep === CONST.WALLET.STEP.ADDITIONAL_DETAILS || currentStep === CONST.WALLET.STEP.ADDITIONAL_DETAILS_KBA) && } - {currentStep === CONST.WALLET.STEP.ONFIDO && } - {currentStep === CONST.WALLET.STEP.TERMS && } - {currentStep === CONST.WALLET.STEP.ACTIVATE && } + Navigation.goBack(ROUTES.SETTINGS_WALLET)} + /> + ); - }} - - ); - } + } + + if (userWallet.shouldShowWalletActivationSuccess) { + return ; + } + + const currentStep = userWallet.currentStep || CONST.WALLET.STEP.ADDITIONAL_DETAILS; + + switch (currentStep) { + case CONST.WALLET.STEP.ADDITIONAL_DETAILS: + case CONST.WALLET.STEP.ADDITIONAL_DETAILS_KBA: + return ; + case CONST.WALLET.STEP.ONFIDO: + return ; + case CONST.WALLET.STEP.TERMS: + return ; + case CONST.WALLET.STEP.ACTIVATE: + return ; + default: + return null; + } + }} + + ); } +EnablePaymentsPage.displayName = 'EnablePaymentsPage'; EnablePaymentsPage.propTypes = propTypes; EnablePaymentsPage.defaultProps = defaultProps; -export default compose( - withLocalize, - withOnyx({ - userWallet: { - key: ONYXKEYS.USER_WALLET, +export default withOnyx({ + userWallet: { + key: ONYXKEYS.USER_WALLET, - // We want to refresh the wallet each time the user attempts to activate the wallet so we won't use the - // stored values here. - initWithStoredValues: false, - }, - }), - withNetwork(), -)(EnablePaymentsPage); + // We want to refresh the wallet each time the user attempts to activate the wallet so we won't use the + // stored values here. + initWithStoredValues: false, + }, +})(EnablePaymentsPage);