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

Sergei / wall - 1140 / Limited functionality in Trader's Hub for "in_progress" & "migrated" #9159

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ca886e1
feat: add 2 modals for test
sergei-deriv Jun 27, 2023
f7a8106
feat: delete wallets-ready modals and refactor a little bit 2 other m…
sergei-deriv Jun 28, 2023
3084ab1
feat: delete buttons for test and add !important for container class
sergei-deriv Jun 28, 2023
7482479
feat: rename modal
sergei-deriv Jun 28, 2023
99413e4
feat: create hook useWalletMigration
sergei-deriv Jun 29, 2023
f93a297
Merge remote-tracking branch 'upstream/feature/wallets_with_traders_h…
sergei-deriv Jun 29, 2023
98b6d5c
feat: add redirect to traders-hub from cashier
sergei-deriv Jun 29, 2023
542216c
feat: rename function in cashier route props
sergei-deriv Jun 29, 2023
ae71649
feat: add as_disabled button and add disabledButtonAction
sergei-deriv Jun 29, 2023
746b12e
feat: separate action for usual button and for disabled button
sergei-deriv Jun 30, 2023
1f31962
feat: add get_more_account as disabled
sergei-deriv Jun 30, 2023
0551c97
Merge remote-tracking branch 'upstream/feature/wallets_with_traders_h…
sergei-deriv Jun 30, 2023
04d4599
fix: delete unused string
sergei-deriv Jun 30, 2023
3cac9b0
feat: move modal to core package
sergei-deriv Jul 3, 2023
02ad0c9
feat: delete modal from appstore package
sergei-deriv Jul 3, 2023
af0a963
Merge remote-tracking branch 'upstream/feature/wallets_with_traders_h…
sergei-deriv Jul 5, 2023
48b9e93
feat: modify useWalletMigration hook
sergei-deriv Jul 5, 2023
ef0c18f
feat: update wallets-banner component
sergei-deriv Jul 5, 2023
1252d83
feat: rename is_wallet_migration_in_progress
sergei-deriv Jul 5, 2023
5241606
refactor: rename button action
sergei-deriv Jul 5, 2023
baa6757
refactor: left components as dummy as possible
sergei-deriv Jul 5, 2023
45399a4
refactor: slightly change GetMoreAccounts component
sergei-deriv Jul 5, 2023
59d2bbf
feat: fix real-account-card tests
sergei-deriv Jul 5, 2023
37b52a4
feat: change done to migrated again
sergei-deriv Jul 6, 2023
e6cad66
feat: change status to state and refactor some components
sergei-deriv Jul 10, 2023
32e9746
refactor: moave back button for testing wallets migration failed modal
sergei-deriv Jul 10, 2023
b45dd32
refactor: revert back comment for WalletsBanner
sergei-deriv Jul 10, 2023
c8363a5
Merge remote-tracking branch 'upstream/feature/wallets_with_traders_h…
sergei-deriv Jul 13, 2023
6ee72ee
feat: add close accounts dialog
sergei-deriv Jul 13, 2023
83b142a
feat: disable more buttons
sergei-deriv Jul 14, 2023
4daeabb
Merge remote-tracking branch 'upstream/feature/wallets_with_traders_h…
sergei-deriv Jul 14, 2023
b2df30e
fix: fix CircleCI test
sergei-deriv Jul 14, 2023
750d065
fix: vercel
thisyahlen-deriv Jul 26, 2023
db4fa2b
Merge branch 'feature/wallets_with_traders_hub' of github.com:binary-…
thisyahlen-deriv Jul 26, 2023
292f462
fix: response cashier menu drawer
thisyahlen-deriv Jul 27, 2023
d585843
Merge remote-tracking branch 'upstream/feature/wallets_with_traders_h…
sergei-deriv Aug 2, 2023
2b1b84a
Merge branch 'sergei/wall-1140/limited-functionality-wallets' of gith…
sergei-deriv Aug 2, 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
27 changes: 22 additions & 5 deletions packages/appstore/src/components/cfds-listing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PlatformLoader from 'Components/pre-loader/platform-loader';
import GetMoreAccounts from 'Components/get-more-accounts';
import { Actions } from 'Components/containers/trading-app-card-actions';
import { getHasDivider } from 'Constants/utils';
import { useWalletMigration } from '@deriv/hooks';
import { useStores } from 'Stores/index';
import { AvailableAccount, TDetailsOfEachMT5Loginid } from 'Types';
import './cfds-listing.scss';
Expand Down Expand Up @@ -53,9 +54,15 @@ const CFDsListing = () => {
CFDs_restricted_countries,
financial_restricted_countries,
} = traders_hub;
const { is_in_progress } = useWalletMigration();

const { toggleCompareAccountsModal, setAccountType } = cfd;
const { is_landing_company_loaded, real_account_creation_unlock_date, account_status } = client;
const {
is_landing_company_loaded,
real_account_creation_unlock_date,
account_status,
setWalletsMigrationInProgressPopup,
} = client;
const { setAppstorePlatform } = common;
const { openDerivRealAccountNeededModal, setShouldShowCooldownModal } = ui;
const has_no_real_account = !has_any_real_account;
Expand Down Expand Up @@ -133,6 +140,11 @@ const CFDsListing = () => {
return null;
};

