forked from deriv-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.
FarhanNurzi/feat: WALL-1574/Add useAvailableAccounts hook to @deriv/a…
…pi (deriv-com#9786) * feat: added use-authorize hook taken from sergei pr Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: sorted imports for use-authorize Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com> * chore: moved default empty string in use-authorize * chore: incorporated code reviews * chore: added useLandingCompany into api package * chore: added useLandingCompany into api package * chore: added useAvailableAccounts and useAccountTypes hooks into api package * chore: added useSettings to @deriv/api * chore: get country_code from user settings instead of authorize * chore: combine get_settings with set_settings * fix: change request type for landing_company * chore: combine get_settings with set_settings * refactor: change function name * chore: add landing_company field to each account types * chore: add missing dependencies for useLandingCompany return data * chore: return all mutation data * chore: export hook * refactor: types and mutation function name * refactor: use-landing-company-hook * fix: remove dependency * fix: remove dependency * refactor: use-available-accounts hook * fix: review comments, remove gaming accounts * refactor: separate accounts usememo --------- Co-authored-by: adrienne-rio <adrienne@deriv.com> Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com>
- Loading branch information
1 parent
379bc41
commit 39ce848
Showing
5 changed files
with
163 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
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,31 @@ | ||
import { useMemo } from 'react'; | ||
import useFetch from '../useFetch'; | ||
|
||
/** | ||
* A custom hook to get available account types for a specific landing company | ||
* | ||
* @param landing_company {string} - The landing company shortcode | ||
*/ | ||
const useAccountTypes = (landing_company?: string) => { | ||
const { data, ...rest } = useFetch('get_account_types', { | ||
payload: { company: landing_company }, | ||
}); | ||
|
||
const modified_data = useMemo(() => { | ||
if (!data?.get_account_types) return; | ||
|
||
return { | ||
/** List of available account types */ | ||
...data.get_account_types, | ||
/** Landing company for the account types */ | ||
landing_company, | ||
}; | ||
}, [data?.get_account_types, landing_company]); | ||
|
||
return { | ||
data: modified_data, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useAccountTypes; |
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,47 @@ | ||
import { useMemo } from 'react'; | ||
import useAccountTypes from './useAccountTypes'; | ||
import useLandingCompany from './useLandingCompany'; | ||
|
||
/** A custom hook to get available accounts for every landing companies */ | ||
const useAvailableAccounts = () => { | ||
const { data: landing_company_data } = useLandingCompany(); | ||
const { data: available_financial_accounts } = useAccountTypes(landing_company_data?.financial_company_shortcode); | ||
const { data: available_virtual_accounts } = useAccountTypes(landing_company_data?.virtual_company_shortcode); | ||
|
||
// memoize the available financial accounts | ||
const financial_accounts = useMemo(() => { | ||
if (!available_financial_accounts) return; | ||
|
||
return { | ||
...available_financial_accounts, | ||
}; | ||
}, [available_financial_accounts]); | ||
|
||
// memoize the available virtual accounts | ||
const virtual_accounts = useMemo(() => { | ||
if (!available_virtual_accounts) return; | ||
|
||
return { | ||
...available_virtual_accounts, | ||
}; | ||
}, [available_virtual_accounts]); | ||
|
||
// memoize the combined available accounts | ||
const available_accounts = useMemo(() => { | ||
if (!available_financial_accounts && !available_virtual_accounts) return; | ||
|
||
return { | ||
/** List of available financial accounts */ | ||
financial_accounts, | ||
/** List of available virtual accounts */ | ||
virtual_accounts, | ||
}; | ||
}, [available_financial_accounts, available_virtual_accounts]); | ||
|
||
return { | ||
/** List of available accounts */ | ||
data: available_accounts, | ||
}; | ||
}; | ||
|
||
export default useAvailableAccounts; |
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