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

Feature/leaderboard time zone #1126

Merged
merged 2 commits into from
Aug 18, 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
13 changes: 9 additions & 4 deletions src/components/board_page_body/board_page_body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const BoardPageBody = () => {
return () => clearTimeout(timer);
}, [leaderboardLiveRemains]);

const timeSpanStart = new Date(timestampToString(startTime).date).toISOString().slice(0, 10);
const timeSpanEnd = new Date(timestampToString(endTime).date).toISOString().slice(0, 10);
/* Info: (20230816 - Julian) Trick: 月榜的時間轉換由起始時間的第二天算,以避免時區誤差 */
const timeSpanMonthly = timestampToString(startTime + 86400).monthAndYear;

const subtitle =
timeSpan === RankingInterval.LIVE ? (
<div className="inline-block text-base md:text-xl">
Expand All @@ -71,21 +76,21 @@ const BoardPageBody = () => {
) : timeSpan === RankingInterval.DAILY ? (
<div className="inline-block text-base md:text-xl">
{t('LEADERBOARD_PAGE.SUBTITLE_DAILY')}{' '}
<span className="text-tidebitTheme">{timestampToString(endTime).date}</span>
<span className="text-tidebitTheme">{timeSpanEnd}</span>
{t('LEADERBOARD_PAGE.SUBTITLE_DAILY_2')}
</div>
) : timeSpan === RankingInterval.WEEKLY ? (
<div className="inline-block text-base md:text-xl">
{t('LEADERBOARD_PAGE.SUBTITLE_WEEKLY')}{' '}
<span className="text-tidebitTheme">{timestampToString(startTime).date}</span>{' '}
<span className="text-tidebitTheme">{timeSpanStart}</span>{' '}
{t('LEADERBOARD_PAGE.SUBTITLE_WEEKLY_2')}{' '}
<span className="text-tidebitTheme">{timestampToString(endTime).date}</span>{' '}
<span className="text-tidebitTheme">{timeSpanEnd}</span>{' '}
{t('LEADERBOARD_PAGE.SUBTITLE_WEEKLY_3')}
</div>
) : timeSpan === RankingInterval.MONTHLY ? (
<div className="inline-block text-base md:text-xl">
{t('LEADERBOARD_PAGE.SUBTITLE_MONTHLY')}{' '}
<span className="text-tidebitTheme">{timestampToString(endTime).monthAndYear}</span>
<span className="text-tidebitTheme">{timeSpanMonthly}</span>
{t('LEADERBOARD_PAGE.SUBTITLE_MONTHLY_2')}
</div>
) : (
Expand Down
26 changes: 22 additions & 4 deletions src/components/deposit_history_modal/deposit_history_modal.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React from 'react';
import React, {useContext} from 'react';
import Image from 'next/image';
import Lottie from 'lottie-react';
import smallConnectingAnimation from '../../../public/animation/lf30_editor_cnkxmhy3.json';
import {GlobalContext} from '../../contexts/global_context';
import {ImCross} from 'react-icons/im';
import {OrderStatusUnion} from '../../constants/order_status_union';
import {UNIVERSAL_NUMBER_FORMAT_LOCALE} from '../../constants/display';
import {FRACTION_DIGITS} from '../../constants/config';
import {timestampToString} from '../../lib/common';
import {useTranslation} from 'react-i18next';
import {IAcceptedDepositOrder} from '../../interfaces/tidebit_defi_background/accepted_deposit_order';
import {ToastId} from '../../constants/toast_id';
import {ToastTypeAndText} from '../../constants/toast_type';

type TranslateFunction = (s: string) => string;
interface IDepositHistoryModal {
Expand All @@ -22,11 +25,11 @@ const DepositHistoryModal = ({
modalClickHandler,
getDepositHistoryData,
}: IDepositHistoryModal) => {
const {t}: {t: TranslateFunction} = useTranslation('common');
const {receipt, createTimestamp} = getDepositHistoryData;
const {orderSnapshot: order, balanceSnapshot} = receipt;
const balance = balanceSnapshot.shift();

const {t}: {t: TranslateFunction} = useTranslation('common');
const globalCtx = useContext(GlobalContext);

const displayedDepositTime = timestampToString(createTimestamp);
const displayedDepositType = t('D_W_MODAL.DEPOSIT');
Expand Down Expand Up @@ -61,6 +64,19 @@ const DepositHistoryModal = ({
</div>
);

const copyClickHandler = () => {
navigator.clipboard.writeText(order.txhash);

globalCtx.toast({
type: ToastTypeAndText.INFO.type,
message: t('TOAST.COPY_SUCCESS'),
toastId: ToastId.COPY_SUCCESS,
autoClose: 300,
isLoading: false,
typeText: t(ToastTypeAndText.INFO.text),
});
};

const displayedDepositDetail =
order.orderStatus === OrderStatusUnion.WAITING ? (
<div className="text-lightGreen5">{t('D_W_MODAL.STATUS_PROCESSING')}</div>
Expand All @@ -69,7 +85,9 @@ const DepositHistoryModal = ({
) : (
<div className="inline-flex text-tidebitTheme">
<div className="mr-2">{order.txhash}</div>
<Image src="/elements/detail_icon.svg" alt="" width={20} height={20} />
<button className="w-max" onClick={copyClickHandler}>
<Image src="/elements/detail_icon.svg" alt="" width={20} height={20} />
</button>
</div>
);

Expand Down
19 changes: 18 additions & 1 deletion src/components/receipt_item/receipt_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
} from '../../interfaces/tidebit_defi_background/order';
import {CFDOperation} from '../../constants/cfd_order_type';
import {FRACTION_DIGITS} from '../../constants/config';
import {ToastId} from '../../constants/toast_id';
import {ToastTypeAndText} from '../../constants/toast_type';
import SafeMath from '../../lib/safe_math';

type TranslateFunction = (s: string) => string;
Expand Down Expand Up @@ -173,6 +175,19 @@ const ReceiptItem = (histories: IReceiptItemProps) => {
}
: () => null;

const copyClickHandler = () => {
navigator.clipboard.writeText(displayedReceiptTxId);

globalCtx.toast({
type: ToastTypeAndText.INFO.type,
message: t('TOAST.COPY_SUCCESS'),
toastId: ToastId.COPY_SUCCESS,
autoClose: 300,
isLoading: false,
typeText: t(ToastTypeAndText.INFO.text),
});
};

const displayedReceiptStateIcon =
orderStatus === OrderStatusUnion.PROCESSING ||
orderStatus === OrderStatusUnion.WAITING ? null : orderType === OrderType.CFD ? (
Expand All @@ -182,7 +197,9 @@ const ReceiptItem = (histories: IReceiptItemProps) => {
<Image src="/elements/position_tab_icon.svg" alt="position_icon" width={25} height={25} />
)
) : (
<Image src="/elements/detail_icon.svg" alt="" width={20} height={20} />
<button onClick={copyClickHandler}>
<Image src="/elements/detail_icon.svg" alt="" width={20} height={20} />
</button>
);

const displayedReceiptFeeText =
Expand Down
2 changes: 2 additions & 0 deletions src/constants/toast_id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type IToastId = {
INVALID_CFD_OPEN_REQUEST: string;
INCONSISTENT_TICKER_OF_QUOTATION: string;
UNKNOWN_ERROR_IN_COMPONENT: string;
COPY_SUCCESS: string;
};

export const ToastId: IToastId = {
Expand All @@ -14,4 +15,5 @@ export const ToastId: IToastId = {
INVALID_CFD_OPEN_REQUEST: 'InvalidCFDOpenRequest',
INCONSISTENT_TICKER_OF_QUOTATION: 'InconsistentTickerOfQuotation',
UNKNOWN_ERROR_IN_COMPONENT: 'UnknownErrorInComponent',
COPY_SUCCESS: 'CopySuccess',
};
3 changes: 2 additions & 1 deletion src/locales/cn/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@
"SUCCESS": "成功",
"WARNING": "警告",
"INFO": "信息",
"PROGRESSING_MESSAGE": "处理中,请稍候..."
"PROGRESSING_MESSAGE": "处理中,请稍候...",
"COPY_SUCCESS": "已复制到剪贴簿!"
},
"SHARING_BOX": {
"TYPE_UP": "看涨",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@
"SUCCESS": "Success",
"WARNING": "Warning",
"INFO": "Info",
"PROGRESSING_MESSAGE": "is still in progress, please wait..."
"PROGRESSING_MESSAGE": "is still in progress, please wait...",
"COPY_SUCCESS": "Copied to clipboard!"
},
"SHARING_BOX": {
"TYPE_UP": "Up",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/tw/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@
"SUCCESS": "成功",
"WARNING": "警告",
"INFO": "訊息",
"PROGRESSING_MESSAGE": "處理中,請稍候..."
"PROGRESSING_MESSAGE": "處理中,請稍候...",
"COPY_SUCCESS": "已複製到剪貼簿!"
},
"SHARING_BOX": {
"TYPE_UP": "看漲",
Expand Down