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

DTRA / Kate / DTRA-1542 / [DTreader-V2]: Guide and Allow equal changes #16215

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
162 changes: 156 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@deriv-com/utils": "^0.0.25",
"@deriv-com/ui": "1.29.9",
"@deriv/api": "^1.0.0",
"@deriv-com/quill-ui": "1.13.22",
"@deriv-com/quill-ui": "1.13.23",
"@deriv/components": "^1.0.0",
"@deriv/hooks": "^1.0.0",
"@deriv/integration": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@datadog/browser-rum": "^5.11.0",
"@deriv-com/analytics": "1.10.0",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "1.13.22",
"@deriv-com/quill-ui": "1.13.23",
"@deriv-com/translations": "1.3.4",
"@deriv-com/ui": "1.29.9",
"@deriv-com/utils": "^0.0.25",
Expand Down
2 changes: 1 addition & 1 deletion packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@cloudflare/stream-react": "^1.9.1",
"@deriv-com/analytics": "1.10.0",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "1.13.22",
"@deriv-com/quill-ui": "1.13.23",
"@deriv-com/utils": "^0.0.25",
"@deriv-com/ui": "1.29.9",
"@deriv/api-types": "1.0.172",
Expand Down
11 changes: 11 additions & 0 deletions packages/trader/src/AppV2/Components/Guide/guide.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
}

&__menu {
position: relative;
width: calc(100vw - var(--component-actionSheet-spacing-padding-lg));
padding-inline-end: var(--component-actionSheet-spacing-padding-lg);
margin-block-end: var(--component-actionSheet-spacing-padding-md);
display: flex;
Expand All @@ -14,6 +16,10 @@
-ms-overflow-style: none;
scrollbar-width: none;

&::-webkit-scrollbar {
display: none;
}

button {
background-color: transparent;
}
Expand All @@ -22,6 +28,7 @@
&__wrapper {
&--content {
padding: var(--component-actionSheet-spacing-padding-lg) var(--component-actionSheet-spacing-padding-lg) 0;
overflow-x: hidden;
}
}

Expand All @@ -30,6 +37,10 @@
height: calc(90dvh - 23rem);
-ms-overflow-style: none;
scrollbar-width: none;

&::-webkit-scrollbar {
display: none;
}
}

&__button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Money } from '@deriv/components';

