From a5b6fb4cef59128c58946b00f3d29a959460e741 Mon Sep 17 00:00:00 2001 From: Muhammad Hamza <120543468+hamza-deriv@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:14:56 +0800 Subject: [PATCH 01/28] Hamza/chore: added pandats service token (#10269) * chore: added pandats service token * chore: include hook in index file * chore: rearrange the import statements --- packages/api/src/hooks/index.ts | 1 + .../api/src/hooks/useDerivezAccountsList.ts | 5 ++++- .../api/src/hooks/useDerivezServiceToken.ts | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 packages/api/src/hooks/useDerivezServiceToken.ts diff --git a/packages/api/src/hooks/index.ts b/packages/api/src/hooks/index.ts index 3f328346ec76..532f4c70681c 100644 --- a/packages/api/src/hooks/index.ts +++ b/packages/api/src/hooks/index.ts @@ -32,3 +32,4 @@ export { default as useTradingPlatformInvestorPasswordReset } from './useTrading export { default as useTradingPlatformPasswordChange } from './useTradingPlatformPasswordChange'; export { default as useTransferBetweenAccounts } from './useTransferBetweenAccounts'; export { default as useWalletAccountsList } from './useWalletAccountsList'; +export { default as useDerivezServiceToken } from './useDerivezServiceToken'; diff --git a/packages/api/src/hooks/useDerivezAccountsList.ts b/packages/api/src/hooks/useDerivezAccountsList.ts index 57e9b37fe27e..e5a361276b00 100644 --- a/packages/api/src/hooks/useDerivezAccountsList.ts +++ b/packages/api/src/hooks/useDerivezAccountsList.ts @@ -1,4 +1,5 @@ import { useMemo } from 'react'; +import useDerivezServiceToken from './useDerivezServiceToken'; import useFetch from '../useFetch'; /** A custom hook that gets the list of created DerivEz accounts. */ @@ -6,6 +7,7 @@ const useDerivezAccountsList = () => { const { data: derivez_accounts } = useFetch('trading_platform_accounts', { payload: { platform: 'derivez' }, }); + const { data: token } = useDerivezServiceToken(); /** Adding neccesary properties to DerivEz accounts */ const modified_derivez_accounts = useMemo( @@ -13,8 +15,9 @@ const useDerivezAccountsList = () => { derivez_accounts?.trading_platform_accounts?.map(account => ({ ...account, loginid: account.account_id, + token, })), - [derivez_accounts?.trading_platform_accounts] + [derivez_accounts?.trading_platform_accounts, token] ); return { diff --git a/packages/api/src/hooks/useDerivezServiceToken.ts b/packages/api/src/hooks/useDerivezServiceToken.ts new file mode 100644 index 000000000000..4eabdd8b0d84 --- /dev/null +++ b/packages/api/src/hooks/useDerivezServiceToken.ts @@ -0,0 +1,18 @@ +import useActiveAccount from './useActiveAccount'; +import useFetch from '../useFetch'; + +/** A custom hook that get Service Token for DerivEz Platform. */ +const useDerivezServiceToken = () => { + const { data: account } = useActiveAccount(); + const { data: derivez_token, ...rest } = useFetch('service_token', { + payload: { service: 'pandats', server: account?.is_virtual ? 'demo' : 'real' }, + }); + + return { + /** return the DerivEz account token */ + data: derivez_token?.service_token?.pandats?.token, + ...rest, + }; +}; + +export default useDerivezServiceToken; From a5eba9f00c9dad431fd8e89af7ed55558f20acfc Mon Sep 17 00:00:00 2001 From: thisyahlen <104053934+thisyahlen-deriv@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:28:13 +0800 Subject: [PATCH 02/28] thisyahlen/chore: api hooks cleanup (#10270) * chore: api hooks cleanup * chore: more cleanup --- packages/api/src/hooks/index.ts | 1 - packages/api/src/hooks/useAccountTypes.ts | 4 +- .../api/src/hooks/useAvailableMT5Accounts.ts | 5 +- packages/api/src/hooks/useAvailableWallets.ts | 3 +- packages/api/src/hooks/useCreateMT5Account.ts | 2 +- .../api/src/hooks/useCreateOtherCFDAccount.ts | 4 +- .../api/src/hooks/useCtraderAccountsList.ts | 4 +- .../api/src/hooks/useDepositCryptoAddress.ts | 1 + .../api/src/hooks/useDepositFiatAddress.ts | 1 + .../api/src/hooks/useDerivezAccountsList.ts | 4 +- .../api/src/hooks/useDxtradeAccountsList.ts | 2 +- packages/api/src/hooks/useMT5AccountsList.ts | 4 ++ .../api/src/hooks/useSortedMT5Accounts.ts | 1 + .../src/hooks/useTradingPlatformAccounts.ts | 48 ------------------- packages/hooks/src/useCFDAllAccounts.ts | 2 +- 15 files changed, 25 insertions(+), 61 deletions(-) delete mode 100644 packages/api/src/hooks/useTradingPlatformAccounts.ts diff --git a/packages/api/src/hooks/index.ts b/packages/api/src/hooks/index.ts index 532f4c70681c..a6c1e0669620 100644 --- a/packages/api/src/hooks/index.ts +++ b/packages/api/src/hooks/index.ts @@ -26,7 +26,6 @@ export { default as useMT5AccountsList } from './useMT5AccountsList'; export { default as useSettings } from './useSettings'; export { default as useSortedMT5Accounts } from './useSortedMT5Accounts'; export { default as useTradingAccountsList } from './useTradingAccountsList'; -export { default as useTradingPlatformAccounts } from './useTradingPlatformAccounts'; export { default as useTradingPlatformInvestorPasswordChange } from './useTradingPlatformInvestorPasswordChange'; export { default as useTradingPlatformInvestorPasswordReset } from './useTradingPlatformInvestorPasswordReset'; export { default as useTradingPlatformPasswordChange } from './useTradingPlatformPasswordChange'; diff --git a/packages/api/src/hooks/useAccountTypes.ts b/packages/api/src/hooks/useAccountTypes.ts index aa0fb603e690..e75f11f825db 100644 --- a/packages/api/src/hooks/useAccountTypes.ts +++ b/packages/api/src/hooks/useAccountTypes.ts @@ -1,9 +1,7 @@ import { useMemo } from 'react'; import useFetch from '../useFetch'; -/** - * A custom hook to get available account types for a specific landing company. - */ +/** A custom hook to get available account types for a specific landing company. */ const useAccountTypes = (landing_company?: string) => { const { data, ...rest } = useFetch('get_account_types', { payload: { company: landing_company }, diff --git a/packages/api/src/hooks/useAvailableMT5Accounts.ts b/packages/api/src/hooks/useAvailableMT5Accounts.ts index 44680f2e12f6..e290f40b95f2 100644 --- a/packages/api/src/hooks/useAvailableMT5Accounts.ts +++ b/packages/api/src/hooks/useAvailableMT5Accounts.ts @@ -7,7 +7,7 @@ const market_type_to_leverage_mapper: Record = { all: 100, }; -/** @description This hook is used to get all the available MT5 accounts. */ +/** A custom hook to get the list of available MT5 accounts. */ const useAvailableMT5Accounts = () => { const { data: mt5_available_accounts, ...rest } = useFetch('trading_platform_available_accounts', { payload: { platform: 'mt5' }, @@ -18,8 +18,11 @@ const useAvailableMT5Accounts = () => { mt5_available_accounts?.trading_platform_available_accounts?.map(account => { return { ...account, + /** The market type for the account */ market_type: account.market_type === 'gaming' ? 'synthetic' : account.market_type, + /** The platform for the account */ platform: 'mt5', + /** Leverage for the account */ leverage: market_type_to_leverage_mapper[ account.market_type as keyof typeof market_type_to_leverage_mapper diff --git a/packages/api/src/hooks/useAvailableWallets.ts b/packages/api/src/hooks/useAvailableWallets.ts index 24de344565b4..1a395679998b 100644 --- a/packages/api/src/hooks/useAvailableWallets.ts +++ b/packages/api/src/hooks/useAvailableWallets.ts @@ -3,6 +3,7 @@ import useAllAvailableAccounts from './useAllAvailableAccounts'; import useCurrencyConfig from './useCurrencyConfig'; import useWalletAccountsList from './useWalletAccountsList'; +/** A custom hook that gets the list of available wallets. */ const useAvailableWallets = () => { const { data: account_type_data, ...rest } = useAllAvailableAccounts(); const { data: added_wallets } = useWalletAccountsList(); @@ -44,7 +45,7 @@ const useAvailableWallets = () => { const getConfigIsCrypto = (currency: string) => getConfig(currency)?.is_crypto; - // Sort the unadded wallets alphabetically by fiat, crypto, then virtual + // Sort the non-added wallets alphabetically by fiat, crypto, then virtual modified_available_wallets.sort((a, b) => { const a_config = getConfigIsCrypto(a.currency || 'BTC'); const b_config = getConfigIsCrypto(b.currency || 'BTC'); diff --git a/packages/api/src/hooks/useCreateMT5Account.ts b/packages/api/src/hooks/useCreateMT5Account.ts index 883d37f54f53..2c88e0973d5b 100644 --- a/packages/api/src/hooks/useCreateMT5Account.ts +++ b/packages/api/src/hooks/useCreateMT5Account.ts @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import useRequest from '../useRequest'; import useInvalidateQuery from '../useInvalidateQuery'; -/** A custom hook that creates the MT5 account. */ +/** A custom hook to create MT5 accounts. */ const useCreateMT5Account = () => { const invalidate = useInvalidateQuery(); const { data, ...rest } = useRequest('mt5_new_account', { diff --git a/packages/api/src/hooks/useCreateOtherCFDAccount.ts b/packages/api/src/hooks/useCreateOtherCFDAccount.ts index a44b2f0abee5..6b9de9d589ff 100644 --- a/packages/api/src/hooks/useCreateOtherCFDAccount.ts +++ b/packages/api/src/hooks/useCreateOtherCFDAccount.ts @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import useRequest from '../useRequest'; import useInvalidateQuery from '../useInvalidateQuery'; -/** A custom hook that creates the Other CFD account. */ +/** A custom hook to create third party CFD accounts. */ const useCreateOtherCFDAccount = () => { const invalidate = useInvalidateQuery(); const { data, ...rest } = useRequest('trading_platform_new_account', { @@ -20,7 +20,7 @@ const useCreateOtherCFDAccount = () => { }, [data]); return { - /** The response and the mutation of the create Other CFD account API request */ + /** The response and the mutation of the create third party CFDs API request */ data: modified_data, ...rest, }; diff --git a/packages/api/src/hooks/useCtraderAccountsList.ts b/packages/api/src/hooks/useCtraderAccountsList.ts index e54709f0bfc9..1a6da2c46a3d 100644 --- a/packages/api/src/hooks/useCtraderAccountsList.ts +++ b/packages/api/src/hooks/useCtraderAccountsList.ts @@ -14,7 +14,9 @@ const useCtraderAccountsList = () => { () => ctrader_accounts?.trading_platform_accounts?.map(account => ({ ...account, - loginid: account.account_id, + /** The id of the cTrader account */ + id: account.account_id, + /** The token of the cTrader account */ token, })), [ctrader_accounts?.trading_platform_accounts, token] diff --git a/packages/api/src/hooks/useDepositCryptoAddress.ts b/packages/api/src/hooks/useDepositCryptoAddress.ts index 2b3ae526f461..9c8bc439aa13 100644 --- a/packages/api/src/hooks/useDepositCryptoAddress.ts +++ b/packages/api/src/hooks/useDepositCryptoAddress.ts @@ -1,6 +1,7 @@ import { useCallback } from 'react'; import useRequest from '../useRequest'; +/** A custom hook to get the deposit crypto address. */ const useDepositCryptoAddress = () => { const { data, mutate: _mutate, ...rest } = useRequest('cashier'); const deposit_address = typeof data?.cashier !== 'string' ? data?.cashier?.deposit?.address : undefined; diff --git a/packages/api/src/hooks/useDepositFiatAddress.ts b/packages/api/src/hooks/useDepositFiatAddress.ts index d6a829341ca7..c0f49dfcf2e9 100644 --- a/packages/api/src/hooks/useDepositFiatAddress.ts +++ b/packages/api/src/hooks/useDepositFiatAddress.ts @@ -1,6 +1,7 @@ import { useCallback } from 'react'; import useRequest from '../useRequest'; +/** A custom hook to get the deposit fiat address. */ const useDepositFiatAddress = () => { const { data, mutate: _mutate, ...rest } = useRequest('cashier'); const deposit_iframe_url = typeof data?.cashier === 'string' ? data?.cashier : undefined; diff --git a/packages/api/src/hooks/useDerivezAccountsList.ts b/packages/api/src/hooks/useDerivezAccountsList.ts index e5a361276b00..5fc96b085e48 100644 --- a/packages/api/src/hooks/useDerivezAccountsList.ts +++ b/packages/api/src/hooks/useDerivezAccountsList.ts @@ -9,12 +9,14 @@ const useDerivezAccountsList = () => { }); const { data: token } = useDerivezServiceToken(); - /** Adding neccesary properties to DerivEz accounts */ + /** Adding necessary properties to DerivEz accounts */ const modified_derivez_accounts = useMemo( () => derivez_accounts?.trading_platform_accounts?.map(account => ({ ...account, + /** The id for the account */ loginid: account.account_id, + /** The token for the account */ token, })), [derivez_accounts?.trading_platform_accounts, token] diff --git a/packages/api/src/hooks/useDxtradeAccountsList.ts b/packages/api/src/hooks/useDxtradeAccountsList.ts index b13b6d536d97..4230b38835e0 100644 --- a/packages/api/src/hooks/useDxtradeAccountsList.ts +++ b/packages/api/src/hooks/useDxtradeAccountsList.ts @@ -9,7 +9,7 @@ const useDxtradeAccountsList = () => { payload: { platform: 'dxtrade' }, }); - /** Adding neccesary properties to Deriv X accounts */ + /** Adding necessary properties to Deriv X accounts */ const modified_dxtrade_accounts = useMemo( () => dxtrade_accounts?.trading_platform_accounts?.map(account => ({ diff --git a/packages/api/src/hooks/useMT5AccountsList.ts b/packages/api/src/hooks/useMT5AccountsList.ts index 0c289221bff5..3cfc463640a5 100644 --- a/packages/api/src/hooks/useMT5AccountsList.ts +++ b/packages/api/src/hooks/useMT5AccountsList.ts @@ -15,7 +15,9 @@ const useMT5AccountsList = () => { /** Adding the neccesary properties to the response */ const getAccountInfo = (login?: string) => { return { + /** The platform of the account linked to the wallet */ platform: wallet?.linked_to?.find(linked => linked.loginid === login)?.platform, + /** The formatted display login of the account */ display_login: login?.replace(/^(MT[DR]?)/, ''), }; }; @@ -23,7 +25,9 @@ const useMT5AccountsList = () => { return mt5_accounts?.mt5_login_list?.map(account => ({ ...account, ...getAccountInfo(account.login), + /** The id of the account */ loginid: account.login, + /** The platform of the account */ platform: 'mt5', })); }, [mt5_accounts?.mt5_login_list, wallet?.linked_to]); diff --git a/packages/api/src/hooks/useSortedMT5Accounts.ts b/packages/api/src/hooks/useSortedMT5Accounts.ts index 1a1507890abc..9ca03c57bb7e 100644 --- a/packages/api/src/hooks/useSortedMT5Accounts.ts +++ b/packages/api/src/hooks/useSortedMT5Accounts.ts @@ -2,6 +2,7 @@ import { useMemo } from 'react'; import useMT5AccountsList from './useMT5AccountsList'; import useAvailableMT5Accounts from './useAvailableMT5Accounts'; +/** A custom hook to get the sorted added and non-added MT5 accounts. */ const useSortedMT5Accounts = () => { const { data: all_available_mt5_accounts } = useAvailableMT5Accounts(); const { data: mt5_accounts, ...rest } = useMT5AccountsList(); diff --git a/packages/api/src/hooks/useTradingPlatformAccounts.ts b/packages/api/src/hooks/useTradingPlatformAccounts.ts deleted file mode 100644 index 39e3d91d1f51..000000000000 --- a/packages/api/src/hooks/useTradingPlatformAccounts.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { useMemo } from 'react'; -import useFetch from '../useFetch'; - -/** A custom hook that gets the list of created other CFD accounts. */ -const useTradingPlatformAccounts = () => { - const { data: derivez_accounts, ...derivez_rest } = useFetch('trading_platform_accounts', { - payload: { platform: 'derivez' }, - }); - const { data: dxtrade_accounts, ...dxtrade_rest } = useFetch('trading_platform_accounts', { - payload: { platform: 'dxtrade' }, - }); - - /** Adding neccesary properties to derivez accounts */ - const modified_derivez_accounts = useMemo( - () => - derivez_accounts?.trading_platform_accounts?.map(account => ({ - ...account, - loginid: account.login, - })), - [derivez_accounts?.trading_platform_accounts] - ); - - /** Adding neccesary properties to dxtrade accounts */ - const modified_dxtrade_accounts = useMemo( - () => - dxtrade_accounts?.trading_platform_accounts?.map(account => ({ - ...account, - loginid: account.account_id, - })), - [dxtrade_accounts?.trading_platform_accounts] - ); - - const data = useMemo( - () => ({ - dxtrade_accounts: modified_dxtrade_accounts || [], - derivez_accounts: modified_derivez_accounts || [], - }), - [modified_dxtrade_accounts, modified_derivez_accounts] - ); - - return { - /** List of all created other CFD accounts */ - data, - ...{ ...derivez_rest, ...dxtrade_rest }, - }; -}; - -export default useTradingPlatformAccounts; diff --git a/packages/hooks/src/useCFDAllAccounts.ts b/packages/hooks/src/useCFDAllAccounts.ts index 109f4a202ba4..da32cccbabbf 100644 --- a/packages/hooks/src/useCFDAllAccounts.ts +++ b/packages/hooks/src/useCFDAllAccounts.ts @@ -1,6 +1,6 @@ import { useStore } from '@deriv/stores'; -/** @deprecated Use `useMT5LoginList` for MT5 accounts and `useTradingPlatformAccounts` for Other CFD accounts from `@deriv/api` instead. */ +/** @deprecated Use `useMT5AccountsList` for MT5 accounts and `useDxtradeAccountsList` for Other CFD accounts from `@deriv/api` instead. */ const useCFDAllAccounts = () => { const { client } = useStore(); const { dxtrade_accounts_list, mt5_login_list, derivez_accounts_list, ctrader_accounts_list } = client; From b41492b2231eb5200f8e3ce4aac31468ec3ac34e Mon Sep 17 00:00:00 2001 From: Likhith Kolayari <98398322+likhith-deriv@users.noreply.github.com> Date: Mon, 25 Sep 2023 10:54:44 +0400 Subject: [PATCH 03/28] fix: resolved routing (#10256) --- .../account/src/Containers/Account/page-overlay-wrapper.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/Containers/Account/page-overlay-wrapper.tsx b/packages/account/src/Containers/Account/page-overlay-wrapper.tsx index 658edbe162bc..5ebe2f3be6b1 100644 --- a/packages/account/src/Containers/Account/page-overlay-wrapper.tsx +++ b/packages/account/src/Containers/Account/page-overlay-wrapper.tsx @@ -24,7 +24,7 @@ const PageOverlayWrapper = observer(({ routes, subroutes }: PageOverlayWrapperPr const { client, common, ui } = useStore(); const { is_mobile } = ui; const { logout } = client; - const { is_from_derivgo, routeBackInApp } = common; + const { is_from_derivgo } = common; const list_groups = routes.map(route_group => ({ icon: route_group.icon, @@ -32,7 +32,7 @@ const PageOverlayWrapper = observer(({ routes, subroutes }: PageOverlayWrapperPr subitems: route_group?.subroutes?.length ? route_group.subroutes.map(sub => subroutes.indexOf(sub)) : [], })); - const onClickClose = React.useCallback(() => routeBackInApp(history), [routeBackInApp, history]); + const onClickClose = React.useCallback(() => history.push(shared_routes.traders_hub), [history]); const selected_route = getSelectedRoute({ routes: subroutes as Array, pathname: location.pathname }); From 4434de854502a51b9839e145f8e907c1b5bd3e7a Mon Sep 17 00:00:00 2001 From: yashim-deriv Date: Mon, 25 Sep 2023 15:41:41 +0800 Subject: [PATCH 04/28] yashim/fix: radio button (#10277) --- .../Components/currency-selector/radio-button.tsx | 3 ++- packages/api/src/hooks/usePOIStatus.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 packages/api/src/hooks/usePOIStatus.ts diff --git a/packages/account/src/Components/currency-selector/radio-button.tsx b/packages/account/src/Components/currency-selector/radio-button.tsx index 6c3a214b3c9f..903646d0dfe4 100644 --- a/packages/account/src/Components/currency-selector/radio-button.tsx +++ b/packages/account/src/Components/currency-selector/radio-button.tsx @@ -63,6 +63,7 @@ const RadioButton = ({ label, second_line_label, onClick, + className, ...props }: TRadioButton) => { return ( @@ -76,7 +77,7 @@ const RadioButton = ({ onChange={onChange} onBlur={onBlur} disabled={props.selected} - className={classNames('currency-list__radio-button')} + className={classNames(className, 'currency-list__radio-button')} {...props} />