-
Notifications
You must be signed in to change notification settings - Fork 394
[FEQ] Ameerul / FEQ-872 / Getting console error while adding payment method in P2P #11293
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
d755a63
3134575
f73fa28
038ced9
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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| import classNames from 'classnames'; | ||
| import React from 'react'; | ||
| import { observer } from 'mobx-react-lite'; | ||
| import { Field, Form } from 'formik'; | ||
| import { Button, DesktopWrapper, Input, Loading, Text } from '@deriv/components'; | ||
| import { useP2PAdvertiserPaymentMethods } from '@deriv/hooks'; | ||
| import { isDesktop, isMobile } from '@deriv/shared'; | ||
| import { Localize, localize } from 'Components/i18next'; | ||
| import { useStores } from 'Stores'; | ||
|
|
@@ -13,6 +13,8 @@ import './edit-payment-method-form.scss'; | |
|
|
||
| const EditPaymentMethodForm = () => { | ||
| const { showModal } = useModalManagerContext(); | ||
| const { mutation, update } = useP2PAdvertiserPaymentMethods(); | ||
| const { error: mutation_error, status: mutation_status } = mutation; | ||
| const { general_store, my_profile_store } = useStores(); | ||
| const { payment_method_to_edit } = my_profile_store; | ||
|
|
||
|
|
@@ -21,6 +23,10 @@ const EditPaymentMethodForm = () => { | |
| fields_initial_values[key] = payment_method_to_edit.fields[key].value; | ||
| }); | ||
|
|
||
| const updatePaymentMethod = values => { | ||
| update(payment_method_to_edit.id, values); | ||
| }; | ||
|
|
||
| React.useEffect(() => { | ||
| return () => { | ||
| my_profile_store.setSelectedPaymentMethod(''); | ||
|
|
@@ -29,6 +35,15 @@ const EditPaymentMethodForm = () => { | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
|
|
||
| React.useEffect(() => { | ||
| if (mutation_status === 'success') { | ||
| my_profile_store.setShouldShowEditPaymentMethodForm(false); | ||
| } else if (mutation_status === 'error') { | ||
| my_profile_store.setAddPaymentMethodErrorMessage(mutation_error.message); | ||
| showModal({ key: 'AddPaymentMethodErrorModal' }); | ||
| } | ||
| }, [mutation_error, mutation_status]); | ||
|
|
||
| if (!payment_method_to_edit) { | ||
| return <Loading is_fullscreen={false} />; | ||
| } | ||
|
|
@@ -38,7 +53,7 @@ const EditPaymentMethodForm = () => { | |
| <ModalForm | ||
| enableReinitialize | ||
| initialValues={fields_initial_values} | ||
| onSubmit={my_profile_store.updatePaymentMethod} | ||
| onSubmit={updatePaymentMethod} | ||
| validate={my_profile_store.validatePaymentMethodFields} | ||
| > | ||
| {({ dirty, handleChange, isSubmitting, errors }) => { | ||
|
|
@@ -106,6 +121,7 @@ const EditPaymentMethodForm = () => { | |
| onChange={handleChange} | ||
| name={payment_method_key} | ||
| required={!!current_field.required} | ||
| value={field.value || ''} | ||
| /> | ||
| ); | ||
| }} | ||
|
|
@@ -156,4 +172,4 @@ const EditPaymentMethodForm = () => { | |
| ); | ||
| }; | ||
|
|
||
| export default observer(EditPaymentMethodForm); | ||
| export default EditPaymentMethodForm; | ||
|
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. Wrapping this component with observer caused the console logging error issue, which is caused by updating the payment method, which is then updating any observables inside this component whilst it is unmounting. We don't need to have observer wrapping this component since it doesn't need to listen to any changes except if there are errors whilst updating the payment method |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to pass a string instead of the component because this is what caused the console error issues. Because we had passed it as a component, the title prop in Modal component is wrapped inside Text which is strange as we had previously returned it as a Text Component.
We could create another prop for specifically passing a component, but the styles are already there, and we don't need to repeat it again and style it ourselves from the child to the parent.
There's no issue with the MobileFullPageModal, so I had left it as it is