-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEQ] Ameerul / FEQ-1005 / P2P Order List (#12176)
* feat: added hook for p2p_order_list * chore: added suggestions * fix: removed default values * fix: removed date epoch conversion, added is to boolean values * chore: empty commit * chore: removed p2p name from filename * fix: failing test cases
- Loading branch information
1 parent
cf4d1a2
commit f3020d6
Showing
3 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import useInfiniteQuery from '../../useInfiniteQuery'; | ||
import useAuthorize from '../useAuthorize'; | ||
|
||
/** This custom hook returns a list of orders under the current client. */ | ||
const useOrderList = ( | ||
payload?: NonNullable<Parameters<typeof useInfiniteQuery<'p2p_order_list'>>[1]>['payload'], | ||
config?: NonNullable<Parameters<typeof useInfiniteQuery<'p2p_order_list'>>[1]>['options'] | ||
) => { | ||
const { isSuccess } = useAuthorize(); | ||
const { data, fetchNextPage, ...rest } = useInfiniteQuery('p2p_order_list', { | ||
payload: { ...payload, offset: payload?.offset, limit: payload?.limit }, | ||
options: { | ||
getNextPageParam: (lastPage, pages) => { | ||
if (!lastPage?.p2p_order_list?.list) return; | ||
|
||
return pages.length; | ||
}, | ||
enabled: isSuccess && (config?.enabled === undefined || config.enabled), | ||
}, | ||
}); | ||
|
||
// Flatten the data array | ||
const flatten_data = React.useMemo(() => { | ||
if (!data?.pages?.length) return; | ||
|
||
return data?.pages?.flatMap(page => page?.p2p_order_list?.list); | ||
}, [data?.pages]); | ||
|
||
// Additional p2p_order_list data | ||
const modified_data = React.useMemo(() => { | ||
if (!flatten_data?.length) return undefined; | ||
|
||
return flatten_data.map(advert => ({ | ||
...advert, | ||
/** Details of the advert for this order. */ | ||
advert_details: { | ||
...advert?.advert_details, | ||
/** Indicates if this is block trade advert or not. */ | ||
is_block_trade: Boolean(advert?.advert_details?.block_trade), | ||
}, | ||
/** Details of the advertiser for this order. */ | ||
advertiser_details: { | ||
...advert?.advertiser_details, | ||
/** Indicates if the advertiser is currently online. */ | ||
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), | ||
}, | ||
/** 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), | ||
/** Indicates that the advertiser was recommended in the most recent review by the current user. */ | ||
is_recommended: Boolean(advert?.advertiser_details?.is_recommended), | ||
}, | ||
is_incoming: Boolean(advert?.is_incoming), | ||
/** 1 if a review can be given, otherwise 0 */ | ||
is_reviewable: Boolean(advert?.is_reviewable), | ||
/** 1 if the latest order changes have been seen by the current client, otherwise 0. */ | ||
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. */ | ||
is_recommended: Boolean(advert?.review_details?.recommended), | ||
}, | ||
/** Indicates that the seller in the process of confirming the order. */ | ||
is_verification_pending: Boolean(advert?.verification_pending), | ||
})); | ||
}, [flatten_data]); | ||
|
||
return { | ||
/** The 'p2p_order_list' response. */ | ||
data: modified_data, | ||
loadMoreOrders: fetchNextPage, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useOrderList; |
f3020d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
deriv-app – ./
deriv-app.vercel.app
binary.sx
deriv-app.binary.sx
deriv-app-git-master.binary.sx