Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisyahlen committed Dec 11, 2024
2 parents 04d3976 + e0651a8 commit 1b63531
Show file tree
Hide file tree
Showing 87 changed files with 1,534 additions and 1,178 deletions.
5 changes: 1 addition & 4 deletions __mocks__/translation.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ const useTranslations = () => ({

const localize = mockFn;

const getAllowedLanguages = jest.fn(unsupported_languages => {
if (unsupported_languages.includes('VI')) {
return { EN: 'English' };
}
const getAllowedLanguages = jest.fn(() => {
return { EN: 'English', VI: 'Tiếng Việt' };
});

Expand Down
14 changes: 8 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { routes } from '@deriv/shared';
import LanguageSettings from '../language-settings';
import { mockStore, StoreProvider } from '@deriv/stores';
import { useDevice } from '@deriv-com/ui';
import { useTranslations } from '@deriv-com/translations';
import { useDevice } from '@deriv-com/ui';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import LanguageSettings from '../language-settings';

jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
Expand Down Expand Up @@ -42,9 +44,6 @@ describe('LanguageSettings', () => {
common: {
current_language: 'lang_1',
},
client: {
has_wallet: false,
},
});
(useTranslations as jest.Mock).mockReturnValue({
currentLang: 'EN',
Expand All @@ -59,7 +58,7 @@ describe('LanguageSettings', () => {
});
};

it('should render LanguageSettings with all allowed languages for non-wallets accounts', () => {
it('should render LanguageSettings with all allowed languages', () => {
renderLanguageSettings();

expect(screen.getByText('Select language')).toBeInTheDocument();
Expand All @@ -73,27 +72,11 @@ describe('LanguageSettings', () => {
expect(lang_2).toBeInTheDocument();
});

it('should render LanguageSettings with only wallets-allowed languages for wallets accounts', () => {
mockRootStore.client.has_wallet = true;

renderLanguageSettings();

expect(screen.getByText('Select language')).toBeInTheDocument();

const lang_1 = screen.getByText('English');
const lang_2 = screen.queryByText('Tiếng Việt');

expect(screen.getByText(/Language 1 Flag/)).toBeInTheDocument();
expect(screen.queryByText(/Language 2 Flag/)).not.toBeInTheDocument();
expect(lang_1).toBeInTheDocument();
expect(lang_2).not.toBeInTheDocument();
});

it('should trigger language change', () => {
it('should trigger language change', async () => {
renderLanguageSettings();

const lang_2 = screen.getByText('Tiếng Việt');
userEvent.click(lang_2);
await userEvent.click(lang_2);

expect(mockRootStore.common.changeSelectedLanguage).toHaveBeenCalled();
});
Expand All @@ -110,17 +93,4 @@ describe('LanguageSettings', () => {
expect(screen.queryByText('Select language')).not.toBeInTheDocument();
expect(screen.getByText('Redirect')).toBeInTheDocument();
});

it('should redirect when the user tries to reach `/account/languages` route having wallet accounts', () => {
mockRootStore.client.has_wallet = true;
Object.defineProperty(window, 'location', {
configurable: true,
value: { pathname: routes.languages },
});

renderLanguageSettings();

expect(screen.queryByText('Select language')).not.toBeInTheDocument();
expect(screen.getByText('Redirect')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Redirect } from 'react-router-dom';
import { UNSUPPORTED_LANGUAGES, WALLETS_UNSUPPORTED_LANGUAGES, routes } from '@deriv/shared';
import { UNSUPPORTED_LANGUAGES, routes } from '@deriv/shared';
import { observer, useStore } from '@deriv/stores';
import { useTranslations, getAllowedLanguages } from '@deriv-com/translations';
import FormSubHeader from '../../../Components/form-sub-header';
import LanguageRadioButton from '../../../Components/language-settings';
import { useDevice } from '@deriv-com/ui';

const LanguageSettings = observer(() => {
const { client, common } = useStore();
const { common } = useStore();
const { switchLanguage, currentLang, localize } = useTranslations();
// [TODO]: Remove changeSelectedLanguage() when whole app starts to use @deriv-com/translations
const { changeSelectedLanguage } = common;
const { has_wallet } = client;
const { isDesktop } = useDevice();

if (!isDesktop) {
Expand All @@ -25,9 +24,7 @@ const LanguageSettings = observer(() => {
switchLanguage(language_key);
};

const allowed_languages: Record<string, string> = getAllowedLanguages(
has_wallet ? WALLETS_UNSUPPORTED_LANGUAGES : UNSUPPORTED_LANGUAGES
);
const allowed_languages: Record<string, string> = getAllowedLanguages(UNSUPPORTED_LANGUAGES);

return (
<div className='settings-language'>
Expand Down
4 changes: 2 additions & 2 deletions packages/bot-skeleton/src/scratch/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { saveWorkspaceToRecent } from '../../utils/local-storage';
import DBotStore from '../dbot-store';
import { LogTypes } from '../../constants/messages';
import { error_message_map } from '../../utils/error-config';
import { botNotification } from '../../../../bot-web-ui/src/components/bot-notification/bot-notification';
import { notification_message } from '../../../../bot-web-ui/src/components/bot-notification/bot-notification-utils';
import { botNotification } from '@deriv/bot-web-ui/src/components/bot-notification/bot-notification';
import { notification_message } from '@deriv/bot-web-ui/src/components/bot-notification/bot-notification-utils';

export const inject_workspace_options = {
media: `${__webpack_public_path__}media/`,
Expand Down
10 changes: 9 additions & 1 deletion packages/bot-skeleton/src/services/tradeEngine/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { formatTime, findValueByKeyRecursively, getRoundedNumber, isEmptyObject
import { localize } from '@deriv/translations';
import { error as logError } from './broadcast';
import { observer as globalObserver } from '../../../utils/observer';
import { config } from '../../../constants';

export const tradeOptionToProposal = (trade_option, purchase_reference) =>
trade_option.contractTypes.map(type => {
Expand Down Expand Up @@ -138,6 +139,11 @@ const getBackoffDelayInMs = (error_obj, delay_index) => {
const { error = {}, msg_type = '', echo_req = {} } = error_obj;
const { code = '', message = '' } = error;
let message_to_print = '';
const trade_type_block = Blockly.derivWorkspace
.getAllBlocks(true)
.find(block => block.type === 'trade_definition_tradetype');
const selected_trade_type = trade_type_block?.getFieldValue('TRADETYPECAT_LIST') || '';
const { TRADE_TYPE_CATEGORY_NAMES } = config;

if (code) {
switch (code) {
Expand Down Expand Up @@ -165,9 +171,10 @@ const getBackoffDelayInMs = (error_obj, delay_index) => {
break;
case 'OpenPositionLimitExceeded':
message_to_print = localize(
'You already have an open position for this contract type, retrying in {{ delay }}s',
'You already have an open position for {{ trade_type }} contract type, retrying in {{ delay }}s',
{
delay: next_delay_in_seconds,
trade_type: TRADE_TYPE_CATEGORY_NAMES?.[selected_trade_type] ?? '',
}
);
break;
Expand Down Expand Up @@ -220,6 +227,7 @@ export const shouldThrowError = (error, errors_to_ignore = []) => {
.concat(default_errors_to_ignore)
.includes(error?.error?.code ?? error?.name);

if (error.error?.code === 'OpenPositionLimitExceeded') globalObserver.emit('bot.recoverOpenPositionLimitExceeded');
return !is_ignorable_error;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/bot-web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"@deriv/api-types": "1.0.172",
"@deriv/bot-skeleton": "^1.0.0",
"@deriv/components": "^1.0.0",
"@deriv/deriv-charts": "^2.7.1",
"@deriv/deriv-charts": "^2.7.2",
"@deriv/hooks": "^1.0.0",
"@deriv/quill-icons": "1.23.3",
"@deriv/shared": "^1.0.0",
Expand Down
18 changes: 15 additions & 3 deletions packages/bot-web-ui/src/components/draggable/draggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ const Draggable: React.FC<TDraggableProps> = ({
setIsDragging(false);
isResizing.current = false;
if (draggableContentBody?.style) {
Object.assign(draggableContentBody.style, previousStyle);
try {
Object.assign(draggableContentBody.style, previousStyle);
} catch {
// no need to handle this error
}
draggableContentBody.style.pointerEvents = previousPointerEvent ?? 'unset';
}
if (boundaryRef) {
Expand All @@ -196,7 +200,12 @@ const Draggable: React.FC<TDraggableProps> = ({
return (
<div
className={`draggable ${isDragging ? 'dragging' : ''}`}
style={{ position: 'absolute', top: position.y, left: position.x, zIndex }}
style={{
position: 'absolute',
top: typeof position.y === 'number' ? position.y : 0,
left: typeof position.x === 'number' ? position.x : 0,
zIndex: typeof zIndex === 'number' ? zIndex : 0,
}}
onMouseDown={() => calculateZindex({ setZIndex })}
onKeyDown={() => calculateZindex({ setZIndex })}
data-testid='dt_react_draggable'
Expand All @@ -206,7 +215,10 @@ const Draggable: React.FC<TDraggableProps> = ({
ref={draggableRef}
className='draggable-content'
data-testid='dt_react_draggable_content'
style={{ width: size.width, height: size.height }}
style={{
width: typeof size.width === 'number' ? size.width : 0,
height: typeof size.height === 'number' ? size.height : 0,
}}
>
<div
id='draggable-content__header'
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-web-ui/src/constants/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type TSupportedContracts = {

export const getSupportedContracts = (is_high_low: boolean): TSupportedContracts => ({
ACCU: {
name: 'Accumulators',
name: localize('Accumulators'),
position: 'top',
},
ASIANU: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ const StrategyList = ({ selector_chip_value, search_value, is_searching, onSelec
const selected_chip_value = TRADE_TYPES[selector_chip_value];

const strategy_types: TStrategyTypes = [
{ type: localize('Accumulators'), items: accumulator },
{ type: localize('Options'), items: options },
{ type: localize('Multipliers'), items: multiplier },
{ type: localize('Accumulators'), items: accumulator },
];

const should_render = (type: string) => selected_chip_value === 'All' || selected_chip_value === type;
const should_render = (type: string) => selected_chip_value === localize('All') || selected_chip_value === type;

const filtered_strategies = strategy_types.filter(({ type }) => should_render(type));
const has_visible_strategies = filtered_strategies.some(({ items }) => items.length > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ export type TRsStrategyName =
| `reverse martingale`
| `reverse d'alembert`
| `1-3-2-6`
| `D’Alembert`;
| `ACCUMULATORS_MARTINGALE`
| `ACCUMULATORS_DALEMBERT`
| `ACCUMULATORS_MARTINGALE_ON_STAT_RESET`
| `ACCUMULATORS_DALEMBERT_ON_STAT_RESET`
| `ACCUMULATORS_REVERSE_MARTINGALE`
| `ACCUMULATORS_REVERSE_MARTINGALE_ON_STAT_RESET`
| `ACCUMULATORS_REVERSE_DALEMBERT`
| `ACCUMULATORS_REVERSE_DALEMBERT_ON_STAT_RESET`;

export type TDurationType = 't' | 's' | 'm' | 'h' | 'd';

Expand Down
11 changes: 11 additions & 0 deletions packages/bot-web-ui/src/stores/run-panel-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export default class RunPanelStore {
setHasOpenContract: action,
setIsRunning: action,
onRunButtonClick: action,
is_contracy_buying_in_progress: observable,
OpenPositionLimitExceededEvent: action,
onStopButtonClick: action,
onClearStatClick: action,
clearStat: action,
Expand Down Expand Up @@ -102,6 +104,7 @@ export default class RunPanelStore {
is_dialog_open = false;
is_sell_requested = false;
show_bot_stop_message = false;
is_contracy_buying_in_progress = false;

run_id = '';
onOkButtonClick: (() => void) | null = null;
Expand All @@ -117,6 +120,9 @@ export default class RunPanelStore {
}

get is_stop_button_disabled() {
if (this.is_contracy_buying_in_progress) {
return false;
}
return [contract_stages.PURCHASE_SENT as number, contract_stages.IS_STOPPING as number].includes(
this.contract_stage
);
Expand Down Expand Up @@ -210,6 +216,7 @@ export default class RunPanelStore {
};

onStopButtonClick = () => {
this.is_contracy_buying_in_progress = false;
const { is_multiplier } = this.root_store.summary_card;

if (is_multiplier) {
Expand Down Expand Up @@ -429,8 +436,11 @@ export default class RunPanelStore {
observer.register('bot.contract', summary_card.onBotContractEvent);
observer.register('bot.contract', transactions.onBotContractEvent);
observer.register('Error', this.onError);
observer.register('bot.recoverOpenPositionLimitExceeded', this.OpenPositionLimitExceededEvent);
};

OpenPositionLimitExceededEvent = () => (this.is_contracy_buying_in_progress = true);

registerReactions = () => {
const { client, common, notifications } = this.core;
let disposeIsSocketOpenedListener: (() => void) | undefined, disposeLogoutListener: (() => void) | undefined;
Expand Down Expand Up @@ -570,6 +580,7 @@ export default class RunPanelStore {
break;
}
case 'contract.purchase_received': {
this.is_contracy_buying_in_progress = false;
this.setContractStage(contract_stages.PURCHASE_RECEIVED);
const { buy } = contract_status;
const { is_virtual } = this.core.client;
Expand Down
4 changes: 2 additions & 2 deletions packages/bot-web-ui/src/stores/transactions-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export default class TransactionsStore {
);
const statistics = trxs.reduce(
(stats, { data }) => {
const { profit = 0, is_completed = false, payout = 0, buy_price = 0 } = data as TContractInfo;
const { profit = 0, is_completed = false, payout, buy_price = 0, bid_price } = data as TContractInfo;
if (is_completed) {
if (profit > 0) {
stats.won_contracts += 1;
stats.total_payout += payout;
stats.total_payout += payout ?? bid_price ?? 0;
} else {
stats.lost_contracts += 1;
}
Expand Down
Loading

0 comments on commit 1b63531

Please sign in to comment.