Skip to content

Commit 685c868

Browse files
Merge branch 'master' of github.com:thisyahlen-deriv/deriv-app into thisyahlen/ctrader_creation
2 parents 1049af6 + eef34c6 commit 685c868

File tree

125 files changed

+1760
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1760
-743
lines changed

packages/api/src/hooks/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
export { default as useAccountsList } from './useAccountsList';
21
export { default as useAccountTypes } from './useAccountTypes';
2+
export { default as useAccountsList } from './useAccountsList';
33
export { default as useActiveAccount } from './useActiveAccount';
44
export { default as useActiveTradingAccount } from './useActiveTradingAccount';
55
export { default as useActiveWalletAccount } from './useActiveWalletAccount';
66
export { default as useAllAvailableAccounts } from './useAllAvailableAccounts';
77
export { default as useAuthorize } from './useAuthorize';
8+
export { default as useAvailableMT5Accounts } from './useAvailableMT5Accounts';
89
export { default as useAvailableWallets } from './useAvailableWallets';
910
export { default as useBalance } from './useBalance';
11+
export { default as useCFDAccountsList } from './useCFDAccountsList';
12+
export { default as useCreateMT5Account } from './useCreateMT5Account';
13+
export { default as useCreateOtherCFDAccount } from './useCreateOtherCFDAccount';
14+
export { default as useCtraderAccountsList } from './useCtraderAccountsList';
15+
export { default as useAccountStatus, default as useCtraderServiceToken } from './useCtraderServiceToken';
1016
export { default as useCurrencyConfig } from './useCurrencyConfig';
17+
export { default as useDerivezAccountsList } from './useDerivezAccountsList';
18+
export { default as useDxtradeAccountsList } from './useDxtradeAccountsList';
1119
export { default as useGetAccountStatus } from './useGetAccountStatus';
1220
export { default as useLandingCompany } from './useLandingCompany';
1321
export { default as useMT5AccountsList } from './useMT5AccountsList';
1422
export { default as useSettings } from './useSettings';
23+
export { default as useSortedMT5Accounts } from './useSortedMT5Accounts';
1524
export { default as useTradingAccountsList } from './useTradingAccountsList';
1625
export { default as useTradingPlatformAccounts } from './useTradingPlatformAccounts';
17-
export { default as useTradingPlatformAvailableAccounts } from './useTradingPlatformAvailableAccounts';
18-
export { default as useWalletAccountsList } from './useWalletAccountsList';
1926
export { default as useTradingPlatformInvestorPasswordChange } from './useTradingPlatformInvestorPasswordChange';
20-
export { default as useCreateMT5Account } from './useCreateMT5Account';
21-
export { default as useCreateOtherCFDAccount } from './useCreateOtherCFDAccount';
22-
export { default as useTradingPlatformPasswordChange } from './useTradingPlatformPasswordChange';
2327
export { default as useTradingPlatformInvestorPasswordReset } from './useTradingPlatformInvestorPasswordReset';
24-
export { default as useDxtradeAccountsList } from './useDxtradeAccountsList';
25-
export { default as useDerivezAccountsList } from './useDerivezAccountsList';
26-
export { default as useCFDAccountsList } from './useCFDAccountsList';
27-
export { default as useCtraderAccountsList } from './useCtraderAccountsList';
28-
export { default as useCtraderServiceToken } from './useCtraderServiceToken';
28+
export { default as useTradingPlatformPasswordChange } from './useTradingPlatformPasswordChange';
29+
export { default as useWalletAccountsList } from './useWalletAccountsList';
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import { useMemo } from 'react';
2+
import useGetAccountStatus from './useGetAccountStatus';
3+
4+
/** A custom hook to check the account status for the current user. */
5+
const useAccountStatus = () => {
6+
const { data: get_account_status_data, ...rest } = useGetAccountStatus();
7+
8+
// Add additional information to the account status response.
9+
const modified_account_status = useMemo(() => {
10+
if (!get_account_status_data?.status) return;
11+
12+
const status = new Set(get_account_status_data?.status);
13+
14+
return {
15+
/** Account status. */
16+
status: get_account_status_data?.status,
17+
/** client's address is verified by third party services. */
18+
is_address_verified: status.has('address_verified'),
19+
/** client is allowed to upload documents. */
20+
is_allow_document_upload: status.has('allow_document_upload'),
21+
/** client is age-verified. */
22+
is_age_verification: status.has('age_verification'),
23+
/** client is fully authenticated. */
24+
is_authenticated: status.has('authenticated'),
25+
/** cashier is locked. */
26+
is_cashier_locked: status.has('cashier_locked'),
27+
/** client has updated tax related information. */
28+
is_crs_tin_information: status.has('crs_tin_information'),
29+
/** deposit is not allowed. */
30+
is_deposit_locked: status.has('deposit_locked'),
31+
/** account is disabled. */
32+
is_disabled: status.has('disabled'),
33+
/** client's submitted proof-of-identity documents have expired. */
34+
is_document_expired: status.has('document_expired'),
35+
/** client's submitted proof-of-identity documents are expiring within a month. */
36+
is_document_expiring_soon: status.has('document_expiring_soon'),
37+
/** Deriv X password is not set. */
38+
is_dxtrade_password_not_set: status.has('dxtrade_password_not_set'),
39+
/** client should complete their financial assessment. */
40+
is_financial_assessment_not_complete: status.has('financial_assessment_not_complete'),
41+
/** client has not completed financial assessment. */
42+
is_financial_information_not_complete: status.has('financial_information_not_complete'),
43+
/** client has accepted financial risk disclosure. */
44+
is_financial_risk_approval: status.has('financial_risk_approval'),
45+
/** client has not set financial limits on their account. Applies to UK and Malta clients. */
46+
is_max_turnover_limit_not_set: status.has('max_turnover_limit_not_set'),
47+
/** MT5 password is not set. */
48+
is_mt5_password_not_set: status.has('mt5_password_not_set'),
49+
/** MT5 deposits allowed, but withdrawal is not allowed. */
50+
is_mt5_withdrawal_locked: status.has('mt5_withdrawal_locked'),
51+
/** user must approve the Affiliate's Code of Conduct Agreement. */
52+
is_needs_affiliate_coc_approval: status.has('needs_affiliate_coc_approval'),
53+
/** trading is disabled. */
54+
is_no_trading: status.has('no_trading'),
55+
/** client cannot trade or withdraw but can deposit. */
56+
is_no_withdrawal_or_trading: status.has('no_withdrawal_or_trading'),
57+
/** p2p is blocked for the current payment agent client. */
58+
is_p2p_blocked_for_pa: status.has('p2p_blocked_for_pa'),
59+
/** withdrawal through payment agent is allowed. */
60+
is_pa_withdrawal_explicitly_allowed: status.has('pa_withdrawal_explicitly_allowed'),
61+
/** this client must reset their password. */
62+
is_password_reset_required: status.has('password_reset_required'),
63+
/** this client has opted for a professional account. */
64+
is_professional: status.has('professional'),
65+
/** this client has requested for a professional account. */
66+
is_professional_requested: status.has('professional_requested'),
67+
/** this client's request for a professional account has been rejected. */
68+
is_professional_rejected: status.has('professional_rejected'),
69+
/** this client is using social signup. */
70+
is_social_signup: status.has('social_signup'),
71+
/** client has not completed the trading experience questionnaire. */
72+
is_trading_experience_not_complete: status.has('trading_experience_not_complete'),
73+
/** client has acknowledged UKGC funds protection notice. */
74+
is_ukgc_funds_protection: status.has('ukgc_funds_protection'),
75+
/** client cannot deposit or buy contracts, but can withdraw or sell contracts. */
76+
is_unwelcome: status.has('unwelcome'),
77+
/** deposits allowed but withdrawals are not allowed. */
78+
is_withdrawal_locked: status.has('withdrawal_locked'),
79+
/** this prevent a client from changing the account currency after deposit attempt. */
80+
is_deposit_attempt: status.has('deposit_attempt'),
81+
/** client POI documents name mismatch. */
82+
is_poi_name_mismatch: status.has('poi_name_mismatch'),
83+
/** the client can resubmit POA documents. */
84+
is_allow_poa_resubmission: status.has('allow_poa_resubmission'),
85+
/** the client can resubmit POI documents. */
86+
is_allow_poi_resubmission: status.has('allow_poi_resubmission'),
87+
/** the client has been sharing payment methods. */
88+
is_shared_payment_method: status.has('shared_payment_method'),
89+
/** client is not allowed to edit personal profile details. */
90+
is_personal_details_locked: status.has('personal_details_locked'),
91+
/** it block any transfer between two accounts. */
92+
is_transfers_blocked: status.has('transfers_blocked'),
93+
/** the DF deposit will be blocked until the client gets age verified. */
94+
is_df_deposit_requires_poi: status.has('df_deposit_requires_poi'),
95+
/** the client has been fully authenticated by IDV. */
96+
is_authenticated_with_idv_photoid: status.has('authenticated_with_idv_photoid'),
97+
/** the client used to be fully authenticated by IDV but it was taken away due to compliance criteria. */
98+
is_idv_revoked: status.has('idv_revoked'),
99+
};
100+
}, [get_account_status_data?.status]);
101+
102+
return {
103+
/** The account status response. */
104+
data: modified_account_status,
105+
...rest,
106+
};
107+
};
108+
109+
export default useAccountStatus;

