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

Removing payment method actions model when payment method is removed from another device #14869

Merged
40 changes: 40 additions & 0 deletions src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ class BasePaymentsPage extends React.Component {
this.debounceSetShouldShowLoadingSpinner();
}

if (this.state.shouldShowDefaultDeleteMenu || this.state.shouldShowPasswordPrompt) {
let shouldResetPaymentMethodData = false;
if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.BANK_ACCOUNT && _.isEmpty(this.props.bankAccountList[this.state.methodID])) {
abdulrahuman5196 marked this conversation as resolved.
Show resolved Hide resolved
shouldResetPaymentMethodData = true;
} else if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.DEBIT_CARD && _.isEmpty(this.props.cardList[this.state.methodID])) {
shouldResetPaymentMethodData = true;
} else if (this.state.selectedPaymentMethodType === CONST.PAYMENT_METHODS.PAYPAL && this.props.payPalMeData !== prevProps.payPalMeData && _.isEmpty(this.props.payPalMeData)) {
shouldResetPaymentMethodData = true;
}
if (shouldResetPaymentMethodData) {
if (this.state.shouldShowDefaultDeleteMenu) {
this.hideDefaultDeleteMenu();
}
if (this.state.shouldShowPasswordPrompt) {
this.hidePasswordPrompt();
}
this.resetSelectedPaymentMethodData();
abdulrahuman5196 marked this conversation as resolved.
Show resolved Hide resolved
}
}

// previously online OR currently offline, skip fetch
if (!prevProps.network.isOffline || this.props.network.isOffline) {
return;
Expand Down Expand Up @@ -138,6 +158,21 @@ class BasePaymentsPage extends React.Component {
});
}

resetSelectedPaymentMethodData() {
InteractionManager.runAfterInteractions(() => {
abdulrahuman5196 marked this conversation as resolved.
Show resolved Hide resolved
// Reset to same values as in the constructor
this.setState({
isSelectedPaymentMethodDefault: false,
selectedPaymentMethod: {},
formattedSelectedPaymentMethod: {
title: '',
},
methodID: null,
selectedPaymentMethodType: null,
});
});
}

/**
* Display the delete/default menu, or the add payment method menu
*
Expand Down Expand Up @@ -242,11 +277,13 @@ class BasePaymentsPage extends React.Component {
this.setState({
showConfirmDeleteContent: false,
});
this.resetSelectedPaymentMethodData();
abdulrahuman5196 marked this conversation as resolved.
Show resolved Hide resolved
});
}

hidePasswordPrompt() {
this.setState({shouldShowPasswordPrompt: false});
this.resetSelectedPaymentMethodData();

// Due to iOS modal freeze issue, password modal freezes the app when closed.
// LayoutAnimation undoes the running animation.
Expand Down Expand Up @@ -521,6 +558,9 @@ export default compose(
walletTerms: {
key: ONYXKEYS.WALLET_TERMS,
},
payPalMeData: {
key: ONYXKEYS.PAYPAL,
},
isLoadingPaymentMethods: {
key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS,
},
Expand Down