Skip to content

Commit

Permalink
chore: resolved conflicts and updated with master
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Fasih Ali Naqvi authored and Muhammad Fasih Ali Naqvi committed May 8, 2024
2 parents 5af959a + 03d030f commit 9c234ba
Show file tree
Hide file tree
Showing 29 changed files with 528 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ const FinancialAssessment = observer(() => {
}
onChange={e => {
setFieldTouched('employment_status', true);
handleChange(e);
setFieldValue(
'occupation',
'',
!shouldHideOccupationField(e.target.value)
);
handleChange(e);
}}
/>
</MobileWrapper>
Expand Down
3 changes: 2 additions & 1 deletion packages/api-v2/src/hooks/useAuthorize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import { useAuthContext } from '../AuthProvider';
import { getAccountListWithAuthToken } from '@deriv/utils';

/** A custom hook that authorize the user with the given token. If no token is given,
* it will use the current token from localStorage.
Expand All @@ -9,7 +10,7 @@ const useAuthorize = () => {
const { data, switchAccount, isLoading, isSuccess, isFetching, isError, refetch, error, loginid } = ctx;

const modifiedData = useMemo(() => {
return { ...data?.authorize };
return { ...data?.authorize, account_list: getAccountListWithAuthToken(data?.authorize?.account_list) };
}, [data]);

const value = useMemo(() => {
Expand Down
3 changes: 2 additions & 1 deletion packages/api-v2/src/hooks/useDerivAccountsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useBalance from './useBalance';
import useCurrencyConfig from './useCurrencyConfig';
import { displayMoney } from '../utils';
import useAuthorizedQuery from '../useAuthorizedQuery';
import { getAccountListWithAuthToken } from '@deriv/utils';

/** A custom hook that returns the list of accounts for the current user. */
const useDerivAccountsList = () => {
Expand All @@ -23,7 +24,7 @@ const useDerivAccountsList = () => {

// Add additional information to the authorize response.
const modified_accounts = useMemo(() => {
return account_list_data?.account_list?.map(account => {
return getAccountListWithAuthToken(account_list_data?.account_list)?.map(account => {
return {
...account,
/** Creation time of the account. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { localize } from '@deriv/translations';
import ContractResultOverlay from 'Components/contract-result-overlay';
import { contract_stages } from 'Constants/contract-stage';
import { useDBotStore } from 'Stores/useDBotStore';
import { rudderStackSendRunBotEvent } from '../../pages/bot-builder/quick-strategy/analytics/rudderstack-quick-strategy';
import CircularWrapper from './circular-wrapper';
import ContractStageText from './contract-stage-text';

Expand Down Expand Up @@ -89,6 +90,7 @@ const TradeAnimation = observer(({ className, should_show_overlay }: TTradeAnima
return;
}
onRunButtonClick();
rudderStackSendRunBotEvent();
}}
has_effect
{...(is_stop_button_visible || !is_unavailable_for_payment_agent ? { primary: true } : { green: true })}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import MobileTransactionCards from '../mobile-transaction-card';

jest.mock('@deriv/bot-skeleton/src/scratch/dbot', () => ({
saveRecentWorkspace: jest.fn(),
unHighlightAllBlocks: jest.fn(),
}));

const mock_transaction_data = {
barrier: '8641.67',
buy_price: 11,
contract_id: 211133945828,
contract_type: 'CALL',
currency: 'USD',
date_start: '2023-6-21 06:10:20 GMT',
display_name: 'Volatility 10 (1s) Index',
entry_tick: '8641.67',
entry_tick_time: '2023-6-21 06:10:21 GMT',
exit_tick: '8641.36',
exit_tick_time: '2023-6-21 06:10:22 GMT',
is_completed: true,
payout: 1.95,
profit: -2,
run_id: 'run-1687327817157',
shortcode: 'CALL_1HZ10V_1.95_1687327820_1T_S0P_0',
tick_count: 1,
transaction_ids: {
buy: 421306672788,
sell: 421306674448,
},
underlying: '1HZ10V',
};

describe('MobileTransactionCards', () => {
it('should render MobileTransactionCards', () => {
render(<MobileTransactionCards transaction={mock_transaction_data} />);
expect(screen.getByTestId('dt_mobile_transaction_card')).toBeInTheDocument();
});

it('should display transaction details', () => {
render(<MobileTransactionCards transaction={mock_transaction_data} />);
expect(screen.getByText('421306672788')).toBeInTheDocument();
expect(screen.getByText('2023-06-21 06:10:20 GMT')).toBeInTheDocument();
expect(screen.getByText('8641.67')).toBeInTheDocument();
expect(screen.getByText('11.00')).toBeInTheDocument();
expect(screen.getByText('2.00')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import TransactionDetailsMobile from '../transaction-details-mobile';

jest.mock('../../../utils/session-storage', () => ({
...jest.requireActual('../../../utils/session-storage'),
getStoredItemsByUser: jest.fn(() => [
{
type: 'contract',
data: {
...mock_contract,
getStoredItemsByUser: jest.fn(() => ({
'001': [
{
type: 'contract',
data: {
...mock_contract,
transaction_ids: {
buy: 421306672718,
sell: 421306674448,
},
},
},
{
type: 'divider',
},
},
{
type: 'divider',
},
]),
],
})),
}));

jest.mock('@deriv/bot-skeleton/src/scratch/blockly', () => jest.fn());
Expand Down Expand Up @@ -51,6 +57,9 @@ describe('TransactionDetailsMobile', () => {
const mock_store = mockStore({});

beforeAll(() => {
const mock_store = mockStore({
client: { loginid: '001' },
});
mock_DBot_store = mockDBotStore(mock_store, mock_ws);

wrapper = ({ children }: { children: JSX.Element }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const IconContainer = ({ message, icon }: { message: string; icon: ReactElement

export default function MobileTransactionCards({ transaction }: { transaction: TTransaction }) {
return (
<div className={`${PARENT_CLASS}__card`}>
<div className={`${PARENT_CLASS}__card`} data-testid='dt_mobile_transaction_card'>
<div className={`${PARENT_CLASS}__card__row`}>
<CardColumn
label={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TFormValues } from '../types';

export const form_name = 'ce_bot_form';
export const STORED_ITEM_NOT_FOUND = 'No results found';

export enum ACTION {
OPEN = 'open',
CLOSE = 'close',
RUN_QUICK_STRATEGY = 'run_quick_strategy',
EDIT_QUICK_STRATEGY = 'edit_quick_strategy',
SELECT_QUICK_STRATEGY_GUIDE = 'select_quick_strategy_guide',
SWITCH_QUICK_STRATEGY_TAB = 'switch_quick_strategy_tab',
}

export type TFormStrategy = {
form_values: TFormValues;
} & TSelectedStrategy;

export type TSelectedStrategy = {
selected_strategy: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Analytics, TEvents } from '@deriv-com/analytics';
import { ACTION, form_name, type TFormStrategy, type TSelectedStrategy } from './constants';
import { getRsStrategyType, getSubpageName, getTradeParameterData } from './utils';

export const rudderStackSendQsOpenEventFromDashboard = () => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.OPEN,
form_name,
subpage_name: getSubpageName(),
subform_name: 'quick_strategy',
subform_source: 'dashboard',
});
};

export const rudderStackSendQsOpenEventFromBotBuilder = () => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.OPEN,
form_name,
subpage_name: getSubpageName(),
subform_name: 'quick_strategy',
subform_source: 'bot_builder',
});
};

export const rudderStackSendQsCloseEvent = ({
quick_strategy_tab,
selected_strategy,
}: TEvents['ce_bot_form'] & TFormStrategy) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.CLOSE,
form_name,
subpage_name: getSubpageName(),
subform_name: 'quick_strategy',
quick_strategy_tab,
strategy_name: getRsStrategyType(selected_strategy),
});
};

export const rudderStackSendQsRunStrategyEvent = ({
form_values,
selected_strategy,
}: TEvents['ce_bot_form'] & TFormStrategy) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.RUN_QUICK_STRATEGY,
form_name,
subform_name: 'quick_strategy',
...getTradeParameterData({ form_values, selected_strategy }),
});
};

export const rudderStackSendQsEditStrategyEvent = ({
form_values,
selected_strategy,
}: TEvents['ce_bot_form'] & TFormStrategy) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.EDIT_QUICK_STRATEGY,
form_name,
subform_name: 'quick_strategy',
...getTradeParameterData({ form_values, selected_strategy }),
});
};

export const rudderStackSendQsSelectedTabEvent = ({ quick_strategy_tab }: TEvents['ce_bot_form']) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.SWITCH_QUICK_STRATEGY_TAB,
form_name,
subform_name: 'quick_strategy',
quick_strategy_tab,
});
};

export const rudderStackSendSelectQsStrategyGuideEvent = ({ selected_strategy }: TSelectedStrategy) => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.SELECT_QUICK_STRATEGY_GUIDE,
form_name,
subform_name: 'quick_strategy',
strategy_name: getRsStrategyType(selected_strategy),
});
};

export const rudderStackSendRunBotEvent = () => {
Analytics.trackEvent('ce_bot_form', {
action: ACTION.SELECT_QUICK_STRATEGY_GUIDE,
form_name,
subpage_name: getSubpageName(),
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { STRATEGIES } from '../config';
import { STORED_ITEM_NOT_FOUND, TFormStrategy } from './constants';

export const getRsDropdownTextFromLocalStorage = () => {
try {
return JSON.parse(localStorage?.getItem('qs-analytics') ?? '{}');
} catch (error) {
// eslint-disable-next-line no-console
console.error('Rudderstack: unable to get dropdown text');
return {};
}
};

const hasStoredText = (parameter: string) => parameter && parameter !== STORED_ITEM_NOT_FOUND;

export const getRsStrategyType = (selected_strategy: string) => STRATEGIES[selected_strategy]?.rs_strategy_name;

export const getQsActiveTabString = (tab: string) => (tab === 'TRADE_PARAMETERS' ? 'trade parameters' : 'learn more');

export const getSubpageName = () => {
const pathname = window.location.hash;
switch (pathname) {
case 'dashboard':
return 'dashboard';
case 'charts':
return 'charts';
case 'tutorials':
return 'tutorials';
default:
return 'bot_builder';
}
};

export const getTradeParameterData = ({ form_values }: TFormStrategy) => {
const { symbol, tradetype, type, stake } = form_values;
const stored_texts = getRsDropdownTextFromLocalStorage();

return {
asset_type: hasStoredText(stored_texts?.symbol) ? stored_texts.symbol : symbol,
trade_type: hasStoredText(stored_texts?.tradetype) ? stored_texts?.tradetype : tradetype,
purchase_condition: hasStoredText(stored_texts?.type) ? stored_texts?.type : type,
initial_stake: hasStoredText(stored_texts?.stake) ? stored_texts?.stake : stake,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const STRATEGIES: TStrategies = {
MARTINGALE: {
name: 'martingale_max-stake',
label: localize('Martingale'),
rs_strategy_type: 'martingale',
rs_strategy_name: 'martingale',
description: MARTINGALE,
fields: [
[
Expand All @@ -235,7 +235,7 @@ export const STRATEGIES: TStrategies = {
D_ALEMBERT: {
name: 'dalembert_max-stake',
label: localize('D’Alembert'),
rs_strategy_type: `d'alembert`,
rs_strategy_name: `d'alembert`,
description: D_ALEMBERT,
fields: [
[
Expand All @@ -259,7 +259,7 @@ export const STRATEGIES: TStrategies = {
OSCARS_GRIND: {
name: 'oscars_grind_max-stake',
label: localize('Oscar’s Grind'),
rs_strategy_type: `oscar's-grind`,
rs_strategy_name: `oscar's-grind`,
description: OSCARS_GRIND,
fields: [
[
Expand All @@ -283,7 +283,7 @@ export const STRATEGIES: TStrategies = {
REVERSE_MARTINGALE: {
name: 'reverse_martingale',
label: localize('Reverse Martingale'),
rs_strategy_type: 'reverse martingale',
rs_strategy_name: 'reverse martingale',
description: REVERSE_MARTINGALE,
fields: [
[
Expand Down Expand Up @@ -316,7 +316,7 @@ export const STRATEGIES: TStrategies = {
REVERSE_D_ALEMBERT: {
name: 'reverse_dalembert',
label: localize('Reverse D’Alembert'),
rs_strategy_type: `reverse d'alembert`,
rs_strategy_name: `reverse d'alembert`,
description: REVERSE_D_ALEMBERT,
fields: [
[
Expand All @@ -340,7 +340,7 @@ export const STRATEGIES: TStrategies = {
STRATEGY_1_3_2_6: {
name: '1_3_2_6',
label: localize('1-3-2-6'),
rs_strategy_type: '1-3-2-6',
rs_strategy_name: '1-3-2-6',
description: STRATEGY_1_3_2_6,
fields: [
[
Expand Down
Loading

0 comments on commit 9c234ba

Please sign in to comment.