Skip to content

Commit

Permalink
[FEQ] Jim/FEQ-990/p2p advert information (#12213)
Browse files Browse the repository at this point in the history
* chore: remove P2P from hook and remove icon related transformations

* chore: move useadvertinfo to api package

* chore: add deprecated message

* chore: remove unnecessary export

* chore: transform other fields based on code review comments

* chore: update based on review comments

* chore: update based on code reviews

Co-authored-by: Niloofar Sadeghi <93518187+niloofar-deriv@users.noreply.github.com>

---------

Co-authored-by: Niloofar Sadeghi <93518187+niloofar-deriv@users.noreply.github.com>
  • Loading branch information
jim-deriv and niloofar-deriv authored Dec 14, 2023
1 parent e15757f commit cf4d1a2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
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'],
options?: NonNullable<Parameters<typeof useQuery<'p2p_advert_info'>>[1]>['options']
) => {
const { data, ...rest } = useQuery('p2p_advert_info', {
payload,
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

0 comments on commit cf4d1a2

Please sign in to comment.