Skip to content

Commit

Permalink
farhan/WALL-1583/Add useLandingCompany hook to @deriv/api (deriv-com#…
Browse files Browse the repository at this point in the history
…9785)

* 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 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 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

---------

Co-authored-by: adrienne-rio <adrienne@deriv.com>
Co-authored-by: Sergei Baranovski <120570511+sergei-deriv@users.noreply.github.com>
  • Loading branch information
3 people authored and vinu-deriv committed Sep 1, 2023
1 parent d9fb90f commit c48cebd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/api/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
34 changes: 34 additions & 0 deletions packages/api/src/hooks/useLandingCompany.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LandingCompanyRequest, 'landing_company'> & {
/** Client's 2-letter country code (obtained from `residence_list` call). */
landing_company: string;
};
response: LandingCompanyResponse;
};
login_history: {
Expand Down

0 comments on commit c48cebd

Please sign in to comment.