diff --git a/packages/api/src/hooks/index.ts b/packages/api/src/hooks/index.ts index 4e7c224e93b1..a8d9120c9d0a 100644 --- a/packages/api/src/hooks/index.ts +++ b/packages/api/src/hooks/index.ts @@ -3,6 +3,7 @@ export { default as useActiveWalletAccounts } from './useActiveWalletAccounts'; export { default as useAuthorize } from './useAuthorize'; export { default as useBalance } from './useBalance'; export { default as useCurrencyConfig } from './useCurrencyConfig'; +export { default as useLandingCompany } from './useLandingCompany'; export { default as useMT5LoginList } from './useMT5LoginList'; export { default as useSettings } from './useSettings'; export { default as useTradingPlatformAccounts } from './useTradingPlatformAccounts'; diff --git a/packages/api/src/hooks/useLandingCompany.ts b/packages/api/src/hooks/useLandingCompany.ts new file mode 100644 index 000000000000..de69b69eaa82 --- /dev/null +++ b/packages/api/src/hooks/useLandingCompany.ts @@ -0,0 +1,34 @@ +import { useMemo } from 'react'; +import useFetch from '../useFetch'; +import useSettings from './useSettings'; + +/** A custom hook that returns the available landing companies of the user's country. */ +const useLandingCompany = () => { + const { data: settings_data } = useSettings(); + const { data, ...rest } = useFetch('landing_company', { + payload: { landing_company: settings_data?.country_code || '' }, + options: { enabled: Boolean(settings_data?.country_code) }, + }); + + const modified_data = useMemo(() => { + if (!data?.landing_company) return; + const { financial_company, gaming_company, virtual_company } = data.landing_company; + return { + ...data.landing_company, + /** Short code of financial landing company */ + financial_company_shortcode: financial_company?.shortcode, + /** Short code of gaming landing company */ + gaming_company_shortcode: gaming_company?.shortcode, + /** Short code of virtual landing company */ + virtual_company_shortcode: virtual_company, + }; + }, [data?.landing_company]); + + return { + /** List of available landing companies */ + data: modified_data, + ...rest, + }; +}; + +export default useLandingCompany; diff --git a/packages/api/types.ts b/packages/api/types.ts index 6d3beef337e9..88a1da62abcd 100644 --- a/packages/api/types.ts +++ b/packages/api/types.ts @@ -707,7 +707,11 @@ type TSocketEndpoints = { response: LandingCompanyDetailsResponse; }; landing_company: { - request: LandingCompanyRequest; + // TODO: Fix typings of this endpoint, because landing_company payload should be a string instead of LandingCompany interface + request: Omit & { + /** Client's 2-letter country code (obtained from `residence_list` call). */ + landing_company: string; + }; response: LandingCompanyResponse; }; login_history: {