Skip to content

Commit

Permalink
[FEQ] Ameerul / FEQ-1004 / P2P Order Information Hook (binary-com#12252)
Browse files Browse the repository at this point in the history
* chore: added p2p-order-info hook, changed other hooks to return null for is_recommended

* chore: added tsdocs to response

* chore: removed null check for is_recommended, and separated it

* chore: added comments
  • Loading branch information
ameerul-deriv committed Dec 20, 2023
1 parent 33682c5 commit 16d9c26
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/hooks/p2p/useAdvertList.ts
Expand Up @@ -51,9 +51,9 @@ const useAdvertList = (
is_online: Boolean(advert?.advertiser_details?.is_online),
/** Indicates that the advertiser was recommended in the most recent review by the current user. */
is_recommended: Boolean(advert?.advertiser_details?.is_recommended),
/** Indicates that the advertiser has not been recommended yet. */
has_not_been_recommended: advert?.advertiser_details.is_recommended === null,
},
/** The advert creation time in epoch. */
created_time: advert?.created_time ? new Date(advert.created_time) : undefined,
}));
}, [flatten_data]);

Expand Down
75 changes: 75 additions & 0 deletions packages/api/src/hooks/p2p/useOrderInfo.ts
@@ -0,0 +1,75 @@
import { useMemo } from 'react';
import useQuery from '../../useQuery';
import useAuthorize from '../useAuthorize';

/** This custom hook that returns information about the given order ID */
const useOrderInfo = (id: string) => {
const { isSuccess } = useAuthorize();
const { data, ...rest } = useQuery('p2p_order_info', { payload: { id }, options: { enabled: isSuccess } });

// modify the data to add additional information
const modified_data = useMemo(() => {
if (!data?.p2p_order_info) return undefined;

const {
advert_details,
advertiser_details,
client_details,
is_incoming,
is_reviewable,
is_seen,
review_details,
verification_pending,
} = data.p2p_order_info;

return {
...data.p2p_order_info,
advert_details: {
...advert_details,
/** Indicates if this is block trade advert or not. */
is_block_trade: Boolean(advert_details.block_trade),
},
advertiser_details: {
...advertiser_details,
/** Indicates if the advertiser is currently online. */
is_online: Boolean(advertiser_details.is_online),
/** Indicates that the advertiser was recommended in the most recent review by the current user. */
is_recommended: Boolean(client_details.is_recommended),
/** Indicates that the advertiser has not been recommended yet. */
has_not_been_recommended: advertiser_details.is_recommended === null,
},
client_details: {
...client_details,
/** Indicates if the advertiser is currently online. */
is_online: Boolean(client_details.is_online),
/** Indicates that the client was recommended in the most recent review by the current user. */
is_recommended: Boolean(client_details.is_recommended),
/** Indicates that the client has not been recommended yet. */
has_not_been_recommended: client_details.is_recommended === null,
},
/** Indicates if the order is created for the advert of the client. */
is_incoming: Boolean(is_incoming),
/** Indicates if a review can be given. */
is_reviewable: Boolean(is_reviewable),
/** Indicates if the latest order changes have been seen by the current client. */
is_seen: Boolean(is_seen),
review_details: {
...review_details,
/** Indicates if the advertiser is recommended or not. */
is_recommended: Boolean(review_details?.recommended),
/** Indicates that the advertiser has not been recommended yet. */
has_not_been_recommended: review_details?.recommended === null,
},
/** Indicates that the seller in the process of confirming the order. */
is_verification_pending: Boolean(verification_pending),
};
}, [data?.p2p_order_info]);

return {
/** The 'p2p_order_info' response. */
data: modified_data,
...rest,
};
};

export default useOrderInfo;
17 changes: 12 additions & 5 deletions packages/api/src/hooks/p2p/useOrderList.ts
Expand Up @@ -46,25 +46,31 @@ const useOrderList = (
is_online: Boolean(advert?.advertiser_details?.is_online),
/** Indicates that the advertiser was recommended in the most recent review by the current user. */
is_recommended: Boolean(advert?.advertiser_details?.is_recommended),
/** Indicates that the advertiser has not been recommended yet. */
has_not_been_recommended: advert?.advertiser_details?.is_recommended === null,
},
/** Details of the client who created the order. */
client_details: {
...advert?.client_details,
/** Indicates if the advertiser is currently online. */
is_online: Boolean(advert?.advertiser_details?.is_online),
is_online: Boolean(advert?.client_details?.is_online),
/** Indicates that the advertiser was recommended in the most recent review by the current user. */
is_recommended: Boolean(advert?.advertiser_details?.is_recommended),
is_recommended: Boolean(advert?.client_details?.is_recommended),
/** Indicates that the advertiser has not been recommended yet. */
has_not_been_recommended: advert?.client_details?.is_recommended === null,
},
is_incoming: Boolean(advert?.is_incoming),
/** 1 if a review can be given, otherwise 0 */
/** Indicates if a review can be given. */
is_reviewable: Boolean(advert?.is_reviewable),
/** 1 if the latest order changes have been seen by the current client, otherwise 0. */
/** Indicates if the latest order changes have been seen by the current client. */
is_seen: Boolean(advert?.is_seen),
/** Details of the review you gave for this order, if any. */
review_details: {
...advert?.review_details,
/** 1 if the advertiser is recommended, 0 if not recommended. */
/** Indicates if the advertiser is recommended. */
is_recommended: Boolean(advert?.review_details?.recommended),
/** Indicates that the advertiser has not been recommended yet. */
has_not_been_recommended: advert?.review_details?.recommended === null,
},
/** Indicates that the seller in the process of confirming the order. */
is_verification_pending: Boolean(advert?.verification_pending),
Expand All @@ -74,6 +80,7 @@ const useOrderList = (
return {
/** The 'p2p_order_list' response. */
data: modified_data,
/** Fetch the next page of orders. */
loadMoreOrders: fetchNextPage,
...rest,
};
Expand Down

0 comments on commit 16d9c26

Please sign in to comment.