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

[FEQ] Jim/FEQ-990/p2p advert information #12213

Merged
1 change: 0 additions & 1 deletion packages/api/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './countries';
export * from './onfido';
export * from './payment-method-icons';
5 changes: 0 additions & 5 deletions packages/api/src/constants/payment-method-icons.ts

This file was deleted.

45 changes: 45 additions & 0 deletions packages/api/src/hooks/p2p/useAdvertInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { useMemo } from 'react';
import useQuery from '../../useQuery';

/**
* This custom hook returns the advert information about the given advert ID.
*/
const useAdvertInfo = (
payload: NonNullable<Parameters<typeof useQuery<'p2p_advert_info'>>[1]>['payload'],
jim-deriv marked this conversation as resolved.
Show resolved Hide resolved
options?: NonNullable<Parameters<typeof useQuery<'p2p_advert_info'>>[1]>['options']
) => {
const { data, ...rest } = useQuery('p2p_advert_info', {
payload: { id: payload?.id, use_client_limits: payload?.use_client_limits },
jim-deriv marked this conversation as resolved.
Show resolved Hide resolved
options,
});

const modified_data = useMemo(() => {
const p2p_advert_info = data?.p2p_advert_info;

if (!p2p_advert_info) return undefined;

return {
...p2p_advert_info,
/** Determines whether the advert is a buy advert or not. */
is_buy: p2p_advert_info.type === 'buy',
/** Determines whether the advert is a sell advert or not. */
is_sell: p2p_advert_info.type === 'sell',
is_block_trade: Boolean(p2p_advert_info.block_trade),
is_deleted: Boolean(p2p_advert_info.deleted),
is_active: Boolean(p2p_advert_info.is_active),
is_visible: Boolean(p2p_advert_info.is_visible),
/**
* @deprecated This property was deprecated on back-end
* @see https://api.deriv.com/api-explorer#p2p_advert_info
* **/
payment_method: p2p_advert_info.payment_method,
};
}, [data?.p2p_advert_info]);

return {
data: modified_data,
...rest,
};
};

export default useAdvertInfo;
3 changes: 0 additions & 3 deletions packages/api/src/hooks/p2p/usePaymentMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMemo } from 'react';
import useAuthorize from '../useAuthorize';
import { PAYMENT_METHOD_ICONS } from '../../constants';
import useQuery from '../../useQuery';

/** A custom hook that returns a list of P2P available payment methods **/
Expand All @@ -21,8 +20,6 @@ const usePaymentMethods = () => {
...payment_method,
/** Payment method field definitions. */
fields,
/** Icon for each payment method based on the type */
icon: PAYMENT_METHOD_ICONS[payment_method.type],
/** Payment method id */
id: key,
};
Expand Down
1 change: 1 addition & 0 deletions packages/hooks/src/useP2PAdvertInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useFetch } from '@deriv/api';
import { TSocketRequestQueryOptions } from '@deriv/api/types';

/**
* @deprecated Please use `useAdvertInfo` from the `api` package instead.
* This custom hook returns the advert info for a specific advert by calling 'p2p_advert_info' endpoint
*/
const useP2PAdvertInfo = (id: string, options: TSocketRequestQueryOptions<'p2p_advert_info'>) => {
Expand Down