type TPurchaseButtonContent = {
current_stake?: number | null;
info: ReturnType<typeof useTraderStore>['proposal_info'][0];
info: ReturnType<typeof useTraderStore>['proposal_info'][0] | Record<string, never>;
is_reverse?: boolean;
} & Pick<
ReturnType<typeof useTraderStore>,
Expand All @@ -32,19 +32,28 @@ const PurchaseButtonContent = ({
is_vanilla_fx,
is_reverse,
}: TPurchaseButtonContent) => {
const localized_basis = getLocalizedBasis();
const {
current_stake: localized_current_stake,
max_payout,
payout,
payout_per_point,
payout_per_pip,
stake,
} = getLocalizedBasis();

const getAmount = () => {
if (is_multiplier) return info.stake;
if (is_accumulator) return has_open_accu_contract ? Number(current_stake) : info.maximum_payout;
return info?.obj_contract_basis?.value;
const { stake, maximum_payout, obj_contract_basis } = info;

if (is_multiplier) return stake;
if (is_accumulator) return has_open_accu_contract ? Number(current_stake) : maximum_payout;
return obj_contract_basis?.value;
};
const getTextBasis = () => {
if (is_turbos || (is_vanilla && !is_vanilla_fx)) return localized_basis.payout_per_point;
if (is_vanilla_fx) return localized_basis.payout_per_pip;
if (is_multiplier) return localized_basis.stake;
if (is_accumulator) return has_open_accu_contract ? localized_basis.current_stake : localized_basis.max_payout;
return localized_basis.payout;
if (is_turbos || (is_vanilla && !is_vanilla_fx)) return payout_per_point;
if (is_vanilla_fx) return payout_per_pip;
if (is_multiplier) return stake;
if (is_accumulator) return has_open_accu_contract ? localized_current_stake : max_payout;
return payout;
};

const text_basis = getTextBasis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ describe('AllowEquals', () => {
expect(screen.getByRole('dialog')).toHaveAttribute('data-state', 'open');
});

it('should call onChange function if user opens ActionSheet, changes ToggleSwitch and clicks on "Save" button', () => {
it('should call onChange function if user opens ActionSheet and clicks on ToggleSwitch', () => {
render(mockAllowEquals());

userEvent.click(screen.getByRole('textbox'));

const [toggle_switch_button, save_button] = screen.getAllByRole('button');
expect(toggle_switch_button).toHaveAttribute('aria-pressed', 'false');
const toggle_switch_button = screen.getByRole('button');
userEvent.click(toggle_switch_button);
expect(toggle_switch_button).toHaveAttribute('aria-pressed', 'true');

userEvent.click(save_button);
expect(default_mock_store.modules.trade.onChange).toBeCalled();
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
$HANDLEBAR_HEIGHT: var(--core-size-1000);
$HEADER_TITLE_HEIGHT: var(--core-size-3200);
$FOOTER_BUTTON_HEIGHT: var(--core-size-4000);

.allow-equals {
&__wrapper {
height: calc(40dvh - $HANDLEBAR_HEIGHT - $HEADER_TITLE_HEIGHT - $FOOTER_BUTTON_HEIGHT);

&--definition {
height: calc(40dvh - $HANDLEBAR_HEIGHT - $HEADER_TITLE_HEIGHT);
}
height: calc(400px - $HANDLEBAR_HEIGHT - $HEADER_TITLE_HEIGHT);
padding-block-start: 0;
}

&__content {
display: flex;
justify-content: space-between;
align-items: center;
padding-block: var(--core-spacing-400);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import { observer } from 'mobx-react';
import clsx from 'clsx';
import { ActionSheet, ToggleSwitch, Text, TextField } from '@deriv-com/quill-ui';
import { ActionSheet, CaptionText, ToggleSwitch, Text, TextField } from '@deriv-com/quill-ui';
import { Localize, localize } from '@deriv/translations';
import { hasCallPutEqual, hasDurationForCallPutEqual } from 'Stores/Modules/Trading/Helpers/allow-equals';
import { useTraderStore } from 'Stores/useTraderStores';
import Carousel from 'AppV2/Components/Carousel';
import AllowEqualsHeader from './allow-equals-header';

type TAllowEqualsProps = {
is_minimized?: boolean;
Expand All @@ -17,7 +15,6 @@ const AllowEquals = observer(({ is_minimized }: TAllowEqualsProps) => {
useTraderStore();

const [is_open, setIsOpen] = React.useState(false);
const [is_allow_equal_enabled, setIsAllowEqualEnabled] = React.useState(!!is_equal);

const has_callputequal_duration = hasDurationForCallPutEqual(
contract_types_list,
Expand All @@ -27,59 +24,11 @@ const AllowEquals = observer(({ is_minimized }: TAllowEqualsProps) => {
const has_callputequal = hasCallPutEqual(contract_types_list);
const has_allow_equals = (has_callputequal_duration || expiry_type === 'endtime') && has_callputequal;

const onSaveButtonClick = () => {
if (!!is_equal !== is_allow_equal_enabled)
onChange({ target: { name: 'is_equal', value: Number(is_allow_equal_enabled) } });
};
const onActionSheetClose = () => {
const onToggleSwitch = (is_enabled: boolean) => {
onChange({ target: { name: 'is_equal', value: Number(is_enabled) } });
setIsOpen(false);
setIsAllowEqualEnabled(!!is_equal);
};

const action_sheet_content = [
{
id: 1,
component: (
<React.Fragment>
<ActionSheet.Content className='allow-equals__wrapper'>
<div className='allow-equals__content'>
<Text>
<Localize i18n_default_text='Allow equals' />
</Text>
<ToggleSwitch
checked={is_allow_equal_enabled}
onChange={(is_enabled: boolean) => setIsAllowEqualEnabled(is_enabled)}
/>
</div>
</ActionSheet.Content>
<ActionSheet.Footer
alignment='vertical'
primaryAction={{
content: <Localize i18n_default_text='Save' />,
onAction: onSaveButtonClick,
}}
/>
</React.Fragment>
),
},
{
id: 2,
component: (
<ActionSheet.Content className='allow-equals__wrapper--definition'>
<div className='allow-equals__content'>
<Text>
<Localize i18n_default_text='Win payout if exit spot is also equal to entry spot.' />
</Text>
</div>
</ActionSheet.Content>
),
},
];

React.useEffect(() => {
setIsAllowEqualEnabled(!!is_equal);
}, [is_equal]);

if (!has_allow_equals) return null;

return (
Expand All @@ -97,9 +46,20 @@ const AllowEquals = observer(({ is_minimized }: TAllowEqualsProps) => {
className={clsx('trade-params__option', is_minimized && 'trade-params__option--minimized')}
onClick={() => setIsOpen(true)}
/>
<ActionSheet.Root isOpen={is_open} onClose={onActionSheetClose} position='left' expandable={false}>
<ActionSheet.Root isOpen={is_open} onClose={() => setIsOpen(false)} position='left' expandable={false}>
<ActionSheet.Portal shouldCloseOnDrag>
<Carousel header={AllowEqualsHeader} pages={action_sheet_content} />
<ActionSheet.Header title={<Localize i18n_default_text='Allow equals' />} />
<ActionSheet.Content className='allow-equals__wrapper'>
<div className='allow-equals__content'>
<Text>
<Localize i18n_default_text='Allow equals' />
</Text>
<ToggleSwitch checked={!!is_equal} onChange={onToggleSwitch} />
</div>
<CaptionText color='quill-typography__color--subtle'>
<Localize i18n_default_text='Win payout if exit spot is also equal to entry spot.' />
</CaptionText>
</ActionSheet.Content>
</ActionSheet.Portal>
</ActionSheet.Root>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const LastDigitPrediction = observer(({ is_minimized, is_stats_mode }: TLastDigi
};
const onActionSheetClose = () => {
setIsOpen(false);
//TODO: check if we need these 2 resets below after latest Quill Action sheet changes will be in our branch
Copy link
Contributor Author

@kate-deriv kate-deriv Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, it's not connected with quill, it's because state is stored in the parent. Hence, remove

setSelectedDigit(last_digit);
};

Expand All @@ -47,7 +46,7 @@ const LastDigitPrediction = observer(({ is_minimized, is_stats_mode }: TLastDigi
key={`last-digit-prediction${is_minimized ? '-minimized' : ''}`}
/>
}
value={last_digit.toString()} // TODO: remove toString after TextField supports a numeric 0 value in quill-ui
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was fixed in the latest quill version

value={last_digit}
className={clsx('trade-params__option', 'trade-params__option--minimized')}
onClick={() => setIsOpen(true)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
padding: 0px;
transition: transform 0.5s, opacity 0.5s, max-height 0.5s, padding 0.1s;

&::-webkit-scrollbar {
display: none;
}
&--enter,
&--exit {
opacity: 0;
Expand Down
4 changes: 4 additions & 0 deletions packages/trader/src/AppV2/Containers/Trade/trade.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
white-space: nowrap;
scrollbar-width: none;

&::-webkit-scrollbar {
display: none;
}

button {
background-color: transparent;
}
Expand Down
Loading