From 88cc3be1a640befb438b9f4a8531361e5e9d5e07 Mon Sep 17 00:00:00 2001 From: Nada Date: Tue, 7 May 2024 16:34:47 +0400 Subject: [PATCH 1/2] fix: list payment methods in create sell ad, paymentmethods in myprofile --- .../useAdvertiserPaymentMethods.ts | 7 ++----- .../SellAdPaymentSelection/SellAdPaymentSelection.tsx | 10 ++++++++-- .../screens/PaymentMethods/PaymentMethods.tsx | 11 ++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/hooks/api/payment-method/p2p-advertiser-payment-methods/useAdvertiserPaymentMethods.ts b/src/hooks/api/payment-method/p2p-advertiser-payment-methods/useAdvertiserPaymentMethods.ts index d4b5dca7..84dd5dc3 100644 --- a/src/hooks/api/payment-method/p2p-advertiser-payment-methods/useAdvertiserPaymentMethods.ts +++ b/src/hooks/api/payment-method/p2p-advertiser-payment-methods/useAdvertiserPaymentMethods.ts @@ -3,11 +3,8 @@ import { useP2PAdvertiserPaymentMethods } from '@deriv-com/api-hooks'; /** A custom hook that returns the list of P2P Advertiser Payment Methods */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -const useAdvertiserPaymentMethods = (_is_enabled = true) => { - const { data, ...rest } = useP2PAdvertiserPaymentMethods({ - //TODO: Add the enabled parameter to the API after api-hooks is updated - // enabled: is_enabled, - }); +const useAdvertiserPaymentMethods = () => { + const { data, ...rest } = useP2PAdvertiserPaymentMethods(); // Modify the response to add additional information const modified_data = useMemo(() => { diff --git a/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx b/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx index 05f2c9a8..25f70252 100644 --- a/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx +++ b/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.tsx @@ -1,4 +1,4 @@ -import { useCallback, useReducer } from 'react'; +import { useCallback, useEffect, useReducer } from 'react'; import { TAdvertiserPaymentMethod, TSelectedPaymentMethod } from 'types'; import { PaymentMethodCard, PaymentMethodForm } from '@/components'; import { api } from '@/hooks'; @@ -15,11 +15,17 @@ type TSellAdPaymentSelectionProps = { const SellAdPaymentSelection = ({ onSelectPaymentMethod, selectedPaymentMethodIds }: TSellAdPaymentSelectionProps) => { const { isMobile } = useDevice(); const isAdvertiser = useIsAdvertiser(); - const { data: advertiserPaymentMethods } = api.advertiserPaymentMethods.useGet(isAdvertiser); + const { data: advertiserPaymentMethods, get } = api.advertiserPaymentMethods.useGet(); const { hideModal, isModalOpenFor, showModal } = useModalManager({ shouldReinitializeModals: false }); const [formState, dispatch] = useReducer(advertiserPaymentMethodsReducer, {}); + useEffect(() => { + if (isAdvertiser) { + get(); + } + }, [isAdvertiser]); + const handleAddPaymentMethod = (selectedPaymentMethod?: TSelectedPaymentMethod) => { dispatch({ payload: { diff --git a/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx b/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx index d9f44bc6..8512bf0f 100644 --- a/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx +++ b/src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx @@ -1,4 +1,4 @@ -import { useCallback, useReducer } from 'react'; +import { useCallback, useEffect, useReducer } from 'react'; import { TSelectedPaymentMethod } from 'types'; import { PaymentMethodForm } from '@/components'; import { api } from '@/hooks'; @@ -15,10 +15,15 @@ import { PaymentMethodsList } from './PaymentMethodsList'; * **/ const PaymentMethods = () => { const isAdvertiser = useIsAdvertiser(); - const { data: p2pAdvertiserPaymentMethods, isPending: isLoading } = - api.advertiserPaymentMethods.useGet(isAdvertiser); + const { data: p2pAdvertiserPaymentMethods, get, isPending: isLoading } = api.advertiserPaymentMethods.useGet(); const [formState, dispatch] = useReducer(advertiserPaymentMethodsReducer, {}); + useEffect(() => { + if (isAdvertiser) { + get(); + } + }, [isAdvertiser]); + const handleAddPaymentMethod = (selectedPaymentMethod?: TSelectedPaymentMethod) => { dispatch({ payload: { From b65e16c60b1b9e4ed0701e6e4131bba2226f7f53 Mon Sep 17 00:00:00 2001 From: Nada Date: Tue, 7 May 2024 16:40:55 +0400 Subject: [PATCH 2/2] fix: build issue fix --- src/components/AdvertsTableRow/AdvertsTableRow.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/AdvertsTableRow/AdvertsTableRow.tsx b/src/components/AdvertsTableRow/AdvertsTableRow.tsx index 7daa3bbd..2bde5979 100644 --- a/src/components/AdvertsTableRow/AdvertsTableRow.tsx +++ b/src/components/AdvertsTableRow/AdvertsTableRow.tsx @@ -23,8 +23,15 @@ const AdvertsTableRow = memo((props: TAdvertsTableRowRenderer) => { const isAdvertiser = useIsAdvertiser(); const { data: paymentMethods } = api.paymentMethods.useGet(); - const { data: advertiserPaymentMethods } = api.advertiserPaymentMethods.useGet(isAdvertiser); + const { data: advertiserPaymentMethods, get } = api.advertiserPaymentMethods.useGet(); const { data } = api.advertiser.useGetInfo() || {}; + + useEffect(() => { + if (isAdvertiser) { + get(); + } + }, [isAdvertiser]); + const { daily_buy = 0, daily_buy_limit = 0, daily_sell = 0, daily_sell_limit = 0 } = data || {}; const exchangeRateRef = useRef(null);