const compareAccountsModalHandle = () => {
if (is_in_progress) setWalletsMigrationInProgressPopup(true);
else toggleCompareAccountsModal();
};

return (
<ListingContainer
title={
Expand All @@ -141,7 +153,7 @@ const CFDsListing = () => {
<Text size='sm' line_height='m' weight='bold' color='prominent'>
{localize('CFDs')}
</Text>
<div className='cfd-accounts__compare-table-title' onClick={toggleCompareAccountsModal}>
<div className='cfd-accounts__compare-table-title' onClick={compareAccountsModalHandle}>
<Text key={0} color='red' size='xxs' weight='bold' styles={{ marginLeft: '1rem' }}>
<Localize i18n_default_text={accounts_sub_text} />
</Text>
Expand All @@ -161,7 +173,7 @@ const CFDsListing = () => {
}
>
{isMobile() && (
<div className='cfd-accounts__compare-table-title' onClick={toggleCompareAccountsModal}>
<div className='cfd-accounts__compare-table-title' onClick={compareAccountsModalHandle}>
<Text size='xs' color='red' weight='bold' line_height='s'>
<Localize i18n_default_text={accounts_sub_text} />
</Text>
Expand All @@ -182,7 +194,7 @@ const CFDsListing = () => {
const has_mt5_account_status =
existing_account.status || is_idv_revoked
? getMT5AccountAuthStatus(
existing_account.status,
existing_account.status ?? '',
existing_account?.short_code_and_region?.toLowerCase()
)
: null;
Expand Down Expand Up @@ -240,10 +252,15 @@ const CFDsListing = () => {
})}
{can_get_more_cfd_mt5_accounts && (
<GetMoreAccounts
onClick={toggleAccountTypeModalVisibility}
onClick={
is_in_progress
? () => setWalletsMigrationInProgressPopup(true)
: toggleAccountTypeModalVisibility
}
icon='IcAppstoreGetMoreAccounts'
title={localize('Get more')}
description={localize('Get more Deriv MT5 account with different type and jurisdiction.')}
is_disabled={is_in_progress}
/>
)}
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Button } from '@deriv/components';
import { localize } from '@deriv/translations';
import TradeButton from 'Components/trade-button/trade-button';
import React from 'react';
import { observer } from 'mobx-react-lite';
import MultiActionButtonGroup from 'Components/multi-action-button-group';

export type Actions = {
Expand All @@ -16,6 +15,7 @@ export type Actions = {
is_buttons_disabled?: boolean;
is_account_being_created?: boolean;
is_real?: boolean;
as_disabled?: boolean;
};

const TradingAppCardActions = ({
Expand All @@ -27,11 +27,12 @@ const TradingAppCardActions = ({
is_account_being_created,
is_buttons_disabled,
is_real,
as_disabled,
mahdiyeh-deriv marked this conversation as resolved.
Show resolved Hide resolved
}: Actions) => {
switch (action_type) {
case 'get':
return (
<Button disabled={is_account_being_created} primary_light onClick={() => onAction?.()}>
<Button disabled={is_account_being_created} primary_light onClick={onAction} as_disabled={as_disabled}>
mahdiyeh-deriv marked this conversation as resolved.
Show resolved Hide resolved
{localize('Get')}
</Button>
);
Expand All @@ -46,6 +47,7 @@ const TradingAppCardActions = ({
onAction={onAction}
is_buttons_disabled={is_buttons_disabled}
is_real={is_real}
as_disabled_deposit_button={as_disabled}
mahdiyeh-deriv marked this conversation as resolved.
Show resolved Hide resolved
/>
);
case 'none':
Expand All @@ -54,4 +56,4 @@ const TradingAppCardActions = ({
}
};

export default observer(TradingAppCardActions);
export default TradingAppCardActions;
12 changes: 11 additions & 1 deletion packages/appstore/src/components/containers/trading-app-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useStores } from 'Stores/index';
import { observer } from 'mobx-react-lite';
import { localize } from '@deriv/translations';
import { CFD_PLATFORMS, ContentFlag, getStaticUrl, getUrlSmartTrader, getUrlBinaryBot } from '@deriv/shared';
import { useWalletMigration } from '@deriv/hooks';
import './trading-app-card.scss';

type TWalletsProps = {
Expand Down Expand Up @@ -42,13 +43,16 @@ const TradingAppCard = ({
is_wallet_demo,
}: Actions & BrandConfig & AvailableAccount & TDetailsOfEachMT5Loginid & TWalletsProps) => {
const {
client,
common,
traders_hub,
modules: { cfd },
} = useStores();
const { is_eu_user, is_demo_low_risk, content_flag, is_real } = traders_hub;
const { current_language } = common;
const { is_account_being_created } = cfd;
const { setWalletsMigrationInProgressPopup } = client;
const { is_in_progress } = useWalletMigration();

const low_risk_cr_non_eu = content_flag === ContentFlag.LOW_RISK_CR_NON_EU;

Expand Down Expand Up @@ -96,6 +100,11 @@ const TradingAppCard = ({
else;
};

const onButtonAction = () => {
if (is_in_progress) setWalletsMigrationInProgressPopup(true);
else onAction?.();
};

return (
<div className='trading-app-card' key={`trading-app-card__${current_language}`}>
<div
Expand Down Expand Up @@ -165,12 +174,13 @@ const TradingAppCard = ({
<TradingAppCardActions
action_type={action_type}
link_to={link_to}
onAction={onAction}
onAction={onButtonAction}
is_external={is_external}
new_tab={new_tab}
is_buttons_disabled={!!mt5_acc_auth_status}
is_account_being_created={!!is_account_being_created}
is_real={is_real}
as_disabled={is_in_progress}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import React from 'react';
import DemoAccountCard from '../demo-account-card';
import { render, screen } from '@testing-library/react';
import { StoreProvider, mockStore } from '@deriv/stores';
import { APIProvider, useFetch } from '@deriv/api';

jest.mock('@deriv/api', () => ({
...jest.requireActual('@deriv/api'),
useFetch: jest.fn(),
}));

const mockUseFetch = useFetch as jest.MockedFunction<typeof useFetch<'wallet_migration'>>;

describe('DemoAccountCard', () => {
it('should render correctly', () => {
Expand Down Expand Up @@ -29,8 +37,13 @@ describe('DemoAccountCard', () => {
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<DemoAccountCard />, {
Expand Down Expand Up @@ -65,8 +78,13 @@ describe('DemoAccountCard', () => {
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<DemoAccountCard />, {
Expand Down Expand Up @@ -103,8 +121,13 @@ describe('DemoAccountCard', () => {
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<DemoAccountCard />, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import CurrencySwitcherContainer from 'Components/containers/currency-switcher-c
import BalanceText from 'Components/elements/text/balance-text';
import './demo-account-card.scss';
import { localize } from '@deriv/translations';
import { usePlatformAccounts } from '@deriv/hooks';
import { usePlatformAccounts, useWalletMigration } from '@deriv/hooks';
import { useStore, observer } from '@deriv/stores';

const DemoAccountCard = observer(() => {
const { client, traders_hub, common } = useStore();
const { accounts, loginid, resetVirtualBalance, default_currency } = client;
const { accounts, loginid, resetVirtualBalance, default_currency, setWalletsMigrationInProgressPopup } = client;
const { selected_account_type } = traders_hub;
const { demo: platform_demo_account } = usePlatformAccounts();
const { is_in_progress } = useWalletMigration();

const canResetBalance = () => {
return loginid && (accounts[loginid]?.balance || 0) !== 10000;
Expand All @@ -33,8 +34,9 @@ const DemoAccountCard = observer(() => {
<Button
key={`currency-switcher__button--key-${current_language}`}
secondary
onClick={resetVirtualBalance}
onClick={is_in_progress ? () => setWalletsMigrationInProgressPopup(true) : resetVirtualBalance}
className='currency-switcher__button'
as_disabled={is_in_progress}
>
{localize('Reset Balance')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { StoreProvider, mockStore } from '@deriv/stores';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
import { APIProvider, useFetch } from '@deriv/api';

jest.mock('@deriv/api', () => ({
...jest.requireActual('@deriv/api'),
useFetch: jest.fn(),
}));

const mockUseFetch = useFetch as jest.MockedFunction<typeof useFetch<'wallet_migration'>>;

describe('RealAccountCard', () => {
it('should render the component', () => {
Expand All @@ -18,8 +26,14 @@ describe('RealAccountCard', () => {
},
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<RealAccountCard />, { wrapper });
Expand Down Expand Up @@ -47,8 +61,14 @@ describe('RealAccountCard', () => {
},
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<RealAccountCard />, { wrapper });
Expand Down Expand Up @@ -78,8 +98,14 @@ describe('RealAccountCard', () => {
},
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<RealAccountCard />, { wrapper });
Expand All @@ -88,7 +114,7 @@ describe('RealAccountCard', () => {
expect(screen.getByText('EUR')).toBeInTheDocument();
});

it('should redirect the user to cashier_deposit page after clicking deposit', () => {
it('should redirect the user to cashier_deposit page after clicking deposit', async () => {
const history = createMemoryHistory();
const mock = mockStore({
client: {
Expand All @@ -110,10 +136,16 @@ describe('RealAccountCard', () => {
},
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<Router history={history}>
<StoreProvider store={mock}>{children}</StoreProvider>
</Router>
<APIProvider>
<Router history={history}>
<StoreProvider store={mock}>{children}</StoreProvider>
</Router>
</APIProvider>
);

const { container } = render(<RealAccountCard />, { wrapper });
Expand Down Expand Up @@ -144,8 +176,14 @@ describe('RealAccountCard', () => {
},
},
});

// @ts-expect-error need to come up with a way to mock the return type of useFetch
mockUseFetch.mockReturnValue({ data: { wallet_migration: { state: 'eligible' } } });

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
<APIProvider>
<StoreProvider store={mock}>{children}</StoreProvider>
</APIProvider>
);

const { container } = render(<RealAccountCard />, { wrapper });
Expand Down
Loading