From 58acbb39741b45b7a175ebe8c2b65cf03fd8a206 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 16 Aug 2023 10:27:17 +0800 Subject: [PATCH 1/2] txhash copy --- .../deposit_history_modal.tsx | 26 ++++++++++++++++--- src/components/receipt_item/receipt_item.tsx | 19 +++++++++++++- src/constants/toast_id.ts | 2 ++ src/locales/cn/common.json | 3 ++- src/locales/en/common.json | 3 ++- src/locales/tw/common.json | 3 ++- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/components/deposit_history_modal/deposit_history_modal.tsx b/src/components/deposit_history_modal/deposit_history_modal.tsx index a6f9650fa..8f3cd7690 100644 --- a/src/components/deposit_history_modal/deposit_history_modal.tsx +++ b/src/components/deposit_history_modal/deposit_history_modal.tsx @@ -1,7 +1,8 @@ -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'; @@ -9,6 +10,8 @@ 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 { @@ -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'); @@ -61,6 +64,19 @@ const DepositHistoryModal = ({ ); + 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 ? (
{t('D_W_MODAL.STATUS_PROCESSING')}
@@ -69,7 +85,9 @@ const DepositHistoryModal = ({ ) : (
{order.txhash}
- +
); diff --git a/src/components/receipt_item/receipt_item.tsx b/src/components/receipt_item/receipt_item.tsx index 9e8c38b67..7b82ba102 100644 --- a/src/components/receipt_item/receipt_item.tsx +++ b/src/components/receipt_item/receipt_item.tsx @@ -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; @@ -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 ? ( @@ -182,7 +197,9 @@ const ReceiptItem = (histories: IReceiptItemProps) => { position_icon ) ) : ( - + ); const displayedReceiptFeeText = diff --git a/src/constants/toast_id.ts b/src/constants/toast_id.ts index 19de7e4cd..1316f4346 100644 --- a/src/constants/toast_id.ts +++ b/src/constants/toast_id.ts @@ -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 = { @@ -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', }; diff --git a/src/locales/cn/common.json b/src/locales/cn/common.json index a050c2797..9493f8382 100644 --- a/src/locales/cn/common.json +++ b/src/locales/cn/common.json @@ -322,7 +322,8 @@ "SUCCESS": "成功", "WARNING": "警告", "INFO": "信息", - "PROGRESSING_MESSAGE": "处理中,请稍候..." + "PROGRESSING_MESSAGE": "处理中,请稍候...", + "COPY_SUCCESS": "已复制到剪贴簿!" }, "SHARING_BOX": { "TYPE_UP": "看涨", diff --git a/src/locales/en/common.json b/src/locales/en/common.json index c2bac7e81..d06ea3bfc 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -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", diff --git a/src/locales/tw/common.json b/src/locales/tw/common.json index 72df23803..5bb13412a 100644 --- a/src/locales/tw/common.json +++ b/src/locales/tw/common.json @@ -322,7 +322,8 @@ "SUCCESS": "成功", "WARNING": "警告", "INFO": "訊息", - "PROGRESSING_MESSAGE": "處理中,請稍候..." + "PROGRESSING_MESSAGE": "處理中,請稍候...", + "COPY_SUCCESS": "已複製到剪貼簿!" }, "SHARING_BOX": { "TYPE_UP": "看漲", From a7455fac7840373900474a9d8be9f60661e66ef2 Mon Sep 17 00:00:00 2001 From: Julian Date: Wed, 16 Aug 2023 17:23:43 +0800 Subject: [PATCH 2/2] leaderboard time zone --- src/components/board_page_body/board_page_body.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/board_page_body/board_page_body.tsx b/src/components/board_page_body/board_page_body.tsx index 917be3406..82831acbf 100644 --- a/src/components/board_page_body/board_page_body.tsx +++ b/src/components/board_page_body/board_page_body.tsx @@ -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 ? (
@@ -71,21 +76,21 @@ const BoardPageBody = () => { ) : timeSpan === RankingInterval.DAILY ? (
{t('LEADERBOARD_PAGE.SUBTITLE_DAILY')}{' '} - {timestampToString(endTime).date} + {timeSpanEnd} {t('LEADERBOARD_PAGE.SUBTITLE_DAILY_2')}
) : timeSpan === RankingInterval.WEEKLY ? (
{t('LEADERBOARD_PAGE.SUBTITLE_WEEKLY')}{' '} - {timestampToString(startTime).date}{' '} + {timeSpanStart}{' '} {t('LEADERBOARD_PAGE.SUBTITLE_WEEKLY_2')}{' '} - {timestampToString(endTime).date}{' '} + {timeSpanEnd}{' '} {t('LEADERBOARD_PAGE.SUBTITLE_WEEKLY_3')}
) : timeSpan === RankingInterval.MONTHLY ? (
{t('LEADERBOARD_PAGE.SUBTITLE_MONTHLY')}{' '} - {timestampToString(endTime).monthAndYear} + {timeSpanMonthly} {t('LEADERBOARD_PAGE.SUBTITLE_MONTHLY_2')}
) : (