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

george / wall-1177 / Demo transfer insufficient funds error #9211

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
043f19e
feat: add demo transfer error handlers, add useTransferBetweenAccount…
heorhi-deriv Jul 2, 2023
b832748
Merge branch 'feature/wallets_with_traders_hub' of https://github.com…
heorhi-deriv Jul 2, 2023
fd17582
fix: types errors
heorhi-deriv Jul 2, 2023
ec6a668
Merge branch feature/wallets_with_traders_hub of https://github.com/b…
heorhi-deriv Jul 5, 2023
9d15504
fix: commit
heorhi-deriv Jul 5, 2023
4a5c6c5
Merge branch feature/wallets_with_traders_hub of https://github.com/b…
heorhi-deriv Jul 5, 2023
f694942
feat: add transfer hooks
heorhi-deriv Jul 5, 2023
266402c
test: add tests
heorhi-deriv Jul 5, 2023
967f210
fix: commit
heorhi-deriv Jul 6, 2023
929ba75
feat: :art: refactor code, add useActiveCFDAccounts hook
heorhi-deriv Jul 6, 2023
a87dcf5
Merge branch 'feature/wallets_with_traders_hub' into Demo-transfer--I…
heorhi-deriv Jul 6, 2023
aab8562
chore: remove comment
heorhi-deriv Jul 6, 2023
27a0772
Merge branch 'Demo-transfer--Insufficient-funds-error-1177' of github…
heorhi-deriv Jul 6, 2023
fda1001
refactor: :fire: cleanup
heorhi-deriv Jul 6, 2023
436de37
fix: useAvaliableWallets hook
heorhi-deriv Jul 6, 2023
71591fc
fix: typescript errors
heorhi-deriv Jul 6, 2023
a6471ec
test: add tests, apply comments
heorhi-deriv Jul 8, 2023
f797448
test: add test, add test accounts
heorhi-deriv Jul 9, 2023
6259978
test: fix tests
heorhi-deriv Jul 10, 2023
14e4d7e
fix: fix ts errors
heorhi-deriv Jul 10, 2023
836354b
fix: apply comments
heorhi-deriv Jul 10, 2023
b506ab3
perf: small improvement
heorhi-deriv Jul 11, 2023
e875d93
perf: small improvement
heorhi-deriv Jul 11, 2023
c0a5141
Merge branch 'feature/wallets_with_traders_hub' of https://github.com…
heorhi-deriv Jul 12, 2023
31cced5
fix: resolve conflicts
heorhi-deriv Jul 12, 2023
63fc44d
refactor: improve logic, fix test
heorhi-deriv Jul 12, 2023
2157895
chore: remove unused import
heorhi-deriv Jul 12, 2023
ac537c2
feat: add reset balance button handler
heorhi-deriv Jul 13, 2023
79a9151
fix: currency register
heorhi-deriv Jul 13, 2023
44a9923
style: fix styles in dark mode
heorhi-deriv Jul 13, 2023
8487772
test: fix test
heorhi-deriv Jul 13, 2023
c5cf831
perf: minor improvements
heorhi-deriv Jul 13, 2023
8e15815
refactor: :zap: transfer account data transfarmation layer
heorhi-deriv Jul 14, 2023
2cde70c
Merge branch 'feature/wallets_with_traders_hub' of https://github.com…
heorhi-deriv Jul 14, 2023
9cb7f60
fix: minor fix
heorhi-deriv Jul 14, 2023
1132539
test: fix tests
heorhi-deriv Jul 14, 2023
6210973
fix: input error color
heorhi-deriv Jul 14, 2023
cbe2607
refactor: split accounts: trading_accounts and wallets
heorhi-deriv Jul 17, 2023
f38bef1
test: fix test
heorhi-deriv Jul 17, 2023
76bd7a9
refactor: improve naming
heorhi-deriv Jul 17, 2023
3503a2c
fix: minor fix
heorhi-deriv Jul 17, 2023
b402dd3
feat: add useExistingCFDAccounts hook
heorhi-deriv Jul 17, 2023
ac1107f
test: fix tests
heorhi-deriv Jul 17, 2023
4f2117d
perf: replace useRequest with usefetch in useExistingCFDAccounts hook
heorhi-deriv Jul 18, 2023
1d56cfb
test: fix test
heorhi-deriv Jul 18, 2023
4f134d1
style: fix selected tile style
heorhi-deriv Jul 18, 2023
698bdab
Merge branch 'feature/wallets_with_traders_hub' of https://github.com…
heorhi-deriv Jul 24, 2023
6bfe62a
Merge branch 'feature/wallets_with_traders_hub' into Demo-transfer--I…
heorhi-deriv Jul 31, 2023
b7e95c3
refactor: apply comments
heorhi-deriv Jul 31, 2023
1c85ac8
Merge branch 'Demo-transfer--Insufficient-funds-error-1177' of github…
heorhi-deriv Jul 31, 2023
869347f
Merge branch 'feature/wallets_with_traders_hub' of https://github.com…
heorhi-deriv Aug 3, 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
24 changes: 23 additions & 1 deletion packages/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,28 @@ import type {
} from '@deriv/api-types';
import type { useMutation, useQuery } from '@tanstack/react-query';

