Skip to content

Commit

Permalink
Merge branch 'binary-com:master' into migrate_svg_to_bvi_dvl
Browse files Browse the repository at this point in the history
  • Loading branch information
shaheer-deriv committed Sep 19, 2023
2 parents ed58be9 + 5f0713a commit 3a251f9
Show file tree
Hide file tree
Showing 96 changed files with 2,146 additions and 3,837 deletions.
4 changes: 2 additions & 2 deletions packages/account/src/Components/Routes/binary-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const BinaryRoutes = (props: TBinaryRoutes) => {
}
>
<Switch>
{getRoutesConfig({ is_appstore }).map((route: TRoute) => (
<RouteWithSubRoutes key={`${route.getTitle?.()}-${route.path}`} {...route} {...props} />
{getRoutesConfig({ is_appstore }).map((route: TRoute, idx: number) => (
<RouteWithSubRoutes key={idx} {...route} {...props} />
))}
</Switch>
</React.Suspense>
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export { default as useDxtradeAccountsList } from './useDxtradeAccountsList';
export { default as useDerivezAccountsList } from './useDerivezAccountsList';
export { default as useCFDAccountsList } from './useCFDAccountsList';
export { default as useCtraderAccountsList } from './useCtraderAccountsList';
export { default as useCtraderServiceToken } from './useCtraderServiceToken';
12 changes: 6 additions & 6 deletions packages/api/src/hooks/useAvailableWallets.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import useWalletAccountsList from './useWalletAccountsList';
import useCurrencyConfig from './useCurrencyConfig';
import { useMemo } from 'react';
import useAllAvailableAccounts from './useAllAvailableAccounts';
import useCurrencyConfig from './useCurrencyConfig';
import useWalletAccountsList from './useWalletAccountsList';

const useAvailableWallets = () => {
const { data: account_type_data } = useAllAvailableAccounts();
const { data: added_wallets } = useWalletAccountsList();
const { getConfig } = useCurrencyConfig();

/** Get the available wallets for the wallet account type */
const modified_available_wallets = React.useMemo(() => {
const modified_available_wallets = useMemo(() => {
if (!account_type_data) return;
const { crypto, doughflow } = account_type_data?.wallet || {};
const crypto_currencies = crypto?.currencies;
Expand All @@ -35,11 +35,11 @@ const useAvailableWallets = () => {
is_added: false,
}));

return [...available_wallets, ...modified_wallets];
return [...available_wallets, ...(modified_wallets || [])];
}, [account_type_data, added_wallets]);

/** Sort the available wallets by fiat, crypto, then virtual */
const sorted_available_wallets = React.useMemo(() => {
const sorted_available_wallets = useMemo(() => {
if (!modified_available_wallets) return;

const getConfigIsCrypto = (currency: string) => getConfig(currency)?.is_crypto;
Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { useMemo } from 'react';
import useFetch from '../useFetch';
import useAuthorize from './useAuthorize';

/** A custom hook that gets the balance for all the user accounts. */
const useBalance = () => {
const { isSuccess } = useAuthorize();
const { data: balance_data, ...rest } = useFetch('balance', {
payload: { account: 'all' },
options: { refetchInterval: 30000 }, // Refetch every 30 seconds to simulate subscription.
options: {
enabled: isSuccess,
refetchInterval: 30000, // Refetch every 30 seconds to simulate subscription.
},
});

// Add additional information to the balance data.
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/hooks/useCreateOtherCFDAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const useCreateOtherCFDAccount = () => {
const { data, ...rest } = useRequest('trading_platform_new_account', {
onSuccess: () => {
invalidate('trading_platform_accounts');
invalidate('service_token');
},
});

Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/hooks/useCtraderAccountsList.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { useMemo } from 'react';
import useCtraderServiceToken from './useCtraderServiceToken';
import useFetch from '../useFetch';

/** A custom hook that gets the list of created cTrader accounts. */
const useCtraderAccountsList = () => {
const { data: ctrader_accounts } = useFetch('trading_platform_accounts', {
payload: { platform: 'ctrader' },
});
const { data: token } = useCtraderServiceToken();

/** Adding neccesary properties to cTrader accounts */
const modified_ctrader_accounts = useMemo(
() =>
ctrader_accounts?.trading_platform_accounts?.map(account => ({
...account,
loginid: account.account_id,
token,
})),
[ctrader_accounts?.trading_platform_accounts]
[ctrader_accounts?.trading_platform_accounts, token]
);

return {
Expand Down
18 changes: 18 additions & 0 deletions packages/api/src/hooks/useCtraderServiceToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import useFetch from '../useFetch';
import useActiveAccount from './useActiveAccount';

/** A custom hook that get Service Token for CTrader Platform. */
const useCtraderServiceToken = () => {
const { data: account } = useActiveAccount();
const { data: ctrader_token, ...rest } = useFetch('service_token', {
payload: { service: 'ctrader', server: account?.is_virtual ? 'demo' : 'real' },
});

return {
/** return the ctrader account token */
data: ctrader_token?.service_token?.ctrader?.token,
...rest,
};
};

export default useCtraderServiceToken;
10 changes: 8 additions & 2 deletions packages/api/src/hooks/useDxtradeAccountsList.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useMemo } from 'react';
import useFetch from '../useFetch';
import useAuthorize from './useAuthorize';

/** A custom hook that gets the list of created Deriv X accounts. */
const useDxtradeAccountsList = () => {
const { data: authorize_data } = useAuthorize();
const { data: dxtrade_accounts } = useFetch('trading_platform_accounts', {
payload: { platform: 'dxtrade' },
});
Expand All @@ -12,9 +14,13 @@ const useDxtradeAccountsList = () => {
() =>
dxtrade_accounts?.trading_platform_accounts?.map(account => ({
...account,
loginid: account.account_id,
display_balance: Intl.NumberFormat(authorize_data?.preferred_language || 'en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
minimumIntegerDigits: 1,
}).format(account?.balance || 0),
})),
[dxtrade_accounts?.trading_platform_accounts]
[authorize_data?.preferred_language, dxtrade_accounts?.trading_platform_accounts]
);

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/hooks/useWalletAccountsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const useWalletAccountsList = () => {

// Sort wallet accounts alphabetically by fiat, crypto, then virtual.
const sorted_accounts = useMemo(() => {
if (!modified_accounts) return [];
if (!modified_accounts) return;

return [...modified_accounts].sort((a, b) => {
if (a.is_virtual !== b.is_virtual) {
Expand Down
141 changes: 141 additions & 0 deletions packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,147 @@ import type {
import type { useMutation, useQuery } from '@tanstack/react-query';

type TPrivateSocketEndpoints = {
service_token: {
request: {
/**
* Must be `1`
*/
service_token: 1;
/**
* [Optional] The 2-letter country code.
*/
country?: string;
/**
* [Optional] The URL of the web page where the Web SDK will be used.
*/
referrer?: string;
/**
* Server (dxtrade and derivez).
*/
server?: 'demo' | 'real';
/**
* The service(s) to retrieve token(s) for.
*/
service:
| ('onfido' | 'sendbird' | 'banxa' | 'wyre' | 'dxtrade' | 'pandats' | 'ctrader')
| ('onfido' | 'sendbird' | 'banxa' | 'wyre' | 'pandats')[];
/**
* [Optional] Used to pass data through the websocket, which may be retrieved via the `echo_req` output field. Maximum size is 3500 bytes.
*/
passthrough?: {
[k: string]: unknown;
};
/**
* [Optional] Used to map request to response.
*/
req_id?: number;
};
response: {
/**
* Service specific tokens and data.
*/
service_token?: {
/**
* Banxa order data.
*/
banxa?: {
/**
* Created order id reference token.
*/
token?: string;
/**
* Banxa order checkout url.
*/
url?: string;
/**
* Banxa order checkout iframe url.
*/
url_iframe?: string;
};
/**
* CTrader data.
*/
ctrader?: {
/**
* CTrader One Time token
*/
token?: string;
};
/**
* Deriv X data.
*/
dxtrade?: {
/**
* Deriv X login token.
*/
token?: string;
};
/**
* Onfido data.
*/
onfido?: {
/**
* Onfido token.
*/
token?: string;
};
/**
* Deriv EZ data.
*/
pandats?: {
/**
* Deriv EZ SSO token
*/
token?: string;
};
/**
* Sendbird data.
*/
sendbird?: {
/**
* Sendbird application ID.
*/
app_id?: string;
/**
* The epoch time in which the token will be expired. Note: the token could be expired sooner than this, due to different reasons.
*/
expiry_time?: number;
/**
* Sendbird token.
*/
token?: string;
};
/**
* Wyre reservation data.
*/
wyre?: {
/**
* Wyre reservation id token
*/
token?: string;
/**
* Wyre reservation URL
*/
url?: string;
};
};
};
/**
* Echo of the request made.
*/
echo_req: {
[k: string]: unknown;
};
/**
* Action name of the request made.
*/
msg_type: 'service_token';
/**
* Optional field sent in request to map to response, present only when request contains `req_id`.
*/
req_id?: number;
[k: string]: unknown;
};
trading_platform_investor_password_reset: {
request: {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/cfd/src/Helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const getTitle = (market_type: string, is_eu_user: boolean) => {
const REAL_DXTRADE_URL = 'https://dx.deriv.com';
const DEMO_DXTRADE_URL = 'https://dx-demo.deriv.com';

const CTRADER_DESKTOP_DOWNLOAD = 'https://deriv.ctrader.com/cbrokerdemo-deriv-setup.exe';
const CTRADER_DESKTOP_DOWNLOAD = 'https://getctrader.com/deriv/ctrader-deriv-setup.exe';

const CTRADER_DOWNLOAD_LINK = 'https://ctrader.com/download/';

Expand Down
2 changes: 1 addition & 1 deletion packages/p2p/crowdin/messages.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/p2p/scripts/extract-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getStringsFromInput = (input, i18n_marker = getRegexPattern()) => {
};

const getTranslatableFiles = () => {
const globs = ['**/*.js', '**/*.jsx'];
const globs = ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx'];
const file_paths = [];

for (let j = 0; j < globs.length; j++) {
Expand Down
Loading

0 comments on commit 3a251f9

Please sign in to comment.