-
Notifications
You must be signed in to change notification settings - Fork 3.9k
FIx payment method popover toggle #26377
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,6 @@ function BaseWalletPage(props) { | |
| selectedPaymentMethodType: null, | ||
| }); | ||
| const addPaymentMethodAnchorRef = useRef(null); | ||
| const deletePaymentMethodAnchorRef = useRef(null); | ||
| const paymentMethodButtonRef = useRef(null); | ||
| const [anchorPosition, setAnchorPosition] = useState({ | ||
| anchorPositionHorizontal: 0, | ||
|
|
@@ -102,19 +101,15 @@ function BaseWalletPage(props) { | |
| }, [paymentMethod.selectedPaymentMethod.bankAccountID, paymentMethod.selectedPaymentMethod.fundID, paymentMethod.selectedPaymentMethodType]); | ||
|
|
||
| const resetSelectedPaymentMethodData = useCallback(() => { | ||
| // The below state values are used by payment method modals and we reset them while closing the modals. | ||
| // We should only reset the values when the modal animation is completed and so using InteractionManager.runAfterInteractions which fires after all animaitons are complete | ||
| InteractionManager.runAfterInteractions(() => { | ||
| // Reset to same values as in the constructor | ||
| setPaymentMethod({ | ||
| isSelectedPaymentMethodDefault: false, | ||
| selectedPaymentMethod: {}, | ||
| formattedSelectedPaymentMethod: { | ||
| title: '', | ||
| }, | ||
| methodID: null, | ||
| selectedPaymentMethodType: null, | ||
| }); | ||
| // Reset to same values as in the constructor | ||
| setPaymentMethod({ | ||
| isSelectedPaymentMethodDefault: false, | ||
| selectedPaymentMethod: {}, | ||
| formattedSelectedPaymentMethod: { | ||
| title: '', | ||
| }, | ||
| methodID: null, | ||
| selectedPaymentMethodType: null, | ||
| }); | ||
| }, [setPaymentMethod]); | ||
|
|
||
|
|
@@ -133,6 +128,11 @@ function BaseWalletPage(props) { | |
| return; | ||
| } | ||
|
|
||
| if (shouldShowDefaultDeleteMenu) { | ||
| setShouldShowDefaultDeleteMenu(false); | ||
| return; | ||
| } | ||
|
|
||
| paymentMethodButtonRef.current = nativeEvent.currentTarget; | ||
|
|
||
| // The delete/default menu | ||
|
|
@@ -212,18 +212,12 @@ function BaseWalletPage(props) { | |
| * Hide the default / delete modal | ||
| * @param {boolean} shouldClearSelectedData - Clear selected payment method data if true | ||
| */ | ||
| const hideDefaultDeleteMenu = useCallback( | ||
| (shouldClearSelectedData = true) => { | ||
| setShouldShowDefaultDeleteMenu(false); | ||
| InteractionManager.runAfterInteractions(() => { | ||
| setShowConfirmDeleteContent(false); | ||
| if (shouldClearSelectedData) { | ||
| resetSelectedPaymentMethodData(); | ||
| } | ||
| }); | ||
| }, | ||
| [setShouldShowDefaultDeleteMenu, setShowConfirmDeleteContent, resetSelectedPaymentMethodData], | ||
| ); | ||
| const hideDefaultDeleteMenu = useCallback(() => { | ||
| setShouldShowDefaultDeleteMenu(false); | ||
| InteractionManager.runAfterInteractions(() => { | ||
| setShowConfirmDeleteContent(false); | ||
| }); | ||
| }, [setShouldShowDefaultDeleteMenu, setShowConfirmDeleteContent]); | ||
|
|
||
| const makeDefaultPaymentMethod = useCallback(() => { | ||
| const paymentCardList = props.fundList || {}; | ||
|
|
@@ -237,15 +231,13 @@ function BaseWalletPage(props) { | |
| } else if (paymentMethod.selectedPaymentMethodType === CONST.PAYMENT_METHODS.DEBIT_CARD) { | ||
| PaymentMethods.makeDefaultPaymentMethod(null, paymentMethod.selectedPaymentMethod.fundID, previousPaymentMethod, currentPaymentMethod); | ||
| } | ||
| resetSelectedPaymentMethodData(); | ||
| }, [ | ||
| paymentMethod.methodID, | ||
| paymentMethod.selectedPaymentMethod.bankAccountID, | ||
| paymentMethod.selectedPaymentMethod.fundID, | ||
| paymentMethod.selectedPaymentMethodType, | ||
| props.bankAccountList, | ||
| props.fundList, | ||
| resetSelectedPaymentMethodData, | ||
| ]); | ||
|
|
||
| const deletePaymentMethod = useCallback(() => { | ||
|
|
@@ -256,8 +248,7 @@ function BaseWalletPage(props) { | |
| } else if (paymentMethod.selectedPaymentMethodType === CONST.PAYMENT_METHODS.DEBIT_CARD) { | ||
| PaymentMethods.deletePaymentCard(paymentMethod.selectedPaymentMethod.fundID); | ||
| } | ||
| resetSelectedPaymentMethodData(); | ||
| }, [paymentMethod.selectedPaymentMethod.bankAccountID, paymentMethod.selectedPaymentMethod.fundID, paymentMethod.selectedPaymentMethodType, resetSelectedPaymentMethodData]); | ||
| }, [paymentMethod.selectedPaymentMethod.bankAccountID, paymentMethod.selectedPaymentMethod.fundID, paymentMethod.selectedPaymentMethodType]); | ||
|
|
||
| const navigateToTransferBalancePage = () => { | ||
| Navigation.navigate(ROUTES.SETTINGS_WALLET_TRANSFER_BALANCE); | ||
|
|
@@ -424,7 +415,8 @@ function BaseWalletPage(props) { | |
| right: anchorPosition.anchorPositionRight, | ||
| }} | ||
| withoutOverlay | ||
| anchorRef={deletePaymentMethodAnchorRef} | ||
| anchorRef={paymentMethodButtonRef} | ||
| onModalHide={resetSelectedPaymentMethodData} | ||
| > | ||
| {!showConfirmDeleteContent ? ( | ||
| <View style={[styles.m5, !isSmallScreenWidth ? styles.sidebarPopover : '']}> | ||
|
|
@@ -440,8 +432,8 @@ function BaseWalletPage(props) { | |
| {shouldShowMakeDefaultButton && ( | ||
| <Button | ||
| onPress={() => { | ||
| setShouldShowDefaultDeleteMenu(false); | ||
| makeDefaultPaymentMethod(); | ||
| setShouldShowDefaultDeleteMenu(false); | ||
| }} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as below (or above) |
||
| text={translate('walletPage.setDefaultConfirmation')} | ||
| /> | ||
|
|
@@ -461,14 +453,13 @@ function BaseWalletPage(props) { | |
| style={[shouldShowMakeDefaultButton ? styles.mt4 : {}]} | ||
| text={translate('common.delete')} | ||
| danger | ||
| ref={deletePaymentMethodAnchorRef} | ||
| /> | ||
| </View> | ||
| ) : ( | ||
| <ConfirmContent | ||
| onConfirm={() => { | ||
| hideDefaultDeleteMenu(false); | ||
| deletePaymentMethod(); | ||
| hideDefaultDeleteMenu(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is actually no problem so far calling
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree |
||
| }} | ||
| onCancel={hideDefaultDeleteMenu} | ||
| contentStyles={!isSmallScreenWidth ? [styles.sidebarPopover, styles.willChangeTransform] : undefined} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.