type TPrivateSocketEndpoints = {
trading_platform_accounts: {
request: {
platform: 'derivez' | 'dxtrade' | 'mt5';
};
response: {
trading_platform_accounts: {
account_id: string;
account_type: 'real' | 'demo';
balance: number;
country: string;
currency: string;
display_balance: string;
email: string;
enabled: 0 | 1;
error: unknown;
login: string;
}[];
};
};
heorhi-deriv marked this conversation as resolved.
Show resolved Hide resolved
};

type TSocketEndpoints = {
active_symbols: {
request: ActiveSymbolsRequest;
Expand Down Expand Up @@ -681,7 +703,7 @@ type TSocketEndpoints = {
request: ServerStatusRequest;
response: ServerStatusResponse;
};
};
} & TPrivateSocketEndpoints;

export type TSocketEndpointNames = keyof TSocketEndpoints;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@ 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',
gradient_card_class: '',
gradient_header_class: '',
icon: '',
is_crypto: false,
is_demo: true,
is_disabled: false,
is_malta_wallet: false,
is_selected: true,
is_virtual: true,
landing_company_name: 'svg',
name: 'Demo USD Wallet',
},
};
});

Expand All @@ -46,7 +59,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 +73,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 +96,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
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,34 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import WalletModalHeader from '../wallet-modal-header';

jest.mock('@deriv/hooks', () => ({
useCurrencyConfig: () => ({ getConfig: () => ({ display_code: 'USD' }) }),
}));

