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] henry/dtra-1237/fix: dtrader-v2 setup #14991

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5baf11b
fix: initial setup
henry-deriv May 6, 2024
8632910
fix: partially finished setup
henry-deriv May 9, 2024
f450178
fix: ensure new header only appears for mobile
henry-deriv May 9, 2024
a509a82
fix: quill-ui version bump
henry-deriv May 10, 2024
1593a82
fix: change classnames
henry-deriv May 10, 2024
8db429d
fix: change to kebab case file names
henry-deriv May 13, 2024
776d53a
fix: resolve comments
henry-deriv May 13, 2024
61c1088
fix: add color to text
henry-deriv May 13, 2024
7b25581
fix: add tests
henry-deriv May 13, 2024
8b8fd1e
fix: sonarcloud
henry-deriv May 13, 2024
b6746b6
fix: sonarcloud issues
henry-deriv May 13, 2024
ac0ec49
fix: parse JSON with try catch in case FeatureFlagsStore returns empty
henry-deriv May 13, 2024
b64ff30
fix: change to quill icons
henry-deriv May 13, 2024
01214a6
fix: add missing css
henry-deriv May 13, 2024
07af4f6
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv May 14, 2024
8ecea00
fix: change hamburger menu icon to standalone
henry-deriv May 14, 2024
7bd0965
fix: move quill-ui to core and wrap application with themeprovider
henry-deriv May 14, 2024
ddec755
fix: import themeprovider from quill/ui
henry-deriv May 14, 2024
fc3d244
fix: wrong import
henry-deriv May 14, 2024
5bf1def
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv May 14, 2024
86401fe
fix: remove unused css and make header bold
henry-deriv May 14, 2024
3cc68db
fix: make labels red when active
henry-deriv May 15, 2024
db600a9
fix: change text to correct component
henry-deriv May 15, 2024
7501931
fix: move themeprovider to appcontent to react to changes in store
henry-deriv May 15, 2024
fe98975
Merge branch 'master' of github.com:binary-com/deriv-app into henry/d…
henry-deriv May 15, 2024
e706195
chore: reset package lock
henry-deriv May 15, 2024
9fbaa8b
fix: update package-lock and add quill-ui to traders package
henry-deriv May 15, 2024
2e9e896
fix: jest config error
henry-deriv May 15, 2024
9f16083
fix: ignore errors from quill-ui
henry-deriv May 15, 2024
6dc46c3
fix: jest config and add babel config
henry-deriv May 15, 2024
80b13f6
fix: remove a plugin
henry-deriv May 15, 2024
93b528c
fix: lets try this
henry-deriv May 15, 2024
9b72174
fix: remove irrelevant files
henry-deriv May 16, 2024
41f986f
fix: resolve conflicts
henry-deriv May 16, 2024
78d8e6c
fix: test
henry-deriv May 16, 2024
8efb948
fix: change
henry-deriv May 16, 2024
2367b75
fix: asdf
henry-deriv May 16, 2024
bf975ac
fix: errors
henry-deriv May 16, 2024
ec8b9b2
fix: give contract details page a new header
henry-deriv May 17, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { observer, useStore } from '@deriv/stores';
import { getCurrencyDisplayCode } from '@deriv/shared';
import AccountInfoIcon from 'App/Components/Layout/Header/account-info-icon';

const DTraderV2Header = observer(() => {
const { client } = useStore();
const { balance, currency, is_virtual, loginid } = client;

const currency_lower = currency?.toLowerCase();

return (
<header className='header header-v2'>
<React.Suspense fallback={<div />}>
<div className='header-v2__acc-info'>
<div className='header-v2__acc-info--top'>
<span className='header-v2__acc-info--logo'>
{(is_virtual || currency) && (
<AccountInfoIcon is_virtual={is_virtual} currency={currency_lower} />
henry-deriv marked this conversation as resolved.
Show resolved Hide resolved
)}
</span>

{loginid}
henry-deriv marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div className='header-v2__acc-info--bottom'>
<span>{`${balance} ${getCurrencyDisplayCode(currency)}`}</span>
</div>
</div>
</React.Suspense>
</header>
);
});

