forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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-1020/add use p2p payment methods hook (binary-com#12146)
* feat: add usepaymentmethods hook * chore: remove exports * chore: mark hook from hooks package as deprecated * chore: add comment * chore: update comment * chore: update name based on reviews
- Loading branch information
Showing
6 changed files
with
47 additions
and
3 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,2 +1,3 @@ | ||
export * from './countries'; | ||
export * from './onfido'; | ||
export * from './payment-method-icons'; |
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,5 @@ | ||
export const PAYMENT_METHOD_ICONS = { | ||
bank: 'IcCashierBankTransfer', | ||
other: 'IcCashierOther', | ||
ewallet: 'IcCashierEwallet', | ||
}; |
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 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,38 @@ | ||
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 **/ | ||
const useP2PPaymentMethods = () => { | ||
const { isSuccess } = useAuthorize(); | ||
const { data, ...rest } = useQuery('p2p_payment_methods', { options: { enabled: isSuccess } }); | ||
// Modify the data to add additional information. | ||
const modified_data = useMemo(() => { | ||
const p2p_payment_methods = data?.p2p_payment_methods; | ||
|
||
if (!p2p_payment_methods) return undefined; | ||
|
||
return Object.keys(p2p_payment_methods).map(key => { | ||
const payment_method = p2p_payment_methods[key]; | ||
const fields = Object.keys(payment_method.fields).map(field_key => payment_method.fields[field_key]); | ||
|
||
return { | ||
...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, | ||
}; | ||
}); | ||
}, [data]); | ||
|
||
return { | ||
data: modified_data, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useP2PPaymentMethods; |
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