-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEQ] Jim/FEQ-990/p2p advert information (#12213)
* 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
1 parent
e15757f
commit cf4d1a2
Showing
5 changed files
with
46 additions
and
9 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
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'; |
This file was deleted.
Oops, something went wrong.
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,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; |
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