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 8 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,4 +3,5 @@ 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 useWalletAccountsList } from './useWalletAccountsList';
33 changes: 33 additions & 0 deletions packages/api/src/hooks/useLandingCompany.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 {
/** Short code of financial landing company */
financial_company: financial_company?.shortcode,
/** Short code of gaming landing company */
gaming_company: gaming_company?.shortcode,
/** Short code of virtual landing company */
virtual_company,
};
}, [data]);

return {
/** List of available landing companies */
data: modified_data,
...rest,
};
};

export default useLandingCompany;
17 changes: 17 additions & 0 deletions packages/api/src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useMemo } from 'react';
import useFetch from '../useFetch';

/** A custom hook to get user settings (email, date of birth, address etc) */
const useSettings = () => {
const { data, ...rest } = useFetch('get_settings');

const modified_data = useMemo(() => ({ ...data?.get_settings }), [data?.get_settings]);

return {
/** User information and settings */
data: modified_data,
...rest,
};
};

export default useSettings;
5 changes: 4 additions & 1 deletion packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ type TSocketEndpoints = {
response: LandingCompanyDetailsResponse;
};
landing_company: {
request: LandingCompanyRequest;
// TODO: Fix typings of this endpoint, because LandingCompany payload should be a string instead of LandingCompany interface
request: {
landing_company: string;
};
farhan-nurzi-deriv marked this conversation as resolved.
Show resolved Hide resolved
response: LandingCompanyResponse;
};
login_history: {
Expand Down