describe('WalletModalHeader', () => {
let mocked_props: React.ComponentProps<typeof WalletModalHeader>;

beforeEach(() => {
mocked_props = {
balance: 999,
closeModal: jest.fn(),
currency: 'USD',
is_dark: false,
is_demo: true,
is_mobile: false,
is_wallet_name_visible: true,
shortcode: 'SVG',
wallet: {
balance: 1000,
currency: 'USD',
gradient_card_class: '',
gradient_header_class: '',
icon: 'IcWalletIcon',
is_crypto: false,
is_demo: true,
is_disabled: false,
is_malta_wallet: false,
is_selected: true,
is_virtual: true,
landing_company_name: 'svg',
name: 'Demo USD Wallet',
},
};
});

Expand All @@ -24,8 +39,8 @@ describe('WalletModalHeader', () => {

expect(screen.getByText('Demo USD Wallet')).toBeInTheDocument();
expect(screen.getByText('Demo')).toBeInTheDocument();
expect(screen.getByText('999.00 USD')).toBeInTheDocument();
expect(screen.getByTestId('dt_currency_icon')).toBeInTheDocument();
expect(screen.getByText('1,000.00 USD')).toBeInTheDocument();
expect(screen.getByTestId('dt_wallet_icon')).toBeInTheDocument();
expect(screen.getByTestId('dt_close_icon')).toBeInTheDocument();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getCashierOptions = (type: TWalletType) => {
{
icon: 'IcAccountTransfer',
label: localize('Transfer'),
content: () => <p>Transfer Real</p>,
content: (props: React.ComponentProps<typeof WalletTransfer>) => <WalletTransfer {...props} />,
},
{
icon: 'IcStatement',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import classNames from 'classnames';
import { Tabs, ThemedScrollbars, Div100vhContainer } from '@deriv/components';
import { getCashierOptions, TWalletType } from './provider';
import { getCashierOptions } from './provider';
import { observer, useStore } from '@deriv/stores';
import type { TWalletAccount } from 'Types';

type TWalletModalBodyProps = {
contentScrollHandler: React.UIEventHandler<HTMLDivElement>;
is_dark: boolean;
is_demo: boolean;
is_mobile: boolean;
setIsWalletNameVisible: (value: boolean) => void;
is_wallet_name_visible: boolean;
wallet_type: TWalletType;
wallet: TWalletAccount;
};

const real_tabs = {
Expand All @@ -32,14 +32,15 @@ const WalletModalBody = observer(
({
contentScrollHandler,
is_dark,
is_demo,
is_mobile,
setIsWalletNameVisible,
is_wallet_name_visible,
wallet_type,
wallet,
}: TWalletModalBodyProps) => {
const store = useStore();

const { is_demo } = wallet;

const {
traders_hub: { active_modal_tab, setWalletModalActiveTab },
} = store;
Expand All @@ -58,7 +59,7 @@ const WalletModalBody = observer(
active_icon_color={is_dark ? 'var(--badge-white)' : ''}
active_index={tabs[active_modal_tab || 'Deposit']}
className={classNames('modal-body__tabs', {
is_scrolled: !is_wallet_name_visible,
is_scrolled: is_mobile && !is_wallet_name_visible,
})}
has_active_line={false}
has_bottom_line={false}
Expand All @@ -72,7 +73,7 @@ const WalletModalBody = observer(
setWalletModalActiveTab(tab_name);
}}
>
{getCashierOptions(wallet_type).map(option => {
{getCashierOptions(is_demo ? 'demo' : 'real').map(option => {
return (
<div key={option.label} icon={option.icon} label={option.label}>
<ThemedScrollbars
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,36 @@
import React from 'react';
import classNames from 'classnames';
import { Badge, Icon, Text } from '@deriv/components';
import { formatMoney, getCurrencyDisplayCode } from '@deriv/shared';
import { localize } from '@deriv/translations';
import { getWalletCurrencyIcon } from '@deriv/utils';
import { Icon, Text, WalletJurisdictionBadge, WalletIcon } from '@deriv/components';
import { formatMoney } from '@deriv/shared';
import { getAccountName } from 'Constants/utils';
import type { TWalletAccount } from 'Types';

type TWalletModalHeaderProps = {
balance?: string | number;
currency: string;
closeModal: VoidFunction;
is_dark: boolean;
is_demo: boolean;
is_mobile: boolean;
shortcode: string;
closeModal: VoidFunction;
is_wallet_name_visible: boolean;
gradient_class: string;
wallet: TWalletAccount;
};

const WalletModalHeader = ({
balance,
closeModal,
currency,
is_dark,
is_demo,
is_mobile,
shortcode,
is_wallet_name_visible,
gradient_class,
wallet,
}: TWalletModalHeaderProps) => {
const header_class_name = 'modal-header';
const {
balance,
currency,
icon,
is_crypto,
is_demo,
gradient_header_class: gradient_class,
landing_company_name: shortcode,
} = wallet;

const wallet_title = React.useMemo(() => {
return `${is_demo ? localize('Demo') : ''} ${getCurrencyDisplayCode(currency)} ${localize('Wallet')}`;
}, [currency, is_demo]);

const getBadgeLabel = React.useCallback(() => {
if (is_demo) return localize('Demo');
switch (shortcode) {
case 'svg':
return shortcode.toUpperCase();
case 'malta':
case 'maltainvest':
return 'malta'.toUpperCase();
default:
return '';
}
}, [is_demo, shortcode]);
const header_class_name = 'modal-header';

const getCloseIcon = React.useCallback(() => {
if (is_demo && is_dark) return 'IcAppstoreCloseLight';
Expand All @@ -54,44 +39,21 @@ const WalletModalHeader = ({
return 'IcAppstoreCloseLight';
}, [is_dark, is_demo]);

const getStylesByClassName = React.useCallback(
(class_name: string) => {
return classNames(class_name, {
[`${class_name}-demo`]: is_demo,
});
},
[is_demo]
);

const getCurrencyIconSize = React.useCallback(() => {
// TODO: add p2p and payment_agent check
const is_square_icon =
['btc', 'eth', 'ltc', 'usdt', 'eusdt', 'tusdt', 'ust', 'usdc', 'p2p', 'payment_agent'].includes(
currency.toLowerCase()
) || is_demo;

const sizes = {
mobile: {
width: is_square_icon ? 64 : 48,
height: is_square_icon ? 40 : 48,
},
desktop: {
width: is_square_icon ? 128 : 64,
height: is_square_icon ? 80 : 64,
},
};

const size = is_mobile ? sizes.mobile : sizes.desktop;

return size;
}, [currency, is_demo, is_mobile]);
const getStylesByClassName = (class_name: string) => {
return classNames(class_name, {
[`${class_name}-demo`]: is_demo,
});
};

const getCurrencyIconProps = React.useCallback(() => {
const icon = getWalletCurrencyIcon(is_demo ? 'demo' : currency, is_dark, true);
const size = getCurrencyIconSize();
const getWalletIconType = (): React.ComponentProps<typeof WalletIcon>['type'] => {
if (is_demo) return 'demo';
return is_crypto ? 'crypto' : 'fiat';
};

return { icon, ...size };
}, [currency, getCurrencyIconSize, is_dark, is_demo]);
const getWalletIconSize = (): React.ComponentProps<typeof WalletIcon>['size'] => {
if (is_mobile) return is_demo || is_crypto ? 'large' : 'xlarge';
return 'xxlarge';
};

return (
<div className={`header-background ${gradient_class}`}>
Expand All @@ -107,26 +69,21 @@ const WalletModalHeader = ({
as='span'
className={getStylesByClassName(`${header_class_name}__title-wallet`)}
>
{wallet_title}
{getAccountName({ ...wallet, account_type: 'wallet' })}
</Text>
{is_demo ? (
<Badge type='contained' background_color='blue' label={getBadgeLabel()} />
) : (
<Badge type='bordered' label={getBadgeLabel()} />
)}
<WalletJurisdictionBadge is_demo={is_demo} shortcode={shortcode} />
</div>
<Text
as='p'
size={is_mobile ? 'xsm' : 'm'}
weight='bold'
className={getStylesByClassName(`${header_class_name}__title-balance`)}
>
{formatMoney(currency, balance, true)} {getCurrencyDisplayCode(currency)}
{formatMoney(currency || '', balance, true)} {wallet.display_currency_code}
</Text>
</div>
{/* TODO: replace Icon with WalletIcon component */}
<div className={classNames(`${header_class_name}__currency-icon icon-visibility`)}>
<Icon {...getCurrencyIconProps()} data_testid='dt_currency_icon' />
<WalletIcon icon={icon} type={getWalletIconType()} size={getWalletIconSize()} />
</div>
<div className={classNames(`${header_class_name}__close-icon`)}>
<Icon icon={getCloseIcon()} onClick={closeModal} data_testid='dt_close_icon' />
Expand Down
Loading
Loading