Skip to content

Commit

Permalink
george / wall-1177 / Demo transfer insufficient funds error (#9211)
Browse files Browse the repository at this point in the history
* feat: add demo transfer error handlers, add useTransferBetweenAccounts hook

* fix: types errors

* fix: commit

* feat: add transfer hooks

* test: add tests

* fix: commit

* feat: 🎨 refactor code, add useActiveCFDAccounts hook

* chore: remove comment

* refactor: 🔥 cleanup

* fix: useAvaliableWallets hook

* fix: typescript errors

* test: add tests, apply comments

* test: add test, add test accounts

* test: fix tests

* fix: fix ts errors

* fix: apply comments

* perf: small improvement

* perf: small improvement

* fix: resolve conflicts

* refactor: improve logic, fix test

* chore: remove unused import

* feat: add reset balance button handler

* fix: currency register

* style: fix styles in dark mode

* test: fix test

* perf: minor improvements

* refactor: ⚡ transfer account data transfarmation layer

* fix: minor fix

* test: fix tests

* fix: input error color

* refactor: split accounts: trading_accounts and wallets

* test: fix test

* refactor: improve naming

* fix: minor fix

* feat: add useExistingCFDAccounts hook

* test: fix tests

* perf: replace useRequest with usefetch in useExistingCFDAccounts hook

* test: fix test

* style: fix selected tile style

* refactor: apply comments
  • Loading branch information
heorhi-deriv committed Aug 4, 2023
1 parent 7190dee commit bd1e873
Show file tree
Hide file tree
Showing 62 changed files with 2,593 additions and 910 deletions.
210 changes: 210 additions & 0 deletions packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,216 @@ type TPrivateEndpoints = {
};

type TPrivateSocketEndpoints = {
trading_platform_accounts: {
request: {
/**
* Must be `1`
*/
trading_platform_accounts: 1;
/**
* Trading platform name
*/
platform: 'dxtrade' | 'mt5' | 'derivez';
/**
* [Optional] Used to pass data through the websocket, which may be retrieved via the `echo_req` output field.
*/
passthrough?: {
[k: string]: unknown;
};
/**
* [Optional] Used to map request to response.
*/
req_id?: number;
};
response: {
/**
* Array containing Trading account objects.
*/
trading_platform_accounts?: {
/**
* ID of Trading account.
*/
account_id?: string;
/**
* Account type.
*/
account_type?: 'demo' | 'real';
/**
* Balance of the Trading account.
*/
balance?: null | number;
/**
* Residence of the MT5 account.
*/
country?: string;
/**
* Currency of the Trading account.
*/
currency?: string;
/**
* Account balance, formatted to appropriate decimal places.
*/
display_balance?: null | string;
/**
* Email address of the MT5 account.
*/
email?: string;
/**
* Account enabled status
*/
enabled?: number;
/**
* Error in MT5 account details.
*/
error?: {
/**
* Error code string.
*/
code?: string;
/**
* Extra information about the error.
*/
details?: {
/**
* MT5 account type.
*/
account_type?: string;
/**
* MT5 account login ID.
*/
login?: string;
/**
* Trade server name of the MT5 account.
*/
server?: string;
/**
* Trade server information.
*/
server_info?: {
/**
* The environment. E.g. Deriv-Server.
*/
environment?: 'Deriv-Demo' | 'Deriv-Server' | 'Deriv-Server-02';
/**
* Geographical location of the server.
*/
geolocation?: {
/**
* Internal server grouping.
*/
group?: string;
/**
* Sever location.
*/
location?: string;
/**
* Sever region.
*/
region?: string;
/**
* Sever sequence.
*/
sequence?: number;
};
/**
* Server id.
*/
id?: string;
};
};
/**
* Error message.
*/
message_to_client?: string;
};
/**
* Group type of the MT5 account, e.g. `demo\svg_financial`
*/
group?: string;
/**
* Landing company shortcode of the Trading account.
*/
landing_company_short?: 'bvi' | 'labuan' | 'malta' | 'maltainvest' | 'svg' | 'vanuatu' | 'seychelles';
/**
* Leverage of the MT5 account (1 to 1000).
*/
leverage?: number;
/**
* Login name used to log in into Trading platform
*/
login?: string;
/**
* Market type
*/
market_type?: 'financial' | 'synthetic' | 'all';
/**
* Name of the owner of the MT5 account.
*/
name?: string;
/**
* Name of trading platform.
*/
platform?: 'dxtrade' | 'mt5';
/**
* Trade server name of the MT5 account.
*/
server?: string;
/**
* Trade server information.
*/
server_info?: {
/**
* The environment. E.g. Deriv-Server.
*/
environment?: 'Deriv-Demo' | 'Deriv-Server' | 'Deriv-Server-02';
/**
* Geographical location of the server.
*/
geolocation?: {
/**
* Internal server grouping.
*/
group?: string;
/**
* Sever location.
*/
location?: string;
/**
* Sever region.
*/
region?: string;
/**
* Sever sequence.
*/
sequence?: number;
};
/**
* Server id.
*/
id?: string;
};
/**
* Sub account type
*/
sub_account_type?: 'financial' | 'financial_stp';
}[];
/**
* Echo of the request made.
*/
echo_req: {
[k: string]: unknown;
};
/**
* Action name of the request made.
*/
msg_type: 'trading_platform_accounts';
/**
* Optional field sent in request to map to response, present only when request contains `req_id`.
*/
req_id?: number;
[k: string]: unknown;
};
};
cashier_payments: {
request: {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ describe('AddWalletCard', () => {
render(
<StoreProvider store={mock}>
<APIProvider>
<AddWalletCard wallet_info={{ currency: 'BTC', is_added: false, landing_company_name: 'svg' }} />
<AddWalletCard
wallet_info={{
currency: 'BTC',
gradient_card_class: '',
is_added: false,
landing_company_name: 'svg',
}}
/>
</APIProvider>
</StoreProvider>
);
Expand All @@ -85,7 +92,14 @@ describe('AddWalletCard', () => {
render(
<StoreProvider store={mock}>
<APIProvider>
<AddWalletCard wallet_info={{ currency: 'BTC', is_added: true, landing_company_name: 'svg' }} />
<AddWalletCard
wallet_info={{
currency: 'BTC',
gradient_card_class: '',
is_added: true,
landing_company_name: 'svg',
}}
/>
</APIProvider>
</StoreProvider>
);
Expand All @@ -101,7 +115,14 @@ describe('AddWalletCard', () => {
render(
<StoreProvider store={mock}>
<APIProvider>
<AddWalletCard wallet_info={{ currency: 'UST', is_added: false, landing_company_name: 'svg' }} />
<AddWalletCard
wallet_info={{
currency: 'UST',
gradient_card_class: '',
is_added: false,
landing_company_name: 'svg',
}}
/>
</APIProvider>
</StoreProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TWalletInfo } from 'Types';
import { Text, WalletCard } from '@deriv/components';
import { useCurrencyConfig } from '@deriv/hooks';
import { observer, useStore } from '@deriv/stores';
import { getWalletCurrencyIcon } from 'Constants/utils';
import { getWalletCurrencyIcon } from '@deriv/utils';
import wallet_description_mapper from 'Constants/wallet_description_mapper';

type TAddWalletCard = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,27 @@ describe('WalletModalBody', () => {
mocked_props = {
contentScrollHandler: jest.fn(),
is_dark: false,
is_demo: true,
is_mobile: false,
setIsWalletNameVisible: jest.fn(),
is_wallet_name_visible: true,
wallet_type: 'demo',
setIsWalletNameVisible: jest.fn(),
wallet: {
balance: 1000,
currency: 'USD',
currency_config: {
display_code: 'USD',
is_crypto: false,
} as typeof mocked_props['wallet']['currency_config'],
gradient_card_class: 'wallet-card__usd',
gradient_header_class: 'wallet-header__usd',
icon: '',
is_demo: true,
is_disabled: 0,
is_malta_wallet: false,
is_selected: true,
is_virtual: 1,
landing_company_name: 'svg',
wallet_currency_type: 'Demo',
},
};
});

Expand All @@ -46,7 +62,6 @@ describe('WalletModalBody', () => {
});

it('Should render proper content under the Transfer tab', () => {
mocked_props.wallet_type = 'real';
const mocked_store = mockStore({
traders_hub: {
active_modal_tab: 'Transfer',
Expand All @@ -61,11 +76,11 @@ describe('WalletModalBody', () => {
const el_transfer_tab = screen.getByText('Transfer');
userEvent.click(el_transfer_tab);

expect(screen.getByText('Transfer Real')).toBeInTheDocument();
expect(screen.getByText('WalletTransfer')).toBeInTheDocument();
});

it('Should trigger setWalletModalActiveTab callback when the user clicked on the tab', () => {
mocked_props.wallet_type = 'real';
mocked_props.wallet.is_demo = false;
const mocked_store = mockStore({
traders_hub: {
active_modal_tab: 'Deposit',
Expand All @@ -84,7 +99,7 @@ describe('WalletModalBody', () => {
});

it('Should trigger contentScrollHandler callback when the user scrolls the content', () => {
mocked_props.wallet_type = 'real';
mocked_props.wallet.is_demo = false;
const mocked_store = mockStore({
traders_hub: {
active_modal_tab: 'Deposit',
Expand Down
Loading

0 comments on commit bd1e873

Please sign in to comment.