Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix App crashes when navigating to enable payments page before logging in #26697

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions src/pages/EnablePayments/EnablePaymentsPage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import PropTypes from 'prop-types';
import React, {useEffect} from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as Wallet from '@userActions/Wallet';
import CONST from '@src/CONST';
Expand All @@ -22,13 +25,20 @@ import userWalletPropTypes from './userWalletPropTypes';
const propTypes = {
/** The user's wallet */
userWallet: userWalletPropTypes,

/** Indicates whether the app is loading initial data */
isLoadingReportData: PropTypes.bool,

...withCurrentUserPersonalDetailsPropTypes,
};

const defaultProps = {
userWallet: {},
isLoadingReportData: true,
...withCurrentUserPersonalDetailsDefaultProps,
};

function EnablePaymentsPage({userWallet}) {
function EnablePaymentsPage({userWallet, isLoadingReportData, personalDetails}) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();

Expand All @@ -47,7 +57,7 @@ function EnablePaymentsPage({userWallet}) {
Wallet.openEnablePaymentsPage();
}, [isOffline, isPendingOnfidoResult, hasFailedOnfido]);

if (_.isEmpty(userWallet)) {
if (_.isEmpty(userWallet) || (isLoadingReportData && _.isEmpty(personalDetails))) {
return <FullScreenLoadingIndicator />;
}

Expand Down Expand Up @@ -94,12 +104,18 @@ EnablePaymentsPage.displayName = 'EnablePaymentsPage';
EnablePaymentsPage.propTypes = propTypes;
EnablePaymentsPage.defaultProps = defaultProps;

export default withOnyx({
userWallet: {
key: ONYXKEYS.USER_WALLET,
export default compose(
withCurrentUserPersonalDetails,
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,
},
})(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,
},
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
}),
)(EnablePaymentsPage);
Loading