Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FarhanNurzi/WALL-1583/Add useLandingCompany hook to @deriv/api #9785

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f368989
feat: added use-authorize hook taken from sergei pr
adrienne-deriv Aug 21, 2023
bc67484
chore: sorted imports for use-authorize
adrienne-deriv Aug 21, 2023
8856b9e
chore: moved default empty string in use-authorize
adrienne-deriv Aug 21, 2023
f72994d
chore: incorporated code reviews
adrienne-deriv Aug 21, 2023
dd451d8
chore: added useLandingCompany into api package
Farhan-slurrp Aug 22, 2023
c67c572
chore: added useSettings to @deriv/api
Farhan-slurrp Aug 24, 2023
a326324
Merge branch 'farhan/use-settings' of https://github.com/farhan-nurzi…
Farhan-slurrp Aug 24, 2023
666c290
chore: get country_code from user settings instead of authorize
Farhan-slurrp Aug 24, 2023
7259b6f
chore: combine get_settings with set_settings
Farhan-slurrp Aug 24, 2023
ddb92f9
Merge branch 'farhan/use-settings' of https://github.com/farhan-nurzi…
Farhan-slurrp Aug 24, 2023
2d93e34
fix: change request type for landing_company
Farhan-slurrp Aug 24, 2023
22a6883
chore: combine get_settings with set_settings
Farhan-slurrp Aug 24, 2023
90788f8
refactor: change function name
Farhan-slurrp Aug 24, 2023
458aab8
chore: add missing dependencies for useLandingCompany return data
Farhan-slurrp Aug 25, 2023
23ef184
Merge branch 'master' of https://github.com/binary-com/deriv-app into…
Farhan-slurrp Aug 25, 2023
2284c72
chore: return all mutation data
Farhan-slurrp Aug 25, 2023
cb12c7c
Merge branch 'master' of https://github.com/binary-com/deriv-app into…
Farhan-slurrp Aug 25, 2023
dbd632d
chore: export hook
Farhan-slurrp Aug 25, 2023
99573d6
Merge branch 'farhan/use-settings' of https://github.com/farhan-nurzi…
Farhan-slurrp Aug 25, 2023
5b54e20
refactor: types and mutation function name
Farhan-slurrp Aug 27, 2023
d609754
refactor: use-landing-company-hook
Farhan-slurrp Aug 27, 2023
2da54f5
Merge branch 'farhan/use-settings' of https://github.com/farhan-nurzi…
Farhan-slurrp Aug 27, 2023
60e212e
fix: remove dependency
Farhan-slurrp Aug 27, 2023
7f4e603
Merge branch 'master' of https://github.com/binary-com/deriv-app into…
Farhan-slurrp Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
yashim-deriv marked this conversation as resolved.
Show resolved Hide resolved
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