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

nada/fix: list payment methods in create sell ad, paymentmethods in myprofile #52

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/components/AdvertsTableRow/AdvertsTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@

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]);

Check warning on line 33 in src/components/AdvertsTableRow/AdvertsTableRow.tsx

View workflow job for this annotation

GitHub Actions / build_to_cloudflare_pages

React Hook useEffect has a missing dependency: 'get'. Either include it or remove the dependency array

const { daily_buy = 0, daily_buy_limit = 0, daily_sell = 0, daily_sell_limit = 0 } = data || {};

const exchangeRateRef = useRef<TExchangeRate | null>(null);
Expand All @@ -50,7 +57,7 @@
target_currencies: [local_currency],
});
}
}, [local_currency]);

Check warning on line 60 in src/components/AdvertsTableRow/AdvertsTableRow.tsx

View workflow job for this annotation

GitHub Actions / build_to_cloudflare_pages

React Hook useEffect has a missing dependency: 'subscribeRates'. Either include it or remove the dependency array

const Container = isMobile ? 'div' : Fragment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
11 changes: 8 additions & 3 deletions src/pages/my-profile/screens/PaymentMethods/PaymentMethods.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down
Loading