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

feat: 🎸 toggle of displaying line graph of open positions, modify the string of toggle of displaying trading view #1342

Merged
merged 2 commits into from
Oct 17, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ src/constants/walletconnect.js
.DS_Store

.vscode
intergration-test/metamask-chrome-11.0.0/
playwright-report/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "src",
"version": "0.8.0+58.1",
"version": "0.8.0+59.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
36 changes: 21 additions & 15 deletions src/components/open_position_item/open_position_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import SafeMath from '../../lib/safe_math';
type TranslateFunction = (s: string) => string;
interface IOpenPositionItemProps {
openCfdDetails: IDisplayCFDOrder;
hideOpenLineGraph?: boolean;
}

const OpenPositionItem = ({openCfdDetails}: IOpenPositionItemProps) => {
const OpenPositionItem = ({openCfdDetails, hideOpenLineGraph}: IOpenPositionItemProps) => {
const {t}: {t: TranslateFunction} = useTranslation('common');

const marketCtx = useContext(MarketContext);
Expand Down Expand Up @@ -263,8 +264,25 @@ const OpenPositionItem = ({openCfdDetails}: IOpenPositionItemProps) => {
: numberFormatted(pnl?.value);

const displayedCreateTime = timestampToString(createTimestamp ?? 0);

const displayedLineGraph = hideOpenLineGraph ? null : (
<div className="-mx-4 mb-0 mt-3 h-60px">
<PositionLineGraph
strokeColor={[
displayedColorHex,
displayedAnnotationColor.DASH_LINE,
displayedAnnotationColor.STRING,
]}
dataArray={positionLineGraphWithSpread}
lineGraphWidth={OPEN_POSITION_LINE_GRAPH_WIDTH}
annotatedValue={displayedAnnotation.VALUE}
annotatedString={displayedAnnotation.STRING}
/>
</div>
);

return (
<div className="relative my-2 min-h-140px">
<div className={`relative my-2 ${hideOpenLineGraph ? `min-h-50px` : `min-h-140px`}`}>
<div
className="absolute z-10 h-160px w-280px bg-transparent hover:cursor-pointer"
onClick={updatedModalClickHandler}
Expand Down Expand Up @@ -294,19 +312,7 @@ const OpenPositionItem = ({openCfdDetails}: IOpenPositionItemProps) => {
</div>

{/* Info: (20230411 - Julian) Line graph */}
<div className="-mx-4 mb-0 mt-3 h-60px">
<PositionLineGraph
strokeColor={[
displayedColorHex,
displayedAnnotationColor.DASH_LINE,
displayedAnnotationColor.STRING,
]}
dataArray={positionLineGraphWithSpread}
lineGraphWidth={OPEN_POSITION_LINE_GRAPH_WIDTH}
annotatedValue={displayedAnnotation.VALUE}
annotatedString={displayedAnnotation.STRING}
/>
</div>
{displayedLineGraph}

<div className="mt-1 flex justify-between">
<div className="">
Expand Down
8 changes: 6 additions & 2 deletions src/components/open_sub_tab/open_sub_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {SKELETON_DISPLAY_TIME} from '../../constants/display';
import {useGlobal} from '../../contexts/global_context';
import {LayoutAssertion} from '../../constants/layout_assertion';

const OpenSubTab = () => {
interface IOpenSubTab {
hideOpenLineGraph?: boolean;
}

const OpenSubTab = (props: IOpenSubTab) => {
const userCtx = useContext(UserContext);
const marketCtx = useContext(MarketContext);
const globalCtx = useGlobal();
Expand Down Expand Up @@ -57,7 +61,7 @@ const OpenSubTab = () => {
cfds.map(cfd => {
return (
<div key={cfd.id}>
{<OpenPositionItem openCfdDetails={cfd} />}
{<OpenPositionItem openCfdDetails={cfd} hideOpenLineGraph={props?.hideOpenLineGraph} />}
<div className="my-auto h-px w-full rounded bg-white/50"></div>
</div>
);
Expand Down
8 changes: 7 additions & 1 deletion src/components/order_section/order_section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export enum ORDER_SECTION_TAB {
POSITION = 'POSITION',
}

const OrderSection = () => {
interface IOrderSection {
hideOpenLineGraph?: boolean;
}

const OrderSection = (props: IOrderSection) => {
const {t}: {t: TranslateFunction} = useTranslation('common');

const globalCtx = useGlobal();
Expand Down Expand Up @@ -64,6 +68,7 @@ const OrderSection = () => {
activePositionTabMobile={positionActiveTab}
openTabClickHandler={openTabClickHandler}
historyTabClickHandler={historyTabClickHandler}
hideOpenLineGraph={props?.hideOpenLineGraph}
/>
) : (
<PositionVisitorTab />
Expand Down Expand Up @@ -156,6 +161,7 @@ const OrderSection = () => {
activePositionTabMobile={positionActiveTab}
openTabClickHandler={openTabClickHandler}
historyTabClickHandler={historyTabClickHandler}
hideOpenLineGraph={props?.hideOpenLineGraph}
/>
</div>
</div>
Expand Down
12 changes: 4 additions & 8 deletions src/components/position_tab/position_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface PositionTabProps {
activePositionTabMobile: string;
openTabClickHandler: () => void;
historyTabClickHandler: () => void;
hideOpenLineGraph?: boolean;
}

type TranslateFunction = (s: string) => string;
Expand All @@ -23,21 +24,16 @@ const PositionTab = ({
activePositionTabMobile,
openTabClickHandler,
historyTabClickHandler,
hideOpenLineGraph,
}: PositionTabProps) => {
const {t}: {t: TranslateFunction} = useTranslation('common');
const globalCtx = useGlobal();

const tabBodyWidth = 'w-320px';

const currentSubTab =
globalCtx.layoutAssertion === LayoutAssertion.MOBILE ? (
activePositionTabMobile === POSITION_TAB.OPEN ? (
<OpenSubTab />
) : (
<HistorySubTab />
)
) : activePositionTabMobile === POSITION_TAB.OPEN ? (
<OpenSubTab />
activePositionTabMobile === POSITION_TAB.OPEN ? (
<OpenSubTab hideOpenLineGraph={hideOpenLineGraph} />
) : (
<HistorySubTab />
);
Expand Down
5 changes: 2 additions & 3 deletions src/components/trade_page_body/trade_page_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import {IRecommendedNews} from '../../interfaces/tidebit_defi_background/news';
interface ITradePageBodyProps {
briefs: IRecommendedNews[];
hideTradingView?: boolean;
hideOpenLineGraph?: boolean;
}

const TradePageBody = (props: ITradePageBodyProps) => {
const displayedOrdersection = <OrderSection />;

return (
<>
<div className="flex min-h-screen flex-col overflow-hidden">
<MarketSection briefs={props.briefs} hideTradingView={props?.hideTradingView} />

{displayedOrdersection}
<OrderSection hideOpenLineGraph={props?.hideOpenLineGraph} />
</div>
</>
);
Expand Down
6 changes: 0 additions & 6 deletions src/contexts/user_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,6 @@ export const UserProvider = ({children}: IUserProvider) => {
eip712signature = await lunar.signTypedData(serviceTermContract);
resultCode = Code.FAILED_TO_VERIFY_SIGNATURE;
const verifyR: boolean = lunar.verifyTypedData(serviceTermContract, eip712signature);
// eslint-disable-next-line no-console
console.log(`verifyR`, verifyR);
if (verifyR) {
const deWT = `${encodedData}.${eip712signature.replace('0x', '')}`;
setDeWT(deWT);
Expand All @@ -672,8 +670,6 @@ export const UserProvider = ({children}: IUserProvider) => {
}
}
} catch (error) {
// eslint-disable-next-line no-console
console.error(`signServiceTerm error`, error);
result.code = resultCode;
result.reason = Reason[resultCode];
return result;
Expand Down Expand Up @@ -832,8 +828,6 @@ export const UserProvider = ({children}: IUserProvider) => {
} else throw new CustomError(Code.BALANCE_NOT_FOUND);
} else throw new CustomError(Code.BALANCE_NOT_FOUND);
} catch (error) {
// eslint-disable-next-line no-console
console.error('error in updateBalance in ctx', error);
throw new CustomError(Code.FAILE_TO_UPDATE_BALANCE);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/pages/trade/cfd/[instId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface IPageProps {
briefs: IRecommendedNews[];
}

const HIDDEN = 'hidden';

const Trading = (props: IPageProps) => {
const marketCtx = useContext(MarketContext);
const appCtx = useContext(AppContext);
Expand All @@ -35,7 +37,8 @@ const Trading = (props: IPageProps) => {
const instId = router.query?.instId as string;
const ticker = instId?.toUpperCase();

const hideTradingView = router.query?.trading_view === 'hide';
const hideTradingView = router.query?.trading_view === HIDDEN;
const hideOpenLineGraph = router.query?.open_line_graph === HIDDEN;

const redirectToTicker = async () => {
if (hasValue(marketCtx.availableTickers) && ticker) {
Expand Down Expand Up @@ -65,7 +68,11 @@ const Trading = (props: IPageProps) => {
{displayedNavBar}

<main>
<TradePageBody briefs={props.briefs} hideTradingView={hideTradingView} />
<TradePageBody
briefs={props.briefs}
hideTradingView={hideTradingView}
hideOpenLineGraph={hideOpenLineGraph}
/>
</main>
</>
) : (
Expand Down