packages/api/src/hooks/useAuthorize.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
1-
import { useEffect, useMemo } from 'react';
2-
import { getActiveAuthTokenIDFromLocalStorage } from '@deriv/utils';
1+
import { useCallback, useMemo } from 'react';
2+
import { getActiveAuthTokenIDFromLocalStorage, getActiveLoginIDFromLocalStorage } from '@deriv/utils';
33
import useFetch from '../useFetch';
4+
import useInvalidateQuery from '../useInvalidateQuery';
45

56
/** A custom hook that authorize the user with the given token. If no token is given,
67
* it will use the current token from localStorage.
78
*/
8-
const useAuthorize = (token?: string) => {
9+
const useAuthorize = () => {
910
const current_token = getActiveAuthTokenIDFromLocalStorage();
11+
const invalidate = useInvalidateQuery();
1012

1113
const { data, ...rest } = useFetch('authorize', {
12-
payload: { authorize: token || current_token || '' },
14+
payload: { authorize: current_token || '' },
1315
options: { enabled: Boolean(current_token) },
1416
});
1517

1618
// Add additional information to the authorize response.
1719
const modified_authorize = useMemo(() => ({ ...data?.authorize }), [data?.authorize]);
1820

19-
useEffect(() => {
20-
if (current_token !== token) {
21-
// Todo: Update the token in the localStorage since we are switching the current account.
22-
}
23-
}, [current_token, token]);
21+
const switchAccount = useCallback(
22+
(loginid: string) => {
23+
const active_loginid = getActiveLoginIDFromLocalStorage();
24+
if (active_loginid !== loginid) {
25+
localStorage.setItem('active_loginid', loginid);
26+
invalidate('authorize');
27+
}
28+
},
29+
[invalidate]
30+
);
2431

2532
return {
2633
/** The authorize response. */
2734
data: modified_authorize,
35+
/** Function to switch to another account */
36+
switchAccount,
2837
...rest,
2938
};
3039
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useMemo } from 'react';
2+
import useFetch from '../useFetch';
3+
4+
/** @description This hook is used to get all the available MT5 accounts. */
5+
const useAvailableMT5Accounts = () => {
6+
const { data: mt5_available_accounts, ...rest } = useFetch('trading_platform_available_accounts', {
7+
payload: { platform: 'mt5' },
8+
});
9+
10+
const modified_mt5_available_accounts = useMemo(
11+
() =>
12+
mt5_available_accounts?.trading_platform_available_accounts?.map(account => {
13+
return {
14+
...account,
15+
market_type: account.market_type === 'gaming' ? 'synthetic' : account.market_type,
16+
} as const;
17+
}),
18+
[mt5_available_accounts?.trading_platform_available_accounts]
19+
);
20+
21+
return {
22+
/** The available MT5 accounts grouped by market type */
23+
data: modified_mt5_available_accounts,
24+
...rest,
25+
};
26+
};
27+
28+
export default useAvailableMT5Accounts;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { useMemo } from 'react';
2+
import useMT5AccountsList from './useMT5AccountsList';
3+
import useAvailableMT5Accounts from './useAvailableMT5Accounts';
4+
5+
const useSortedMT5Accounts = () => {
6+
const { data: all_available_mt5_accounts } = useAvailableMT5Accounts();
7+
const { data: mt5_accounts, ...rest } = useMT5AccountsList();
8+
9+
const modified_data = useMemo(() => {
10+
if (!all_available_mt5_accounts || !mt5_accounts) return;
11+
12+
return all_available_mt5_accounts?.map(available_account => {
13+
const created_account = mt5_accounts?.find(account => {
14+
return (
15+
available_account.market_type === account.market_type &&
16+
available_account.shortcode === account.landing_company_short
17+
);
18+
});
19+
if (created_account)
20+
return {
21+
...created_account,
22+
/** Determine if the account is added or not */
23+
is_added: true,
24+
} as const;
25+
26+
return {
27+
...available_account,
28+
/** Determine if the account is added or not */
29+
is_added: false,
30+
} as const;
31+
});
32+
}, [all_available_mt5_accounts, mt5_accounts]);
33+
34+
// // Reduce out the added and non added accounts to make sure only one of each market_type is shown for not added
35+
const filtered_data = useMemo(() => {
36+
if (!modified_data) return;
37+
38+
const added_accounts = modified_data.filter(account => account.is_added);
39+
const non_added_accounts = modified_data.filter(account => !account.is_added);
40+
41+
const filtered_non_added_accounts = non_added_accounts.reduce((acc, account) => {
42+
const existing_account = acc.find(acc_account => acc_account.market_type === account.market_type);
43+
const added_account = added_accounts.find(acc_account => acc_account.market_type === account.market_type);
44+
if (existing_account || added_account) return acc;
45+
46+
return [...acc, account];
47+
}, [] as typeof non_added_accounts);
48+
49+
return [...added_accounts, ...filtered_non_added_accounts];
50+
}, [modified_data]);
51+
52+
// Sort the data by market_type to make sure the order is 'synthetic', 'financial', 'all'
53+
const sorted_data = useMemo(() => {
54+
const market_type_order = ['synthetic', 'financial', 'all'];
55+
56+
if (!filtered_data) return;
57+
58+
const sorted_data = market_type_order.reduce((acc, market_type) => {
59+
const accounts = filtered_data.filter(account => account.market_type === market_type);
60+
if (!accounts.length) return acc;
61+
return [...acc, ...accounts];
62+
}, [] as typeof filtered_data);
63+
64+
return sorted_data;
65+
}, [filtered_data]);
66+
67+
return {
68+
data: sorted_data,
69+
...rest,
70+
};
71+
};
72+
73+
export default useSortedMT5Accounts;

packages/api/src/hooks/useTradingPlatformAvailableAccounts.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/appstore/src/components/cfds-listing/cfds-listing.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,23 @@
558558
}
559559
}
560560
}
561+
&-ctrader {
562+
&-container {
563+
display: flex;
564+
flex-direction: column;
565+
margin-top: 4rem;
566+
margin-bottom: 6rem;
567+
@include mobile {
568+
margin-top: 5rem;
569+
margin-bottom: 0;
570+
}
571+
}
572+
&__banner-text {
573+
display: flex;
574+
flex-direction: column;
575+
}
576+
}
577+
561578
&--windows {
562579
display: flex;
563580
gap: 1.6rem;

packages/bot-web-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@datadog/browser-logs": "^4.36.0",
7171
"@deriv/bot-skeleton": "^1.0.0",
7272
"@deriv/components": "^1.0.0",
73-
"@deriv/deriv-charts": "1.3.2",
73+
"@deriv/deriv-charts": "1.3.5",
7474
"@deriv/shared": "^1.0.0",
7575
"@deriv/stores": "^1.0.0",
7676
"@deriv/translations": "^1.0.0",

packages/cfd/src/Containers/mt5-trade-modal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ type TMT5TradeModalProps = {
2323

2424
const MT5TradeModal = observer(
2525
({ is_eu_user, is_open, onPasswordManager, toggleModal, is_demo }: TMT5TradeModalProps) => {
26-
const { traders_hub, common } = useStore();
26+
const { traders_hub, common, ui } = useStore();
2727

2828
const { show_eu_related_content } = traders_hub;
2929
const { platform } = common;
30+
const { is_mobile } = ui;
3031

3132
const { mt5_trade_account, dxtrade_tokens, derivez_tokens, ctrader_tokens } = useCfdStore();
3233

@@ -52,6 +53,7 @@ const MT5TradeModal = observer(
5253
ctrader_tokens={ctrader_tokens}
5354
dxtrade_tokens={dxtrade_tokens}
5455
derivez_tokens={derivez_tokens}
56+
is_mobile={is_mobile}
5557
/>
5658
);
5759
};

0 commit comments

Comments
 (0)