export default DTraderV2Header;
11 changes: 10 additions & 1 deletion packages/core/src/App/Containers/Layout/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useFeatureFlags, useStoreWalletAccountsList } from '@deriv/hooks';
import { makeLazyLoader, moduleLoader, routes } from '@deriv/shared';
import { observer, useStore } from '@deriv/stores';
import { useReadLocalStorage } from 'usehooks-ts';
import { useDevice } from '@deriv/components';

const HeaderFallback = () => <div className='header' />;

Expand Down Expand Up @@ -38,10 +39,16 @@ const TradersHubHeaderWallets = makeLazyLoader(
() => <HeaderFallback />
)();

const DTraderV2Header = makeLazyLoader(
() => moduleLoader(() => import(/* webpackChunkName: "dtrader-v2-header" */ './dtrader-v2-header')),
() => <HeaderFallback />
)();

const Header = observer(() => {
const { client } = useStore();
const { accounts, is_logged_in, setAccounts, loginid, switchAccount } = client;
const { pathname } = useLocation();
const { is_mobile } = useDevice();

const is_wallets_cashier_route = pathname.includes(routes.wallets_cashier);

Expand All @@ -60,7 +67,7 @@ const Header = observer(() => {
is_wallets_cashier_route;

const client_accounts = useReadLocalStorage('client.accounts');
const { is_next_wallet_enabled } = useFeatureFlags();
const { is_next_wallet_enabled, is_dtrader_v2_enabled } = useFeatureFlags();
const { has_wallet } = useStoreWalletAccountsList();
const should_show_wallets = is_next_wallet_enabled && has_wallet;

Expand All @@ -82,6 +89,8 @@ const Header = observer(() => {
result = should_show_wallets ? <TradersHubHeaderWallets /> : <TradersHubHeader />;
} else if (pathname === routes.onboarding) {
result = null;
} else if (pathname === routes.trade && is_dtrader_v2_enabled && is_mobile) {
result = <DTraderV2Header />;
} else {
result = should_show_wallets ? <DTraderHeaderWallets /> : <DTraderHeader />;
}
Expand Down
40 changes: 40 additions & 0 deletions packages/core/src/sass/app/_common/layout/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,43 @@
}
}
}

.header-v2 {
display: flex;
henry-deriv marked this conversation as resolved.
Show resolved Hide resolved
justify-content: center;

&__acc-info {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

&--top {
display: flex;
align-items: center;
justify-content: center;
gap: 0.4rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use quill token here?

Copy link
Contributor Author

@henry-deriv henry-deriv May 10, 2024

Choose a reason for hiding this comment

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

i think we are waiting for prince to turn quill-tokens into a library. So that i can put quill-token library in package.json and use the tokens

}

&--logo {
height: 16px;
width: 16px;

svg {
henry-deriv marked this conversation as resolved.
Show resolved Hide resolved
width: 1.6rem;
height: 1.6rem;
}
}

&--bottom {
display: flex;
align-items: center;
justify-content: center;
gap: 0.2rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use quill token here?


span {
font-weight: bold;
}
}
}
}
1 change: 1 addition & 0 deletions packages/trader/build/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
const ALIASES = {
_common: path.resolve(__dirname, '../src/_common'),
App: path.resolve(__dirname, '../src/App'),
AppV2: path.resolve(__dirname, '../src/AppV2'),
Assets: path.resolve(__dirname, '../src/Assets'),
Constants: path.resolve(__dirname, '../src/Constants'),
Fonts: path.resolve(__dirname, '../src/public/fonts'),
Expand Down
1 change: 1 addition & 0 deletions packages/trader/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'^.+\\.svg$': '<rootDir>/../../__mocks__/styleMock.js',
'^_common/(.*)$': '<rootDir>/src/_common/$1',
'^App/(.*)$': '<rootDir>/src/App/$1',
'^AppV2/(.*)$': '<rootDir>/src/AppV2/$1',
'^Assets/(.*)$': '<rootDir>/src/Assets/$1',
'^Constants/(.*)$': '<rootDir>/src/Constants/$1',
'^Constants$': '<rootDir>/src/Constants/index.js',
Expand Down
2 changes: 2 additions & 0 deletions packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@cloudflare/stream-react": "^1.9.1",
"@deriv-com/analytics": "1.4.13",
"@deriv-com/utils": "^0.0.20",
"@deriv-com/quill-ui": "^1.9.17",
"@deriv/api-types": "^1.0.172",
"@deriv/components": "^1.0.0",
"@deriv/deriv-api": "^1.0.15",
Expand All @@ -98,6 +99,7 @@
"@deriv/shared": "^1.0.0",
"@deriv/stores": "^1.0.0",
"@deriv/translations": "^1.0.0",
"@deriv/quill-icons": "^1.22.4",
"@types/react-loadable": "^5.5.6",
"classnames": "^2.2.6",
"extend": "^3.0.2",
Expand Down
61 changes: 61 additions & 0 deletions packages/trader/src/AppV2/Components/BottomNav/BottomNav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import { Localize } from '@deriv/translations';
import {
LegacyMarketBasketIndicesIcon,
LegacyMenuHamburger1pxIcon,
StandaloneChartCandlestickRegularIcon,
StandaloneClockThreeRegularIcon,
} from '@deriv/quill-icons';
import BottomNavItem from './BottomNavItem';
import { Badge } from '@deriv-com/quill-ui';

type BottomNavProps = {
className?: string;
children: React.ReactNode[];
};

const BottomNavItems = [
{
icon: <StandaloneChartCandlestickRegularIcon iconSize='sm' />,
label: <Localize i18n_default_text='Trade' />,
},
{
icon: <LegacyMarketBasketIndicesIcon iconSize='sm' />,
Copy link
Contributor

@kate-deriv kate-deriv May 10, 2024

Choose a reason for hiding this comment

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

When I click on the icon, it doesn't change the color. Same for 'menu'. Should it change or not? Because half of the icons do it, half - not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah currently in discussion with quill-icons team to allow fill for Legacy icons. They allow fill/color-change for standalone and some other icons but not legacy icons

label: <Localize i18n_default_text='Markets' />,
},
{
icon: (
<Badge variant='notification' position='top-right' label='10' color='danger' size='sm' contentSize='sm'>
<StandaloneClockThreeRegularIcon iconSize='sm' />
</Badge>
),
label: <Localize i18n_default_text='Positions' />,
},
{
icon: <LegacyMenuHamburger1pxIcon iconSize='sm' />,
label: <Localize i18n_default_text='Menu' />,
},
];

const BottomNav = ({ className, children }: BottomNavProps) => {
const [selectedIndex, setSelectedIndex] = React.useState(0);
return (
<div className={className}>
<div className='bottom-nav-container'>
{BottomNavItems.map((item, index) => (
<BottomNavItem
key={index}
Copy link
Contributor

Choose a reason for hiding this comment

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

May we use i18n_default_text as key (item.label.props.i18n_default_text)? Not sure if it works, but sonarCloud is complaining

index={index}
icon={item.icon}
selectedIndex={selectedIndex}
label={item.label}
setSelectedIndex={setSelectedIndex}
/>
))}
</div>
{children[selectedIndex]}
</div>
);
};

export default BottomNav;
29 changes: 29 additions & 0 deletions packages/trader/src/AppV2/Components/BottomNav/BottomNavItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { CaptionText } from '@deriv-com/quill-ui';
import classNames from 'classnames';
import React from 'react';

type BottomNavItemProps = {
icon: React.ReactNode;
selectedIndex: number;
label: React.ReactNode;
setSelectedIndex: (index: number) => void;
index: number;
};

const BottomNavItem = ({ icon, selectedIndex, label, index, setSelectedIndex }: BottomNavItemProps) => {
const isActive = index === selectedIndex;
return (
<button
className={classNames('bottom-nav-item', isActive ? 'bottom-nav-item--active' : '')}
onClick={() => setSelectedIndex(index)}
>
<span>{icon}</span>
{/* //waiting on quill-tokens */}
<CaptionText size='sm' color='var(--core-color-opacity-black-600)'>
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, but maybe we need to use <Text/> instead of <CaptionText/>? It will help to get rid of color prop
Screenshot 2024-05-10 at 2 08 09 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just above where you've underline it says

mobile/semantic/typography/caption/regular/default. Not sure what to use

{label}
</CaptionText>
</button>
);
};

export default BottomNavItem;
33 changes: 33 additions & 0 deletions packages/trader/src/AppV2/Components/BottomNav/bottomNav.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.bottom-nav {
&-container {
display: flex;
padding: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use quill token here?

align-items: flex-start;
gap: 10px;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use quill token here?

align-self: stretch;
Copy link
Contributor

Choose a reason for hiding this comment

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

align-self won't work with flex-container (only with flex items), so it can be deleted without any consequences I guess

position: fixed;
bottom: 0;
width: 100%;
border-top: 1px solid var(--core-color-opacity-black-100); // waiting on quill tokens in deriv-app
}
&-items {
display: flex;
flex-direction: column;
align-items: center;
flex: 1 0 0;
}
&-item {
display: flex;
flex-direction: column;
align-items: center;
flex: 1 0 0;

&--active {
color: var(--core-color-opacity-coral-600);

svg {
fill: var(--core-color-opacity-coral-600);
}
}
}
}
4 changes: 4 additions & 0 deletions packages/trader/src/AppV2/Components/BottomNav/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import BottomNav from './BottomNav';
import './bottomNav.scss';

export default BottomNav;
4 changes: 4 additions & 0 deletions packages/trader/src/AppV2/Containers/Markets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Markets from './markets';
import './markets.scss';

export default Markets;
Empty file.
7 changes: 7 additions & 0 deletions packages/trader/src/AppV2/Containers/Markets/markets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const Markets = () => {
return <div>Markets</div>;
};

export default Markets;
4 changes: 4 additions & 0 deletions packages/trader/src/AppV2/Containers/Menu/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Menu from './menu';
import './menu.scss';

export default Menu;
Empty file.
7 changes: 7 additions & 0 deletions packages/trader/src/AppV2/Containers/Menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const Menu = () => {
return <div>Menu</div>;
};

export default Menu;
4 changes: 4 additions & 0 deletions packages/trader/src/AppV2/Containers/Positions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Positions from './positions';
import './positions.scss';

export default Positions;
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const Positions = () => {
return <div>Positions</div>;
};

export default Positions;
4 changes: 4 additions & 0 deletions packages/trader/src/AppV2/Containers/Trade/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Trade from './trade';
import './trade.scss';

export default Trade;
Empty file.
7 changes: 7 additions & 0 deletions packages/trader/src/AppV2/Containers/Trade/trade.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const Trade = () => {
return <div>Trade</div>;
};

export default Trade;
38 changes: 38 additions & 0 deletions packages/trader/src/AppV2/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import type { TWebSocket } from 'Types';
import initStore from 'App/init-store';
import 'Sass/app.scss';
import type { TCoreStores } from '@deriv/stores/types';
import TraderProviders from '../trader-providers';
import BottomNav from './Components/BottomNav';
import Trade from './Containers/Trade';
import Markets from './Containers/Markets';
import Positions from './Containers/Positions';
import Menu from './Containers/Menu';

type Apptypes = {
passthrough: {
root_store: TCoreStores;
WS: TWebSocket;
};
};

const App = ({ passthrough }: Apptypes) => {
const root_store = initStore(passthrough.root_store, passthrough.WS);
React.useEffect(() => {
return () => root_store.ui.setPromptHandler(false);
}, [root_store]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it track changes in such huge object as root_store? Please, ignore if irrelevant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i copied pasta app.tsx in AppV1. Not entirely sure what its doing tbh.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kate-deriv React.useEffect will just track the reference of the object and it won't track the nested props. So, this code is safe in terms of performance.


return (
<TraderProviders store={root_store}>
<BottomNav>
<Trade />
<Markets />
<Positions />
<Menu />
</BottomNav>
</TraderProviders>
);
};

export default App;
3 changes: 3 additions & 0 deletions packages/trader/src/AppV2/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import App from './app';

export default App;
11 changes: 10 additions & 1 deletion packages/trader/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import { makeLazyLoader, moduleLoader } from '@deriv/shared';
import { Loading } from '@deriv/components';

const App = makeLazyLoader(
() => moduleLoader(() => import(/* webpackChunkName: "trader-app", webpackPreload: true */ './App/index')),
() =>
moduleLoader(() => {
const is_dtrader_v2 = JSON.parse(localStorage.getItem('FeatureFlagsStore') ?? '').data.dtrader_v2;
balakrishna-deriv marked this conversation as resolved.
Show resolved Hide resolved
const is_mobile = window.innerWidth < 600;

if (is_dtrader_v2 && is_mobile) {
return import(/* webpackChunkName: "trader-app-v2", webpackPreload: true */ './AppV2/index');
}
return import(/* webpackChunkName: "trader-app", webpackPreload: true */ './App/index');
}),
() => <Loading />
)();

Expand Down
Loading
Loading