Skip to content

Commit

Permalink
fix: 🐛 reserve report link, my asset percentage, trade tab
Browse files Browse the repository at this point in the history
Closes: #1190 #1249 #1198
  • Loading branch information
arealclimber committed Sep 25, 2023
1 parent 30349c8 commit c29f3fc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 18 deletions.
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+50.3",
"version": "0.8.0+51.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
22 changes: 14 additions & 8 deletions src/components/pnl_section/pnl_section.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, {useContext} from 'react';
import {useTranslation} from 'next-i18next';
import {UserContext} from '../../contexts/user_context';
import {numberFormatted} from '../../lib/common';
import {ratioToPercentage, numberFormatted, roundToDecimalPlaces} from '../../lib/common';
import {DEFAULT_PNL_DATA, TypeOfPnLColor} from '../../constants/display';
import {ProfitState} from '../../constants/profit_state';
import {unitAsset} from '../../constants/config';
import SafeMath from '../../lib/safe_math';

type TranslateFunction = (s: string) => string;

Expand All @@ -23,23 +24,27 @@ const PnlSection = () => {
{title: t('MY_ASSETS_PAGE.PNL_SECTION_30_DAYS'), ...pnl30Days},
{title: t('MY_ASSETS_PAGE.PNL_SECTION_CUMULATIVE'), ...cumulativePnl},
].map(({amount, percentage, ...rest}) => {
const amountValue = numberFormatted(amount.value);
const percent = ratioToPercentage(percentage.value);

const result = {
content:
amount.type === ProfitState.PROFIT
? `+${numberFormatted(amount.value)} ${unitAsset}`
? `+${amountValue} ${unitAsset}`
: amount.type === ProfitState.LOSS
? `-${numberFormatted(amount.value)} ${unitAsset}`
? `-${amountValue} ${unitAsset}`
: amount.type === ProfitState.EQUAL
? `${numberFormatted(amount.value)} ${unitAsset}`
? `${amountValue} ${unitAsset}`
: '-',
remarks:
/* Info: (20230602 - Julian) 調整 format (e.g. 0.012 -> 1.2%) */
percentage.type === ProfitState.PROFIT
? `▴ ${numberFormatted(percentage.value * 100)} %`
: percentage.type === ProfitState.LOSS
? `▾ ${numberFormatted(percentage.value * 100)} %`
? `▴ ${percent} %`
: // ? `▴ ${numberFormatted(SafeMath.mult(percentage.value, 100))} %`
percentage.type === ProfitState.LOSS
? `▾ ${percent} %`
: percentage.type === ProfitState.EQUAL
? `${numberFormatted(percentage.value * 100)} %`
? `${percent} %`
: '-',
textColor:
percentage.type === ProfitState.PROFIT && amount.type === ProfitState.PROFIT
Expand All @@ -49,6 +54,7 @@ const PnlSection = () => {
: TypeOfPnLColor.EQUAL,
...rest,
};

return result;
});

Expand Down
6 changes: 4 additions & 2 deletions src/components/reserve_ratio/reserve_ratio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {MarketContext} from '../../contexts/market_context';
import {useTranslation} from 'next-i18next';
import SafeMath from '../../lib/safe_math';
import {UNIVERSAL_NUMBER_FORMAT_LOCALE} from '../../constants/display';
import {FRACTION_DIGITS} from '../../constants/config';
import {BAIFA_LINK, FRACTION_DIGITS} from '../../constants/config';
import {TranslateFunction} from '../../interfaces/tidebit_defi_background/locale';
import Link from 'next/link';
import ReserveCard from '../reserve_card/reserve_card';
Expand All @@ -18,6 +18,8 @@ const ReserveRatio = () => {
const {websiteReserve} = useContext(MarketContext);
const {BTC, ETH, USDT} = websiteReserve;

const baifaProjectId = process.env.BAIFA_PROJECT_ID;

// TODO: 用 isNumber 檢驗,資料傳給卡片之前都整理成 string (20230914 - Shirley)
const usdtReserveRatio = numberFormatted(USDT.reserveRatio);
const usdtUserHolding = numberFormatted(USDT.usersHolding);
Expand Down Expand Up @@ -54,7 +56,7 @@ const ReserveRatio = () => {
<div className="flex w-full justify-center lg:justify-end pr-0 transition-all duration-150 lg:pr-1/8 2xl:pr-1/5">
<a
// TODO: Report updated from context (20230619 - Shirley)
href={t('HOME_PAGE.REPORTS_LINK')}
href={`${BAIFA_LINK}/reports/${baifaProjectId}/${t('HOME_PAGE.REPORTS_LINK')}`}
download
target="_blank"
className="flex space-x-2 hover:text-tidebitTheme"
Expand Down
10 changes: 6 additions & 4 deletions src/components/trade_tab/trade_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ const TradeTab = () => {
<div
className={`${
longTpToggle ? `translate-y-2` : `invisible translate-y-0`
} transition-all duration-150 ease-in-out`}
} lg:-mt-5 transition-all duration-150 ease-in-out`}
>
<div className="text-xs text-lightWhite">
* {t('TRADE_PAGE.TRADE_TAB_EXPECTED_PROFIT')}: {estimatedLongProfitValueRef.current.symbol}{' '}
Expand Down Expand Up @@ -956,7 +956,7 @@ const TradeTab = () => {
<div
className={`${
longSlToggle ? `translate-y-5` : `invisible translate-y-0`
} flex items-center transition-all duration-150 ease-in-out`}
} lg:mb-10 lg:mt-0 flex items-center transition-all duration-150 ease-in-out`}
>
<input
type="checkbox"
Expand Down Expand Up @@ -1044,7 +1044,9 @@ const TradeTab = () => {

const displayedExpectedShortProfit = (
<div
className={`${shortTpToggle ? `translate-y-2` : `invisible translate-y-0`} transition-all`}
className={`${
shortTpToggle ? `translate-y-2` : `invisible translate-y-0`
} lg:-mt-5 transition-all`}
>
<div className="text-xs text-lightWhite">
* {t('TRADE_PAGE.TRADE_TAB_EXPECTED_PROFIT')}: {estimatedShortProfitValueRef.current.symbol}{' '}
Expand Down Expand Up @@ -1100,7 +1102,7 @@ const TradeTab = () => {
<div
className={`${
shortSlToggle ? `translate-y-5` : `invisible translate-y-0`
} mb-10 mt-0 items-center transition-all`}
} lg:mb-10 lg:mt-0 mb-10 mt-0 items-center transition-all`}
>
<div className="mt-0 flex items-center">
<input
Expand Down
4 changes: 4 additions & 0 deletions src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,7 @@ export function isValidTradeURL(url: string): boolean {

return result;
}

export function ratioToPercentage(decimal: number): string {
return `${(decimal * 100).toFixed(2)}`;
}
2 changes: 1 addition & 1 deletion src/locales/cn/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"APP_DOWLOAD_CONTAINER_TITLE_HIGHLIGHT": "TideBit",
"APP_DOWLOAD_CONTAINER_TITLE_2": "进行交易。",
"DOWNLOAD_REPORT": "下载报告",
"REPORTS_LINK": "/whitepaper/tidebit_tech_whitepaper_v2.0.4_cn.pdf",
"REPORTS_LINK": "/balance",
"COMPREHENSIVE_INCOME_STATEMENT_LINK": "/comprehensive-income",
"BALANCE_SHEET_LINK": "/balance",
"CASH_FLOW_STATEMENT_LINK": "/cash-flow",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"APP_DOWLOAD_CONTAINER_TITLE_HIGHLIGHT": "TideBit",
"APP_DOWLOAD_CONTAINER_TITLE_2": "anywhere, anytime",
"DOWNLOAD_REPORT": "Download Report",
"REPORTS_LINK": "/whitepaper/tidebit_tech_whitepaper_v2.0.4_en.pdf",
"REPORTS_LINK": "/balance",
"COMPREHENSIVE_INCOME_STATEMENT_LINK": "/comprehensive-income",
"BALANCE_SHEET_LINK": "/balance",
"CASH_FLOW_STATEMENT_LINK": "/cash-flow",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/tw/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"APP_DOWLOAD_CONTAINER_TITLE_HIGHLIGHT": "TideBit",
"APP_DOWLOAD_CONTAINER_TITLE_2": "進行交易。",
"DOWNLOAD_REPORT": "下載報告",
"REPORTS_LINK": "/whitepaper/tidebit_tech_whitepaper_v2.0.4_zh.pdf",
"REPORTS_LINK": "/balance",
"COMPREHENSIVE_INCOME_STATEMENT_LINK": "/comprehensive-income",
"BALANCE_SHEET_LINK": "/balance",
"CASH_FLOW_STATEMENT_LINK": "/cash-flow",
Expand Down

0 comments on commit c29f3fc

Please sign in to comment.