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/Maryia/DTRA-1279/Redesign: Positions page #15234

Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d491b16
chore: empty commit
kate-deriv May 16, 2024
5319334
Merge branch 'binary-com:master' into maryia/kate/DTRA-1279/redesign_…
maryia-deriv May 17, 2024
ef49019
feat: tabs + background + initialized EmptyMessage component
maryia-deriv May 17, 2024
b7249bd
Merge branch 'binary-com:master' into maryia/kate/DTRA-1279/redesign_…
maryia-deriv May 17, 2024
e2ed78f
Merge branch 'maryia/kate/DTRA-1279/redesign_position_page' of github…
maryia-deriv May 17, 2024
306b749
Merge pull request #49 from maryia-deriv/maryia/positions_redesign/ta…
maryia-deriv May 17, 2024
163829f
Maryia/Positions-redesign/improve EmptyMessage component + add tests …
maryia-deriv May 18, 2024
44bcd50
Merge branch 'binary-com:master' into maryia/kate/DTRA-1279/redesign_…
kate-deriv May 20, 2024
51fe756
chore: empty commit
kate-deriv May 20, 2024
8e843d3
Merge branch 'binary-com:master' into maryia/kate/DTRA-1279/redesign_…
kate-deriv May 20, 2024
4be88d0
DTRA-1279 / Kate / Filter [WIP] (#51)
kate-deriv May 20, 2024
146a56f
chore: empty commit
kate-deriv May 20, 2024
185a4bc
fix: sonarcloud issues
kate-deriv May 20, 2024
1609ba2
Merge branch 'binary-com:master' into maryia/kate/DTRA-1279/redesign_…
kate-deriv May 21, 2024
32e60f1
chore: empty commit
kate-deriv May 21, 2024
59e9b17
chore: add modules store and useclosedposition hook (#52)
balakrishna-deriv May 21, 2024
2e7c763
refactor: remove todo and change some prop based on quill updates (#54)
kate-deriv May 21, 2024
559182d
DTRA-1279 / Kate / Use hook for real data (#55)
kate-deriv May 21, 2024
7ffc67e
Merge branch master into maryia/kate/DTRA-1279/redesign_position_page
kate-deriv May 21, 2024
4c4ced5
Maryia/positions-redesign/Contract cards [WIP] (#53)
maryia-deriv May 21, 2024
1437e77
DTRA-1279 / Kate / Refactor handling open and closed positions and th…
kate-deriv May 22, 2024
6c5106b
Maryia/positions-redesign/Contract cards improvements + fetching Open…
maryia-deriv May 23, 2024
db3f8d2
fix: style
kate-deriv May 23, 2024
5e29ab9
DTRA-1279/ Kate / Create filter component (#57)
kate-deriv May 23, 2024
6ad25f5
DTRA-1279 / Kate / Refactor: add new content for empty page (#59)
kate-deriv May 23, 2024
42dc7af
Maryia/positions-redesign/Contract cards data update fix (#61)
maryia-deriv May 23, 2024
3a5dc29
chore: update quill version (#63)
kate-deriv May 24, 2024
13254e6
Maryia/positions-redesign/Contract card loading state and status time…
maryia-deriv May 24, 2024
4abfa7d
DTRA-1279/ Kate/ Feat: add Date picker (#62)
kate-deriv May 24, 2024
7e4e35b
chore: localization
kate-deriv May 24, 2024
d1edd0c
DTRA-1279 / Kate/ Add filtration hooks (#65)
kate-deriv May 25, 2024
3c699fe
DTRA-1279 / Kate / Add tests (#66)
kate-deriv May 25, 2024
29053e5
DTRA-1279 / Kate / Double filtration and extra filter options (#67)
kate-deriv May 27, 2024
abd7ffd
chore: update quill and token library version
kate-deriv May 27, 2024
e0e6896
DTRA-1279 / Kate / Add section separator (#68)
kate-deriv May 27, 2024
06c9356
DTRA-1279 / Kate / Tech Debt (#69)
kate-deriv May 27, 2024
c56fb28
Maryia/positions-redesign/finilise contract card + add total profit l…
maryia-deriv May 27, 2024
c36e3ae
fix: loading state and loading more on infinite scroll in Closed tab …
maryia-deriv May 28, 2024
132fe7b
DTRA-1279 / Kate / Tech Debt part 2 [WIP] (#72)
kate-deriv May 28, 2024
b6e45fb
Maryia/positions-redesign/test contract card + fix scroll behavior, d…
maryia-deriv May 28, 2024
2105c28
refactor: update quill version and refactor
kate-deriv May 28, 2024
588856c
Merge branch master of github.com:binary-com/deriv-app into maryia/ka…
kate-deriv May 28, 2024
336c62c
refactor: chip component (#74)
kate-deriv May 28, 2024
4906b00
refactor: position content page
kate-deriv May 28, 2024
b38274e
Maryia/positions-redesign/test: ContractCardList, ContractCardStatusT…
maryia-deriv May 28, 2024
2f79d0a
Maryia/positions-redesign/fix: tests + address sonarcloud + use clsx …
maryia-deriv May 28, 2024
28f35b3
refactor: sonarcloud - reduce complexity
maryia-deriv May 28, 2024
1be30a2
fix: cards filtering in PositionsContent + tests + style+bug fixes
maryia-deriv May 29, 2024
823d896
build: trigger checks
maryia-deriv May 29, 2024
e640142
fix: hasNoActiveFilters condition
maryia-deriv May 29, 2024
6e0d5a3
Merge branch 'binary-com:master' into maryia/kate/DTRA-1279/redesign_…
kate-deriv May 29, 2024
096946b
fix: update package version and remove prop from action sheet
kate-deriv May 29, 2024
134e067
chore: rename function
kate-deriv May 29, 2024
8581ea2
Maryia/positions-redesign/feat: display correct active positions coun…
maryia-deriv May 29, 2024
0826f6c
refactor: filter behaviour
kate-deriv May 29, 2024
70b2058
chore: add padding
kate-deriv May 29, 2024
82a2c35
fix: positions count in footer to not show 0 (#78)
maryia-deriv May 29, 2024
fc343cd
refactor: total profit loss
kate-deriv May 29, 2024
85f0fdd
chore: add tests for tpl and refactor date picker
kate-deriv May 29, 2024
75e0e40
refactor: add loadre inside of empty positions
kate-deriv May 29, 2024
3b69cd1
fix: tests
kate-deriv May 29, 2024
81ee2d0
Maryia/positions-redesign/fix: loader on infinite scroll in Closed ta…
maryia-deriv May 29, 2024
1a677eb
chore: rename timet
kate-deriv May 29, 2024
ebcd0df
DTRA-1279 / Kate / Add a single date selection (#80)
kate-deriv May 29, 2024
8d622f5
Merge branch master of github.com:binary-com/deriv-app into maryia/ka…
maryia-deriv May 29, 2024
3c37e0b
Merge branch master of github.com:binary-com/deriv-app into maryia/ka…
kate-deriv May 30, 2024
9217413
Merge branch master into maryia/kate/DTRA-1279/redesign_position_page
kate-deriv Jun 4, 2024
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
157 changes: 153 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { formatDuration, getDiffDuration } from '@deriv/shared';
import { TGetCardLables } from '../types';

type TRemainingTimeProps = {
as?: React.ElementType;
end_time?: number;
start_time: moment.Moment;
format?: string;
getCardLabels: TGetCardLables;
};

const RemainingTime = ({ end_time, format, getCardLabels, start_time }: TRemainingTimeProps) => {
const RemainingTime = ({ as = 'div', end_time, format, getCardLabels, start_time }: TRemainingTimeProps) => {
const Tag = as;
if (!end_time || start_time.unix() > +end_time) {
return <React.Fragment>{''}</React.Fragment>;
}
Expand All @@ -24,7 +26,7 @@ const RemainingTime = ({ end_time, format, getCardLabels, start_time }: TRemaini
}
const is_zeroes = /^00:00$/.test(remaining_time);

return <React.Fragment>{!is_zeroes && <div className='dc-remaining-time'>{remaining_time}</div>}</React.Fragment>;
return <React.Fragment>{!is_zeroes && <Tag className='dc-remaining-time'>{remaining_time}</Tag>}</React.Fragment>;
Copy link
Contributor Author

@maryia-deriv maryia-deriv May 28, 2024

Choose a reason for hiding this comment

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

Extended the component functionality with the as prop in order to substitute the div tag with a span and avoid a console error 'div cannot be a descendant of p' that is thrown when it's a div because we are passing RemainingTime in ContractCardStatusTimer down to the Tag component from quill-ui library where it renders RemainingTime as a label inside p tag.

};

export default RemainingTime;
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"@babel/polyfill": "^7.4.4",
"@datadog/browser-rum": "^5.11.0",
"@deriv-com/analytics": "1.5.8",
"@deriv-com/quill-tokens": "^2.0.2",
"@deriv-com/quill-ui": "^1.10.2",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "^1.10.13",
"@deriv-com/translations": "^1.2.3",
"@deriv-com/utils": "^0.0.20",
"@deriv/account": "^1.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/reports/src/Containers/open-positions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ const OpenPositions = observer(({ component_icon, ...props }: TOpenPositions) =>
/>
);
};
// TODO: Uncomment and update this when DTrader 2.0 development starts:
// if (useFeatureFlags().is_dtrader_v2_enabled) return <Text size='l'>I am Open positions for DTrader 2.0.</Text>;
Copy link
Contributor Author

@maryia-deriv maryia-deriv May 28, 2024

Choose a reason for hiding this comment

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

it's unlikely that we're gonna do the redesign of reports under dtrader_v2 flag. this comment doesn't seem necessary anymore.


return (
<React.Fragment>
<NotificationMessages />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { formatMoney, toMoment, getSymbolDisplayName, getMarketInformation } from '@deriv/shared';
import { ActiveSymbols, ProfitTable } from '@deriv/api-types';

export type TTransaction = NonNullable<NonNullable<ProfitTable>['transactions']>[number];

export const formatProfitTableTransactions = (
transaction: TTransaction,
currency: string,
active_symbols: ActiveSymbols = []
) => {
const format_string = 'DD MMM YYYY HH:mm:ss';
const purchase_time =
transaction.purchase_time && `${toMoment(Number(transaction.purchase_time)).format(format_string)}`;
const purchase_time_unix = transaction.purchase_time;
const sell_time = transaction.sell_time && `${toMoment(Number(transaction.sell_time)).format(format_string)}`;
const payout = transaction.payout ?? NaN;
const sell_price = transaction.sell_price ?? NaN;
const buy_price = transaction.buy_price ?? NaN;
const profit_loss = formatMoney(currency, Number(sell_price - buy_price), true);
const display_name = getSymbolDisplayName(
active_symbols,
getMarketInformation(transaction.shortcode ?? '').underlying
);

return {
...transaction,
...{
payout,
sell_price,
buy_price,
profit_loss,
sell_time,
purchase_time,
display_name,
purchase_time_unix,
},
};
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a copy of the same migrated file from https://github.com/binary-com/deriv-app/pull/15327/files. Copied to avoid a conflict.

5 changes: 3 additions & 2 deletions packages/reports/src/Stores/useReportsStores.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react';
import { useStore } from '@deriv/stores';
import ProfitStores from './Modules/Profit/profit-store';
import StatementStores from './Modules/Statement/statement-store';
import { formatProfitTableTransactions } from './Modules/Profit/Helpers/format-response';

type TOverrideProfitStore = Omit<ProfitStores, 'data' | 'date_from' | 'totals'> & {
date_from: number;
data: { [key: string]: string }[];
data: ReturnType<typeof formatProfitTableTransactions>[];
totals: { [key: string]: unknown };
};

Expand Down Expand Up @@ -39,7 +40,7 @@ type TOverrideStatementStore = Omit<
suffix_icon: string;
};

type TReportsStore = {
export type TReportsStore = {
profit_table: TOverrideProfitStore;
statement: TOverrideStatementStore;
};
Expand Down
73 changes: 73 additions & 0 deletions packages/shared/src/utils/contract/__tests__/contract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,76 @@ describe('isForwardStartingBuyTransaction', () => {
).toBe(false);
});
});

describe('getCurrentTick', () => {
const tickStreamWithFourTicks = [
{
epoch: 1716910930,
tick: 1338.44,
tick_display_value: '1338.44',
},
{
epoch: 1716910932,
tick: 1338.71,
tick_display_value: '1338.71',
},
{
epoch: 1716910934,
tick: 1338.69,
tick_display_value: '1338.69',
},
{
epoch: 1716910936,
tick: 1338.94,
tick_display_value: '1338.94',
},
];
it('should return tick_passed if tick_passed is available for a non-digit/non-asian contract', () => {
const mockedAccuContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.ACCUMULATOR,
tick_passed: 2,
});
expect(ContractUtils.getCurrentTick(mockedAccuContractInfo)).toEqual(2);
});
it('should return tick_stream.length - 1 if tick_passed is missing for a non-digit/non-asian contract', () => {
const mockedRiseContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.RISE,
tick_stream: tickStreamWithFourTicks,
});
expect(ContractUtils.getCurrentTick(mockedRiseContractInfo)).toEqual(3);
});
it('should return tick_stream.length for a digit/asian contract', () => {
const mockedDigitContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.MATCH_DIFF.MATCH,
tick_stream: tickStreamWithFourTicks,
});
const mockedAsianContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.ASIAN.UP,
tick_stream: tickStreamWithFourTicks,
});
expect(ContractUtils.getCurrentTick(mockedDigitContractInfo)).toEqual(4);
expect(ContractUtils.getCurrentTick(mockedAsianContractInfo)).toEqual(4);
});
it('should return 0 if tick_stream is empty/missing for a digit/asian contract', () => {
const mockedDigitContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.MATCH_DIFF.MATCH,
});
const mockedAsianContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.ASIAN.UP,
tick_stream: [],
});
expect(ContractUtils.getCurrentTick(mockedDigitContractInfo)).toEqual(0);
expect(ContractUtils.getCurrentTick(mockedAsianContractInfo)).toEqual(0);
});
it('should return 0 if both tick_stream and tick_passed are empty/missing for a non-digit/non-asian contract', () => {
const mockedAccuContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.ACCUMULATOR,
});
const mockedRiseContractInfo = mockContractInfo({
contract_type: CONTRACT_TYPES.RISE,
tick_stream: [],
});
expect(ContractUtils.getCurrentTick(mockedAccuContractInfo)).toEqual(0);
expect(ContractUtils.getCurrentTick(mockedRiseContractInfo)).toEqual(0);
});
});
2 changes: 1 addition & 1 deletion packages/shared/src/utils/contract/contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const getCurrentTick = (contract_info: TContractInfo) => {
const current_tick =
isDigitContract(contract_info.contract_type) || isAsiansContract(contract_info.contract_type)
? tick_stream.length
: tick_stream.length - 1;
: contract_info.tick_passed ?? tick_stream.length - 1;
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 change is needed to make this helper work for ACCU contracts as well.

return !current_tick || current_tick < 0 ? 0 : current_tick;
};

Expand Down
11 changes: 11 additions & 0 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ const mock = (): TStores & { is_mock: boolean } => {
barriers: [],
error: '',
getPositionById: jest.fn(),
is_active_empty: false,
is_loading: false,
is_accumulator: false,
is_multiplier: false,
Expand Down Expand Up @@ -632,6 +633,16 @@ const mock = (): TStores & { is_mock: boolean } => {
setAccountType: jest.fn(),
setMigratedMT5Accounts: jest.fn(),
},
positions: {
openContractTypeFilter: [],
closedContractTypeFilter: [],
timeFilter: '',
customTimeRangeFilter: '',
setClosedContractTypeFilter: jest.fn(),
setOpenContractTypeFilter: jest.fn(),
setTimeFilter: jest.fn(),
setCustomTimeRangeFilter: jest.fn(),
},
trade: {
accumulator_range_list: [],
active_symbols: [],
Expand Down
5 changes: 5 additions & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ type BrandConfig = {
};

export type TPortfolioPosition = {
barrier?: number;
contract_info: ProposalOpenContract &
Portfolio1 & {
contract_update?: ContractUpdate;
};
details?: string;
display_name: string;
entry_spot?: number;
id?: number;
indicative: number;
payout?: number;
Expand All @@ -167,7 +169,9 @@ export type TPortfolioPosition = {
is_unsupported: boolean;
contract_update: ProposalOpenContract['limit_order'];
is_sell_requested: boolean;
is_valid_to_sell?: boolean;
profit_loss: number;
status?: null | string;
};

type TAppRoutingHistory = {
Expand Down Expand Up @@ -801,6 +805,7 @@ type TPortfolioStore = {
barriers: TBarriers;
error: string;
getPositionById: (id: number) => TPortfolioPosition;
is_active_empty: boolean;
is_loading: boolean;
is_multiplier: boolean;
is_accumulator: boolean;
Expand Down
6 changes: 4 additions & 2 deletions packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"dependencies": {
"@cloudflare/stream-react": "^1.9.1",
"@deriv-com/analytics": "1.5.8",
"@deriv-com/quill-tokens": "^2.0.2",
"@deriv-com/quill-ui": "^1.10.2",
"@deriv-com/quill-tokens": "^2.0.4",
"@deriv-com/quill-ui": "^1.10.13",
"@deriv-com/utils": "^0.0.20",
"@deriv/api-types": "1.0.172",
"@deriv/components": "^1.0.0",
Expand All @@ -104,6 +104,7 @@
"@deriv/quill-icons": "^1.22.10",
"@types/react-loadable": "^5.5.6",
"classnames": "^2.2.6",
"clsx": "^2.1.1",
"extend": "^3.0.2",
"formik": "^2.1.4",
"framer-motion": "^6.5.1",
Expand All @@ -121,6 +122,7 @@
"react-loadable": "^5.5.0",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-swipeable": "^6.2.1",
"react-transition-group": "4.4.2"
}
}
60 changes: 33 additions & 27 deletions packages/trader/src/App/Components/Routes/binary-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,45 @@ import { NavLink } from 'react-router-dom';
import { findRouteByPath, normalizePath } from './helpers';
import getRoutesConfig from '../../Constants/routes-config';

type TBinaryLinkProps = React.PropsWithChildren<{
active_class?: string;
className?: string;
to?: string;
onClick?: () => void;
}>;
type TBinaryLinkProps = Omit<React.HTMLProps<HTMLAnchorElement>, 'title' | 'ref'> &
React.PropsWithChildren<{
active_class?: string;
className?: string;
to?: string;
onClick?: () => void;
}>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we updated the props type in order to be able to pass some native event handlers like onDragStart and added forwardRef because we are using this component in ContractCardComponent with react-swipeable which passes a ref down to BinaryLink.


// TODO: solve circular dependency problem
// when binary link is imported into components present in routes config
// or into their descendants
const BinaryLink = ({ active_class = '', to, children, ...props }: TBinaryLinkProps) => {
const path = normalizePath(to);
const route = findRouteByPath(path, getRoutesConfig());
const BinaryLink = React.forwardRef<HTMLAnchorElement, TBinaryLinkProps>(
({ active_class = '', to, children, ...props }, ref) => {
const path = normalizePath(to);
const route = findRouteByPath(path, getRoutesConfig());

if (!route) {
throw new Error(`Route not found: ${to}`);
if (!route) {
throw new Error(`Route not found: ${to}`);
}

return to ? (
<NavLink
data-testid='dt_binary_link'
to={path}
activeClassName={active_class || 'active'}
exact={route.exact}
ref={ref}
{...props}
>
{children}
</NavLink>
) : (
<a data-testid='dt_binary_link' ref={ref} {...props}>
{children}
</a>
);
}
);

return to ? (
<NavLink
data-testid='dt_binary_link'
to={path}
activeClassName={active_class || 'active'}
exact={route.exact}
{...props}
>
{children}
</NavLink>
) : (
<a data-testid='dt_binary_link' {...props}>
{children}
</a>
);
};
BinaryLink.displayName = 'BinaryLink';

export default BinaryLink;
Loading
Loading