Skip to content

Commit

Permalink
Merge pull request #123 from jim-deriv/Jim/85355/transfer-top-up
Browse files Browse the repository at this point in the history
Jim/85355/transfer top up
  • Loading branch information
matin-deriv committed Jan 10, 2023
2 parents b390b34 + fcf6668 commit a886796
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 55 deletions.
27 changes: 19 additions & 8 deletions packages/appstore/src/components/cfds-listing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const CFDsListing = () => {
no_MF_account,
toggleAccountTransferModal,
is_demo,
showTopUpModal,
} = traders_hub;

const { toggleCompareAccountsModal, setAccountType } = cfd;
Expand Down Expand Up @@ -125,11 +126,11 @@ const CFDsListing = () => {
platform={existing_account.platform}
description={existing_account.description}
key={existing_account.key}
type={existing_account.type}
action_type={existing_account.action_type}
availability={selected_region}
has_divider={(!is_eu_user || is_demo) && getHasDivider(index, list_size, 3)}
onAction={(e?: React.MouseEvent<HTMLButtonElement>) => {
if (existing_account.type === 'get') {
if (existing_account.action_type === 'get') {
if ((has_no_real_account && is_real) || no_real_mf_account_eu_regulator) {
openDerivRealAccountNeededModal();
} else {
Expand All @@ -140,9 +141,12 @@ const CFDsListing = () => {
setAppstorePlatform(existing_account.platform);
getAccount();
}
} else if (existing_account.type === 'transfer_trade') {
if (e?.currentTarget?.name === 'transfer-btn') {
} else if (existing_account.action_type === 'multi-action') {
const button_name = e?.currentTarget?.name;
if (button_name === 'transfer-btn') {
toggleAccountTransferModal();
} else if (button_name === 'topup-btn') {
showTopUpModal(existing_account);
} else {
startTrade(existing_account.platform, existing_account);
}
Expand Down Expand Up @@ -195,10 +199,17 @@ const CFDsListing = () => {
description={existing_account.display_login}
platform={account.platform}
key={`trading_app_card_${existing_account.display_login}`}
type='transfer_trade'
action_type='multi-action'
availability={selected_region}
onAction={() => {
startTrade(account.platform, existing_account);
onAction={(e?: React.MouseEvent<HTMLButtonElement>) => {
const button_name = e?.currentTarget?.name;
if (button_name === 'transfer-btn') {
toggleAccountTransferModal();
} else if (button_name === 'topup-btn') {
showTopUpModal(existing_account);
} else {
startTrade(account.platform, existing_account);
}
}}
/>
))
Expand All @@ -221,7 +232,7 @@ const CFDsListing = () => {
}
}}
key={`trading_app_card_${account.name}`}
type='get'
action_type='get'
availability={selected_region}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import { Button } from '@deriv/components';
import { localize } from '@deriv/translations';
import TradeButton from 'Components/trade-button/trade-button';
import TransferTradeButtonGroup from 'Components/transfer-trade-button-group';
import React from 'react';
import { observer } from 'mobx-react-lite';
import MultiActionButtonGroup from 'Components/multi-action-button-group';

export type Actions = {
type: 'get' | 'none' | 'trade' | 'dxtrade' | 'transfer_trade' | 'dxtrade_transfer_trade';
action_type: 'get' | 'none' | 'trade' | 'dxtrade' | 'multi-action'; // multi-action can be tranfer_trade or top_up_trade
link_to?: string;
has_divider?: boolean;
onAction?: (e?: React.MouseEvent<HTMLButtonElement>) => void;
is_external?: boolean;
is_buttons_disabled?: boolean;
is_real?: boolean;
};

const TradingAppCardActions = ({ type, link_to, onAction, is_external, is_buttons_disabled }: Actions) => {
switch (type) {
const TradingAppCardActions = ({
action_type,
link_to,
onAction,
is_external,
is_buttons_disabled,
is_real,
}: Actions) => {
switch (action_type) {
case 'get':
return (
<Button primary_light onClick={() => onAction?.()}>
Expand All @@ -26,12 +34,13 @@ const TradingAppCardActions = ({ type, link_to, onAction, is_external, is_button
return <TradeButton link_to={link_to} onAction={onAction} is_external={is_external} />;
case 'dxtrade':
return <TradeButton link_to={link_to} />;
case 'transfer_trade':
case 'multi-action':
return (
<TransferTradeButtonGroup
<MultiActionButtonGroup
link_to={link_to}
onAction={onAction}
is_buttons_disabled={is_buttons_disabled}
is_real={is_real}
/>
);
case 'none':
Expand Down
21 changes: 16 additions & 5 deletions packages/appstore/src/components/containers/trading-app-card.scss
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
.trading-app-card {
display: inline-flex;
align-items: center;
height: max-content;
height: 100%;

&__icon {
&--container {
display: inline-flex;
align-items: center;
justify-content: center;
height: 100%;
padding: 0 0 2rem;
}
}

&__container {
display: inline-flex;
justify-content: space-between;
align-items: flex-start;
align-items: center;
width: 100%;
padding: 0 0 1rem;
height: 100%;
padding: 0 0 2rem;
margin-left: 1.6rem;
}

&__details {
display: flex;
justify-content: center;
display: inline-flex;
flex-direction: column;
justify-content: center;
height: 100%;
padding: 0 2rem 0 0;
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ContentFlag } from '@deriv/shared';
const TradingAppCard = ({
name,
icon,
type,
action_type,
description,
is_deriv_platform = false,
onAction,
Expand All @@ -23,7 +23,7 @@ const TradingAppCard = ({
mt5_acc_auth_status,
}: Actions & BrandConfig & AvailableAccount & TDetailsOfEachMT5Loginid) => {
const { traders_hub } = useStores();
const { is_eu_user, is_demo_low_risk, content_flag } = traders_hub;
const { is_eu_user, is_demo_low_risk, content_flag, is_real } = traders_hub;

const low_risk_cr_non_eu = content_flag === ContentFlag.LOW_RISK_CR_NON_EU;

Expand All @@ -36,7 +36,7 @@ const TradingAppCard = ({

return (
<div className='trading-app-card'>
<div>
<div className='trading-app-card__icon--container'>
<TradigPlatformIconProps icon={icon} size={48} />
</div>
<div className={classNames('trading-app-card__container', { 'trading-app-card--divider': has_divider })}>
Expand Down Expand Up @@ -76,11 +76,12 @@ const TradingAppCard = ({
</div>
<div className='trading-app-card__actions'>
<TradingAppCardActions
type={type}
action_type={action_type}
link_to={link_to}
onAction={onAction}
is_external={is_external}
is_buttons_disabled={!!mt5_acc_auth_status}
is_real={is_real}
/>
</div>
</div>
Expand Down
27 changes: 25 additions & 2 deletions packages/appstore/src/components/modals/modal-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TCurrentList = DetailsOfEachMT5Loginid & {

const ModalManager = () => {
const store = useStores();
const { common, client, modules, traders_hub } = store;
const { common, client, modules, traders_hub, ui } = store;
const { is_logged_in, is_eu, is_eu_country, has_active_real_account } = client;
const { platform } = common;
const {
Expand All @@ -37,7 +37,18 @@ const ModalManager = () => {
toggleMT5TradeModal,
getRealSyntheticAccountsExistingData,
getRealFinancialAccountsExistingData,
current_account,
dxtrade_companies,
mt5_companies,
topUpVirtual,
} = modules.cfd;
const {
is_top_up_virtual_open,
is_top_up_virtual_in_progress,
is_top_up_virtual_success,
closeTopUpModal,
closeSuccessTopUpModal,
} = ui;
const { is_demo, is_account_transfer_modal_open, toggleAccountTransferModal } = traders_hub;

const [password_manager, setPasswordManager] = React.useState<{
Expand Down Expand Up @@ -105,7 +116,19 @@ const ModalManager = () => {
<CFDDbviOnBoarding context={store} />
<CFDResetPasswordModal context={store} platform={platform} />
<CFDServerErrorDialog context={store} />
<CFDTopUpDemoModal context={store} />
<CFDTopUpDemoModal
context={store}
dxtrade_companies={dxtrade_companies}
mt5_companies={mt5_companies}
current_account={current_account}
closeSuccessTopUpModal={closeSuccessTopUpModal}
closeTopUpModal={closeTopUpModal}
is_top_up_virtual_open={is_top_up_virtual_open}
is_top_up_virtual_in_progress={is_top_up_virtual_in_progress}
is_top_up_virtual_success={is_top_up_virtual_success}
platform={platform}
topUpVirtual={topUpVirtual}
/>
<MT5TradeModal
context={store}
current_list={current_list}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import MultiActionButtonGroup from './multi-action-button-group';
import './multi-action-button-group.scss';

export default MultiActionButtonGroup;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.transfer-trade-button-group {
.multi-action-button-group {
display: flex;
flex-direction: column;
justify-content: space-between;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Button } from '@deriv/components';
import { localize } from '@deriv/translations';
import { Actions } from 'Components/containers/trading-app-card-actions';
import TradeButton from 'Components/trade-button';
import React from 'react';

/**
* Handles Transfer, Trade and top up. It uses the name attribute of the <button /> element to distinguish between transfer and top up
* @param { string } link_to // contains the URL for the trade button
* @param { onAction } // a callback function that handles the current action
* @param { boolean } // indicates whether the current account type is real or demo
* @returns {JSX.Element}
* */
const MultiActionButtonGroup = ({
link_to,
onAction,
is_buttons_disabled,
is_real,
}: Pick<Actions, 'link_to' | 'onAction' | 'is_buttons_disabled' | 'is_real'>) => {
return (
<div className='multi-action-button-group'>
<Button
secondary
name={`${is_real ? 'transfer-btn' : 'topup-btn'}`}
onClick={onAction}
is_disabled={is_buttons_disabled}
>
{is_real ? localize('Transfer') : localize('Top up')}
</Button>
<TradeButton link_to={link_to} onAction={onAction} is_buttons_disabled={is_buttons_disabled} />
</div>
);
};
export default MultiActionButtonGroup;
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const OptionsAndMultipliersListing = () => {
description={localize('Get a real Deriv account, start trading and manage your funds.')}
icon='Options'
availability='All'
type='get'
action_type='get'
onAction={() => {
if (no_MF_account) {
ui.openRealAccountSignup('maltainvest');
Expand All @@ -99,7 +99,7 @@ const OptionsAndMultipliersListing = () => {
<TradingAppCard
key={`trading_app_card_${available_platform.name}`}
{...available_platform}
type={
action_type={
is_demo || (has_any_real_account && !is_eu_user) || (has_maltainvest_account && is_eu_user)
? 'trade'
: 'none'
Expand Down

This file was deleted.

This file was deleted.

15 changes: 13 additions & 2 deletions packages/core/src/Stores/traders-hub-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default class TradersHubStore extends BaseStore {
toggleIsTourOpen: action.bound,
toggleRegulatorsCompareModal: action.bound,
updatePlatformBalance: action.bound,
showTopUpModal: action.bound,
});

reaction(
Expand Down Expand Up @@ -538,7 +539,7 @@ export default class TradersHubStore extends BaseStore {
platform: account.platform,
description: existing_account.display_login,
key: `trading_app_card_${existing_account.display_login}`,
type: 'transfer_trade',
action_type: 'multi-action',
availability: this.selected_region,
market_type: account.market_type,
},
Expand All @@ -553,7 +554,7 @@ export default class TradersHubStore extends BaseStore {
platform: account.platform,
description: account.description,
key: `trading_app_card_${account.name}`,
type: 'get',
action_type: 'get',
availability: this.selected_region,
market_type: account.market_type,
},
Expand Down Expand Up @@ -628,4 +629,14 @@ export default class TradersHubStore extends BaseStore {
);
return { balance: total_balance.balance, currency: base_currency };
}
showTopUpModal(data) {
const { ui, modules } = this.root_store;
const { openTopUpModal } = ui;
const { setCurrentAccount } = modules.cfd;
setCurrentAccount(data, {
category: this.selected_account_type,
type: data.market_type,
});
openTopUpModal();
}
}

0 comments on commit a886796

Please sign in to comment.