= ({ collection, iconURL, list,
) : (
- {isLoading ? i18n.t('nft.loading') : i18n.t(`nft.no_record`)}
+ {isLoading ? t('nft.loading') : t(`nft.no_record`)}
|
)}
@@ -98,6 +100,7 @@ const TransferTableRow: FC<{
iconURL?: string | null
isShowInAge?: boolean
}> = ({ collection, item, iconURL, isShowInAge }) => {
+ const { t } = useTranslation()
const coverUrl = item.item.icon_url ?? iconURL
const parsedBlockCreateAt = useParsedDate(item.transaction.block_timestamp)
const now = useTimestamp()
@@ -171,7 +174,7 @@ const TransferTableRow: FC<{
- {i18n.t(`nft.action_type.${item.action}`)} |
+ {t(`nft.action_type.${item.action}`)} |
{isShowInAge ? timeRelativeBlockCreate : parsedBlockCreateAt} |
{item.from ? (
@@ -212,12 +215,13 @@ const TransferTableRow: FC<{
}
const TransferCardGroup: FC = ({ collection, iconURL, list, isLoading }) => {
+ const { t } = useTranslation()
return (
{list.length ? (
list.map(item => )
) : (
- - {isLoading ? i18n.t('nft.loading') : i18n.t(`nft.no_record`)}
+ - {isLoading ? t('nft.loading') : t(`nft.no_record`)}
)}
)
@@ -228,6 +232,7 @@ const TransferCard: FC<{
item: TransferRes
iconURL?: string | null
}> = ({ collection, item, iconURL }) => {
+ const { t } = useTranslation()
const coverUrl = item.item.icon_url ?? iconURL
const parsedBlockCreateAt = useParsedDate(item.transaction.block_timestamp)
@@ -284,7 +289,7 @@ const TransferCard: FC<{
- - {i18n.t('nft.tx_hash')}
+ - {t('nft.tx_hash')}
-
- - {i18n.t('nft.action')}
- - {i18n.t(`nft.action_type.${item.action}`)}
+ - {t('nft.action')}
+ - {t(`nft.action_type.${item.action}`)}
- - {i18n.t('nft.age')}
+ - {t('nft.age')}
- {parsedBlockCreateAt}
- - {i18n.t('nft.from')}
+ - {t('nft.from')}
-
{item.from ? (
- - {i18n.t('nft.to')}
+ - {t('nft.to')}
-
{item.to ? (
isLoading: boolean
}> = ({ list, isLoading }) => {
+ const { t } = useTranslation()
+
return (
- {i18n.t('nft.holder')} |
+ {t('nft.holder')} |
- {i18n.t('nft.quantity')}
+ {t('nft.quantity')}
|
@@ -49,7 +51,7 @@ const NftHolderList: React.FC<{
) : (
- {isLoading ? i18n.t('nft.loading') : i18n.t(`nft.no_record`)}
+ {isLoading ? t('nft.loading') : t(`nft.no_record`)}
|
)}
diff --git a/src/components/NftItemTransfers/index.tsx b/src/components/NftItemTransfers/index.tsx
index ef9507df1..b5aca7fde 100644
--- a/src/components/NftItemTransfers/index.tsx
+++ b/src/components/NftItemTransfers/index.tsx
@@ -1,10 +1,11 @@
import { useState } from 'react'
import { Link } from 'react-router-dom'
import { Tooltip } from 'antd'
-import i18n from '../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import { getPrimaryColor } from '../../constants/common'
-import { dayjs, parseDate } from '../../utils/date'
+import { dayjs, useParseDate } from '../../utils/date'
import styles from './styles.module.scss'
+import { useCurrentLanguage } from '../../utils/i18n'
const primaryColor = getPrimaryColor()
@@ -40,30 +41,34 @@ export interface TransferListRes {
}
const NftItemTransfers: React.FC<{ list: TransferListRes['data']; isLoading: boolean }> = ({ list, isLoading }) => {
const [isShowInAge, setIsShowInAge] = useState(false)
- dayjs.locale(i18n.language === 'zh' ? 'zh-cn' : 'en')
+ const { t } = useTranslation()
+ const parseDate = useParseDate()
+ const currentLanguage = useCurrentLanguage()
+
+ dayjs.locale(currentLanguage === 'zh' ? 'zh-cn' : 'en')
return (
- {i18n.t('nft.tx_hash')} |
- {i18n.t('nft.action')} |
+ {t('nft.tx_hash')} |
+ {t('nft.action')} |
setIsShowInAge(show => !show)}
className={styles.age}
- title={i18n.t('nft.toggle-age')}
+ title={t('nft.toggle-age')}
style={{
color: primaryColor,
}}
>
- {i18n.t('nft.age')}
+ {t('nft.age')}
|
- {i18n.t('nft.from')} |
- {i18n.t('nft.to')} |
+ {t('nft.from')} |
+ {t('nft.to')} |
@@ -87,7 +92,7 @@ const NftItemTransfers: React.FC<{ list: TransferListRes['data']; isLoading: boo
- {i18n.t(`nft.action_type.${item.action}`)} |
+ {t(`nft.action_type.${item.action}`)} |
{isShowInAge
? dayjs(item.transaction.block_timestamp).fromNow()
@@ -133,7 +138,7 @@ const NftItemTransfers: React.FC<{ list: TransferListRes['data']; isLoading: boo
) : (
|
- {isLoading ? i18n.t('nft.loading') : i18n.t(`nft.no_record`)}
+ {isLoading ? t('nft.loading') : t(`nft.no_record`)}
|
)}
@@ -145,7 +150,7 @@ const NftItemTransfers: React.FC<{ list: TransferListRes['data']; isLoading: boo
-
- - {i18n.t('nft.tx_hash')}
+ - {t('nft.tx_hash')}
-
- - {i18n.t('nft.action')}
- - {i18n.t(`nft.action_type.${item.action}`)}
+ - {t('nft.action')}
+ - {t(`nft.action_type.${item.action}`)}
- - {i18n.t('nft.age')}
+ - {t('nft.age')}
- {parseDate(item.transaction.block_timestamp)}
- - {i18n.t('nft.from')}
+ - {t('nft.from')}
-
{item.from ? (
- - {i18n.t('nft.to')}
+ - {t('nft.to')}
-
{item.to ? (
))
) : (
-
- {isLoading ? i18n.t('nft.loading') : i18n.t(`nft.no_record`)}
+ - {isLoading ? t('nft.loading') : t(`nft.no_record`)}
)}
diff --git a/src/components/Pagination/index.tsx b/src/components/Pagination/index.tsx
index 9bd1a37ea..cb6e5ae71 100644
--- a/src/components/Pagination/index.tsx
+++ b/src/components/Pagination/index.tsx
@@ -1,10 +1,10 @@
import { useState } from 'react'
+import { useTranslation } from 'react-i18next'
import { PaginationLeftItem, PaginationRightItem, PaginationPanel } from './styled'
import LeftBlack from '../../assets/pagination_black_left.png'
import RightBlack from '../../assets/pagination_black_right.png'
import LeftGrey from '../../assets/pagination_grey_left.png'
import RightGrey from '../../assets/pagination_grey_right.png'
-import i18n from '../../utils/i18n'
import { useIsMobile } from '../../utils/hook'
import SimpleButton from '../SimpleButton'
import { HelpTip } from '../HelpTip'
@@ -25,15 +25,16 @@ const Pagination = ({
annotation?: string
}) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const [inputPage, setInputPage] = useState(gotoPage)
const total = Math.max(totalPages, 1)
const current = Math.min(Math.max(currentPage, 1), totalPages)
- const mobilePagination = `${i18n.t('pagination.total_page')} ${total} ${i18n.t('pagination.end_page')}`
- const pcPagination = `${i18n.t('pagination.current_page')} ${current} ${i18n.t(
- 'pagination.of_page',
- )} ${total} ${i18n.t('pagination.end_page')}`
+ const mobilePagination = `${t('pagination.total_page')} ${total} ${t('pagination.end_page')}`
+ const pcPagination = `${t('pagination.current_page')} ${current} ${t('pagination.of_page')} ${total} ${t(
+ 'pagination.end_page',
+ )}`
const annotationComp = annotation ? : null
@@ -48,7 +49,7 @@ const Pagination = ({
changePage(1)}>
- {i18n.t('pagination.first')}
+ {t('pagination.first')}
changePage(current - 1)}>
@@ -71,11 +72,11 @@ const Pagination = ({
)}
changePage(total)}>
- {i18n.t('pagination.last')}
+ {t('pagination.last')}
- {i18n.t('pagination.page')}
+ {t('pagination.page')}
changePage(inputPage)}>
- {i18n.t('pagination.goto')}
+ {t('pagination.goto')}
diff --git a/src/components/Script/index.tsx b/src/components/Script/index.tsx
index c36762906..89ccd07ec 100644
--- a/src/components/Script/index.tsx
+++ b/src/components/Script/index.tsx
@@ -1,6 +1,6 @@
import { ReactNode } from 'react'
+import { useTranslation } from 'react-i18next'
import { ScriptItemPanel, ScriptPanel } from './styled'
-import i18n from '../../utils/i18n'
import HashTag from '../HashTag'
import { getContractHashTag } from '../../utils/util'
import { HelpTip } from '../HelpTip'
@@ -18,18 +18,20 @@ const ScriptItem = ({ title, tooltip, children }: { title: string; tooltip?: str
const Script = ({ script }: { script: State.Script }) => {
const contractHashTag = getContractHashTag(script)
+ const { t } = useTranslation()
+
return (
-
+
{script.codeHash}
{contractHashTag && }
-
+
{script.hashType}
-
+
{script.args}
diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx
index 01f6778d0..cdc3a39d7 100644
--- a/src/components/Search/index.tsx
+++ b/src/components/Search/index.tsx
@@ -1,13 +1,12 @@
-import { useState, useRef, useEffect, useMemo, FC, memo } from 'react'
+import { useState, useRef, useEffect, FC, memo } from 'react'
import { useHistory } from 'react-router'
import { AxiosError } from 'axios'
-import { useTranslation } from 'react-i18next'
+import { TFunction, useTranslation } from 'react-i18next'
import { SearchImage, SearchInputPanel, SearchPanel, SearchButton, SearchContainer } from './styled'
import { explorerService, Response } from '../../services/ExplorerService'
import SearchLogo from '../../assets/search_black.png'
import ClearLogo from '../../assets/clear.png'
import { addPrefixForHash, containSpecialChar } from '../../utils/string'
-import i18n from '../../utils/i18n'
import { HttpErrorCode, SearchFailType } from '../../constants/common'
import { useIsMobile } from '../../utils/hook'
import { isChainTypeError } from '../../utils/chain'
@@ -28,9 +27,9 @@ const clearSearchInput = (inputElement: any) => {
}
}
-const setSearchLoading = (inputElement: any) => {
+const setSearchLoading = (inputElement: any, t: TFunction) => {
const input: HTMLInputElement = inputElement.current
- input.value = i18n.t('search.loading')
+ input.value = t('search.loading')
}
const setSearchContent = (inputElement: any, content: string) => {
@@ -45,6 +44,7 @@ const handleSearchResult = (
inputElement: any,
setSearchValue: Function,
history: ReturnType,
+ t: TFunction,
) => {
const query = searchValue.trim().replace(',', '') // remove front and end blank and ','
if (!query || containSpecialChar(query)) {
@@ -56,7 +56,7 @@ const handleSearchResult = (
return
}
- setSearchLoading(inputElement)
+ setSearchLoading(inputElement, t)
explorerService.api
.fetchSearchResult(addPrefixForHash(query))
.then((response: any) => {
@@ -103,9 +103,9 @@ const Search: FC<{
onEditEnd?: () => void
}> = memo(({ content, hasButton, onEditEnd }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const history = useHistory()
- const [t] = useTranslation()
- const SearchPlaceholder = useMemo(() => t('navbar.search_placeholder'), [t])
+ const SearchPlaceholder = t('navbar.search_placeholder')
const [searchValue, setSearchValue] = useState(content || '')
const [placeholder, setPlaceholder] = useState(SearchPlaceholder)
const inputElement = useRef(null)
@@ -138,7 +138,7 @@ const Search: FC<{
const searchKeyAction = (event: any) => {
if (event.keyCode === 13) {
- handleSearchResult(searchValue, inputElement, setSearchValue, history)
+ handleSearchResult(searchValue, inputElement, setSearchValue, history, t)
onEditEnd?.()
}
}
@@ -165,11 +165,11 @@ const Search: FC<{
{hasButton && (
{
- handleSearchResult(searchValue, inputElement, setSearchValue, history)
+ handleSearchResult(searchValue, inputElement, setSearchValue, history, t)
onEditEnd?.()
}}
>
- {i18n.t('search.search')}
+ {t('search.search')}
)}
diff --git a/src/components/Sheet/index.tsx b/src/components/Sheet/index.tsx
index 0cb700946..ef24153dd 100644
--- a/src/components/Sheet/index.tsx
+++ b/src/components/Sheet/index.tsx
@@ -1,3 +1,4 @@
+import { useTranslation } from 'react-i18next'
import { SheetPanel, SheetPointPanel, SheetItem } from './styled'
import { createGlobalState, createGlobalStateSetter, useGlobalState } from '../../utils/state'
@@ -8,6 +9,7 @@ export const setNetworkErrMsgs = createGlobalStateSetter(globalNetworkErrMsgs)
export const setChainAlerts = createGlobalStateSetter(globalChainAlerts)
const Sheet = () => {
+ const { t } = useTranslation()
const [networkErrMsgs] = useGlobalState(globalNetworkErrMsgs)
const [chainAlerts] = useGlobalState(globalChainAlerts)
const messages: string[] = chainAlerts.concat(networkErrMsgs)
@@ -19,7 +21,7 @@ const Sheet = () => {
return (
{messages.length > 1 && ยท}
- {context}
+ {t(context)}
)
})}
diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx
index 259f79c6c..67b5e31a1 100644
--- a/src/components/Table/index.tsx
+++ b/src/components/Table/index.tsx
@@ -1,6 +1,6 @@
import { memo, ReactNode } from 'react'
import { Col, Row } from 'antd'
-import i18n from '../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import { TableTitleRowItem, TableContentRowItem, HighlightLink, TableMinerContentPanel } from './styled'
import AddressText from '../AddressText'
@@ -31,6 +31,7 @@ export const TableMinerContentItem = memo(
textCenter?: boolean
fontSize?: string
}) => {
+ const { t } = useTranslation()
return (
{content ? (
@@ -48,7 +49,7 @@ export const TableMinerContentItem = memo(
) : (
- {i18n.t('address.unable_decode_address')}
+ {t('address.unable_decode_address')}
)}
)
diff --git a/src/components/Text/CopyTooltipText/index.tsx b/src/components/Text/CopyTooltipText/index.tsx
index 7582fc369..5e970be81 100644
--- a/src/components/Text/CopyTooltipText/index.tsx
+++ b/src/components/Text/CopyTooltipText/index.tsx
@@ -1,17 +1,19 @@
-import i18n from '../../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import { copyElementValue } from '../../../utils/util'
import SimpleButton from '../../SimpleButton'
import { useSetToast } from '../../Toast'
export default ({ content }: { content: string }) => {
const setToast = useSetToast()
+ const { t } = useTranslation()
+
return (
{
event.stopPropagation()
copyElementValue(document.getElementById(`copy__content__${content}`))
- setToast({ message: i18n.t('common.copied') })
+ setToast({ message: t('common.copied') })
event.preventDefault()
}}
>
diff --git a/src/components/Transaction/TransactionCellArrow/index.tsx b/src/components/Transaction/TransactionCellArrow/index.tsx
index 8fa6ceb26..4b5ebf3e4 100644
--- a/src/components/Transaction/TransactionCellArrow/index.tsx
+++ b/src/components/Transaction/TransactionCellArrow/index.tsx
@@ -1,12 +1,12 @@
import { Link } from 'react-router-dom'
import { Tooltip } from 'antd'
+import { useTranslation } from 'react-i18next'
import { CellType } from '../../../constants/common'
import RightGreenArrow from '../../../assets/right_green_arrow.png'
import RightBlueArrow from '../../../assets/right_blue_arrow.png'
import LiveCellIcon from '../../../assets/live_cell.png'
import LiveCellBlueIcon from '../../../assets/live_cell_blue.png'
import { isMainnet } from '../../../utils/chain'
-import i18n from '../../../utils/i18n'
import { RightArrowImage, LeftArrowImage } from './styled'
const CellInputIcon = ({ cell }: { cell: State.Cell }) =>
@@ -21,6 +21,8 @@ const CellInputIcon = ({ cell }: { cell: State.Cell }) =>
) : null
const CellOutputIcon = ({ cell }: { cell: State.Cell }) => {
+ const { t } = useTranslation()
+
if (cell.status === 'dead') {
return (
@@ -29,7 +31,7 @@ const CellOutputIcon = ({ cell }: { cell: State.Cell }) => {
)
}
return (
-
+
)
diff --git a/src/components/TransactionItem/TransactionIncome/index.tsx b/src/components/TransactionItem/TransactionIncome/index.tsx
index edb9cdf74..f188b001c 100644
--- a/src/components/TransactionItem/TransactionIncome/index.tsx
+++ b/src/components/TransactionItem/TransactionIncome/index.tsx
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js'
import { Tooltip } from 'antd'
-import i18n from '../../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import { TransactionIncomePanel, TransactionCapacityValuePanel } from './styled'
import { shannonToCkb } from '../../../utils/util'
import { localeNumberString } from '../../../utils/number'
@@ -10,6 +10,7 @@ import CurrentAddressIcon from '../../../assets/current_address.svg'
export default ({ income }: { income: string }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
let bigIncome = new BigNumber(income)
if (bigIncome.isNaN()) {
bigIncome = new BigNumber(0)
@@ -18,7 +19,7 @@ export default ({ income }: { income: string }) => {
{isMobile && (
-
+
)}
@@ -27,7 +28,7 @@ export default ({ income }: { income: string }) => {
color="inherit"
/>
{!isMobile && (
-
+
)}
diff --git a/src/components/TransactionItem/TransactionItemCell/index.tsx b/src/components/TransactionItem/TransactionItemCell/index.tsx
index 2068789b6..6a32695d0 100644
--- a/src/components/TransactionItem/TransactionItemCell/index.tsx
+++ b/src/components/TransactionItem/TransactionItemCell/index.tsx
@@ -2,11 +2,12 @@ import { FC, ReactNode } from 'react'
import { Link } from 'react-router-dom'
import { Popover, Tooltip } from 'antd'
import classNames from 'classnames'
+import { useTranslation } from 'react-i18next'
import NervosDAOCellIcon from '../../../assets/nervos_dao_cell.png'
import NervosDAOWithdrawingIcon from '../../../assets/nervos_dao_withdrawing.png'
import CurrentAddressIcon from '../../../assets/current_address.svg'
import UDTTokenIcon from '../../../assets/udt_token.png'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { useCurrentLanguage } from '../../../utils/i18n'
import { localeNumberString, parseUDTAmount } from '../../../utils/number'
import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util'
import {
@@ -70,10 +71,12 @@ const AddressTextWithAlias: FC<{
)
}
-const udtAmount = (udt: State.UDTInfo) =>
- udt.published
+const useUdtAmount = (udt: State.UDTInfo) => {
+ const { t } = useTranslation()
+ return udt.published
? `${parseUDTAmount(udt.amount, udt.decimal)} ${udt.uan || udt.symbol}`
- : `${i18n.t('udt.unknown_token')} #${udt.typeHash.substring(udt.typeHash.length - 4)}`
+ : `${t('udt.unknown_token')} #${udt.typeHash.substring(udt.typeHash.length - 4)}`
+}
const WithdrawPopoverItem = ({
width,
@@ -92,27 +95,27 @@ const WithdrawPopoverItem = ({
const WithdrawPopoverInfo = ({ cell }: { cell: State.Cell }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
let width = 'short'
- if (currentLanguage() === 'en') {
+ if (currentLanguage === 'en') {
width = isDaoDepositCell(cell.cellType) ? 'long' : 'medium'
}
return (
- {isDaoWithdrawCell(cell.cellType)
- ? i18n.t('nervos_dao.withdraw_tooltip')
- : i18n.t('nervos_dao.withdraw_request_tooltip')}
+ {isDaoWithdrawCell(cell.cellType) ? t('nervos_dao.withdraw_tooltip') : t('nervos_dao.withdraw_request_tooltip')}
}
/>
{
/>
- {`${i18n.t('block.block')} `}
+ {`${t('block.block')} `}
{localeNumberString(cell.compensationStartedBlockNumber)}
@@ -137,17 +140,17 @@ const WithdrawPopoverInfo = ({ cell }: { cell: State.Cell }) => {
/>
{isDaoWithdrawCell(cell.cellType) && (
<>
- {`${i18n.t('block.block')} `}
+ {`${t('block.block')} `}
{localeNumberString(cell.compensationStartedBlockNumber)}
@@ -160,7 +163,7 @@ const WithdrawPopoverInfo = ({ cell }: { cell: State.Cell }) => {
/>
>
@@ -171,6 +174,7 @@ const WithdrawPopoverInfo = ({ cell }: { cell: State.Cell }) => {
const TransactionCellNervosDao = ({ cell, cellType }: { cell: State.Cell; cellType: CellType }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
return (
@@ -181,9 +185,7 @@ const TransactionCellNervosDao = ({ cell, cellType }: { cell: State.Cell; cellTy
) : (
{
return (
- {udtAmount(extraInfo)}
+ {useUdtAmount(extraInfo)}
{
const isMobile = useIsMobile()
+ const { t } = useTranslation()
if (cell.fromCellbase) {
return
}
- let addressText = i18n.t('address.unable_decode_address')
+ let addressText = t('address.unable_decode_address')
let highLight = false
if (cell.addressHash) {
addressText = cell.addressHash
@@ -253,14 +256,14 @@ const TransactionCell = ({ cell, address, cellType }: { cell: State.Cell; addres
{cellType === CellType.Output && }
{!highLight && !isMobile && (
-
+
)}
{!highLight && isMobile && (
-
+
)}
diff --git a/src/components/TransactionItem/TransactionItemCellList/index.tsx b/src/components/TransactionItem/TransactionItemCellList/index.tsx
index af441df2e..5d2ed3d8f 100644
--- a/src/components/TransactionItem/TransactionItemCellList/index.tsx
+++ b/src/components/TransactionItem/TransactionItemCellList/index.tsx
@@ -1,7 +1,7 @@
import { ReactNode } from 'react'
import { Link } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import TransactionCellListPanel from './styled'
-import i18n from '../../../utils/i18n'
const MAX_CELL_SHOW_SIZE = 10
@@ -13,13 +13,16 @@ export default ({
cells: State.Cell[]
transaction: State.Transaction
render: (cell: State.Cell) => ReactNode
-}) => (
-
- {cells && cells.map((cell, index) => index < MAX_CELL_SHOW_SIZE && render(cell))}
- {cells && cells.length >= MAX_CELL_SHOW_SIZE && (
-
- {i18n.t('common.view_all')}
-
- )}
-
-)
+}) => {
+ const { t } = useTranslation()
+ return (
+
+ {cells && cells.map((cell, index) => index < MAX_CELL_SHOW_SIZE && render(cell))}
+ {cells && cells.length >= MAX_CELL_SHOW_SIZE && (
+
+ {t('common.view_all')}
+
+ )}
+
+ )
+}
diff --git a/src/components/TransactionItem/TransactionLiteItem/index.tsx b/src/components/TransactionItem/TransactionLiteItem/index.tsx
index a49f49c81..a0a8439f8 100644
--- a/src/components/TransactionItem/TransactionLiteItem/index.tsx
+++ b/src/components/TransactionItem/TransactionLiteItem/index.tsx
@@ -1,19 +1,20 @@
import { Link } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import { localeNumberString } from '../../../utils/number'
import AddressText from '../../AddressText'
import styles from './index.module.scss'
import TransactionLiteIncome from '../TransactionLiteIncome'
-import i18n from '../../../utils/i18n'
import { useIsMobile, useParsedDate } from '../../../utils/hook'
const TransactionLiteItem = ({ transaction, address }: { transaction: State.Transaction; address?: string }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const parsedBlockCreateAt = useParsedDate(transaction.blockTimestamp)
return (
- {isMobile && {i18n.t('transaction.transaction_hash')} }
+ {isMobile && {t('transaction.transaction_hash')} }
- {isMobile && {i18n.t('transaction.height')} }
+ {isMobile && {t('transaction.height')} }
{localeNumberString(transaction.blockNumber)}
- {isMobile && {i18n.t('transaction.time')} }
+ {isMobile && {t('transaction.time')} }
{parsedBlockCreateAt}
- {isMobile && {`${i18n.t('transaction.input')} & ${i18n.t('transaction.output')}`} }
+ {isMobile && {`${t('transaction.input')} & ${t('transaction.output')}`} }
+ {transaction.displayInputs && `${t('transaction.input')}: ${transaction.displayInputs.length}`}
- {transaction.displayInputs && `${i18n.t('transaction.input')}: ${transaction.displayInputs.length}`}
-
-
- {transaction.displayOutputs && `${i18n.t('transaction.output')}: ${transaction.displayOutputs.length}`}
+ {transaction.displayOutputs && `${t('transaction.output')}: ${transaction.displayOutputs.length}`}
- {isMobile && {i18n.t('transaction.capacity_change')} }
+ {isMobile && {t('transaction.capacity_change')} }
{address && }
diff --git a/src/components/TransactionItem/index.tsx b/src/components/TransactionItem/index.tsx
index bebf31670..1ff620794 100644
--- a/src/components/TransactionItem/index.tsx
+++ b/src/components/TransactionItem/index.tsx
@@ -1,4 +1,5 @@
import { ReactNode, useEffect, useRef } from 'react'
+import { useTranslation } from 'react-i18next'
import RightArrowIcon from '../../assets/input_arrow_output.png'
import DownArrowIcon from '../../assets/input_arrow_output_down.png'
import { localeNumberString } from '../../utils/number'
@@ -6,7 +7,6 @@ import TransactionCell from './TransactionItemCell'
import TransactionCellList from './TransactionItemCellList'
import TransactionIncome from './TransactionIncome'
import { FullPanel, TransactionHashBlockPanel, TransactionCellPanel, TransactionPanel } from './styled'
-import i18n from '../../utils/i18n'
import { CellType } from '../../constants/common'
import AddressText from '../AddressText'
import { useIsLGScreen, useParsedDate } from '../../utils/hook'
@@ -35,6 +35,7 @@ const TransactionItem = ({
scrollIntoViewOnMount?: boolean
}) => {
const isLG = useIsLGScreen()
+ const { t } = useTranslation()
const ref = useRef (null)
useEffect(() => {
@@ -67,7 +68,7 @@ const TransactionItem = ({
{!isBlock && (
- {`(${i18n.t('block.block')} ${localeNumberString(transaction.blockNumber)}) ${parsedBlockCreateAt}`}
+ {`(${t('block.block')} ${localeNumberString(transaction.blockNumber)}) ${parsedBlockCreateAt}`}
)}
@@ -93,7 +94,7 @@ const TransactionItem = ({
)}
/>
) : (
- {i18n.t('transaction.empty_output')}
+ {t('transaction.empty_output')}
)}
diff --git a/src/contexts/providers/hook.ts b/src/contexts/providers/hook.ts
index 3588c9ef6..24552a4a1 100644
--- a/src/contexts/providers/hook.ts
+++ b/src/contexts/providers/hook.ts
@@ -1,24 +1,13 @@
import { useState } from 'react'
import { FLUSH_CHART_CACHE_POLLING_TIME } from '../../constants/common'
-import { AppCachedKeys } from '../../constants/cache'
-import { fetchCachedData } from '../../utils/cache'
-import { changeLanguage } from '../../utils/i18n'
import { useInterval } from '../../utils/hook'
import flushCacheInfo from '../../service/app/charts/cache'
-const initAppLanguage = () => {
- const language =
- fetchCachedData<'zh' | 'en'>(AppCachedKeys.AppLanguage) || (navigator.language.includes('zh') ? 'zh' : 'en')
- changeLanguage(language)
-}
-
export const useInitApp = () => {
const [init, setInit] = useState(false)
if (!init) {
setInit(true)
- // TODO: This function may not belong here.
- initAppLanguage()
flushCacheInfo()
}
diff --git a/src/pages/Address/AddressComp.tsx b/src/pages/Address/AddressComp.tsx
index d8eadbe0a..b859c3c67 100644
--- a/src/pages/Address/AddressComp.tsx
+++ b/src/pages/Address/AddressComp.tsx
@@ -4,10 +4,10 @@ import { useQuery } from 'react-query'
import { Radio } from 'antd'
import { Base64 } from 'js-base64'
import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils'
+import { TFunction, useTranslation } from 'react-i18next'
import OverviewCard, { OverviewItemData } from '../../components/Card/OverviewCard'
import TransactionItem from '../../components/TransactionItem/index'
import { explorerService } from '../../services/ExplorerService'
-import i18n from '../../utils/i18n'
import { parseSporeCellData } from '../../utils/spore'
import { localeNumberString, parseUDTAmount } from '../../utils/number'
import { shannonToCkb, deprecatedAddrToNewAddr, handleNftImgError, patchMibaoImg } from '../../utils/util'
@@ -47,26 +47,26 @@ import { omit } from '../../utils/object'
import { CsvExport } from '../../components/CsvExport'
import PaginationWithRear from '../../components/PaginationWithRear'
-const addressAssetInfo = (address: State.Address, useMiniStyle: boolean) => {
+const addressAssetInfo = (address: State.Address, useMiniStyle: boolean, t: TFunction) => {
const items = [
{
title: '',
content: '',
},
{
- title: i18n.t('address.occupied'),
- tooltip: i18n.t('glossary.occupied'),
+ title: t('address.occupied'),
+ tooltip: t('glossary.occupied'),
content: ,
isAsset: true,
},
{
icon: CKBTokenIcon,
- title: i18n.t('common.ckb_unit'),
+ title: t('common.ckb_unit'),
content: ,
},
{
- title: i18n.t('address.dao_deposit'),
- tooltip: i18n.t('glossary.nervos_dao_deposit'),
+ title: t('address.dao_deposit'),
+ tooltip: t('glossary.nervos_dao_deposit'),
content: ,
isAsset: true,
},
@@ -75,9 +75,9 @@ const addressAssetInfo = (address: State.Address, useMiniStyle: boolean) => {
content: '',
},
{
- title: i18n.t('address.compensation'),
+ title: t('address.compensation'),
content: ,
- tooltip: i18n.t('glossary.nervos_dao_compensation'),
+ tooltip: t('glossary.nervos_dao_compensation'),
isAsset: true,
},
] as OverviewItemData[]
@@ -99,6 +99,7 @@ const UDT_LABEL: Record = {
}
const AddressUDTItem = ({ udtAccount }: { udtAccount: State.UDTAccount }) => {
+ const { t } = useTranslation()
const { symbol, uan, amount, udtIconFile, typeHash, udtType, collection, cota } = udtAccount
const isSudt = udtType === 'sudt'
const isSpore = udtType === 'spore_cell'
@@ -167,7 +168,7 @@ const AddressUDTItem = ({ udtAccount }: { udtAccount: State.UDTAccount }) => {
return (
- {isUnverified ? `${i18n.t('udt.unverified')}: ` : null}
+ {isUnverified ? `${t('udt.unverified')}: ` : null}
{UDT_LABEL[udtType] ?? 'unknown'}
@@ -210,16 +211,17 @@ const lockScriptIcon = (show: boolean) => {
return isMainnet() ? ArrowDownIcon : ArrowDownBlueIcon
}
-const getAddressInfo = ({ liveCellsCount, minedBlocksCount, type, addressHash, lockInfo }: State.Address) => {
+const useAddressInfo = ({ liveCellsCount, minedBlocksCount, type, addressHash, lockInfo }: State.Address) => {
+ const { t } = useTranslation()
const items: OverviewItemData[] = [
{
- title: i18n.t('address.live_cells'),
- tooltip: i18n.t('glossary.live_cells'),
+ title: t('address.live_cells'),
+ tooltip: t('glossary.live_cells'),
content: localeNumberString(liveCellsCount),
},
{
- title: i18n.t('address.block_mined'),
- tooltip: i18n.t('glossary.block_mined'),
+ title: t('address.block_mined'),
+ tooltip: t('glossary.block_mined'),
content: localeNumberString(minedBlocksCount),
},
]
@@ -227,22 +229,22 @@ const getAddressInfo = ({ liveCellsCount, minedBlocksCount, type, addressHash, l
if (type === 'LockHash') {
if (!addressHash) {
items.push({
- title: i18n.t('address.address'),
- content: i18n.t('address.unable_decode_address'),
+ title: t('address.address'),
+ content: t('address.unable_decode_address'),
})
} else {
items.push({
- title: i18n.t('address.address'),
+ title: t('address.address'),
contentWrapperClass: styles.addressWidthModify,
content: {addressHash},
})
}
}
if (lockInfo && lockInfo.epochNumber !== '0' && lockInfo.estimatedUnlockTime !== '0') {
- const estimate = Number(lockInfo.estimatedUnlockTime) > new Date().getTime() ? i18n.t('address.estimated') : ''
+ const estimate = Number(lockInfo.estimatedUnlockTime) > new Date().getTime() ? t('address.estimated') : ''
items.push({
- title: i18n.t('address.lock_until'),
- content: `${lockInfo.epochNumber} ${i18n.t('address.epoch')} (${estimate} ${parseSimpleDateNoSecond(
+ title: t('address.lock_until'),
+ content: `${lockInfo.epochNumber} ${t('address.epoch')} (${estimate} ${parseSimpleDateNoSecond(
lockInfo.estimatedUnlockTime,
)})`,
})
@@ -252,12 +254,13 @@ const getAddressInfo = ({ liveCellsCount, minedBlocksCount, type, addressHash, l
const AddressLockScript: FC<{ address: State.Address }> = ({ address }) => {
const [showLock, setShowLock] = useState (false)
+ const { t } = useTranslation()
return (
-
+
setShowLock(!showLock)}>
- {i18n.t('address.lock_script')}
+ {t('address.lock_script')}
{showLock && address.lockScript && }
@@ -268,6 +271,7 @@ const AddressLockScript: FC<{ address: State.Address }> = ({ address }) => {
export const AddressOverview: FC<{ address: State.Address }> = ({ address }) => {
const isLG = useIsLGScreen()
+ const { t } = useTranslation()
const { udtAccounts = [] } = address
const { data: initList } = useQuery>(
@@ -289,10 +293,10 @@ export const AddressOverview: FC<{ address: State.Address }> = ({ address }) =>
)
return (
- }>
+ }>
{udtAccounts.length || cotaList?.length ? (
- {i18n.t('address.user_defined_token')}
+ {t('address.user_defined_token')}
{udtAccounts.map(udt => (
@@ -335,6 +339,7 @@ export const AddressTransactions = ({
timeOrderBy: State.SortOrderTypes
}) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const { currentPage, pageSize, setPage } = usePaginationParamsInListPage()
const searchParams = useSearchParams('layout')
const defaultLayout = 'professional'
@@ -374,7 +379,7 @@ export const AddressTransactions = ({
return (
<>
onChangeLayout(value)}
value={layout}
@@ -405,11 +410,11 @@ export const AddressTransactions = ({
<>
{!isMobile && (
- {i18n.t('transaction.transaction_hash')}
- {i18n.t('transaction.height')}
- {i18n.t('transaction.time')}
- {`${i18n.t('transaction.input')} & ${i18n.t('transaction.output')}`}
- {i18n.t('transaction.capacity_change')}
+ {t('transaction.transaction_hash')}
+ {t('transaction.height')}
+ {t('transaction.time')}
+ {`${t('transaction.input')} & ${t('transaction.output')}`}
+ {t('transaction.capacity_change')}
)}
{txList.map((transaction: State.Transaction) => (
diff --git a/src/pages/Address/index.tsx b/src/pages/Address/index.tsx
index b2a91539a..6b7953907 100644
--- a/src/pages/Address/index.tsx
+++ b/src/pages/Address/index.tsx
@@ -1,8 +1,8 @@
import { useParams } from 'react-router-dom'
import { useQuery } from 'react-query'
+import { useTranslation } from 'react-i18next'
import AddressHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
-import i18n from '../../utils/i18n'
import { AddressContentPanel } from './styled'
import { AddressTransactions, AddressOverview } from './AddressComp'
import { explorerService } from '../../services/ExplorerService'
@@ -12,6 +12,7 @@ import { isAxiosError } from '../../utils/error'
export const Address = () => {
const { address } = useParams<{ address: string }>()
+ const { t } = useTranslation()
const { currentPage, pageSize } = usePaginationParamsInListPage()
// REFACTOR: avoid using useSortParam
@@ -57,7 +58,7 @@ export const Address = () => {
{
+ const { t } = useTranslation()
if (!miner) {
- return {i18n.t('address.unable_decode_address')}
+ return {t('address.unable_decode_address')}
}
return (
@@ -104,30 +104,31 @@ const BlockMinerReward = ({
export const BlockOverview: FC<{ block: State.Block }> = ({ block }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const tipBlockNumber = useLatestBlockNumber()
const [showAllOverview, setShowAllOverview] = useState(false)
const minerReward =
const rootInfoItems = [
{
- title: i18n.t('block.transactions_root'),
- tooltip: i18n.t('glossary.transactions_root'),
+ title: t('block.transactions_root'),
+ tooltip: t('glossary.transactions_root'),
content: `${block.transactionsRoot}`,
},
]
const sentBlockNumber = `${Number(block.number) + DELAY_BLOCK_NUMBER}`
let overviewItems: OverviewItemData[] = [
{
- title: i18n.t('block.block_height'),
- tooltip: i18n.t('glossary.block_height'),
+ title: t('block.block_height'),
+ tooltip: t('glossary.block_height'),
content: (
-
+
{localeNumberString(block.number)}
-
+
= ({ block }) => {
),
},
{
- title: i18n.t('block.miner'),
- tooltip: i18n.t('glossary.miner'),
+ title: t('block.miner'),
+ tooltip: t('glossary.miner'),
contentWrapperClass: styles.addressWidthModify,
content: ,
},
{
- title: i18n.t('transaction.transactions'),
- tooltip: i18n.t('glossary.transactions'),
+ title: t('transaction.transactions'),
+ tooltip: t('glossary.transactions'),
content: localeNumberString(block.transactionsCount),
},
{
- title: i18n.t('block.miner_message'),
- tooltip: i18n.t('glossary.miner_message'),
+ title: t('block.miner_message'),
+ tooltip: t('glossary.miner_message'),
contentWrapperClass: styles.addressWidthModify,
- content: ,
+ content: ,
},
{
- title: i18n.t('block.size'),
- tooltip: i18n.t('glossary.size'),
+ title: t('block.size'),
+ tooltip: t('glossary.size'),
content: block.size ? (
= ({ block }) => {
numerator={block.size}
maxInEpoch={block.largestBlockInEpoch}
maxInChain={block.largestBlock}
- titleInEpoch={i18n.t('block.compared_to_the_max_size_in_epoch')}
- titleInChain={i18n.t('block.compared_to_the_max_size_in_chain')}
+ titleInEpoch={t('block.compared_to_the_max_size_in_epoch')}
+ titleInChain={t('block.compared_to_the_max_size_in_chain')}
unit="Bytes"
/>
@@ -182,8 +183,8 @@ export const BlockOverview: FC<{ block: State.Block }> = ({ block }) => {
},
null,
{
- title: i18n.t('block.cycles'),
- tooltip: i18n.t('glossary.cycles'),
+ title: t('block.cycles'),
+ tooltip: t('glossary.cycles'),
content: block.cycles ? (
= ({ block }) => {
numerator={block.cycles}
maxInEpoch={block.maxCyclesInEpoch}
maxInChain={block.maxCycles}
- titleInEpoch={i18n.t('block.compared_to_the_max_cycles_in_epoch')}
- titleInChain={i18n.t('block.compared_to_the_max_cycles_in_chain')}
+ titleInEpoch={t('block.compared_to_the_max_cycles_in_epoch')}
+ titleInChain={t('block.compared_to_the_max_cycles_in_chain')}
/>
) : (
@@ -206,29 +207,29 @@ export const BlockOverview: FC<{ block: State.Block }> = ({ block }) => {
},
null,
{
- title: i18n.t('block.proposal_transactions'),
- tooltip: i18n.t('glossary.proposal_transactions'),
+ title: t('block.proposal_transactions'),
+ tooltip: t('glossary.proposal_transactions'),
content: block.proposalsCount ? localeNumberString(block.proposalsCount) : 0,
},
{
- title: i18n.t('block.epoch'),
- tooltip: i18n.t('glossary.epoch'),
+ title: t('block.epoch'),
+ tooltip: t('glossary.epoch'),
content: localeNumberString(block.epoch),
},
{
- title: i18n.t('block.miner_reward'),
- tooltip: i18n.t('glossary.miner_reward'),
+ title: t('block.miner_reward'),
+ tooltip: t('glossary.miner_reward'),
content: (
),
},
{
- title: i18n.t('block.epoch_start_number'),
- tooltip: i18n.t('glossary.epoch_start_number'),
+ title: t('block.epoch_start_number'),
+ tooltip: t('glossary.epoch_start_number'),
content: (
{localeNumberString(block.startNumber)}
@@ -236,27 +237,27 @@ export const BlockOverview: FC<{ block: State.Block }> = ({ block }) => {
),
},
{
- title: i18n.t('block.difficulty'),
- tooltip: i18n.t('glossary.difficulty'),
+ title: t('block.difficulty'),
+ tooltip: t('glossary.difficulty'),
content: handleDifficulty(block.difficulty),
},
{
- title: i18n.t('block.block_index'),
- tooltip: i18n.t('glossary.block_index'),
+ title: t('block.block_index'),
+ tooltip: t('glossary.block_index'),
content: `${Number(block.blockIndexInEpoch) + 1}/${block.length}`,
},
{
- title: i18n.t('block.nonce'),
- tooltip: i18n.t('glossary.nonce'),
+ title: t('block.nonce'),
+ tooltip: t('glossary.nonce'),
content: <>{`0x${new BigNumber(block.nonce).toString(16)}`}>,
},
{
- title: i18n.t('block.timestamp'),
- tooltip: i18n.t('glossary.timestamp'),
+ title: t('block.timestamp'),
+ tooltip: t('glossary.timestamp'),
content: `${parseSimpleDate(block.timestamp)}`,
},
{
- title: i18n.t('block.uncle_count'),
+ title: t('block.uncle_count'),
tooltip: (
{
+ const { t } = useTranslation()
const totalPages = Math.ceil(total / pageSize)
const { push } = useHistory()
const { hash } = useLocation()
@@ -333,7 +335,7 @@ export const BlockComp = ({
return (
<>
{
push(`/block/${blockId}?${new URLSearchParams({ filter })}`)
}}
diff --git a/src/pages/BlockDetail/index.tsx b/src/pages/BlockDetail/index.tsx
index e60af85d6..1e681e8eb 100644
--- a/src/pages/BlockDetail/index.tsx
+++ b/src/pages/BlockDetail/index.tsx
@@ -1,8 +1,8 @@
import { useParams, useLocation } from 'react-router-dom'
import { useQuery } from 'react-query'
+import { useTranslation } from 'react-i18next'
import BlockHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
-import i18n from '../../utils/i18n'
import { BlockDetailPanel } from './styled'
import { BlockComp, BlockOverview } from './BlockComp'
import { usePaginationParamsInPage } from '../../utils/hook'
@@ -12,6 +12,7 @@ import { QueryResult } from '../../components/QueryResult'
import { defaultBlockInfo } from './state'
export default () => {
+ const { t } = useTranslation()
const { search } = useLocation()
const { param: blockHeightOrHash } = useParams<{ param: string }>()
const { currentPage, pageSize: pageSizeParam, setPage } = usePaginationParamsInPage()
@@ -59,7 +60,7 @@ export default () => {
return (
-
+
diff --git a/src/pages/BlockList/index.tsx b/src/pages/BlockList/index.tsx
index a4344b5f2..f6bfe5246 100644
--- a/src/pages/BlockList/index.tsx
+++ b/src/pages/BlockList/index.tsx
@@ -10,7 +10,6 @@ import { TableTitleRow, TableContentRow, TableTitleRowItem } from '../../compone
import { deprecatedAddrToNewAddr, shannonToCkb } from '../../utils/util'
import { DELAY_BLOCK_NUMBER } from '../../constants/common'
import { localeNumberString } from '../../utils/number'
-import i18n from '../../utils/i18n'
import DecimalCapacity from '../../components/DecimalCapacity'
import { ItemCardData, ItemCardGroup } from '../../components/Card/ItemCard'
import AddressText from '../../components/AddressText'
@@ -84,17 +83,18 @@ const getTableContentDataList = (block: State.Block, index: number, page: number
}
const BlockCardGroup: FC<{ blocks: State.Block[]; isFirstPage: boolean }> = ({ blocks, isFirstPage }) => {
+ const { t } = useTranslation()
const items: ItemCardData[] = [
{
- title: i18n.t('home.height'),
+ title: t('home.height'),
render: block => ,
},
{
- title: i18n.t('home.transactions'),
+ title: t('home.transactions'),
render: block => localeNumberString(block.transactionsCount),
},
{
- title: i18n.t('home.block_reward'),
+ title: t('home.block_reward'),
render: (block, index) =>
index < DELAY_BLOCK_NUMBER && isFirstPage ? (
@@ -107,7 +107,7 @@ const BlockCardGroup: FC<{ blocks: State.Block[]; isFirstPage: boolean }> = ({ b
),
},
{
- title: i18n.t('block.miner'),
+ title: t('block.miner'),
render: block => (
= ({ b
),
},
{
- title: i18n.t('home.time'),
+ title: t('home.time'),
render: block => parseSimpleDate(block.timestamp),
},
]
diff --git a/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx b/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx
index 4170a8df6..dc501e10d 100644
--- a/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx
+++ b/src/pages/FeeRateTracker/FeeRateTrackerComp.tsx
@@ -2,13 +2,14 @@ import BigNumber from 'bignumber.js'
import { useMemo } from 'react'
import dayjs from 'dayjs'
import classNames from 'classnames'
+import { useTranslation } from 'react-i18next'
import styles from './styles.module.scss'
-import i18n from '../../utils/i18n'
import { ReactChartCore } from '../StatisticsChart/common'
import { ReactComponent as BikeIcon } from '../../assets/bike.svg'
import { ReactComponent as CarIcon } from '../../assets/car.svg'
import { ReactComponent as RocketIcon } from '../../assets/rocket.svg'
import { ChartColor } from '../../constants/common'
+import { useCurrentLanguage } from '../../utils/i18n'
const textStyleInChart: echarts.EChartOption.TextStyle = {
color: '#999999',
@@ -41,6 +42,7 @@ const calcFeeRate = (tfrs: FeeRateTracker.TransactionFeeRate[]): string =>
const colors = ChartColor.moreColors
export const FeeRateCards = ({ transactionFeeRates }: { transactionFeeRates: FeeRateTracker.TransactionFeeRate[] }) => {
+ const { t } = useTranslation()
const allFrs = transactionFeeRates.sort((a, b) => a.confirmationTime - b.confirmationTime)
const avgConfirmationTime = getWeightedMedian(allFrs)
@@ -52,21 +54,21 @@ export const FeeRateCards = ({ transactionFeeRates }: { transactionFeeRates: Fee
const feeRateCards: FeeRateTracker.FeeRateCard[] = [
{
- priority: i18n.t('fee_rate_tracker.low'),
+ priority: t('fee_rate_tracker.low'),
icon: ,
feeRate: calcFeeRate(lowFrs),
priorityClass: styles.low,
confirmationTime: lowConfirmationTime,
},
{
- priority: i18n.t('fee_rate_tracker.average'),
+ priority: t('fee_rate_tracker.average'),
icon: ,
feeRate: calcFeeRate(allFrs),
priorityClass: styles.average,
confirmationTime: avgConfirmationTime,
},
{
- priority: i18n.t('fee_rate_tracker.high'),
+ priority: t('fee_rate_tracker.high'),
icon: ,
feeRate: calcFeeRate(highFrs),
priorityClass: styles.high,
@@ -83,10 +85,10 @@ export const FeeRateCards = ({ transactionFeeRates }: { transactionFeeRates: Fee
{`${feeRate} shannons/kB`}
{confirmationTime >= 60
- ? `${Math.floor(confirmationTime / 60)} ${i18n.t('fee_rate_tracker.mins')}${
- confirmationTime % 60 === 0 ? '' : ` ${confirmationTime % 60} ${i18n.t('fee_rate_tracker.secs')}`
+ ? `${Math.floor(confirmationTime / 60)} ${t('fee_rate_tracker.mins')}${
+ confirmationTime % 60 === 0 ? '' : ` ${confirmationTime % 60} ${t('fee_rate_tracker.secs')}`
}`
- : `${confirmationTime} ${i18n.t('fee_rate_tracker.secs')}`}
+ : `${confirmationTime} ${t('fee_rate_tracker.secs')}`}
))}
@@ -99,6 +101,7 @@ export const ConfirmationTimeFeeRateChart = ({
}: {
transactionFeeRates: FeeRateTracker.TransactionFeeRate[]
}) => {
+ const { t } = useTranslation()
const data = transactionFeeRates.reduce>>((acc, cur) => {
if (!cur.confirmationTime) {
return acc
@@ -123,16 +126,14 @@ export const ConfirmationTimeFeeRateChart = ({
formatter(params) {
const feeRate: echarts.EChartOption.Tooltip.Format = Array.isArray(params) ? params[0] : params
const count: echarts.EChartOption.Tooltip.Format = Array.isArray(params) ? params[1] : params
- return `${i18n.t('fee_rate_tracker.fee_rate')}: ${feeRate.value?.toLocaleString(
- 'en',
- )} shannons/kB ${i18n.t('fee_rate_tracker.confirmation_time')}: ${feeRate.name} ${i18n.t(
- 'fee_rate_tracker.count',
- )}: ${count.value}`
+ return `${t('fee_rate_tracker.fee_rate')}: ${feeRate.value?.toLocaleString('en')} shannons/kB ${t(
+ 'fee_rate_tracker.confirmation_time',
+ )}: ${feeRate.name} ${t('fee_rate_tracker.count')}: ${count.value}`
},
},
xAxis: {
type: 'category',
- name: `${i18n.t('fee_rate_tracker.confirmation_time')} (${i18n.t('fee_rate_tracker.seconds')})`,
+ name: `${t('fee_rate_tracker.confirmation_time')} (${t('fee_rate_tracker.seconds')})`,
nameGap: 32,
nameLocation: 'middle',
nameTextStyle: textStyleInChart,
@@ -166,7 +167,7 @@ export const ConfirmationTimeFeeRateChart = ({
color: '#e5e5e5',
},
},
- name: `${i18n.t('fee_rate_tracker.fee_rate')}(shannons/kB)`,
+ name: `${t('fee_rate_tracker.fee_rate')}(shannons/kB)`,
},
{
position: 'right',
@@ -189,7 +190,7 @@ export const ConfirmationTimeFeeRateChart = ({
splitLine: {
show: false,
},
- name: `${i18n.t('fee_rate_tracker.count')}`,
+ name: `${t('fee_rate_tracker.count')}`,
},
],
series: [
@@ -227,6 +228,7 @@ export const FeeRateTransactionCountChartCore = ({
}: {
pendingTransactionFeeRates: FeeRateTracker.PendingTransactionFeeRate[]
}) => {
+ const { t } = useTranslation()
const feeRateCount = pendingTransactionFeeRates.reduce((acc, cur) => {
const count = acc.get(cur.feeRate) ?? 0
acc.set(cur.feeRate, count + 1)
@@ -246,12 +248,12 @@ export const FeeRateTransactionCountChartCore = ({
backgroundColor: 'rgba(0, 0, 0, 0.8)',
formatter(params) {
const param: echarts.EChartOption.Tooltip.Format = Array.isArray(params) ? params[0] : params
- return `${param.name} shannons/kB ${i18n.t('fee_rate_tracker.transaction_count')}: ${param.value}`
+ return `${param.name} shannons/kB ${t('fee_rate_tracker.transaction_count')}: ${param.value}`
},
},
xAxis: {
type: 'category',
- name: `${i18n.t('fee_rate_tracker.fee_rate')} (shannons/kB)`,
+ name: `${t('fee_rate_tracker.fee_rate')} (shannons/kB)`,
nameGap: 32,
nameLocation: 'middle',
nameTextStyle: textStyleInChart,
@@ -278,7 +280,7 @@ export const FeeRateTransactionCountChartCore = ({
color: '#e5e5e5',
},
},
- name: i18n.t('fee_rate_tracker.transaction_count'),
+ name: t('fee_rate_tracker.transaction_count'),
},
series: [
{
@@ -306,10 +308,11 @@ export const FeeRateTransactionCountChart = ({
}: {
pendingTransactionFeeRates: FeeRateTracker.PendingTransactionFeeRate[]
}) => {
+ const currentLanguage = useCurrentLanguage()
return useMemo(() => {
return
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [pendingTransactionFeeRates, i18n.language])
+ }, [pendingTransactionFeeRates, currentLanguage])
}
export const LastNDaysTransactionFeeRateChart = ({
@@ -317,6 +320,7 @@ export const LastNDaysTransactionFeeRateChart = ({
}: {
lastNDaysTransactionFeeRates: FeeRateTracker.LastNDaysTransactionFeeRate[]
}) => {
+ const { t } = useTranslation()
const sortedLastNDaysTransactionFeeRates = lastNDaysTransactionFeeRates
.filter(r => dayjs(r.date).isValid())
.sort((a, b) => (dayjs(a.date).isBefore(dayjs(b.date)) ? -1 : 1))
@@ -333,14 +337,14 @@ export const LastNDaysTransactionFeeRateChart = ({
formatter(params) {
const param: echarts.EChartOption.Tooltip.Format = Array.isArray(params) ? params[0] : params
const feeRate = sortedLastNDaysTransactionFeeRates.find(r => dayjs(r.date).format('MM/DD') === param.name)
- return `${i18n.t('fee_rate_tracker.date')}: ${
- feeRate ? dayjs(feeRate.date).format('YYYY/MM/DD') : ''
- } ${i18n.t('fee_rate_tracker.average_fee_rate')}: ${param.value?.toLocaleString('en')} shannons/kB`
+ return `${t('fee_rate_tracker.date')}: ${feeRate ? dayjs(feeRate.date).format('YYYY/MM/DD') : ''} ${t(
+ 'fee_rate_tracker.average_fee_rate',
+ )}: ${param.value?.toLocaleString('en')} shannons/kB`
},
},
xAxis: {
type: 'category',
- name: `${i18n.t('fee_rate_tracker.date')}`,
+ name: `${t('fee_rate_tracker.date')}`,
nameGap: 32,
nameLocation: 'middle',
nameTextStyle: textStyleInChart,
@@ -373,7 +377,7 @@ export const LastNDaysTransactionFeeRateChart = ({
color: '#e5e5e5',
},
},
- name: `${i18n.t('fee_rate_tracker.fee_rate')}(shannons/kB)`,
+ name: `${t('fee_rate_tracker.fee_rate')}(shannons/kB)`,
},
series: [
{
diff --git a/src/pages/FeeRateTracker/index.tsx b/src/pages/FeeRateTracker/index.tsx
index 1564a3492..1f36ba05e 100644
--- a/src/pages/FeeRateTracker/index.tsx
+++ b/src/pages/FeeRateTracker/index.tsx
@@ -1,5 +1,6 @@
import { useRef, useState } from 'react'
import { useQuery } from 'react-query'
+import { useTranslation } from 'react-i18next'
import styles from './styles.module.scss'
import Content from '../../components/Content'
import { toCamelcase } from '../../utils/util'
@@ -11,12 +12,12 @@ import {
LastNDaysTransactionFeeRateChart,
} from './FeeRateTrackerComp'
import Loading from '../../components/Loading'
-import i18n from '../../utils/i18n'
import { localeNumberString } from '../../utils/number'
import { getFeeRateSamples } from '../../utils/chart'
import { explorerService, useStatistics } from '../../services/ExplorerService'
const FeeRateTracker = () => {
+ const { t } = useTranslation()
const lastFetchedTime = useRef(Number.MAX_SAFE_INTEGER)
const deltaSecond = useRef(0)
const [secondAfterUpdate, setSecondAfterUpdate] = useState(0)
@@ -55,11 +56,11 @@ const FeeRateTracker = () => {
return (
- {i18n.t('fee_rate_tracker.title')}
+ {t('fee_rate_tracker.title')}
- {i18n.t('fee_rate_tracker.updated_time', {
+ {t('fee_rate_tracker.updated_time', {
second: secondAfterUpdate,
})}
@@ -78,7 +79,7 @@ const FeeRateTracker = () => {
- {`${i18n.t('fee_rate_tracker.confirmation_time_x_avg_fee_rate')}${isMobile ? '\n' : ' '}(${i18n.t(
+ {`${t('fee_rate_tracker.confirmation_time_x_avg_fee_rate')}${isMobile ? '\n' : ' '}(${t(
'fee_rate_tracker.last_n_transactions',
{
c: localeNumberString(10000),
@@ -94,7 +95,7 @@ const FeeRateTracker = () => {
- {i18n.t('fee_rate_tracker.fee_rate_of_pending_transactions')}
+ {t('fee_rate_tracker.fee_rate_of_pending_transactions')}
{transactionFeesStatistic?.pendingTransactionFeeRates ? (
{
- {i18n.t('fee_rate_tracker.n_days_historical_fee_rate', { n: 7 })}
+ {t('fee_rate_tracker.n_days_historical_fee_rate', { n: 7 })}
{transactionFeesStatistic?.lastNDaysTransactionFeeRates ? (
{
+ const { t } = useTranslation()
const { estimatedDate } = useHalving()
const [days, hours, minutes, seconds] = useCountdown(estimatedDate)
@@ -12,28 +13,28 @@ export const HalvingCountdown = () => {
{days}
- {i18n.t('common.days')}
+ {t('common.days')}
{hours.toString().padStart(2, '0')}
- {i18n.t('common.hours')}
+ {t('common.hours')}
{minutes.toString().padStart(2, '0')}
- {i18n.t('common.minutes')}
+ {t('common.minutes')}
{seconds.toString().padStart(2, '0')}
- {i18n.t('common.seconds')}
+ {t('common.seconds')}
)
diff --git a/src/pages/Halving/HalvingInfo.tsx b/src/pages/Halving/HalvingInfo.tsx
index f6677def1..92182a065 100644
--- a/src/pages/Halving/HalvingInfo.tsx
+++ b/src/pages/Halving/HalvingInfo.tsx
@@ -2,8 +2,8 @@ import { Tooltip } from 'antd'
import BigNumber from 'bignumber.js'
import classnames from 'classnames'
import dayjs from 'dayjs'
+import { useTranslation } from 'react-i18next'
import { ReactComponent as WarningCircle } from '../../assets/warning_circle.svg'
-import i18n from '../../utils/i18n'
import { useHalving, useIsMobile } from '../../utils/hook'
import { useStatistics } from '../../services/ExplorerService'
import styles from './index.module.scss'
@@ -11,6 +11,7 @@ import styles from './index.module.scss'
export const HalvingInfo = () => {
const statistics = useStatistics()
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const { currentEpoch, targetEpoch, estimatedDate } = useHalving()
const utcOffset = dayjs().utcOffset() / 60
@@ -20,7 +21,7 @@ export const HalvingInfo = () => {
{new BigNumber(statistics.tipBlockNumber).toFormat()}
- {i18n.t('halving.current_block')}
+ {t('halving.current_block')}
@@ -30,14 +31,14 @@ export const HalvingInfo = () => {
{statistics.epochInfo.index} / {statistics.epochInfo.epochLength}
- {i18n.t('halving.current_epoch')}
+ {t('halving.current_epoch')}
{new BigNumber(targetEpoch).toFormat()}
- {i18n.t('halving.target_epoch')}
+ {t('halving.target_epoch')}
@@ -57,9 +58,7 @@ export const HalvingInfo = () => {
-
- {i18n.t('halving.estimated_time')}
-
+ {t('halving.estimated_time')}
>
@@ -70,7 +69,7 @@ export const HalvingInfo = () => {
{new BigNumber(statistics.tipBlockNumber).toFormat()}
- {i18n.t('halving.current_block')}
+ {t('halving.current_block')}
@@ -80,13 +79,13 @@ export const HalvingInfo = () => {
{statistics.epochInfo.index} / {statistics.epochInfo.epochLength}
- {i18n.t('halving.current_epoch')}
+ {t('halving.current_epoch')}
{new BigNumber(targetEpoch).toFormat()}
- {i18n.t('halving.target_epoch')}
+ {t('halving.target_epoch')}
@@ -101,7 +100,7 @@ export const HalvingInfo = () => {
- {i18n.t('halving.estimated_time')}
+ {t('halving.estimated_time')}
)
diff --git a/src/pages/Halving/HalvingTable.tsx b/src/pages/Halving/HalvingTable.tsx
index f50d04c0a..ffc3ea769 100644
--- a/src/pages/Halving/HalvingTable.tsx
+++ b/src/pages/Halving/HalvingTable.tsx
@@ -1,171 +1,174 @@
-import i18n from '../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import styles from './index.module.scss'
-export const HalvingTable = () => (
-
-
- {i18n.t('halving.table_event')} |
- {i18n.t('halving.table_date')} |
- {i18n.t('halving.table_epoch_number')} |
- {i18n.t('halving.table_epoch_reward')} |
- {i18n.t('halving.table_block_reward')} |
- {i18n.t('halving.table_daily_reward')} |
- {i18n.t('halving.table_total')} |
-
-
-
- {i18n.t('halving.table_launches')} |
- 16 Nov 2019 |
- 0 ({i18n.t('halving.genesis_epoch')}) |
- 1,917,808 CKB |
- 1,065 CKB |
- 11,506,849 CKB |
- 16,800,000,000 CKB |
-
-
-
-
- {i18n.t('ordinal.first')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
-
- |
-
- {i18n.t('halving.expected')} 19 Nov 2023
- |
-
- 8,760
- |
-
- 958,904 CKB
- |
-
- 533 CKB
- |
-
- 5,753,424 CKB
- |
-
- 8,400,000,000 CKB
- |
-
-
-
- {i18n.t('ordinal.second')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2027 |
- 17,520 |
- 479,452 CKB |
- 266 CKB |
- 2,876,712 CKB |
- 4,200,000,000 CKB |
-
-
-
- {i18n.t('ordinal.3rd')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2031 |
- 26,280 |
- 239,726 CKB |
- 133 CKB |
- 1,438,356 CKB |
- 2,100,000,000 CKB |
-
-
-
- {i18n.t('ordinal.4th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2035 |
- 35,040 |
- 119,863 CKB |
- 67 CKB |
- 719,178 CKB |
- 1,050,000,000 CKB |
-
-
-
- {i18n.t('ordinal.5th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2039 |
- 43,800 |
- 59,932 CKB |
- 33.5 CKB |
- 359,589 CKB |
- 525,000,000 CKB |
-
-
-
- {i18n.t('ordinal.6th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2043 |
- 52,560 |
- 29,966 CKB |
- 16.75 CKB |
- 179,794.5 CKB |
- 262,500,000 CKB |
-
-
-
- {i18n.t('ordinal.7th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2047 |
- 61,320 |
- 14,983 CKB |
- 8.375 CKB |
- 89,897.25 CKB |
- 131,250,000 CKB |
-
-
-
- {i18n.t('ordinal.8th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2051 |
- 70,080 |
- 7,491 CKB |
- 4.1875 CKB |
- 44,948.625 CKB |
- 65,625,000 CKB |
-
-
-
- {i18n.t('ordinal.9th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2055 |
- 78,840 |
- 3,746 CKB |
- 2.09375 CKB |
- 22,474.3125 CKB |
- 32,812,500 CKB |
-
-
-
- {i18n.t('ordinal.10th')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- |
- {i18n.t('halving.expected')} November 2059 |
- 87,600 |
- 1,873 CKB |
- 1.046875 CKB |
- 11,237.15625 CKB |
- 16,406,250 CKB |
-
-
-
-)
+export const HalvingTable = () => {
+ const { t } = useTranslation()
+ return (
+
+
+ {t('halving.table_event')} |
+ {t('halving.table_date')} |
+ {t('halving.table_epoch_number')} |
+ {t('halving.table_epoch_reward')} |
+ {t('halving.table_block_reward')} |
+ {t('halving.table_daily_reward')} |
+ {t('halving.table_total')} |
+
+
+
+ {t('halving.table_launches')} |
+ 16 Nov 2019 |
+ 0 ({t('halving.genesis_epoch')}) |
+ 1,917,808 CKB |
+ 1,065 CKB |
+ 11,506,849 CKB |
+ 16,800,000,000 CKB |
+
+
+
+
+ {t('ordinal.first')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+
+ |
+
+ {t('halving.expected')} 19 Nov 2023
+ |
+
+ 8,760
+ |
+
+ 958,904 CKB
+ |
+
+ 533 CKB
+ |
+
+ 5,753,424 CKB
+ |
+
+ 8,400,000,000 CKB
+ |
+
+
+
+ {t('ordinal.second')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2027 |
+ 17,520 |
+ 479,452 CKB |
+ 266 CKB |
+ 2,876,712 CKB |
+ 4,200,000,000 CKB |
+
+
+
+ {t('ordinal.3rd')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2031 |
+ 26,280 |
+ 239,726 CKB |
+ 133 CKB |
+ 1,438,356 CKB |
+ 2,100,000,000 CKB |
+
+
+
+ {t('ordinal.4th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2035 |
+ 35,040 |
+ 119,863 CKB |
+ 67 CKB |
+ 719,178 CKB |
+ 1,050,000,000 CKB |
+
+
+
+ {t('ordinal.5th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2039 |
+ 43,800 |
+ 59,932 CKB |
+ 33.5 CKB |
+ 359,589 CKB |
+ 525,000,000 CKB |
+
+
+
+ {t('ordinal.6th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2043 |
+ 52,560 |
+ 29,966 CKB |
+ 16.75 CKB |
+ 179,794.5 CKB |
+ 262,500,000 CKB |
+
+
+
+ {t('ordinal.7th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2047 |
+ 61,320 |
+ 14,983 CKB |
+ 8.375 CKB |
+ 89,897.25 CKB |
+ 131,250,000 CKB |
+
+
+
+ {t('ordinal.8th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2051 |
+ 70,080 |
+ 7,491 CKB |
+ 4.1875 CKB |
+ 44,948.625 CKB |
+ 65,625,000 CKB |
+
+
+
+ {t('ordinal.9th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2055 |
+ 78,840 |
+ 3,746 CKB |
+ 2.09375 CKB |
+ 22,474.3125 CKB |
+ 32,812,500 CKB |
+
+
+
+ {t('ordinal.10th')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ |
+ {t('halving.expected')} November 2059 |
+ 87,600 |
+ 1,873 CKB |
+ 1.046875 CKB |
+ 11,237.15625 CKB |
+ 16,406,250 CKB |
+
+
+
+ )
+}
diff --git a/src/pages/Halving/index.tsx b/src/pages/Halving/index.tsx
index cf9d8646c..7cad229a4 100644
--- a/src/pages/Halving/index.tsx
+++ b/src/pages/Halving/index.tsx
@@ -1,6 +1,7 @@
import { Progress, Tooltip, Popover, Table } from 'antd'
import BigNumber from 'bignumber.js'
import classnames from 'classnames'
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import baseIssuance from '../../assets/ckb_base_issuance_trend.png'
import blockRewards from '../../assets/block-rewards.png'
@@ -10,7 +11,6 @@ import halvingSuccessBg from '../../assets/halving_success_bg.png'
import { ReactComponent as CalendarIcon } from '../../assets/calendar.svg'
import { ReactComponent as XIcon } from '../../assets/X.svg'
import { ReactComponent as WarningCircle } from '../../assets/warning_circle.svg'
-import i18n, { currentLanguage } from '../../utils/i18n'
import { HalvingTable } from './HalvingTable'
import { HalvingInfo } from './HalvingInfo'
import SmallLoading from '../../components/Loading/SmallLoading'
@@ -19,6 +19,7 @@ import { HalvingCountdown } from './HalvingCountdown'
import { useCountdown, useHalving, useIsMobile } from '../../utils/hook'
import { getPrimaryColor, EPOCHS_PER_HALVING, THEORETICAL_EPOCH_TIME } from '../../constants/common'
import styles from './index.module.scss'
+import { useCurrentLanguage } from '../../utils/i18n'
function numberToOrdinal(number: number) {
switch (number) {
@@ -43,6 +44,7 @@ function numberToOrdinal(number: number) {
}
export const HalvingCountdownPage = () => {
+ const { t } = useTranslation()
const isMobile = useIsMobile()
const statistics = useStatistics()
const { currentEpoch, estimatedDate, currentEpochUsedTime, halvingCount, inCelebration, skipCelebration, isLoading } =
@@ -56,19 +58,19 @@ export const HalvingCountdownPage = () => {
const shortCountdown = () => {
if (days > 0) {
- return `${days}${i18n.t('symbol.char_space')}${i18n.t('unit.days')}`
+ return `${days}${t('symbol.char_space')}${t('unit.days')}`
}
if (hours > 0) {
- return `${hours}${i18n.t('symbol.char_space')}${i18n.t('unit.hours')}`
+ return `${hours}${t('symbol.char_space')}${t('unit.hours')}`
}
if (minutes > 0) {
- return `${minutes}${i18n.t('symbol.char_space')}${i18n.t('unit.minutes')}`
+ return `${minutes}${t('symbol.char_space')}${t('unit.minutes')}`
}
- return `${seconds}${i18n.t('symbol.char_space')}${i18n.t('unit.seconds')}`
+ return `${seconds}${t('symbol.char_space')}${t('unit.seconds')}`
}
- const shareText = i18n.t('halving.share_text', {
- times: i18n.t(`ordinal.${numberToOrdinal(halvingCount)}`),
+ const shareText = t('halving.share_text', {
+ times: t(`ordinal.${numberToOrdinal(halvingCount)}`),
date: estimatedDate.toUTCString(),
countdown: shortCountdown(),
})
@@ -100,15 +102,15 @@ export const HalvingCountdownPage = () => {
style={{ paddingTop: isMobile ? 64 : 128, paddingBottom: 128, backgroundImage: `url(${halvingSuccessBg})` }}
>
- {i18n.t('halving.congratulations')}!
+ {t('halving.congratulations')}!
- {i18n.t('halving.the')}
- {i18n.t('symbol.char_space')}
- {i18n.t(`ordinal.${numberToOrdinal(halvingCount)}`)}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.actived')}{' '}
+ {t('halving.the')}
+ {t('symbol.char_space')}
+ {t(`ordinal.${numberToOrdinal(halvingCount)}`)}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
+ {t('symbol.char_space')}
+ {t('halving.actived')}{' '}
{new BigNumber(getTargetBlockByHavingCount(halvingCount)).toFormat()}.
@@ -120,9 +122,9 @@ export const HalvingCountdownPage = () => {
type="button"
onClick={() => skipCelebration()}
>
- {i18n.t('halving.next')}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
+ {t('halving.next')}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
@@ -134,7 +136,7 @@ export const HalvingCountdownPage = () => {
return (
- {i18n.t('halving.comming_soon')}
+ {t('halving.comming_soon')}
@@ -145,9 +147,9 @@ export const HalvingCountdownPage = () => {
- {i18n.t(`ordinal.${numberToOrdinal(halvingCount)}`)}
- {i18n.t('symbol.char_space')}
- {i18n.t('halving.halving')}
+ {t(`ordinal.${numberToOrdinal(halvingCount)}`)}
+ {t('symbol.char_space')}
+ {t('halving.halving')}
{halvingCount > 1 && (
{
pagination={false}
dataSource={new Array(halvingCount - 1).fill({}).map((_, index) => ({
key: index,
- event: `${i18n.t(`ordinal.${numberToOrdinal(index + 1)}`)}
- ${i18n.t('symbol.char_space')}
- ${i18n.t('halving.halving')}`,
+ event: `${t(`ordinal.${numberToOrdinal(index + 1)}`)}
+ ${t('symbol.char_space')}
+ ${t('halving.halving')}`,
epoch: new BigNumber(EPOCHS_PER_HALVING * (index + 1)).toFormat(),
height: getTargetBlockByHavingCount(index + 1),
}))}
@@ -211,11 +213,11 @@ export const HalvingCountdownPage = () => {
overlayInnerStyle={{ color: '#333333' }}
title={
<>
- {i18n.t('halving.countdown_tooltip_section1')}
+ {t('halving.countdown_tooltip_section1')}
- {i18n.t('halving.countdown_tooltip_section2')}
+ {t('halving.countdown_tooltip_section2')}
- {i18n.t('halving.countdown_tooltip_section3')}
+ {t('halving.countdown_tooltip_section3')}
>
}
>
@@ -250,10 +252,10 @@ export const HalvingCountdownPage = () => {
- Nervos CKB Layer 1 {i18n.t('halving.halving_countdown')}
+ Nervos CKB {t('halving.halving_countdown')}
- Nervos CKB Layer 1 {i18n.t('halving.halving_desc_prefix')}{' '}
- {i18n.t('halving.base_issuance_rewards')} {i18n.t('halving.halving_desc_suffix')}
+ Nervos CKB {t('halving.halving_desc_prefix')} {t('halving.base_issuance_rewards')}{' '}
+ {t('halving.halving_desc_suffix')}
{renderHalvingPanel()}
@@ -263,60 +265,60 @@ export const HalvingCountdownPage = () => {
- {i18n.t('halving.halving_event')}
- {i18n.t('halving.halving_event_section_1')}
- {i18n.t('halving.halving_event_section_2')}
+ {t('halving.halving_event')}
+ {t('halving.halving_event_section_1')}
+ {t('halving.halving_event_section_2')}
- {i18n.t('halving.significance')}
- {i18n.t('halving.significance_section_1')}
- {i18n.t('halving.significance_section_2')}
+ {t('halving.significance')}
+ {t('halving.significance_section_1')}
+ {t('halving.significance_section_2')}
- {i18n.t('halving.how_does_work')}
- {i18n.t('halving.how_does_work_section_1')}
+ {t('halving.how_does_work')}
+ {t('halving.how_does_work_section_1')}
- {i18n.t('halving.how_does_work_section_2')}
- {i18n.t('halving.how_does_work_section_3')}
+ {t('halving.how_does_work_section_2')}
+ {t('halving.how_does_work_section_3')}
- {i18n.t('halving.how_does_work_section_4')} 4 * 365 * (24 / 4) = 8760,{' '}
- {i18n.t('halving.how_does_work_section_5')}: the_Nth_halving_epoch = 8760 * N .
+ {t('halving.how_does_work_section_4')} 4 * 365 * (24 / 4) = 8760,{' '}
+ {t('halving.how_does_work_section_5')}: the_Nth_halving_epoch = 8760 * N .
- {i18n.t('halving.how_does_work_section_6')}
+ {t('halving.how_does_work_section_6')}
- {i18n.t('halving.when')}
+ {t('halving.when')}
- {i18n.t('halving.when_section_1')}
+ {t('halving.when_section_1')}
- โ ๏ธ {i18n.t('halving.when_section_2')}
- {i18n.t('halving.when_section_3')}, {i18n.t('halving.and')}{' '}
- {i18n.t('halving.when_section_4')}:
+ โ ๏ธ {t('halving.when_section_2')}
+ {t('halving.when_section_3')}, {t('halving.and')}{' '}
+ {t('halving.when_section_4')}:
- {i18n.t('halving.when_section_5')}
- {i18n.t('halving.base_issuance_rewards')}
- {i18n.t('halving.when_section_6')}
+ {t('halving.when_section_5')}
+ {t('halving.base_issuance_rewards')}
+ {t('halving.when_section_6')}
-
+
diff --git a/src/pages/Home/AverageBlockTimeChart/index.tsx b/src/pages/Home/AverageBlockTimeChart/index.tsx
index a7a03039a..993ff8442 100644
--- a/src/pages/Home/AverageBlockTimeChart/index.tsx
+++ b/src/pages/Home/AverageBlockTimeChart/index.tsx
@@ -2,7 +2,7 @@ import { memo, useMemo } from 'react'
import 'echarts/lib/chart/line'
import 'echarts/lib/component/title'
import echarts from 'echarts/lib/echarts'
-import i18n from '../../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import { parseDateNoTime } from '../../../utils/date'
import { localeNumberString } from '../../../utils/number'
import SmallLoading from '../../../components/Loading/SmallLoading'
@@ -13,98 +13,104 @@ import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
import { ReactChartCore } from '../../StatisticsChart/common'
-const getOption = (
- statisticAverageBlockTimes: State.StatisticAverageBlockTime[],
- useMiniStyle: boolean,
-): echarts.EChartOption => ({
- color: ['#ffffff'],
- title: {
- text: i18n.t('statistic.average_block_time_title'),
- textAlign: 'left',
- textStyle: {
- color: '#ffffff',
- fontSize: 12,
- fontWeight: 'lighter',
- fontFamily: 'Lato',
- },
- },
- grid: {
- left: useMiniStyle ? '1%' : '2%',
- right: '3%',
- top: useMiniStyle ? '20%' : '15%',
- bottom: '2%',
- containLabel: true,
- },
- backgroundColor: '#00000000',
- xAxis: [
- {
- axisLine: {
- lineStyle: {
+const useOption = () => {
+ const { t } = useTranslation()
+ return (
+ statisticAverageBlockTimes: State.StatisticAverageBlockTime[],
+ useMiniStyle: boolean,
+ ): echarts.EChartOption => {
+ return {
+ color: ['#ffffff'],
+ title: {
+ text: t('statistic.average_block_time_title'),
+ textAlign: 'left',
+ textStyle: {
color: '#ffffff',
- width: 1,
+ fontSize: 12,
+ fontWeight: 'lighter',
+ fontFamily: 'Lato',
},
},
- data: statisticAverageBlockTimes.map(data => data.timestamp),
- axisLabel: {
- formatter: (value: string) => parseDateNoTime(value, true),
- },
- boundaryGap: false,
- },
- ],
- yAxis: [
- {
- position: 'left',
- type: 'value',
- scale: true,
- nameTextStyle: {
- align: 'left',
+ grid: {
+ left: useMiniStyle ? '1%' : '2%',
+ right: '3%',
+ top: useMiniStyle ? '20%' : '15%',
+ bottom: '2%',
+ containLabel: true,
},
- splitLine: {
- lineStyle: {
- color: '#ffffff',
- width: 0.5,
- opacity: 0.2,
+ backgroundColor: '#00000000',
+ xAxis: [
+ {
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ },
+ data: statisticAverageBlockTimes.map(data => data.timestamp),
+ axisLabel: {
+ formatter: (value: string) => parseDateNoTime(value, true),
+ },
+ boundaryGap: false,
},
- },
- axisLine: {
- lineStyle: {
- color: '#ffffff',
- width: 1,
+ ],
+ yAxis: [
+ {
+ position: 'left',
+ type: 'value',
+ scale: true,
+ nameTextStyle: {
+ align: 'left',
+ },
+ splitLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 0.5,
+ opacity: 0.2,
+ },
+ },
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ },
+ axisLabel: {
+ formatter: (value: string) => localeNumberString(value),
+ },
+ boundaryGap: false,
},
- },
- axisLabel: {
- formatter: (value: string) => localeNumberString(value),
- },
- boundaryGap: false,
- },
- {
- position: 'right',
- type: 'value',
- axisLine: {
- lineStyle: {
- color: '#ffffff',
- width: 1,
+ {
+ position: 'right',
+ type: 'value',
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ },
},
- },
- },
- ],
- series: [
- {
- name: i18n.t('statistic.daily_moving_average'),
- type: 'line',
- yAxisIndex: 0,
- lineStyle: {
- color: '#ffffff',
- width: 1,
- },
- symbol: 'none',
- data: statisticAverageBlockTimes.map(data => (Number(data.avgBlockTimeDaily) / 1000).toFixed(2)),
- },
- ],
-})
+ ],
+ series: [
+ {
+ name: t('statistic.daily_moving_average'),
+ type: 'line',
+ yAxisIndex: 0,
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ symbol: 'none',
+ data: statisticAverageBlockTimes.map(data => (Number(data.avgBlockTimeDaily) / 1000).toFixed(2)),
+ },
+ ],
+ }
+ }
+}
export default memo(() => {
const isLG = useIsLGScreen()
+ const parseOption = useOption()
const query = useChartQueryWithCache(
explorerService.api.fetchStatisticAverageBlockTimes,
@@ -132,7 +138,7 @@ export default memo(() => {
return (
({
- color: ['#ffffff'],
- title: {
- text: i18n.t('block.hash_rate_hps'),
- textAlign: 'left',
- textStyle: {
- color: '#ffffff',
- fontSize: 12,
- fontWeight: 'lighter',
- fontFamily: 'Lato',
- },
- },
- grid: {
- left: useMiniStyle ? '1%' : '2%',
- right: '3%',
- top: useMiniStyle ? '20%' : '15%',
- bottom: '2%',
- containLabel: true,
- },
- xAxis: [
- {
- axisLine: {
- lineStyle: {
+const useOption = () => {
+ const { t } = useTranslation()
+ return (statisticHashRates: State.StatisticHashRate[], useMiniStyle: boolean): echarts.EChartOption => {
+ return {
+ color: ['#ffffff'],
+ title: {
+ text: t('block.hash_rate_hps'),
+ textAlign: 'left',
+ textStyle: {
color: '#ffffff',
- width: 1,
+ fontSize: 12,
+ fontWeight: 'lighter',
+ fontFamily: 'Lato',
},
},
- data: statisticHashRates.map(data => data.createdAtUnixtimestamp),
- axisLabel: {
- formatter: (value: string) => parseDateNoTime(value, true),
+ grid: {
+ left: useMiniStyle ? '1%' : '2%',
+ right: '3%',
+ top: useMiniStyle ? '20%' : '15%',
+ bottom: '2%',
+ containLabel: true,
},
- boundaryGap: false,
- },
- ],
- yAxis: [
- {
- position: 'left',
- type: 'value',
- scale: true,
- axisLine: {
- lineStyle: {
- color: '#ffffff',
- width: 1,
+ xAxis: [
+ {
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ },
+ data: statisticHashRates.map(data => data.createdAtUnixtimestamp),
+ axisLabel: {
+ formatter: (value: string) => parseDateNoTime(value, true),
+ },
+ boundaryGap: false,
},
- },
- splitLine: {
- lineStyle: {
- color: '#ffffff',
- width: 0.5,
- opacity: 0.2,
+ ],
+ yAxis: [
+ {
+ position: 'left',
+ type: 'value',
+ scale: true,
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ },
+ splitLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 0.5,
+ opacity: 0.2,
+ },
+ },
+ axisLabel: {
+ formatter: (value: string) => handleAxis(new BigNumber(value), 0),
+ },
+ boundaryGap: ['5%', '2%'],
},
- },
- axisLabel: {
- formatter: (value: string) => handleAxis(new BigNumber(value), 0),
- },
- boundaryGap: ['5%', '2%'],
- },
- {
- position: 'right',
- type: 'value',
- axisLine: {
- lineStyle: {
- color: '#ffffff',
- width: 1,
+ {
+ position: 'right',
+ type: 'value',
+ axisLine: {
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ },
},
- },
- },
- ],
- series: [
- {
- name: i18n.t('block.hash_rate'),
- type: 'line',
- yAxisIndex: 0,
- lineStyle: {
- color: '#ffffff',
- width: 1,
- },
- symbol: 'none',
- data: statisticHashRates.map(data => new BigNumber(data.avgHashRate).toNumber()),
- },
- ],
-})
-
+ ],
+ series: [
+ {
+ name: t('block.hash_rate'),
+ type: 'line',
+ yAxisIndex: 0,
+ lineStyle: {
+ color: '#ffffff',
+ width: 1,
+ },
+ symbol: 'none',
+ data: statisticHashRates.map(data => new BigNumber(data.avgHashRate).toNumber()),
+ },
+ ],
+ }
+ }
+}
export default memo(() => {
const isLG = useIsLGScreen()
-
const query = useChartQueryWithCache(explorerService.api.fetchStatisticHashRate, ChartCachedKeys.HashRate, 'date')
const fullStatisticHashRates = useMemo(() => query.data ?? [], [query.data])
+ const parseOption = useOption()
const statisticHashRates = useMemo(() => {
const last14Days = -15 // one day offset
@@ -119,10 +123,11 @@ export default memo(() => {
)
}
+
return (
= ({ block, isDelayBlock }) => {
+ const { t } = useTranslation()
const liveCellChanges = Number(block.liveCellChanges)
const blockReward = isDelayBlock ? (
@@ -48,11 +49,11 @@ const _BlockCardItem: FC<{ block: State.Block; isDelayBlock?: boolean }> = ({ bl
- {i18n.t('home.miner')}
+ {t('home.miner')}
- {`${i18n.t('home.reward')}`}
+ {`${t('home.reward')}`}
{blockReward}
@@ -60,7 +61,7 @@ const _BlockCardItem: FC<{ block: State.Block; isDelayBlock?: boolean }> = ({ bl
{`${block.transactionsCount} TXs`}
- {`${liveCellChanges >= 0 ? '+' : '-'}${Math.abs(liveCellChanges)} ${i18n.t('home.cells')}`}
+ {`${liveCellChanges >= 0 ? '+' : '-'}${Math.abs(liveCellChanges)} ${t('home.cells')}`}
@@ -76,10 +77,11 @@ const _TransactionCardItem: FC<{
transaction: State.Transaction
tipBlockNumber: number
}> = ({ transaction, tipBlockNumber }) => {
+ const { t } = useTranslation()
const liveCellChanges = Number(transaction.liveCellChanges)
let confirmation = tipBlockNumber - Number(transaction.blockNumber)
confirmation = confirmation < 0 ? 0 : confirmation
- const confirmationUnit = confirmation > 1 ? i18n.t('address.confirmations') : i18n.t('address.confirmation')
+ const confirmationUnit = confirmation > 1 ? t('address.confirmations') : t('address.confirmation')
const parsedBlockCreateAt = useParsedDate(transaction.blockTimestamp)
@@ -100,7 +102,7 @@ const _TransactionCardItem: FC<{
- {i18n.t('block.block')}
+ {t('block.block')}
#
@@ -114,7 +116,7 @@ const _TransactionCardItem: FC<{
hideZero
/>
- {`${liveCellChanges >= 0 ? '+' : '-'}${Math.abs(liveCellChanges)} ${i18n.t('home.cells')}`}
+ {`${liveCellChanges >= 0 ? '+' : '-'}${Math.abs(liveCellChanges)} ${t('home.cells')}`}
diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx
index 2e2de35d6..8cf9aa046 100644
--- a/src/pages/Home/index.tsx
+++ b/src/pages/Home/index.tsx
@@ -23,7 +23,6 @@ import {
import { localeNumberString, handleHashRate, handleDifficulty } from '../../utils/number'
import { handleBigNumber } from '../../utils/string'
import { isMainnet } from '../../utils/chain'
-import i18n from '../../utils/i18n'
import LatestBlocksIcon from '../../assets/latest_blocks.png'
import LatestTransactionsIcon from '../../assets/latest_transactions.png'
import { BlockCardItem, TransactionCardItem } from './TableCard'
@@ -71,53 +70,56 @@ const parseHashRate = (hashRate: string | undefined) => (hashRate ? handleHashRa
const parseBlockTime = (blockTime: string | undefined) => (blockTime ? parseTime(Number(blockTime)) : '- -')
-const getBlockchainDataList = (statistics: State.Statistics, isMobile: boolean, isLG: boolean): BlockchainData[] => [
- {
- name: i18n.t('blockchain.latest_block'),
- value: localeNumberString(statistics.tipBlockNumber),
- showSeparate: true,
- },
- {
- name: i18n.t('blockchain.average_block_time'),
- value: parseBlockTime(statistics.averageBlockTime),
- showSeparate: !isMobile,
- },
- {
- name: i18n.t('blockchain.hash_rate'),
- value: parseHashRate(statistics.hashRate),
- showSeparate: true,
- },
- {
- name: i18n.t('blockchain.difficulty'),
- value: handleDifficulty(statistics.currentEpochDifficulty),
- showSeparate: true,
- },
- {
- name: i18n.t('blockchain.epoch'),
- value: statistics.epochInfo.epochNumber,
- rightValue: `${statistics.epochInfo.index}/${statistics.epochInfo.epochLength}`,
- showSeparate: true,
- },
- {
- name: i18n.t('blockchain.estimated_epoch_time'),
- value: parseTimeNoSecond(Number(statistics.estimatedEpochTime)),
- showSeparate: !isLG,
- },
- {
- name: i18n.t('blockchain.transactions_per_minute'),
- value: handleBigNumber(statistics.transactionsCountPerMinute, 2),
- showSeparate: true,
- },
- {
- name: i18n.t('blockchain.transactions_last_24hrs'),
- value: handleBigNumber(statistics.transactionsLast24Hrs, 2),
- showSeparate: false,
- },
-]
+const useBlockchainDataList = (statistics: State.Statistics, isMobile: boolean, isLG: boolean): BlockchainData[] => {
+ const { t } = useTranslation()
+ return [
+ {
+ name: t('blockchain.latest_block'),
+ value: localeNumberString(statistics.tipBlockNumber),
+ showSeparate: true,
+ },
+ {
+ name: t('blockchain.average_block_time'),
+ value: parseBlockTime(statistics.averageBlockTime),
+ showSeparate: !isMobile,
+ },
+ {
+ name: t('blockchain.hash_rate'),
+ value: parseHashRate(statistics.hashRate),
+ showSeparate: true,
+ },
+ {
+ name: t('blockchain.difficulty'),
+ value: handleDifficulty(statistics.currentEpochDifficulty),
+ showSeparate: true,
+ },
+ {
+ name: t('blockchain.epoch'),
+ value: statistics.epochInfo.epochNumber,
+ rightValue: `${statistics.epochInfo.index}/${statistics.epochInfo.epochLength}`,
+ showSeparate: true,
+ },
+ {
+ name: t('blockchain.estimated_epoch_time'),
+ value: parseTimeNoSecond(Number(statistics.estimatedEpochTime)),
+ showSeparate: !isLG,
+ },
+ {
+ name: t('blockchain.transactions_per_minute'),
+ value: handleBigNumber(statistics.transactionsCountPerMinute, 2),
+ showSeparate: true,
+ },
+ {
+ name: t('blockchain.transactions_last_24hrs'),
+ value: handleBigNumber(statistics.transactionsLast24Hrs, 2),
+ showSeparate: false,
+ },
+ ]
+}
const HomeHeaderTopPanel: FC = memo(() => {
const ref = useRef(null)
-
+ const { t } = useTranslation()
const { height: resizedHeight } = useResizeDetector({
targetRef: ref,
handleWidth: false,
@@ -145,7 +147,7 @@ const HomeHeaderTopPanel: FC = memo(() => {
return (
- {i18n.t('common.ckb_explorer')}
+ {t('common.ckb_explorer')}
{isFullDisplayInScreen && }
)
@@ -185,11 +187,11 @@ const TransactionList: FC<{ transactions: State.Transaction[]; tipBlockNumber: n
export default () => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const isLG = useIsLGScreen()
const history = useHistory()
const statistics = useStatistics()
const tipBlockNumber = useLatestBlockNumber()
- const [t] = useTranslation()
const blocksQuery = useQuery(
'latest_blocks',
@@ -233,7 +235,7 @@ export default () => {
handleBlockchainAlert()
}, BLOCKCHAIN_ALERT_POLLING_TIME)
- const blockchainDataList = getBlockchainDataList(statistics, isMobile, isLG)
+ const blockchainDataList = useBlockchainDataList(statistics, isMobile, isLG)
return (
@@ -286,7 +288,7 @@ export default () => {
- {i18n.t('home.latest_blocks')}
+ {t('home.latest_blocks')}
{
- {i18n.t('home.latest_transactions')}
+ {t('home.latest_transactions')}
{
}
}
-const nervosDaoItemContents = (nervosDao: State.NervosDao): NervosDaoItemContent[] => [
- {
- title: i18n.t('nervos_dao.deposit'),
- change: handleBigNumberFloor(shannonToCkbDecimal(nervosDao.depositChanges, 2), 2),
- changeSymbol: numberSymbol(Number(nervosDao.depositChanges)),
- content: localeNumberString(shannonToCkbDecimal(nervosDao.totalDeposit, 2)),
- tooltip: i18n.t('nervos_dao.today_update'),
- },
- {
- title: i18n.t('nervos_dao.addresses'),
- titleTooltip: i18n.t('nervos_dao.deposit_address_tooltip'),
- change: localeNumberString(nervosDao.depositorChanges),
- changeSymbol: numberSymbol(Number(nervosDao.depositorChanges), false),
- content: localeNumberString(nervosDao.depositorsCount),
- tooltip: i18n.t('nervos_dao.today_update'),
- },
+const useNervosDaoItemContents = (nervosDao: State.NervosDao): NervosDaoItemContent[] => {
+ const { t } = useTranslation()
+ return [
+ {
+ title: t('nervos_dao.deposit'),
+ change: handleBigNumberFloor(shannonToCkbDecimal(nervosDao.depositChanges, 2), 2),
+ changeSymbol: numberSymbol(Number(nervosDao.depositChanges)),
+ content: localeNumberString(shannonToCkbDecimal(nervosDao.totalDeposit, 2)),
+ tooltip: t('nervos_dao.today_update'),
+ },
+ {
+ title: t('nervos_dao.addresses'),
+ titleTooltip: t('nervos_dao.deposit_address_tooltip'),
+ change: localeNumberString(nervosDao.depositorChanges),
+ changeSymbol: numberSymbol(Number(nervosDao.depositorChanges), false),
+ content: localeNumberString(nervosDao.depositorsCount),
+ tooltip: t('nervos_dao.today_update'),
+ },
- {
- title: i18n.t('nervos_dao.claimed_compensation'),
- change: handleBigNumberFloor(shannonToCkbDecimal(nervosDao.claimedCompensationChanges, 2), 2),
- changeSymbol: numberSymbol(Number(nervosDao.claimedCompensationChanges)),
- content: localeNumberString(shannonToCkbDecimal(nervosDao.claimedCompensation, 2)),
- tooltip: i18n.t('nervos_dao.today_update'),
- },
- {
- title: i18n.t('nervos_dao.average_deposit_time'),
- content: `${handleBigNumber(nervosDao.averageDepositTime, 1)} ${i18n.t('nervos_dao.days')}`,
- },
- {
- title: i18n.t('nervos_dao.estimated_apc'),
- titleTooltip: i18n.t('glossary.estimated_apc'),
- content: `${Number(nervosDao.estimatedApc).toFixed(2)}%`,
- },
- {
- title: i18n.t('nervos_dao.unclaimed_compensation'),
- change: handleBigNumberFloor(shannonToCkbDecimal(nervosDao.unclaimedCompensationChanges, 2), 2),
- changeSymbol: numberSymbol(Number(nervosDao.unclaimedCompensationChanges)),
- content: localeNumberString(shannonToCkbDecimal(nervosDao.unclaimedCompensation, 2)),
- tooltip: i18n.t('nervos_dao.today_update'),
- },
-]
+ {
+ title: t('nervos_dao.claimed_compensation'),
+ change: handleBigNumberFloor(shannonToCkbDecimal(nervosDao.claimedCompensationChanges, 2), 2),
+ changeSymbol: numberSymbol(Number(nervosDao.claimedCompensationChanges)),
+ content: localeNumberString(shannonToCkbDecimal(nervosDao.claimedCompensation, 2)),
+ tooltip: t('nervos_dao.today_update'),
+ },
+ {
+ title: t('nervos_dao.average_deposit_time'),
+ content: `${handleBigNumber(nervosDao.averageDepositTime, 1)} ${t('nervos_dao.days')}`,
+ },
+ {
+ title: t('nervos_dao.estimated_apc'),
+ titleTooltip: t('glossary.estimated_apc'),
+ content: `${Number(nervosDao.estimatedApc).toFixed(2)}%`,
+ },
+ {
+ title: t('nervos_dao.unclaimed_compensation'),
+ change: handleBigNumberFloor(shannonToCkbDecimal(nervosDao.unclaimedCompensationChanges, 2), 2),
+ changeSymbol: numberSymbol(Number(nervosDao.unclaimedCompensationChanges)),
+ content: localeNumberString(shannonToCkbDecimal(nervosDao.unclaimedCompensation, 2)),
+ tooltip: t('nervos_dao.today_update'),
+ },
+ ]
+}
const NervosDaoLeftItem = ({ item, firstLine }: { item: NervosDaoItemContent; firstLine?: boolean }) => (
@@ -131,8 +134,7 @@ const NervosDaoLeftItem = ({ item, firstLine }: { item: NervosDaoItemContent; fi
const NervosDaoOverviewLeftComp: FC<{ nervosDao: State.NervosDao }> = ({ nervosDao }) => {
const isMobile = useIsMobile()
-
- const leftItems = nervosDaoItemContents(nervosDao)
+ const leftItems = useNervosDaoItemContents(nervosDao)
if (isMobile) {
return (
@@ -180,7 +182,8 @@ const NervosDaoOverviewLeftComp: FC<{ nervosDao: State.NervosDao }> = ({ nervosD
)
}
-const getOption = (nervosDao: State.NervosDao, colors: string[], isMobile: boolean): echarts.EChartOption => {
+const useOption = (nervosDao: State.NervosDao, colors: string[], isMobile: boolean): echarts.EChartOption => {
+ const { t } = useTranslation()
const { miningReward, depositCompensation, treasuryAmount } = nervosDao
const sum =
shannonToCkbDecimal(miningReward) + shannonToCkbDecimal(depositCompensation) + shannonToCkbDecimal(treasuryAmount)
@@ -193,17 +196,17 @@ const getOption = (nervosDao: State.NervosDao, colors: string[], isMobile: boole
{
name: names[0],
value: shannonToCkbDecimal(miningReward),
- title: i18n.t('nervos_dao.mining_reward'),
+ title: t('nervos_dao.mining_reward'),
},
{
name: names[1],
value: shannonToCkbDecimal(depositCompensation),
- title: i18n.t('nervos_dao.deposit_compensation'),
+ title: t('nervos_dao.deposit_compensation'),
},
{
name: names[2],
value: shannonToCkbDecimal(treasuryAmount),
- title: i18n.t('nervos_dao.burnt'),
+ title: t('nervos_dao.burnt'),
},
]
const selectedData: any = {
@@ -218,14 +221,12 @@ const getOption = (nervosDao: State.NervosDao, colors: string[], isMobile: boole
tooltip: {
trigger: 'item',
formatter: (value: any) =>
- `${value.data.title}: ${localeNumberString(value.data.value)} ${i18n.t('common.ckb_unit')} (${
- value.data.name
- })`,
+ `${value.data.title}: ${localeNumberString(value.data.value)} ${t('common.ckb_unit')} (${value.data.name})`,
position: ['10%', '50%'],
},
series: [
{
- name: i18n.t('nervos_dao.secondary_issuance'),
+ name: t('nervos_dao.secondary_issuance'),
type: 'pie',
radius: '75%',
center: ['50%', '50%'],
@@ -283,27 +284,28 @@ const NervosDaoPieItem = ({ item }: { item: NervosDaoPieItemContent }) => (
export default ({ nervosDao }: { nervosDao: State.NervosDao }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const isExactLG = useIsLGScreen(true)
const nervosDaoPieItemContents = useCallback(
(nervosDao: State.NervosDao): NervosDaoPieItemContent[] => [
{
- title: i18n.t('nervos_dao.mining_reward'),
+ title: t('nervos_dao.mining_reward'),
content: ,
color: ChartColor.daoColors[0],
},
{
- title: i18n.t('nervos_dao.deposit_compensation'),
+ title: t('nervos_dao.deposit_compensation'),
content: ,
color: ChartColor.daoColors[1],
},
{
- title: i18n.t('nervos_dao.burnt'),
+ title: t('nervos_dao.burnt'),
content: ,
color: ChartColor.daoColors[2],
},
],
- [],
+ [t],
)
return (
@@ -313,11 +315,11 @@ export default ({ nervosDao }: { nervosDao: State.NervosDao }) => {
- {i18n.t('nervos_dao.secondary_issuance')}
-
+ {t('nervos_dao.secondary_issuance')}
+
void
filterNoResult?: boolean
}) => {
+ const { t } = useTranslation()
const totalPages = Math.ceil(total / pageSize)
if (filterNoResult) {
return (
- {i18n.t('search.dao_filter_no_result')}
+ {t('search.dao_filter_no_result')}
)
}
diff --git a/src/pages/NervosDao/DepositorRank/index.tsx b/src/pages/NervosDao/DepositorRank/index.tsx
index 1c46f2a33..3a41fe229 100644
--- a/src/pages/NervosDao/DepositorRank/index.tsx
+++ b/src/pages/NervosDao/DepositorRank/index.tsx
@@ -1,7 +1,7 @@
import { FC } from 'react'
+import { useTranslation } from 'react-i18next'
import { localeNumberString } from '../../../utils/number'
import { shannonToCkb } from '../../../utils/util'
-import i18n from '../../../utils/i18n'
import DecimalCapacity from '../../../components/DecimalCapacity'
import { handleBigNumber } from '../../../utils/string'
import {
@@ -30,21 +30,23 @@ const AddressTextCol = ({ address }: { address: string }) => {
}
const DepositorCardGroup: FC<{ depositors: (State.NervosDaoDepositor & { rank: number })[] }> = ({ depositors }) => {
+ const { t } = useTranslation()
+
const items: ItemCardData[] = [
{
- title: i18n.t('nervos_dao.dao_title_rank'),
+ title: t('nervos_dao.dao_title_rank'),
render: depositor => depositor.rank,
},
{
- title: i18n.t('nervos_dao.dao_title_address'),
+ title: t('nervos_dao.dao_title_address'),
render: depositor => ,
},
{
- title: i18n.t('nervos_dao.dao_title_deposit_capacity'),
+ title: t('nervos_dao.dao_title_deposit_capacity'),
render: depositor => ,
},
{
- title: i18n.t('nervos_dao.dao_title_deposit_time'),
+ title: t('nervos_dao.dao_title_deposit_time'),
render: depositor => handleBigNumber(depositor.averageDepositTime, 1),
},
]
@@ -53,6 +55,7 @@ const DepositorCardGroup: FC<{ depositors: (State.NervosDaoDepositor & { rank: n
}
export default ({ depositors, filter }: { depositors: State.NervosDaoDepositor[]; filter?: string }) => {
+ const { t } = useTranslation()
const rankedDepositors = depositors.map((depositor, index) => ({
...depositor,
rank: index + 1,
@@ -67,10 +70,10 @@ export default ({ depositors, filter }: { depositors: State.NervosDaoDepositor[]
) : (
- {i18n.t('nervos_dao.dao_title_rank')}
- {i18n.t('nervos_dao.dao_title_address')}
- {i18n.t('nervos_dao.dao_title_deposit_capacity')}
- {i18n.t('nervos_dao.dao_title_deposit_time')}
+ {t('nervos_dao.dao_title_rank')}
+ {t('nervos_dao.dao_title_address')}
+ {t('nervos_dao.dao_title_deposit_capacity')}
+ {t('nervos_dao.dao_title_deposit_time')}
{filteredDepositors.map(depositor => (
diff --git a/src/pages/NftCollectionInfo/index.tsx b/src/pages/NftCollectionInfo/index.tsx
index 116601412..05837b63b 100644
--- a/src/pages/NftCollectionInfo/index.tsx
+++ b/src/pages/NftCollectionInfo/index.tsx
@@ -2,9 +2,8 @@ import type { AxiosResponse } from 'axios'
import { Link, useParams, useHistory } from 'react-router-dom'
import { useQuery } from 'react-query'
import { Popover } from 'antd'
+import { TFunction, useTranslation } from 'react-i18next'
import Content from '../../components/Content'
-import Pagination from '../../components/Pagination'
-import NftHolderList from '../../components/NftHolderList'
import NftCollectionOverview from '../../components/NftCollectionOverview'
import NftCollectionTransfers from '../../components/NftCollectionTransfers'
import NftCollectionInventory from '../../components/NftCollectionInventory'
@@ -12,11 +11,12 @@ import Filter from '../../components/Search/Filter'
import { ReactComponent as FilterIcon } from '../../assets/filter_icon.svg'
import { ReactComponent as SelectedCheckIcon } from '../../assets/selected_check_icon.svg'
import { explorerService } from '../../services/ExplorerService'
-import i18n from '../../utils/i18n'
import { useSearchParams, useIsMobile } from '../../utils/hook'
import styles from './styles.module.scss'
import { CsvExport } from '../../components/CsvExport'
import PaginationWithRear from '../../components/PaginationWithRear'
+import NftHolderList from '../../components/NftHolderList'
+import Pagination from '../../components/Pagination'
export interface InventoryRes {
data: Array<{
@@ -88,30 +88,34 @@ export interface HolderListRes {
}
const tabs = ['transfers', 'holders', 'inventory']
-const filterList: Array> = [
- {
- value: 'mint',
- title: i18n.t('udt.view-mint-txns'),
- },
- {
- value: 'normal',
- title: i18n.t('udt.view-transfer-txns'),
- },
- {
- value: 'destruction',
- title: i18n.t('udt.view-burn-txns'),
- },
-]
+function getFilterList(t: TFunction): Array> {
+ return [
+ {
+ value: 'mint',
+ title: t('udt.view-mint-txns'),
+ },
+ {
+ value: 'normal',
+ title: t('udt.view-transfer-txns'),
+ },
+ {
+ value: 'destruction',
+ title: t('udt.view-burn-txns'),
+ },
+ ]
+}
const PAGE_SIZE = 50
const NftCollectionInfo = () => {
const { id } = useParams<{ id: string }>()
const history = useHistory()
+ const { t } = useTranslation()
const { tab = tabs[0], page = '1' } = useSearchParams('tab', 'page', 'tx_type')
const { type, filter, sort } = useSearchParams('type', 'filter', 'sort')
const isMobile = useIsMobile()
- const isFilteredByType = filterList.some(f => f.value === type)
+ const filteredList = getFilterList(t)
+ const isFilteredByType = filteredList.some(f => f.value === type)
const { isLoading: isTransferListLoading, data: transferListRes } = useQuery>(
['nft-collection-transfer-list', id, page, filter, type],
@@ -214,13 +218,13 @@ const NftCollectionInfo = () => {
- {i18n.t(`nft.activity`)}
+ {t(`nft.activity`)}
- {i18n.t(`nft.holder-list`)}
+ {t(`nft.holder-list`)}
- {i18n.t(`nft.inventory`)}
+ {t(`nft.inventory`)}
@@ -229,7 +233,7 @@ const NftCollectionInfo = () => {
{
history.push(`/nft-collections/${id}?${new URLSearchParams({ tab, filter })}`)
}}
@@ -246,7 +250,7 @@ const NftCollectionInfo = () => {
overlayClassName={styles.antPopover}
content={
- {filterList.map(f => (
+ {filteredList.map(f => (
> = [
- {
- value: 'all',
- title: i18n.t('nft.all-type'),
- },
- {
- value: 'm_nft',
- title: i18n.t('nft.m_nft'),
- },
- {
- value: 'nrc721',
- title: i18n.t('nft.nrc_721'),
- },
- {
- value: 'cota',
- title: i18n.t('nft.cota'),
- },
- {
- value: 'spore',
- title: i18n.t('nft.spore'),
- },
-]
+function useFilterList(): Array > {
+ const { t } = useTranslation()
+ return [
+ {
+ value: 'all',
+ title: t('nft.all-type'),
+ },
+ {
+ value: 'm_nft',
+ title: t('nft.m_nft'),
+ },
+ {
+ value: 'nrc721',
+ title: t('nft.nrc_721'),
+ },
+ {
+ value: 'cota',
+ title: t('nft.cota'),
+ },
+ {
+ value: 'spore',
+ title: t('nft.spore'),
+ },
+ ]
+}
export const isTxFilterType = (s?: string): boolean => {
return s ? ['all', 'm_nft', 'nrc721', 'cota', 'spore'].includes(s) : false
@@ -56,19 +58,20 @@ export interface NFTCollection {
const TypeFilter = () => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const { type } = useSearchParams('type')
const isActive = isTxFilterType(type)
-
+ const list = useFilterList()
return (
- {i18n.t('nft.standard')}
+ {t('nft.standard')}
- {filterList.map(f => (
+ {list.map(f => (
{
}
const HolderMinterSort = () => {
+ const { t } = useTranslation()
const { sortBy, handleSortClick } = useSortParam(
s => s === 'transactions' || s === 'holder' || s === 'minted',
)
@@ -101,7 +105,7 @@ const HolderMinterSort = () => {
onClick={() => handleSortClick('holder')}
aria-hidden
>
- {i18n.t('nft.holder')}
+ {t('nft.holder')}
/
{
onClick={() => handleSortClick('minted')}
aria-hidden
>
- {i18n.t('nft.minted')}
+ {t('nft.minted')}
)
}
const TypeInfo: React.FC<{ nft: NFTCollection }> = ({ nft: item }) => {
- return i18n.t(`glossary.${item.standard}`) ? (
+ const { t } = useTranslation()
+ return t(`glossary.${item.standard}`) ? (
= ({ nft: item }) => {
/>
}
>
- {i18n.t(`nft.${item.standard}`)}
+ {t(`nft.${item.standard}`)}
) : (
- i18n.t(`nft.${item.standard}`)
+ t(`nft.${item.standard}`)
)
}
export const ListOnDesktop: React.FC<{ isLoading: boolean; list: Array }> = ({ list, isLoading }) => {
+ const { t } = useTranslation()
return (
- {i18n.t('nft.collection_name')} |
+ {t('nft.collection_name')} |
|
- {i18n.t('nft.transactions')}
+ {t('nft.transactions')}
|
|
- {i18n.t('nft.minter_address')} |
+ {t('nft.minter_address')} |
@@ -242,7 +248,7 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: Array
- {isLoading ? 'loading' : i18n.t(`nft.no_record`)}
+ {isLoading ? 'loading' : t(`nft.no_record`)}
|
)}
@@ -252,6 +258,7 @@ export const ListOnDesktop: React.FC<{ isLoading: boolean; list: Array }> = ({ list, isLoading }) => {
+ const { t } = useTranslation()
return (
@@ -300,13 +307,13 @@ export const ListOnMobile: React.FC<{ isLoading: boolean; list: Array
- - {i18n.t(`nft.standard`)}
+ - {t(`nft.standard`)}
-
- - {`${i18n.t('nft.holder')}/${i18n.t('nft.minted')}`}
+ - {`${t('nft.holder')}/${t('nft.minted')}`}
-
{`${(item.holders_count ?? 0).toLocaleString('en')}/${(item.items_count ?? 0).toLocaleString(
'en',
@@ -315,7 +322,7 @@ export const ListOnMobile: React.FC<{ isLoading: boolean; list: Array
{item.creator ? (
- - {i18n.t(`nft.minter_address`)}
+ - {t(`nft.minter_address`)}
-
{isLoading ? 'loading' : i18n.t(`nft.no_record`)}
+ {isLoading ? 'loading' : t(`nft.no_record`)}
)}
diff --git a/src/pages/NftCollections/index.tsx b/src/pages/NftCollections/index.tsx
index 49e1cd212..f4dbbacf8 100644
--- a/src/pages/NftCollections/index.tsx
+++ b/src/pages/NftCollections/index.tsx
@@ -1,12 +1,12 @@
import type { AxiosResponse } from 'axios'
import { useHistory, useLocation } from 'react-router-dom'
import { useQuery } from 'react-query'
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import { NFTCollection, ListOnDesktop, ListOnMobile, isTxFilterType } from './List'
import Pagination from '../../components/Pagination'
import { getPrimaryColor } from '../../constants/common'
import { explorerService } from '../../services/ExplorerService'
-import i18n from '../../utils/i18n'
import { udtSubmitEmail } from '../../utils/util'
import { useSearchParams, useSortParam } from '../../utils/hook'
import styles from './styles.module.scss'
@@ -30,6 +30,7 @@ const submitTokenInfoUrl = udtSubmitEmail()
const NftCollections = () => {
const history = useHistory()
+ const { t } = useTranslation()
const { search } = useLocation()
const { page = '1', type } = useSearchParams('page', 'type')
@@ -61,7 +62,7 @@ const NftCollections = () => {
diff --git a/src/pages/NftInfo/index.tsx b/src/pages/NftInfo/index.tsx
index c1aa6c6e1..5553a4a35 100644
--- a/src/pages/NftInfo/index.tsx
+++ b/src/pages/NftInfo/index.tsx
@@ -4,7 +4,7 @@ import { useQuery } from 'react-query'
import { Tooltip } from 'antd'
import { Base64 } from 'js-base64'
import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils'
-import i18n from '../../utils/i18n'
+import { useTranslation } from 'react-i18next'
import NftItemTransfers, { TransferListRes } from '../../components/NftItemTransfers'
import Pagination from '../../components/Pagination'
import { ReactComponent as Cover } from '../../assets/nft_cover.svg'
@@ -20,6 +20,7 @@ const primaryColor = getPrimaryColor()
const NftInfo = () => {
const { id, collection } = useParams >()
const history = useHistory()
+ const { t } = useTranslation()
const { page = '1' } = useSearchParams('page')
const { data } = useQuery<
AxiosResponse<{
@@ -112,7 +113,7 @@ const NftInfo = () => {
{data ? `${data.data.collection.name} #${data.data.token_id}` : '-'}
- - {i18n.t('nft.owner')}
+ - {t('nft.owner')}
-
{data?.data.owner ? (
{
- - {i18n.t('nft.minter_address')}
+ - {t('nft.minter_address')}
-
{data?.data.collection.creator ? (
{
- {`#${data?.data.token_id}`}
- - {i18n.t('nft.standard')}
- - {data ? i18n.t(`nft.${data.data.collection.standard}`) : '-'}
+ - {t('nft.standard')}
+ - {data ? t(`nft.${data.data.collection.standard}`) : '-'}
- {i18n.t(`nft.activity`)}
+ {t(`nft.activity`)}
{
+ const { t } = useTranslation()
const history = useHistory()
const { codeHash, hashType } = useParams<{ codeHash: string; hashType: string }>()
@@ -166,10 +167,10 @@ export const ScriptCells = ({
- {i18n.t('transaction.transaction')} |
- {i18n.t('scripts.index')} |
- {i18n.t('transaction.capacity')} |
- {i18n.t('scripts.cell_info')} |
+ {t('transaction.transaction')} |
+ {t('scripts.index')} |
+ {t('transaction.capacity')} |
+ {t('scripts.cell_info')} |
@@ -215,6 +216,7 @@ export const ScriptCells = ({
export const CodeHashMessage = ({ codeHash }: { codeHash: string }) => {
const setToast = useSetToast()
+ const { t } = useTranslation()
return (
@@ -225,7 +227,7 @@ export const CodeHashMessage = ({ codeHash }: { codeHash: string }) => {
onClick={() => {
navigator.clipboard.writeText(codeHash).then(
() => {
- setToast({ message: i18n.t('common.copied') })
+ setToast({ message: t('common.copied') })
},
error => {
console.error(error)
diff --git a/src/pages/Script/index.tsx b/src/pages/Script/index.tsx
index 08070d8f2..c821a523f 100644
--- a/src/pages/Script/index.tsx
+++ b/src/pages/Script/index.tsx
@@ -4,9 +4,10 @@ import { useParams } from 'react-router-dom'
import { Tabs } from 'antd'
import { useQuery } from 'react-query'
import { AxiosResponse } from 'axios'
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import OverviewCard, { OverviewItemData } from '../../components/Card/OverviewCard'
-import i18n from '../../utils/i18n'
+import { useCurrentLanguage } from '../../utils/i18n'
import { HashCardPanel } from '../../components/Card/HashCard/styled'
import { localeNumberString } from '../../utils/number'
import { CodeHashMessage, ScriptCells, ScriptTransactions } from './ScriptsComp'
@@ -22,52 +23,56 @@ import { explorerService, Response } from '../../services/ExplorerService'
const scriptDataList = isMainnet() ? MainnetContractHashTags : TestnetContractHashTags
-const scriptHashNameMap = new Map (
- scriptDataList
- .map(scriptData =>
- scriptData.codeHashes.map(
- codeHash =>
- [
- `${codeHash}_${scriptData.hashType}`,
- scriptNameList.has(scriptData.tag)
- ? scriptNameList.get(scriptData.tag)!.name
- : i18n.t('scripts.unnamed_script'),
- ] as [string, string],
- ),
- )
- .flat(),
-)
-
-const getScriptInfo = (scriptInfo: ScriptInfo) => {
+const useScriptHashNameMap = (): Map => {
+ const { t } = useTranslation()
+ return new Map(
+ scriptDataList
+ .map(scriptData =>
+ scriptData.codeHashes.map(
+ codeHash =>
+ [
+ `${codeHash}_${scriptData.hashType}`,
+ scriptNameList.has(scriptData.tag)
+ ? scriptNameList.get(scriptData.tag)!.name
+ : t('scripts.unnamed_script'),
+ ] as [string, string],
+ ),
+ )
+ .flat(),
+ )
+}
+
+const useScriptInfo = (scriptInfo: ScriptInfo) => {
+ const { t } = useTranslation()
const { scriptName, scriptType, id, codeHash, hashType, capacityOfDeployedCells, capacityOfReferringCells } =
scriptInfo
const items: OverviewItemData[] = [
{
- title: i18n.t('scripts.script_name'),
- tooltip: i18n.t('glossary.script_name'),
+ title: t('scripts.script_name'),
+ tooltip: t('glossary.script_name'),
content: scriptName,
},
{
- title: i18n.t('scripts.hash_type'),
- tooltip: i18n.t('glossary.hash_type'),
+ title: t('scripts.hash_type'),
+ tooltip: t('glossary.hash_type'),
content: {hashType},
},
{
- title: i18n.t('scripts.script_type'),
- content: scriptType ? i18n.t(`scripts.${scriptType}`) : '-',
+ title: t('scripts.script_type'),
+ content: scriptType ? t(`scripts.${scriptType}`) : '-',
},
{
- title: i18n.t('scripts.type_id'),
+ title: t('scripts.type_id'),
content: id ? : '-',
},
{
- title: i18n.t('scripts.code_hash'),
- tooltip: i18n.t('glossary.code_hash'),
+ title: t('scripts.code_hash'),
+ tooltip: t('glossary.code_hash'),
content: ,
},
{
- title: i18n.t('scripts.capacity_of_deployed_cells'),
- tooltip: i18n.t('glossary.capacity_of_deployed_cells'),
+ title: t('scripts.capacity_of_deployed_cells'),
+ tooltip: t('glossary.capacity_of_deployed_cells'),
content: ,
},
{
@@ -75,7 +80,7 @@ const getScriptInfo = (scriptInfo: ScriptInfo) => {
content: '',
},
{
- title: i18n.t('scripts.capacity_of_referring_cells'),
+ title: t('scripts.capacity_of_referring_cells'),
content: ,
},
]
@@ -86,18 +91,22 @@ const getScriptInfo = (scriptInfo: ScriptInfo) => {
const ScriptsTitleOverview = ({ scriptInfo }: { scriptInfo: ScriptInfo }) => {
return (
-
+
)
}
-const seekScriptName = (codeHash: string, hashType: string): string =>
- scriptHashNameMap.has(`${codeHash}_${hashType}`)
- ? scriptHashNameMap.get(`${codeHash}_${hashType}`)!
- : i18n.t('scripts.unnamed_script')
+const useSeekScriptName = (codeHash: string, hashType: string): string => {
+ const { t } = useTranslation()
+ const nameMap = useScriptHashNameMap()
+ return nameMap.has(`${codeHash}_${hashType}`) ? nameMap.get(`${codeHash}_${hashType}`)! : t('scripts.unnamed_script')
+}
export const ScriptPage = () => {
const history = useHistory()
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const { codeHash, hashType, tab } = useParams<{ codeHash: string; hashType: string; tab: ScriptTabType }>()
const { currentPage, pageSize } = usePaginationParamsInPage()
@@ -133,7 +142,7 @@ export const ScriptPage = () => {
countOfDeployedCells: 0,
countOfReferringCells: 0,
} as ScriptInfo)
- scriptInfo.scriptName = seekScriptName(scriptInfo.codeHash, scriptInfo.hashType)
+ scriptInfo.scriptName = useSeekScriptName(scriptInfo.codeHash, scriptInfo.hashType)
useEffect(() => {
setCountOfTransactions(scriptInfo.countOfTransactions)
@@ -148,7 +157,7 @@ export const ScriptPage = () => {
{
}}
items={[
{
- label: `${i18n.t('transaction.transactions')} (${localeNumberString(countOfTransactions!)})`,
+ label: `${t('transaction.transactions')} (${localeNumberString(countOfTransactions!)})`,
key: 'transactions',
children: ,
},
{
- label: `${i18n.t('scripts.deployed_cells')} (${localeNumberString(countOfDeployedCells)})`,
+ label: `${t('scripts.deployed_cells')} (${localeNumberString(countOfDeployedCells)})`,
key: 'deployed_cells',
children: ,
},
{
- label: `${i18n.t('scripts.referring_cells')} (${localeNumberString(countOfReferringCells)})`,
+ label: `${t('scripts.referring_cells')} (${localeNumberString(countOfReferringCells)})`,
key: 'referring_cells',
children: ,
},
diff --git a/src/pages/ScriptList/index.tsx b/src/pages/ScriptList/index.tsx
index 62b29f323..d35099c84 100644
--- a/src/pages/ScriptList/index.tsx
+++ b/src/pages/ScriptList/index.tsx
@@ -1,7 +1,7 @@
import { FC } from 'react'
import { useLocation } from 'react-router'
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
-import i18n from '../../utils/i18n'
import styles from './styles.module.scss'
import { MainnetContractHashTags, TestnetContractHashTags } from '../../constants/scripts'
import { isMainnet } from '../../utils/chain'
@@ -191,12 +191,13 @@ export const scripts = new Map([
const keysWithLinkValueInScript: Array = ['rfc', 'code', 'deprecated', 'website']
const ScriptList: FC = () => {
+ const { t } = useTranslation()
const location = useLocation()
const defaultOpenLabel = decodeURIComponent(location.hash.slice(1))
return (
- {i18n.t(`script_list.title`)}
+ {t(`script_list.title`)}
{[...scripts].map(([label, meta]) => {
const script = scriptDataList.find(s => s.tag === label)
@@ -207,12 +208,12 @@ const ScriptList: FC = () => {
{meta.description}
- {`${i18n.t('script_list.links')}:`}
+ {`${t('script_list.links')}:`}
{script ? (
<>
- {`${i18n.t(`script_list.on_chain_data`)}:`}
+ {`${t(`script_list.on_chain_data`)}:`}
{script.codeHashes.map((codeHash: string, idx: number) => (
{`{
diff --git a/src/pages/SearchFail/index.tsx b/src/pages/SearchFail/index.tsx
index f27cd9f25..7c0cac619 100644
--- a/src/pages/SearchFail/index.tsx
+++ b/src/pages/SearchFail/index.tsx
@@ -1,24 +1,25 @@
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import Search from '../../components/Search'
-import i18n from '../../utils/i18n'
import { SearchFailType, MAINNET_URL, TESTNET_URL } from '../../constants/common'
import { isMainnet } from '../../utils/chain'
import { SearchContent, SearchPanel } from './styled'
import { useSearchParams } from '../../utils/hook'
-const chainErrorMessage = () =>
- isMainnet() ? i18n.t('search.address_type_testnet_error') : i18n.t('search.address_type_mainnet_error')
-
-const chainUrlMessage = () =>
- isMainnet() ? i18n.t('search.address_type_testnet_url') : i18n.t('search.address_type_mainnet_url')
-
const targetUrl = isMainnet() ? TESTNET_URL : MAINNET_URL
export default ({ address }: { address?: string }) => {
+ const { t } = useTranslation()
const params = useSearchParams('q', 'type')
const { q, type } = params
const query = address || q
+ const chainErrorMessage = () =>
+ isMainnet() ? t('search.address_type_testnet_error') : t('search.address_type_mainnet_error')
+
+ const chainUrlMessage = () =>
+ isMainnet() ? t('search.address_type_testnet_url') : t('search.address_type_mainnet_url')
+
return (
@@ -35,8 +36,8 @@ export default ({ address }: { address?: string }) => {
) : (
<>
- {i18n.t('search.empty_result')}
- {i18n.t('search.empty_result_items')}
+ {t('search.empty_result')}
+ {t('search.empty_result_items')}
>
)}
diff --git a/src/pages/SimpleUDT/SimpleUDTComp.tsx b/src/pages/SimpleUDT/SimpleUDTComp.tsx
index 218f9ae27..1ffb77201 100644
--- a/src/pages/SimpleUDT/SimpleUDTComp.tsx
+++ b/src/pages/SimpleUDT/SimpleUDTComp.tsx
@@ -1,9 +1,9 @@
import { ReactNode } from 'react'
import { Tooltip } from 'antd'
import { Link } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import OverviewCard, { OverviewItemData } from '../../components/Card/OverviewCard'
import TransactionItem from '../../components/TransactionItem/index'
-import i18n from '../../utils/i18n'
import { SimpleUDTTransactionsPagination, SimpleUDTTransactionsPanel, UDTNoResultPanel } from './styled'
import { parseUDTAmount } from '../../utils/number'
import { ReactComponent as OpenInNew } from '../../assets/open_in_new.svg'
@@ -13,9 +13,10 @@ import AddressText from '../../components/AddressText'
import PaginationWithRear from '../../components/PaginationWithRear'
import { CsvExport } from '../../components/CsvExport'
-const addressContent = (address: string) => {
+const useAddressContent = (address: string) => {
+ const { t } = useTranslation()
if (!address) {
- return i18n.t('address.unable_decode_address')
+ return t('address.unable_decode_address')
}
const newAddress = deprecatedAddrToNewAddr(address)
@@ -30,7 +31,7 @@ const addressContent = (address: string) => {
{newAddress !== address && (
-
+
@@ -40,32 +41,33 @@ const addressContent = (address: string) => {
)
}
-const simpleUDTInfo = (udt: State.UDT) => {
+const useSimpleUDTInfo = (udt: State.UDT) => {
+ const { t } = useTranslation()
const { displayName, uan, fullName, issuerAddress, symbol, addressesCount, decimal, totalAmount } = udt
return [
{
- title: i18n.t('udt.name'),
+ title: t('udt.name'),
content: displayName || fullName,
},
{
- title: i18n.t('udt.issuer'),
+ title: t('udt.issuer'),
contentWrapperClass: styles.addressWidthModify,
- content: addressContent(issuerAddress),
+ content: useAddressContent(issuerAddress),
},
{
- title: i18n.t('udt.holder_addresses'),
+ title: t('udt.holder_addresses'),
content: addressesCount,
},
{
- title: i18n.t(uan ? 'udt.uan' : 'udt.symbol'),
+ title: t(uan ? 'udt.uan' : 'udt.symbol'),
content: uan || symbol,
},
{
- title: i18n.t('udt.decimal'),
+ title: t('udt.decimal'),
content: decimal,
},
{
- title: i18n.t('udt.total_amount'),
+ title: t('udt.total_amount'),
content: parseUDTAmount(totalAmount, decimal),
},
] as OverviewItemData[]
@@ -73,7 +75,7 @@ const simpleUDTInfo = (udt: State.UDT) => {
export const SimpleUDTOverview = ({ children, udt }: { children: ReactNode; udt: State.UDT }) => {
return (
-
+
{children}
)
@@ -96,12 +98,13 @@ export const SimpleUDTComp = ({
filterNoResult?: boolean
id: string
}) => {
+ const { t } = useTranslation()
const totalPages = Math.ceil(total / pageSize)
if (filterNoResult) {
return (
- {i18n.t('search.udt_filter_no_result')}
+ {t('search.udt_filter_no_result')}
)
}
diff --git a/src/pages/SimpleUDT/index.tsx b/src/pages/SimpleUDT/index.tsx
index bbbf33097..90a19a043 100644
--- a/src/pages/SimpleUDT/index.tsx
+++ b/src/pages/SimpleUDT/index.tsx
@@ -5,7 +5,6 @@ import { useQuery } from 'react-query'
import { Popover } from 'antd'
import SimpleUDTHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
-import i18n from '../../utils/i18n'
import { SimpleUDTContentPanel, UDTTransactionTitlePanel, TypeScriptController } from './styled'
import SimpleUDTComp, { SimpleUDTOverview } from './SimpleUDTComp'
import { useIsMobile, usePaginationParamsInPage } from '../../utils/hook'
@@ -40,10 +39,10 @@ enum TransactionType {
}
export const SimpleUDT = () => {
+ const { t } = useTranslation()
const isMobile = useIsMobile()
const { push } = useHistory()
const { search } = useLocation()
- const [t] = useTranslation()
const [showType, setShowType] = useState(false)
const { hash: typeHash } = useParams<{ hash: string }>()
const { currentPage, pageSize: _pageSize, setPage } = usePaginationParamsInPage()
@@ -95,15 +94,15 @@ export const SimpleUDT = () => {
const filterList: { value: TransactionType; title: string }[] = [
{
value: TransactionType.Mint,
- title: i18n.t('udt.view-mint-txns'),
+ title: t('udt.view-mint-txns'),
},
{
value: TransactionType.Transfer,
- title: i18n.t('udt.view-transfer-txns'),
+ title: t('udt.view-transfer-txns'),
},
{
value: TransactionType.Burn,
- title: i18n.t('udt.view-burn-txns'),
+ title: t('udt.view-burn-txns'),
},
]
@@ -112,14 +111,10 @@ export const SimpleUDT = () => {
return (
-
+
setShowType(!showType)}>
- {i18n.t('udt.type_script')}
+ {t('udt.type_script')}
{showType && typeScript && }
diff --git a/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx b/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx
index 3426ee07e..25ceb9ede 100644
--- a/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx
+++ b/src/pages/StatisticsChart/activities/AddressBalanceRank.tsx
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react'
import { useHistory } from 'react-router'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { useCurrentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, parseNumericAbbr } from '../../../utils/chart'
import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util'
import { localeNumberString } from '../../../utils/number'
@@ -15,86 +15,90 @@ const getAddressWithRanking = (statisticAddressBalanceRanks: State.StatisticAddr
return addressBalanceRank ? addressBalanceRank.address : ''
}
-const getOption = (
- statisticAddressBalanceRanks: State.StatisticAddressBalanceRank[],
- chartColor: State.ChartColor,
- isMobile: boolean,
- isThumbnail = false,
- getAdaptAddressText: (address: string) => string,
-): echarts.EChartOption => {
- const gridThumbnail = {
- left: '4%',
- right: '10%',
- top: '8%',
- bottom: '6%',
- containLabel: true,
- }
- const grid = {
- left: '5%',
- right: '3%',
- top: isMobile ? '3%' : '8%',
- bottom: '5%',
- containLabel: true,
- }
- return {
- color: chartColor.colors,
- tooltip: !isThumbnail
- ? {
- trigger: 'axis',
- formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 60 : 35)
- let result = `${tooltipColor('#333333')}${widthSpan(
- i18n.t('statistic.address'),
- )} ${getAdaptAddressText(getAddressWithRanking(statisticAddressBalanceRanks, dataList[0].name))} `
- result += `${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.balance'))} \
- ${localeNumberString(dataList[0].data)} ${i18n.t('common.ckb_unit')} `
- result += `${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.rank'))} ${
- dataList[0].name
- } `
- return result
+const useOption = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+ return (
+ statisticAddressBalanceRanks: State.StatisticAddressBalanceRank[],
+ chartColor: State.ChartColor,
+ isMobile: boolean,
+ isThumbnail = false,
+ getAdaptAddressText: (address: string) => string,
+ ): echarts.EChartOption => {
+ const gridThumbnail = {
+ left: '4%',
+ right: '10%',
+ top: '8%',
+ bottom: '6%',
+ containLabel: true,
+ }
+ const grid = {
+ left: '5%',
+ right: '3%',
+ top: isMobile ? '3%' : '8%',
+ bottom: '5%',
+ containLabel: true,
+ }
+ return {
+ color: chartColor.colors,
+ tooltip: !isThumbnail
+ ? {
+ trigger: 'axis',
+ formatter: (dataList: any) => {
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 60 : 35)
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.address'))} ${getAdaptAddressText(
+ getAddressWithRanking(statisticAddressBalanceRanks, dataList[0].name),
+ )} `
+ result += `${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.balance'))} \
+ ${localeNumberString(dataList[0].data)} ${t('common.ckb_unit')} `
+ result += `${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.rank'))} ${
+ dataList[0].name
+ } `
+ return result
+ },
+ }
+ : undefined,
+ grid: isThumbnail ? gridThumbnail : grid,
+ dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
+ xAxis: [
+ {
+ name: isMobile || isThumbnail ? '' : t('statistic.rank'),
+ nameLocation: 'middle',
+ nameGap: 30,
+ type: 'category',
+ boundaryGap: false,
+ data: statisticAddressBalanceRanks.map(data => data.ranking),
+ },
+ ],
+ yAxis: [
+ {
+ position: 'left',
+ name: isMobile || isThumbnail ? '' : `${t('statistic.balance_ranking')} ${t('statistic.log')}`,
+ type: 'log',
+ logBase: 10,
+ scale: true,
+ axisLine: {
+ lineStyle: {
+ color: chartColor.colors[0],
+ },
},
- }
- : undefined,
- grid: isThumbnail ? gridThumbnail : grid,
- dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
- xAxis: [
- {
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.rank'),
- nameLocation: 'middle',
- nameGap: 30,
- type: 'category',
- boundaryGap: false,
- data: statisticAddressBalanceRanks.map(data => data.ranking),
- },
- ],
- yAxis: [
- {
- position: 'left',
- name: isMobile || isThumbnail ? '' : `${i18n.t('statistic.balance_ranking')} ${i18n.t('statistic.log')}`,
- type: 'log',
- logBase: 10,
- scale: true,
- axisLine: {
- lineStyle: {
- color: chartColor.colors[0],
+ axisLabel: {
+ formatter: (value: string) => `${parseNumericAbbr(value)}`,
},
},
- axisLabel: {
- formatter: (value: string) => `${parseNumericAbbr(value)}`,
+ ],
+ series: [
+ {
+ name: t('statistic.balance_ranking'),
+ type: 'bar',
+ yAxisIndex: 0,
+ barWidth: 8,
+ symbol: isThumbnail ? 'none' : 'circle',
+ symbolSize: 3,
+ data: statisticAddressBalanceRanks.map(data => shannonToCkb(data.balance)),
},
- },
- ],
- series: [
- {
- name: i18n.t('statistic.balance_ranking'),
- type: 'bar',
- yAxisIndex: 0,
- barWidth: 8,
- symbol: isThumbnail ? 'none' : 'circle',
- symbolSize: 3,
- data: statisticAddressBalanceRanks.map(data => shannonToCkb(data.balance)),
- },
- ],
+ ],
+ }
}
}
@@ -128,9 +132,10 @@ export const AddressBalanceRankChart = ({ isThumbnail = false }: { isThumbnail?:
)
const adaptPCEllipsis = useAdaptPCEllipsis(60)
+ const parseOption = useOption()
const getEChartOption: SmartChartPageProps['getEChartOption'] = useCallback(
- (...args) => getOption(...args, address => adaptPCEllipsis(address, 6)),
- [adaptPCEllipsis],
+ (...args) => parseOption(...args, address => adaptPCEllipsis(address, 6)),
+ [adaptPCEllipsis, parseOption],
)
return (
diff --git a/src/pages/StatisticsChart/activities/AddressCount.tsx b/src/pages/StatisticsChart/activities/AddressCount.tsx
index 6d41c6084..4defb2c32 100644
--- a/src/pages/StatisticsChart/activities/AddressCount.tsx
+++ b/src/pages/StatisticsChart/activities/AddressCount.tsx
@@ -1,18 +1,20 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticAddressCounts: State.StatisticAddressCount[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -33,12 +35,10 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 155 : 110)
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 155 : 110)
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
result += `${tooltipColor(chartColor.colors[0])}\
- ${widthSpan(i18n.t('statistic.address_count'))} ${handleAxis(dataList[0].data[1])} `
+ ${widthSpan(t('statistic.address_count'))} ${handleAxis(dataList[0].data[1])} `
return result
},
}
@@ -47,7 +47,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -60,7 +60,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.address_count'),
+ name: isMobile || isThumbnail ? '' : t('statistic.address_count'),
type: 'value',
scale: true,
nameTextStyle: {
@@ -78,7 +78,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.address_count'),
+ name: t('statistic.address_count'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -105,7 +105,7 @@ export const AddressCountChart = ({ isThumbnail = false }: { isThumbnail?: boole
description={t('statistic.address_count_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticAddressCount}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.AddressCount}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/activities/BalanceDistribution.tsx b/src/pages/StatisticsChart/activities/BalanceDistribution.tsx
index 65146d09c..7af5da615 100644
--- a/src/pages/StatisticsChart/activities/BalanceDistribution.tsx
+++ b/src/pages/StatisticsChart/activities/BalanceDistribution.tsx
@@ -1,24 +1,31 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis, handleLogGroupAxis } from '../../../utils/chart'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { localeNumberString } from '../../../utils/number'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 270 : 110)
+const widthSpan = (value: string, currentLanguage: string) => tooltipWidth(value, currentLanguage === 'en' ? 270 : 110)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string }): string => {
- return `${tooltipColor(color)}${widthSpan(seriesName)} ${localeNumberString(data)} `
+const parseTooltip = ({
+ seriesName,
+ data,
+ color,
+ currentLanguage,
+}: SeriesItem & { data: string; currentLanguage: LanuageType }): string => {
+ return `${tooltipColor(color)}${widthSpan(seriesName, currentLanguage)} ${localeNumberString(data)} `
}
-const getOption = (
+const useOption = (
statisticBalanceDistributions: State.StatisticBalanceDistribution[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '4%',
@@ -41,13 +48,14 @@ const getOption = (
formatter: (dataList: any) => {
const list = dataList as (SeriesItem & { data: string })[]
let result = `${tooltipColor('#333333')}${widthSpan(
- i18n.t('statistic.addresses_balance'),
+ t('statistic.addresses_balance'),
+ currentLanguage,
)} ${handleLogGroupAxis(
new BigNumber(list[0].name),
list[0].dataIndex === statisticBalanceDistributions.length - 1 ? '+' : '',
- )} ${i18n.t('common.ckb_unit')} `
+ )} ${t('common.ckb_unit')}`
list.forEach(data => {
- result += parseTooltip(data)
+ result += parseTooltip({ ...data, currentLanguage })
})
return result
},
@@ -57,10 +65,10 @@ const getOption = (
? {
data: [
{
- name: i18n.t('statistic.addresses_balance_group'),
+ name: t('statistic.addresses_balance_group'),
},
{
- name: i18n.t('statistic.addresses_below_specific_balance'),
+ name: t('statistic.addresses_below_specific_balance'),
},
],
}
@@ -69,7 +77,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : `${i18n.t('statistic.addresses_balance')} (CKB)`,
+ name: isMobile || isThumbnail ? '' : `${t('statistic.addresses_balance')} (CKB)`,
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -87,7 +95,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.addresses_balance_group'),
+ name: isMobile || isThumbnail ? '' : t('statistic.addresses_balance_group'),
type: 'value',
scale: true,
nameTextStyle: {
@@ -104,7 +112,7 @@ const getOption = (
},
{
position: 'right',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.addresses_below_specific_balance'),
+ name: isMobile || isThumbnail ? '' : t('statistic.addresses_below_specific_balance'),
type: 'value',
splitLine: {
show: false,
@@ -125,7 +133,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.addresses_balance_group'),
+ name: t('statistic.addresses_balance_group'),
type: 'bar',
areaStyle: {
color: chartColor.areaColor,
@@ -135,7 +143,7 @@ const getOption = (
data: statisticBalanceDistributions.map(data => new BigNumber(data.addresses).toNumber()),
},
{
- name: i18n.t('statistic.addresses_below_specific_balance'),
+ name: t('statistic.addresses_below_specific_balance'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
@@ -180,7 +188,7 @@ export const BalanceDistributionChart = ({ isThumbnail = false }: { isThumbnail?
description={t('statistic.balance_distribution_description')}
isThumbnail={isThumbnail}
fetchData={fetchStatisticBalanceDistributions}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.BalanceDistribution}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/activities/CellCount.tsx b/src/pages/StatisticsChart/activities/CellCount.tsx
index 159f09b0c..9ebe59486 100644
--- a/src/pages/StatisticsChart/activities/CellCount.tsx
+++ b/src/pages/StatisticsChart/activities/CellCount.tsx
@@ -1,33 +1,50 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 125 : 80)
+const widthSpan = (value: string, currentLanguage: LanuageType) =>
+ tooltipWidth(value, currentLanguage === 'en' ? 125 : 80)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
- if (seriesName === i18n.t('statistic.dead_cell')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.dead_cell'))} ${handleAxis(data[2], 2)} `
+const useTooltip = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+ return ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
+ if (seriesName === t('statistic.dead_cell')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.dead_cell'), currentLanguage)} ${handleAxis(
+ data[2],
+ 2,
+ )} `
+ }
+ if (seriesName === t('statistic.all_cells')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.all_cells'), currentLanguage)} ${handleAxis(
+ data[1],
+ 2,
+ )} `
+ }
+ if (seriesName === t('statistic.live_cell')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.live_cell'), currentLanguage)} ${handleAxis(
+ data[3],
+ 2,
+ )} `
+ }
+ return ''
}
- if (seriesName === i18n.t('statistic.all_cells')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.all_cells'))} ${handleAxis(data[1], 2)} `
- }
- if (seriesName === i18n.t('statistic.live_cell')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.live_cell'))} ${handleAxis(data[3], 2)} `
- }
- return ''
}
-const getOption = (
+const useOption = (
statisticCellCounts: State.StatisticCellCount[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -42,6 +59,7 @@ const getOption = (
bottom: '5%',
containLabel: true,
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.colors,
tooltip: !isThumbnail
@@ -49,7 +67,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'), currentLanguage)} ${
list[0].data[0]
} `
list.forEach(data => {
@@ -64,13 +82,13 @@ const getOption = (
? []
: [
{
- name: i18n.t('statistic.all_cells'),
+ name: t('statistic.all_cells'),
},
{
- name: i18n.t('statistic.live_cell'),
+ name: t('statistic.live_cell'),
},
{
- name: i18n.t('statistic.dead_cell'),
+ name: t('statistic.dead_cell'),
},
],
},
@@ -78,7 +96,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -102,7 +120,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.all_cells'),
+ name: t('statistic.all_cells'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -115,7 +133,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.dead_cell'),
+ name: t('statistic.dead_cell'),
type: 'line',
stack: 'sum',
yAxisIndex: 0,
@@ -126,7 +144,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.live_cell'),
+ name: t('statistic.live_cell'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -166,7 +184,7 @@ export const CellCountChart = ({ isThumbnail = false }: { isThumbnail?: boolean
title={t('statistic.cell_count')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticCellCount}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.CellCount}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/activities/TransactionCount.tsx b/src/pages/StatisticsChart/activities/TransactionCount.tsx
index 933d35e2f..e1756fea4 100644
--- a/src/pages/StatisticsChart/activities/TransactionCount.tsx
+++ b/src/pages/StatisticsChart/activities/TransactionCount.tsx
@@ -1,18 +1,22 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticTransactionCounts: State.StatisticTransactionCount[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -33,12 +37,10 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 120 : 65)
- let result = ` ${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 120 : 65)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(
- i18n.t('statistic.transaction_count'),
+ t('statistic.transaction_count'),
)} ${handleAxis(dataList[0].data[1])} `
return result
},
@@ -48,7 +50,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -58,7 +60,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.transaction_count'),
+ name: isMobile || isThumbnail ? '' : t('statistic.transaction_count'),
type: 'value',
scale: true,
axisLine: {
@@ -73,7 +75,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.transaction_count'),
+ name: t('statistic.transaction_count'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -101,7 +103,7 @@ export const TransactionCountChart = ({ isThumbnail = false }: { isThumbnail?: b
title={t('statistic.transaction_count')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticTransactionCount}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.TransactionCount}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/activities/TxFeeHistory.tsx b/src/pages/StatisticsChart/activities/TxFeeHistory.tsx
index 75b8aa870..f21cf514b 100644
--- a/src/pages/StatisticsChart/activities/TxFeeHistory.tsx
+++ b/src/pages/StatisticsChart/activities/TxFeeHistory.tsx
@@ -1,6 +1,5 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
@@ -8,13 +7,17 @@ import { shannonToCkbDecimal } from '../../../utils/util'
import { isMainnet } from '../../../utils/chain'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticTxFeeHistories: State.StatisticTransactionFee[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -35,11 +38,9 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 145 : 90)
- let result = ` ${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
- result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.tx_fee'))} ${handleAxis(
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 145 : 90)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
+ result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.tx_fee'))} ${handleAxis(
dataList[0].data[1],
)} `
return result
@@ -50,7 +51,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -63,7 +64,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : `${i18n.t('statistic.tx_fee')} ${i18n.t('statistic.log')}`,
+ name: isMobile || isThumbnail ? '' : `${t('statistic.tx_fee')} ${t('statistic.log')}`,
type: isMainnet() ? 'log' : 'value',
logBase: 10,
scale: true,
@@ -79,7 +80,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.tx_fee'),
+ name: t('statistic.tx_fee'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -108,7 +109,7 @@ export const TxFeeHistoryChart = ({ isThumbnail = false }: { isThumbnail?: boole
description={t('statistic.tx_fee_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticTxFeeHistory}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.TransactionFee}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/block/AverageBlockTime.tsx b/src/pages/StatisticsChart/block/AverageBlockTime.tsx
index 128e7a3e3..ed573a62e 100644
--- a/src/pages/StatisticsChart/block/AverageBlockTime.tsx
+++ b/src/pages/StatisticsChart/block/AverageBlockTime.tsx
@@ -1,18 +1,20 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { parseDateNoTime, parseSimpleDate, parseSimpleDateNoSecond } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { localeNumberString } from '../../../utils/number'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticAverageBlockTimes: State.StatisticAverageBlockTime[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '3%',
right: '3%',
@@ -36,16 +38,16 @@ const getOption = (
}
}
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 180 : 100)
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 180 : 100)
const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string }): string => {
- if (seriesName === i18n.t('statistic.daily_moving_average')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.daily_moving_average'))} ${localeNumberString(
+ if (seriesName === t('statistic.daily_moving_average')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.daily_moving_average'))} ${localeNumberString(
data[1],
)} `
}
- if (seriesName === i18n.t('statistic.weekly_moving_average')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.weekly_moving_average'))} ${localeNumberString(
+ if (seriesName === t('statistic.weekly_moving_average')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.weekly_moving_average'))} ${localeNumberString(
data[2],
)} `
}
@@ -58,9 +60,11 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(
- i18n.t('statistic.date'),
- )} ${parseSimpleDateNoSecond(new Date(list[0].data[0]), '/', false)} `
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${parseSimpleDateNoSecond(
+ new Date(list[0].data[0]),
+ '/',
+ false,
+ )} `
list.forEach(data => {
result += parseTooltip(data)
})
@@ -72,10 +76,10 @@ const getOption = (
? {
data: [
{
- name: i18n.t('statistic.daily_moving_average'),
+ name: t('statistic.daily_moving_average'),
},
{
- name: i18n.t('statistic.weekly_moving_average'),
+ name: t('statistic.weekly_moving_average'),
},
],
}
@@ -84,7 +88,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category', // TODO: use type: time
@@ -100,7 +104,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.daily_moving_average'),
+ name: isMobile || isThumbnail ? '' : t('statistic.daily_moving_average'),
type: 'value',
scale: true,
nameTextStyle: {
@@ -119,7 +123,7 @@ const getOption = (
},
{
position: 'right',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.weekly_moving_average'),
+ name: isMobile || isThumbnail ? '' : t('statistic.weekly_moving_average'),
type: 'value',
scale: true,
nameTextStyle: {
@@ -139,7 +143,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.daily_moving_average'),
+ name: t('statistic.daily_moving_average'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -150,7 +154,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.weekly_moving_average'),
+ name: t('statistic.weekly_moving_average'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
@@ -185,7 +189,7 @@ export const AverageBlockTimeChart = ({ isThumbnail = false }: { isThumbnail?: b
description={t('statistic.average_block_time_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticAverageBlockTimes}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.AverageBlockTime}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx b/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx
index 8d4cde2a6..fe06a2929 100644
--- a/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx
+++ b/src/pages/StatisticsChart/block/BlockTimeDistribution.tsx
@@ -1,16 +1,19 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticBlockTimeDistributions: State.StatisticBlockTimeDistribution[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -31,11 +34,9 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 80 : 80)
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.time'))} ${
- dataList[0].name
- } `
- result += `${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.block_count'))} ${
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 80 : 80)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.time'))} ${dataList[0].name} `
+ result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.block_count'))} ${
dataList[0].data
}% `
return result
@@ -46,7 +47,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.time'),
+ name: isMobile || isThumbnail ? '' : t('statistic.time'),
nameLocation: 'middle',
nameGap: 30,
data: statisticBlockTimeDistributions.map(data => data.time),
@@ -59,7 +60,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.block_count'),
+ name: isMobile || isThumbnail ? '' : t('statistic.block_count'),
type: 'value',
scale: true,
axisLine: {
@@ -74,7 +75,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.block_count'),
+ name: t('statistic.block_count'),
type: 'line',
yAxisIndex: 0,
areaStyle: {
@@ -124,7 +125,7 @@ export const BlockTimeDistributionChart = ({ isThumbnail = false }: { isThumbnai
description={t('statistic.block_time_distribution_description')}
isThumbnail={isThumbnail}
fetchData={fetchStatisticBlockTimeDistributions}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.BlockTimeDistribution}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx b/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx
index 6b3d552fd..39358624a 100644
--- a/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx
+++ b/src/pages/StatisticsChart/block/EpochTimeDistribution.tsx
@@ -1,18 +1,22 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { localeNumberString } from '../../../utils/number'
import { parseHourFromMinute } from '../../../utils/date'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticEpochTimeDistributions: State.StatisticEpochTimeDistribution[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -33,13 +37,13 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 80 : 80)
- let result = ` ${tooltipColor('#333333')}${widthSpan(
- i18n.t('statistic.time_hour'),
- )} ${parseHourFromMinute(dataList[0].name)} `
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 80 : 80)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.time_hour'))} ${parseHourFromMinute(
+ dataList[0].name,
+ )} `
result += `\
${tooltipColor(chartColor.colors[0])}\
- ${widthSpan(i18n.t('statistic.epochs'))} \
+ ${widthSpan(t('statistic.epochs'))} \
${localeNumberString(dataList[0].data)} `
return result
},
@@ -49,7 +53,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.time_hour'),
+ name: isMobile || isThumbnail ? '' : t('statistic.time_hour'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -63,7 +67,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.epochs'),
+ name: isMobile || isThumbnail ? '' : t('statistic.epochs'),
type: 'value',
scale: true,
axisLine: {
@@ -78,7 +82,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.epochs'),
+ name: t('statistic.epochs'),
type: 'bar',
yAxisIndex: 0,
areaStyle: {
@@ -118,7 +122,7 @@ export const EpochTimeDistributionChart = ({ isThumbnail = false }: { isThumbnai
description={t('statistic.epoch_time_distribution_description')}
isThumbnail={isThumbnail}
fetchData={fetchStatisticEpochTimeDistributions}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.EpochTimeDistribution}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/common/index.tsx b/src/pages/StatisticsChart/common/index.tsx
index d12885913..9dbe7139e 100644
--- a/src/pages/StatisticsChart/common/index.tsx
+++ b/src/pages/StatisticsChart/common/index.tsx
@@ -12,13 +12,13 @@ import 'echarts/lib/component/dataZoom'
import 'echarts/lib/component/brush'
import echarts from 'echarts/lib/echarts'
import { EChartOption, ECharts } from 'echarts'
+import { useTranslation } from 'react-i18next'
import { LoadingPanel, ChartNoDataPanel, ChartDetailTitle, ChartDetailPanel, ChartNotePanel } from './styled'
import Loading from '../../../components/Loading'
import ChartNoDataImage from '../../../assets/chart_no_data.png'
import ChartNoDataAggronImage from '../../../assets/chart_no_data_aggron.png'
import { isMainnet } from '../../../utils/chain'
import SmallLoading from '../../../components/Loading/SmallLoading'
-import i18n from '../../../utils/i18n'
import Content from '../../../components/Content'
import { useChartQueryWithCache, useIsMobile, usePrevious, useWindowResize } from '../../../utils/hook'
import { isDeepEqual } from '../../../utils/util'
@@ -28,18 +28,21 @@ import { Response } from '../../../services/ExplorerService'
const LoadingComp = ({ isThumbnail }: { isThumbnail?: boolean }) => (isThumbnail ? : )
-const ChartLoading = ({ show, isThumbnail = false }: { show: boolean; isThumbnail?: boolean }) => (
-
- {show ? (
-
- ) : (
-
-
- {i18n.t('statistic.no_data')}
-
- )}
-
-)
+const ChartLoading = ({ show, isThumbnail = false }: { show: boolean; isThumbnail?: boolean }) => {
+ const { t } = useTranslation()
+ return (
+
+ {show ? (
+
+ ) : (
+
+
+ {t('statistic.no_data')}
+
+ )}
+
+ )
+}
const ReactChartCore = ({
option,
@@ -123,6 +126,7 @@ const ChartPage = ({
data?: (string | number)[][]
}) => {
const csv = dataToCsv(data)
+ const { t } = useTranslation()
const fileName = (title.indexOf(' (') > 0 ? title.substring(0, title.indexOf(' (')) : title)
.replace(/&/g, '')
.toLowerCase()
@@ -142,7 +146,7 @@ const ChartPage = ({
target="_blank"
download={`${fileName}.csv`}
>
- {i18n.t('statistic.download_data')}
+ {t('statistic.download_data')}
)}
@@ -163,7 +167,7 @@ export interface SmartChartPageProps {
dataList: T[],
chartColor: State.ChartColor,
isMobile: boolean,
- isThumbnail: boolean,
+ isThumbnail?: boolean,
) => echarts.EChartOption
toCSV: (dataList: T[]) => (string | number)[][]
cacheKey?: string
diff --git a/src/pages/StatisticsChart/index.tsx b/src/pages/StatisticsChart/index.tsx
index c6fbce4f8..f365ec4df 100644
--- a/src/pages/StatisticsChart/index.tsx
+++ b/src/pages/StatisticsChart/index.tsx
@@ -1,8 +1,8 @@
import { ReactNode } from 'react'
import { Link } from 'react-router-dom'
import 'default-passive-events'
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
-import i18n from '../../utils/i18n'
import { DifficultyHashRateChart } from './mining/DifficultyHashRate'
import { DifficultyUncleRateEpochChart } from './mining/DifficultyUncleRateEpoch'
import { TransactionCountChart } from './activities/TransactionCount'
@@ -65,174 +65,179 @@ const ChartCard = ({ chartData }: { chartData: ChartData }) => {
)
}
-const chartsData = (): ChartCategory[] => [
- {
- category: i18n.t('statistic.category_block'),
- charts: [
- {
- title: `${i18n.t('statistic.block_time_distribution')}`,
- chart: ,
- path: '/charts/block-time-distribution',
- description: i18n.t('statistic.block_time_distribution_description'),
- },
- {
- title: `${i18n.t('statistic.epoch_time_distribution')}`,
- chart: ,
- path: '/charts/epoch-time-distribution',
- description: i18n.t('statistic.epoch_time_distribution_description'),
- },
- {
- title: `${i18n.t('statistic.average_block_time')}`,
- chart: ,
- path: '/charts/average-block-time',
- description: i18n.t('statistic.average_block_time_description'),
- },
- ],
- },
- {
- category: i18n.t('statistic.category_mining'),
- charts: [
- {
- title: `${i18n.t('block.difficulty')} & ${i18n.t('block.hash_rate')} & ${i18n.t('block.uncle_rate')}`,
- chart: ,
- path: '/charts/difficulty-hash-rate',
- },
- {
- title: `${i18n.t('block.epoch_time')} & ${i18n.t('block.epoch_length')}`,
- chart: ,
- path: '/charts/epoch-time-length',
- },
- {
- title: `${i18n.t('block.difficulty')}`,
- chart: ,
- path: '/charts/difficulty',
- },
- {
- title: `${i18n.t('block.hash_rate')}`,
- chart: ,
- path: '/charts/hash-rate',
- description: i18n.t('glossary.hash_rate'),
- },
- {
- title: `${i18n.t('block.uncle_rate')}`,
- chart: ,
- path: '/charts/uncle-rate',
- description: i18n.t('statistic.uncle_rate_description'),
- },
- {
- title: `${i18n.t('statistic.miner_addresses_rank')}`,
- chart: ,
- path: '/charts/miner-address-distribution',
- },
- {
- title: `${i18n.t('statistic.miner_version_distribution')}`,
- chart: ,
- path: '/charts/miner-version-distribution',
- },
- ],
- },
- {
- category: i18n.t('statistic.category_activities'),
- charts: [
- {
- title: `${i18n.t('statistic.transaction_count')}`,
- chart: ,
- path: '/charts/transaction-count',
- },
- {
- title: `${i18n.t('statistic.address_count')}`,
- chart: ,
- path: '/charts/address-count',
- description: i18n.t('statistic.address_count_description'),
- },
- {
- title: i18n.t('statistic.cell_count'),
- chart: ,
- path: '/charts/cell-count',
- },
- {
- title: `${i18n.t('statistic.balance_ranking')}`,
- chart: ,
- path: '/charts/address-balance-rank',
- description: i18n.t('statistic.balance_ranking_description'),
- },
- {
- title: `${i18n.t('statistic.balance_distribution')}`,
- chart: ,
- path: '/charts/balance-distribution',
- description: i18n.t('statistic.balance_distribution_description'),
- },
- {
- title: `${i18n.t('statistic.tx_fee_history')}`,
- chart: ,
- path: '/charts/tx-fee-history',
- description: i18n.t('statistic.tx_fee_description'),
- },
- ],
- },
- {
- category: i18n.t('blockchain.nervos_dao'),
- charts: [
- {
- title: `${i18n.t('statistic.total_dao_deposit_title')}`,
- chart: ,
- path: '/charts/total-dao-deposit',
- description: i18n.t('statistic.total_dao_deposit_description'),
- },
- {
- title: `${i18n.t('statistic.new_dao_deposit_title')}`,
- chart: ,
- path: '/charts/new-dao-deposit',
- },
- {
- title: `${i18n.t('statistic.circulation_ratio')}`,
- chart: ,
- path: '/charts/circulation-ratio',
- description: i18n.t('statistic.deposit_to_circulation_ratio_description'),
- },
- ],
- },
- {
- category: i18n.t('statistic.category_monetary'),
- charts: [
- {
- title: `${i18n.t('statistic.total_supply')}`,
- chart: ,
- path: '/charts/total-supply',
- description: i18n.t('statistic.total_supply_description'),
- },
- {
- title: `${i18n.t('statistic.nominal_apc')}`,
- chart: ,
- path: '/charts/nominal-apc',
- description: i18n.t('statistic.nominal_rpc_description'),
- },
- {
- title: `${i18n.t('nervos_dao.secondary_issuance')}`,
- chart: ,
- path: '/charts/secondary-issuance',
- description: i18n.t('statistic.secondary_issuance_description'),
- },
- {
- title: `${i18n.t('statistic.inflation_rate')}`,
- chart: ,
- path: '/charts/inflation-rate',
- description: i18n.t('statistic.inflation_rate_description'),
- },
- {
- title: `${i18n.t('statistic.liquidity')}`,
- chart: ,
- path: '/charts/liquidity',
- },
- ],
- },
-]
+const useChartsData = () => {
+ const { t } = useTranslation()
+ return (): ChartCategory[] => [
+ {
+ category: t('statistic.category_block'),
+ charts: [
+ {
+ title: `${t('statistic.block_time_distribution')}`,
+ chart: ,
+ path: '/charts/block-time-distribution',
+ description: t('statistic.block_time_distribution_description'),
+ },
+ {
+ title: `${t('statistic.epoch_time_distribution')}`,
+ chart: ,
+ path: '/charts/epoch-time-distribution',
+ description: t('statistic.epoch_time_distribution_description'),
+ },
+ {
+ title: `${t('statistic.average_block_time')}`,
+ chart: ,
+ path: '/charts/average-block-time',
+ description: t('statistic.average_block_time_description'),
+ },
+ ],
+ },
+ {
+ category: t('statistic.category_mining'),
+ charts: [
+ {
+ title: `${t('block.difficulty')} & ${t('block.hash_rate')} & ${t('block.uncle_rate')}`,
+ chart: ,
+ path: '/charts/difficulty-hash-rate',
+ },
+ {
+ title: `${t('block.epoch_time')} & ${t('block.epoch_length')}`,
+ chart: ,
+ path: '/charts/epoch-time-length',
+ },
+ {
+ title: `${t('block.difficulty')}`,
+ chart: ,
+ path: '/charts/difficulty',
+ },
+ {
+ title: `${t('block.hash_rate')}`,
+ chart: ,
+ path: '/charts/hash-rate',
+ description: t('glossary.hash_rate'),
+ },
+ {
+ title: `${t('block.uncle_rate')}`,
+ chart: ,
+ path: '/charts/uncle-rate',
+ description: t('statistic.uncle_rate_description'),
+ },
+ {
+ title: `${t('statistic.miner_addresses_rank')}`,
+ chart: ,
+ path: '/charts/miner-address-distribution',
+ },
+ {
+ title: `${t('statistic.miner_version_distribution')}`,
+ chart: ,
+ path: '/charts/miner-version-distribution',
+ },
+ ],
+ },
+ {
+ category: t('statistic.category_activities'),
+ charts: [
+ {
+ title: `${t('statistic.transaction_count')}`,
+ chart: ,
+ path: '/charts/transaction-count',
+ },
+ {
+ title: `${t('statistic.address_count')}`,
+ chart: ,
+ path: '/charts/address-count',
+ description: t('statistic.address_count_description'),
+ },
+ {
+ title: t('statistic.cell_count'),
+ chart: ,
+ path: '/charts/cell-count',
+ },
+ {
+ title: `${t('statistic.balance_ranking')}`,
+ chart: ,
+ path: '/charts/address-balance-rank',
+ description: t('statistic.balance_ranking_description'),
+ },
+ {
+ title: `${t('statistic.balance_distribution')}`,
+ chart: ,
+ path: '/charts/balance-distribution',
+ description: t('statistic.balance_distribution_description'),
+ },
+ {
+ title: `${t('statistic.tx_fee_history')}`,
+ chart: ,
+ path: '/charts/tx-fee-history',
+ description: t('statistic.tx_fee_description'),
+ },
+ ],
+ },
+ {
+ category: t('blockchain.nervos_dao'),
+ charts: [
+ {
+ title: `${t('statistic.total_dao_deposit_title')}`,
+ chart: ,
+ path: '/charts/total-dao-deposit',
+ description: t('statistic.total_dao_deposit_description'),
+ },
+ {
+ title: `${t('statistic.new_dao_deposit_title')}`,
+ chart: ,
+ path: '/charts/new-dao-deposit',
+ },
+ {
+ title: `${t('statistic.circulation_ratio')}`,
+ chart: ,
+ path: '/charts/circulation-ratio',
+ description: t('statistic.deposit_to_circulation_ratio_description'),
+ },
+ ],
+ },
+ {
+ category: t('statistic.category_monetary'),
+ charts: [
+ {
+ title: `${t('statistic.total_supply')}`,
+ chart: ,
+ path: '/charts/total-supply',
+ description: t('statistic.total_supply_description'),
+ },
+ {
+ title: `${t('statistic.nominal_apc')}`,
+ chart: ,
+ path: '/charts/nominal-apc',
+ description: t('statistic.nominal_rpc_description'),
+ },
+ {
+ title: `${t('nervos_dao.secondary_issuance')}`,
+ chart: ,
+ path: '/charts/secondary-issuance',
+ description: t('statistic.secondary_issuance_description'),
+ },
+ {
+ title: `${t('statistic.inflation_rate')}`,
+ chart: ,
+ path: '/charts/inflation-rate',
+ description: t('statistic.inflation_rate_description'),
+ },
+ {
+ title: `${t('statistic.liquidity')}`,
+ chart: ,
+ path: '/charts/liquidity',
+ },
+ ],
+ },
+ ]
+}
export default () => {
+ const { t } = useTranslation()
+ const chartsData = useChartsData()
return (
- {i18n.t('statistic.charts_title')}
+ {t('statistic.charts_title')}
{chartsData().map(chartData => (
{chartData.category}
diff --git a/src/pages/StatisticsChart/mining/Difficulty.tsx b/src/pages/StatisticsChart/mining/Difficulty.tsx
index 3bd7b723b..75274cb3a 100644
--- a/src/pages/StatisticsChart/mining/Difficulty.tsx
+++ b/src/pages/StatisticsChart/mining/Difficulty.tsx
@@ -1,19 +1,22 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { handleDifficulty } from '../../../utils/number'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticDifficulties: State.StatisticDifficulty[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -34,12 +37,10 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 70 : 35)
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 70 : 35)
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
result += `${tooltipColor(chartColor.colors[0])}\
- ${widthSpan(i18n.t('block.difficulty'))} ${handleDifficulty(dataList[0].data[1])} `
+ ${widthSpan(t('block.difficulty'))} ${handleDifficulty(dataList[0].data[1])} `
return result
},
}
@@ -48,7 +49,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -58,7 +59,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('block.difficulty'),
+ name: isMobile || isThumbnail ? '' : t('block.difficulty'),
type: 'value',
scale: true,
axisLine: {
@@ -73,7 +74,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('block.difficulty'),
+ name: t('block.difficulty'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -104,7 +105,7 @@ export const DifficultyChart = ({ isThumbnail = false }: { isThumbnail?: boolean
title={t('block.difficulty')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticDifficulty}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.Difficulty}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx b/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx
index dcf53f444..f8ae4840c 100644
--- a/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx
+++ b/src/pages/StatisticsChart/mining/DifficultyHashRate.tsx
@@ -1,18 +1,21 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { handleDifficulty, handleHashRate } from '../../../utils/number'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticDifficultyHashRates: State.StatisticDifficultyHashRate[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '4%',
@@ -28,20 +31,23 @@ const getOption = (
containLabel: true,
})
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 70 : 50)
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 70 : 50)
- const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string }): string => {
- if (seriesName === i18n.t('block.uncle_rate')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('block.uncle_rate'))} ${data}% `
- }
- if (seriesName === i18n.t('block.difficulty')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('block.difficulty'))} ${handleDifficulty(data)} `
- }
- if (seriesName.startsWith(i18n.t('block.hash_rate'))) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('block.hash_rate'))} ${handleHashRate(data)} `
+ const useTooltip = () => {
+ return ({ seriesName, data, color }: SeriesItem & { data: string }): string => {
+ if (seriesName === t('block.uncle_rate')) {
+ return `${tooltipColor(color)}${widthSpan(t('block.uncle_rate'))} ${data}% `
+ }
+ if (seriesName === t('block.difficulty')) {
+ return `${tooltipColor(color)}${widthSpan(t('block.difficulty'))} ${handleDifficulty(data)} `
+ }
+ if (seriesName.startsWith(t('block.hash_rate'))) {
+ return `${tooltipColor(color)}${widthSpan(t('block.hash_rate'))} ${handleHashRate(data)} `
+ }
+ return ''
}
- return ''
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.moreColors,
tooltip: !isThumbnail
@@ -49,7 +55,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any): string => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('block.epoch'))} ${list[0].name} `
+ let result = `${tooltipColor('#333333')}${widthSpan(t('block.epoch'))} ${list[0].name} `
list.forEach(data => {
result += parseTooltip(data)
})
@@ -61,13 +67,13 @@ const getOption = (
? {
data: [
{
- name: i18n.t('block.difficulty'),
+ name: t('block.difficulty'),
},
{
- name: i18n.t('block.hash_rate_hps'),
+ name: t('block.hash_rate_hps'),
},
{
- name: i18n.t('block.uncle_rate'),
+ name: t('block.uncle_rate'),
},
],
}
@@ -76,7 +82,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('block.epoch'),
+ name: isMobile || isThumbnail ? '' : t('block.epoch'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -90,7 +96,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('block.difficulty'),
+ name: isMobile || isThumbnail ? '' : t('block.difficulty'),
type: 'value',
scale: true,
axisLine: {
@@ -104,7 +110,7 @@ const getOption = (
},
{
position: 'right',
- name: isMobile || isThumbnail ? '' : i18n.t('block.hash_rate_hps'),
+ name: isMobile || isThumbnail ? '' : t('block.hash_rate_hps'),
type: 'value',
splitLine: {
show: false,
@@ -131,7 +137,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('block.difficulty'),
+ name: t('block.difficulty'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -139,7 +145,7 @@ const getOption = (
data: statisticDifficultyHashRates.map(data => new BigNumber(data.difficulty).toNumber()),
},
{
- name: i18n.t('block.hash_rate_hps'),
+ name: t('block.hash_rate_hps'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
@@ -147,7 +153,7 @@ const getOption = (
data: statisticDifficultyHashRates.map(data => new BigNumber(data.hashRate).toNumber()),
},
{
- name: i18n.t('block.uncle_rate'),
+ name: t('block.uncle_rate'),
type: 'line',
smooth: true,
yAxisIndex: 2,
@@ -160,7 +166,7 @@ const getOption = (
symbol: 'none',
data: [
{
- name: i18n.t('block.uncle_rate_target'),
+ name: t('block.uncle_rate_target'),
yAxis: 2.5,
},
],
@@ -186,7 +192,7 @@ export const DifficultyHashRateChart = ({ isThumbnail = false }: { isThumbnail?:
title={`${t('block.difficulty')} & ${t('block.hash_rate')} & ${t('block.uncle_rate')}`}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticDifficultyHashRate}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.DifficultyHashRate}
cacheMode="epoch"
diff --git a/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx b/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx
index 51b833e52..d371058ff 100644
--- a/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx
+++ b/src/pages/StatisticsChart/mining/DifficultyUncleRateEpoch.tsx
@@ -1,31 +1,40 @@
import { FC } from 'react'
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { handleAxis } from '../../../utils/chart'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { parseHourFromMillisecond } from '../../../utils/date'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 90 : 80)
+const widthSpan = (value: string, currentLanguage: LanuageType) =>
+ tooltipWidth(value, currentLanguage === 'en' ? 90 : 80)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string }) => {
- if (seriesName === i18n.t('block.epoch_time')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('block.epoch_time'))} ${data} h `
+const useTooltip = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+ return ({ seriesName, data, color }: SeriesItem & { data: string }) => {
+ if (seriesName === t('block.epoch_time')) {
+ return `${tooltipColor(color)}${widthSpan(t('block.epoch_time'), currentLanguage)} ${data} h `
+ }
+ if (seriesName === t('block.epoch_length')) {
+ return `${tooltipColor(color)}${widthSpan(t('block.epoch_length'), currentLanguage)} ${data} `
+ }
+ return ''
}
- if (seriesName === i18n.t('block.epoch_length')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('block.epoch_length'))} ${data} `
- }
- return ''
}
-const getOption = (
+const useOption = (
statisticChartData: State.StatisticDifficultyUncleRateEpoch[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '4%',
@@ -47,6 +56,7 @@ const getOption = (
const epochLengthSerie = statisticChartData.map(data => data.epochLength)
const endValue = statisticChartData[statisticChartData.length - 1]?.epochNumber ?? '0'
const startValue = Math.max(+endValue - COUNT_IN_THUMBNAIL, 0).toString()
+ const parseTooltip = useTooltip()
return {
color: chartColor.moreColors,
@@ -55,7 +65,9 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('block.epoch'))} ${list[0].name} `
+ let result = `${tooltipColor('#333333')}${widthSpan(t('block.epoch'), currentLanguage)} ${
+ list[0].name
+ } `
list.forEach(data => {
result += parseTooltip(data)
})
@@ -67,10 +79,10 @@ const getOption = (
? {
data: [
{
- name: i18n.t('block.epoch_time'),
+ name: t('block.epoch_time'),
},
{
- name: i18n.t('block.epoch_length'),
+ name: t('block.epoch_length'),
},
],
textStyle: {
@@ -100,7 +112,7 @@ const getOption = (
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('block.epoch'),
+ name: isMobile || isThumbnail ? '' : t('block.epoch'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -114,7 +126,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('block.epoch_time'),
+ name: isMobile || isThumbnail ? '' : t('block.epoch_time'),
type: 'value',
scale: true,
axisLine: {
@@ -128,7 +140,7 @@ const getOption = (
},
{
position: 'right',
- name: isMobile || isThumbnail ? '' : i18n.t('block.epoch_length'),
+ name: isMobile || isThumbnail ? '' : t('block.epoch_length'),
type: 'value',
scale: true,
splitLine: {
@@ -167,7 +179,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('block.epoch_time'),
+ name: t('block.epoch_time'),
type: 'bar',
step: 'start',
yAxisIndex: 0,
@@ -176,7 +188,7 @@ const getOption = (
data: isThumbnail ? epochTimeSerie.slice(-1 * COUNT_IN_THUMBNAIL) : epochTimeSerie,
},
{
- name: i18n.t('block.epoch_length'),
+ name: t('block.epoch_length'),
type: 'bar',
step: 'start',
yAxisIndex: 1,
@@ -200,7 +212,7 @@ export const DifficultyUncleRateEpochChart: FC<{ isThumbnail?: boolean }> = ({ i
title={`${t('block.epoch_time')} & ${t('block.epoch_length')}`}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticDifficultyUncleRateEpoch}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.DifficultyUncleRateEpoch}
cacheMode="epoch"
diff --git a/src/pages/StatisticsChart/mining/HashRate.tsx b/src/pages/StatisticsChart/mining/HashRate.tsx
index 941f7a377..678bd8861 100644
--- a/src/pages/StatisticsChart/mining/HashRate.tsx
+++ b/src/pages/StatisticsChart/mining/HashRate.tsx
@@ -1,19 +1,23 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, handleAxis } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { handleHashRate } from '../../../utils/number'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
+import { useCurrentLanguage } from '../../../utils/i18n'
-const getOption = (
+const useOption = (
statisticHashRates: State.StatisticHashRate[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -34,13 +38,11 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 75 : 50)
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
- result += `${tooltipColor(chartColor.colors[0])}${widthSpan(
- i18n.t('block.hash_rate'),
- )} ${handleHashRate(dataList[0].data[1])} `
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 75 : 50)
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
+ result += `${tooltipColor(chartColor.colors[0])}${widthSpan(t('block.hash_rate'))} ${handleHashRate(
+ dataList[0].data[1],
+ )} `
return result
},
}
@@ -49,7 +51,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -59,7 +61,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('block.hash_rate'),
+ name: isMobile || isThumbnail ? '' : t('block.hash_rate'),
type: 'value',
scale: true,
axisLine: {
@@ -74,7 +76,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('block.hash_rate'),
+ name: t('block.hash_rate'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -102,7 +104,7 @@ export const HashRateChart = ({ isThumbnail = false }: { isThumbnail?: boolean }
description={t('glossary.hash_rate')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticHashRate}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.HashRate}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx b/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx
index 29b67e5dd..edf3bced3 100644
--- a/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx
+++ b/src/pages/StatisticsChart/mining/MinerAddressDistribution.tsx
@@ -1,11 +1,11 @@
import { useCallback } from 'react'
import { useHistory } from 'react-router'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { tooltipColor, tooltipWidth, SmartChartPage, SmartChartPageProps } from '../common'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
import { useAdaptMobileEllipsis, useAdaptPCEllipsis, useIsMobile } from '../../../utils/hook'
+import { useCurrentLanguage } from '../../../utils/i18n'
const Colors = [
'#069ECD',
@@ -20,65 +20,69 @@ const Colors = [
'#FBB04C',
]
-const getOption = (
- statisticMinerAddresses: State.StatisticMinerAddress[],
- chartColor: State.ChartColor,
- isMobile: boolean,
- isThumbnail = false,
- getAdaptAddressText: (address: string) => string,
-): echarts.EChartOption => {
- const gridThumbnail = {
- left: '4%',
- right: '10%',
- top: '8%',
- bottom: '6%',
- containLabel: true,
- }
- const grid = {
- left: '3%',
- right: '3%',
- top: '5%',
- bottom: '5%',
- containLabel: true,
- }
+const useOption = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+ return (
+ statisticMinerAddresses: State.StatisticMinerAddress[],
+ chartColor: State.ChartColor,
+ isMobile: boolean,
+ isThumbnail = false,
+ getAdaptAddressText: (address: string) => string,
+ ): echarts.EChartOption => {
+ const gridThumbnail = {
+ left: '4%',
+ right: '10%',
+ top: '8%',
+ bottom: '6%',
+ containLabel: true,
+ }
+ const grid = {
+ left: '3%',
+ right: '3%',
+ top: '5%',
+ bottom: '5%',
+ containLabel: true,
+ }
- return {
- color: [chartColor.colors[0], ...Colors],
- tooltip: !isThumbnail
- ? {
- formatter: (data: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 60 : 65)
- let result = `${tooltipColor('#333333')}${widthSpan(
- i18n.t('statistic.address'),
- )} ${getAdaptAddressText(data.data.title)} `
- result += `${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.miner_ratio'))} ${(
- Number(data.data.value) * 100
- ).toFixed(1)}% `
- return result
- },
- }
- : undefined,
- grid: isThumbnail ? gridThumbnail : grid,
- series: [
- {
- name: i18n.t('statistic.miner_ratio'),
- type: 'pie',
- radius: isMobile || isThumbnail ? '50%' : '75%',
- center: ['50%', '50%'],
- itemStyle: {
- emphasis: {
- shadowBlur: 10,
- shadowOffsetX: 0,
- shadowColor: 'rgba(0, 0, 0, 0.5)',
+ return {
+ color: [chartColor.colors[0], ...Colors],
+ tooltip: !isThumbnail
+ ? {
+ formatter: (data: any) => {
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 60 : 65)
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.address'))} ${getAdaptAddressText(
+ data.data.title,
+ )} `
+ result += `${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.miner_ratio'))} ${(
+ Number(data.data.value) * 100
+ ).toFixed(1)}% `
+ return result
+ },
+ }
+ : undefined,
+ grid: isThumbnail ? gridThumbnail : grid,
+ series: [
+ {
+ name: t('statistic.miner_ratio'),
+ type: 'pie',
+ radius: isMobile || isThumbnail ? '50%' : '75%',
+ center: ['50%', '50%'],
+ itemStyle: {
+ emphasis: {
+ shadowBlur: 10,
+ shadowOffsetX: 0,
+ shadowColor: 'rgba(0, 0, 0, 0.5)',
+ },
},
+ data: statisticMinerAddresses.map(data => ({
+ name: `${getAdaptAddressText(data.address.toLowerCase())} (${(Number(data.radio) * 100).toFixed(1)}%)`,
+ title: data.address.toLowerCase(),
+ value: data.radio,
+ })),
},
- data: statisticMinerAddresses.map(data => ({
- name: `${getAdaptAddressText(data.address.toLowerCase())} (${(Number(data.radio) * 100).toFixed(1)}%)`,
- title: data.address.toLowerCase(),
- value: data.radio,
- })),
- },
- ],
+ ],
+ }
}
}
@@ -115,10 +119,11 @@ export const MinerAddressDistributionChart = ({ isThumbnail = false }: { isThumb
const isMobile = useIsMobile()
const adaptMobileEllipsis = useAdaptMobileEllipsis()
const adaptPCEllipsis = useAdaptPCEllipsis(80)
+ const parseOption = useOption()
const getEChartOption: SmartChartPageProps['getEChartOption'] = useCallback(
(...args) =>
- getOption(...args, address => (isMobile ? adaptMobileEllipsis(address, 4) : adaptPCEllipsis(address, 2))),
- [adaptMobileEllipsis, adaptPCEllipsis, isMobile],
+ parseOption(...args, address => (isMobile ? adaptMobileEllipsis(address, 4) : adaptPCEllipsis(address, 2))),
+ [adaptMobileEllipsis, adaptPCEllipsis, isMobile, parseOption],
)
return (
diff --git a/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx b/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx
index 0ff226310..7cc120d78 100644
--- a/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx
+++ b/src/pages/StatisticsChart/mining/MinerVersionDistribution.tsx
@@ -1,9 +1,9 @@
import { useTranslation } from 'react-i18next'
import { EChartOption } from 'echarts'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
+import { useCurrentLanguage } from '../../../utils/i18n'
const Colors = [
'#069ECD',
@@ -23,12 +23,15 @@ interface VersionRecord {
percent: number
}
-const getOption = (
+const useOption = (
list: Array,
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -48,11 +51,9 @@ const getOption = (
? {
formatter: data => {
const item = Array.isArray(data) ? data[0] : data
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 80 : 60)
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.version'))} ${
- item.data.title
- } `
- result += `${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.percent'))} ${
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 80 : 60)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.version'))} ${item.data.title} `
+ result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.percent'))} ${
item.data.value
}% `
return result
@@ -75,7 +76,7 @@ const getOption = (
},
series: [
{
- name: i18n.t('statistic.miner_version_distribution'),
+ name: t('statistic.miner_version_distribution'),
type: 'pie',
radius: isMobile || isThumbnail ? '50%' : '75%',
center: ['50%', '50%'],
@@ -87,7 +88,7 @@ const getOption = (
},
},
data: list.map(data => {
- const version = data.version === 'others' ? i18n.t(`statistic.others`) : data.version
+ const version = data.version === 'others' ? t(`statistic.others`) : data.version
return {
name: `${version} (${data.percent}%)`,
title: version,
@@ -118,7 +119,7 @@ export const MinerVersionDistributionChart = ({ isThumbnail = false }: { isThumb
title={t('statistic.miner_version_distribution')}
isThumbnail={isThumbnail}
fetchData={fetchData}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.MinerVersionDistribution}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/mining/UncleRate.tsx b/src/pages/StatisticsChart/mining/UncleRate.tsx
index de8589e86..7d59ecebb 100644
--- a/src/pages/StatisticsChart/mining/UncleRate.tsx
+++ b/src/pages/StatisticsChart/mining/UncleRate.tsx
@@ -1,22 +1,26 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { explorerService } from '../../../services/ExplorerService'
import { ChartCachedKeys } from '../../../constants/cache'
+import { useCurrentLanguage } from '../../../utils/i18n'
const max = (statisticUncleRates: State.StatisticUncleRate[]) => {
const array = statisticUncleRates.flatMap(data => Number(data.uncleRate) * 100)
return Math.max(5, Math.ceil(Math.max(...array)))
}
-const getOption = (
+const useOption = (
statisticUncleRates: State.StatisticUncleRate[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '12%',
@@ -37,11 +41,9 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 75 : 50)
- let result = ` ${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
- result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('block.uncle_rate'))} ${
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 75 : 50)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
+ result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(t('block.uncle_rate'))} ${
dataList[0].data[1]
}% `
return result
@@ -52,7 +54,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -62,7 +64,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('block.uncle_rate'),
+ name: isMobile || isThumbnail ? '' : t('block.uncle_rate'),
type: 'value',
scale: true,
max: max(statisticUncleRates),
@@ -79,7 +81,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('block.uncle_rate'),
+ name: t('block.uncle_rate'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -88,7 +90,7 @@ const getOption = (
symbol: 'none',
data: [
{
- name: i18n.t('block.uncle_rate_target'),
+ name: t('block.uncle_rate_target'),
yAxis: 2.5,
},
],
@@ -118,7 +120,7 @@ export const UncleRateChart = ({ isThumbnail = false }: { isThumbnail?: boolean
description={t('statistic.uncle_rate_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticUncleRate}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.UncleRate}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx b/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx
index 561a136f8..9047f2711 100644
--- a/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx
+++ b/src/pages/StatisticsChart/monetary/AnnualPercentageCompensation.tsx
@@ -1,16 +1,20 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { useCurrentLanguage } from '../../../utils/i18n'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const getOption = (
+const useOption = (
statisticAnnualPercentageCompensations: State.StatisticAnnualPercentageCompensation[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -31,11 +35,9 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 220 : 80)
- let result = ` ${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.year'))} ${
- dataList[0].data[0]
- } `
- result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(i18n.t('statistic.nominal_apc'))} ${
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 220 : 80)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.year'))} ${dataList[0].data[0]} `
+ result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.nominal_apc'))} ${
dataList[0].data[1]
}% `
return result
@@ -46,7 +48,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.year'),
+ name: isMobile || isThumbnail ? '' : t('statistic.year'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -59,7 +61,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: i18n.t('statistic.nominal_apc'),
+ name: t('statistic.nominal_apc'),
type: 'value',
nameTextStyle: {
align: 'left',
@@ -76,7 +78,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.nominal_apc'),
+ name: t('statistic.nominal_apc'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -116,7 +118,7 @@ export const AnnualPercentageCompensationChart = ({ isThumbnail = false }: { isT
description={t('statistic.nominal_rpc_description')}
isThumbnail={isThumbnail}
fetchData={fetchStatisticAnnualPercentageCompensations}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.APC}
cacheMode="forever"
diff --git a/src/pages/StatisticsChart/monetary/InflationRate.tsx b/src/pages/StatisticsChart/monetary/InflationRate.tsx
index b1fbf438f..335cab5ad 100644
--- a/src/pages/StatisticsChart/monetary/InflationRate.tsx
+++ b/src/pages/StatisticsChart/monetary/InflationRate.tsx
@@ -1,16 +1,19 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { useCurrentLanguage } from '../../../utils/i18n'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const getOption = (
+const useOption = (
statisticInflationRates: State.StatisticInflationRate[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -26,20 +29,23 @@ const getOption = (
containLabel: true,
}
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 220 : 80)
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 220 : 80)
- const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: string }): string => {
- if (seriesName === i18n.t('statistic.nominal_inflation_rate')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.nominal_inflation_rate'))} ${data}% `
- }
- if (seriesName === i18n.t('statistic.nominal_apc')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.nominal_apc'))} ${data}% `
- }
- if (seriesName === i18n.t('statistic.real_inflation_rate')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.real_inflation_rate'))} ${data}% `
+ const useTooltip = () => {
+ return ({ seriesName, data, color }: SeriesItem & { data: string }): string => {
+ if (seriesName === t('statistic.nominal_inflation_rate')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.nominal_inflation_rate'))} ${data}% `
+ }
+ if (seriesName === t('statistic.nominal_apc')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.nominal_apc'))} ${data}% `
+ }
+ if (seriesName === t('statistic.real_inflation_rate')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.real_inflation_rate'))} ${data}% `
+ }
+ return ''
}
- return ''
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.moreColors,
tooltip: !isThumbnail
@@ -47,7 +53,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.year'))} ${list[0].name} `
+ let result = `${tooltipColor('#333333')}${widthSpan(t('statistic.year'))} ${list[0].name} `
list.forEach(data => {
result += parseTooltip(data)
})
@@ -60,13 +66,13 @@ const getOption = (
? []
: [
{
- name: i18n.t('statistic.real_inflation_rate'),
+ name: t('statistic.real_inflation_rate'),
},
{
- name: i18n.t('statistic.nominal_apc'),
+ name: t('statistic.nominal_apc'),
},
{
- name: i18n.t('statistic.nominal_inflation_rate'),
+ name: t('statistic.nominal_inflation_rate'),
},
],
},
@@ -74,7 +80,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.year'),
+ name: isMobile || isThumbnail ? '' : t('statistic.year'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -102,7 +108,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.nominal_inflation_rate'),
+ name: t('statistic.nominal_inflation_rate'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -113,7 +119,7 @@ const getOption = (
data: statisticInflationRates.map(data => Number(data.nominalInflationRate).toFixed(4)),
},
{
- name: i18n.t('statistic.nominal_apc'),
+ name: t('statistic.nominal_apc'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -124,7 +130,7 @@ const getOption = (
data: statisticInflationRates.map(data => Number(data.nominalApc).toFixed(4)),
},
{
- name: i18n.t('statistic.real_inflation_rate'),
+ name: t('statistic.real_inflation_rate'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -175,7 +181,7 @@ export const InflationRateChart = ({ isThumbnail = false }: { isThumbnail?: bool
description={t('statistic.inflation_rate_description')}
isThumbnail={isThumbnail}
fetchData={fetchStatisticInflationRates}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.InflationRate}
cacheMode="forever"
diff --git a/src/pages/StatisticsChart/monetary/Liquidity.tsx b/src/pages/StatisticsChart/monetary/Liquidity.tsx
index 15c8b55d7..fadefb080 100644
--- a/src/pages/StatisticsChart/monetary/Liquidity.tsx
+++ b/src/pages/StatisticsChart/monetary/Liquidity.tsx
@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { useCurrentLanguage } from '../../../utils/i18n'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { DATA_ZOOM_CONFIG, parseNumericAbbr } from '../../../utils/chart'
@@ -7,12 +7,16 @@ import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const getOption = (
+const useOption = (
statisticLiquidity: State.StatisticLiquidity[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -28,33 +32,32 @@ const getOption = (
containLabel: true,
}
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 140 : 120)
+ const widthSpan = (value: string, language: string) => tooltipWidth(value, language === 'en' ? 140 : 120)
- const parseTooltip = ({
- seriesName,
- data,
- color,
- }: SeriesItem & { data: [string, string, string, string] }): string => {
- if (seriesName === i18n.t('statistic.circulating_supply')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('statistic.circulating_supply'))} ${parseNumericAbbr(
- data[3],
- 2,
- )} `
- }
- if (seriesName === i18n.t('statistic.dao_deposit')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('statistic.dao_deposit'))} ${parseNumericAbbr(
- data[2],
- 2,
- )} `
- }
- if (seriesName === i18n.t('statistic.tradable')) {
- return `${tooltipColor(color)}${widthSpan(i18n.t('statistic.tradable'))} ${parseNumericAbbr(
- data[1],
- 2,
- )} `
+ const useTooltip = () => {
+ return ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
+ if (seriesName === t('statistic.circulating_supply')) {
+ return `${tooltipColor(color)}${widthSpan(
+ t('statistic.circulating_supply'),
+ currentLanguage,
+ )} ${parseNumericAbbr(data[3], 2)} `
+ }
+ if (seriesName === t('statistic.dao_deposit')) {
+ return `${tooltipColor(color)}${widthSpan(t('statistic.dao_deposit'), currentLanguage)} ${parseNumericAbbr(
+ data[2],
+ 2,
+ )} `
+ }
+ if (seriesName === t('statistic.tradable')) {
+ return `${tooltipColor(color)}${widthSpan(t('statistic.tradable'), currentLanguage)} ${parseNumericAbbr(
+ data[1],
+ 2,
+ )} `
+ }
+ return ''
}
- return ''
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.liquidityColors,
tooltip: !isThumbnail
@@ -62,7 +65,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'), currentLanguage)} ${
list[0].data[0]
} `
list.forEach(data => {
@@ -77,13 +80,13 @@ const getOption = (
? []
: [
{
- name: i18n.t('statistic.circulating_supply'),
+ name: t('statistic.circulating_supply'),
},
{
- name: i18n.t('statistic.dao_deposit'),
+ name: t('statistic.dao_deposit'),
},
{
- name: i18n.t('statistic.tradable'),
+ name: t('statistic.tradable'),
},
],
},
@@ -91,7 +94,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -114,7 +117,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.tradable'),
+ name: t('statistic.tradable'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -129,7 +132,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.dao_deposit'),
+ name: t('statistic.dao_deposit'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -144,7 +147,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.circulating_supply'),
+ name: t('statistic.circulating_supply'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -184,7 +187,7 @@ export const LiquidityChart = ({ isThumbnail = false }: { isThumbnail?: boolean
title={t('statistic.liquidity')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticLiquidity}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.Liquidity}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx b/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx
index 92ace10ed..3ab2afc32 100644
--- a/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx
+++ b/src/pages/StatisticsChart/monetary/SecondaryIssuance.tsx
@@ -1,32 +1,44 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 155 : 70)
+const widthSpan = (value: string, currentLanguage: LanuageType) =>
+ tooltipWidth(value, currentLanguage === 'en' ? 155 : 70)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
- if (seriesName === i18n.t('nervos_dao.deposit_compensation')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('nervos_dao.deposit_compensation'))} ${data[3]}% `
- }
- if (seriesName === i18n.t('nervos_dao.mining_reward')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('nervos_dao.mining_reward'))} ${data[2]}% `
- }
- if (seriesName === i18n.t('nervos_dao.burnt')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('nervos_dao.burnt'))} ${data[1]}% `
+const useTooltip = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
+ return ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
+ if (seriesName === t('nervos_dao.deposit_compensation')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('nervos_dao.deposit_compensation'), currentLanguage)} ${
+ data[3]
+ }% `
+ }
+ if (seriesName === t('nervos_dao.mining_reward')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('nervos_dao.mining_reward'), currentLanguage)} ${data[2]}% `
+ }
+ if (seriesName === t('nervos_dao.burnt')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('nervos_dao.burnt'), currentLanguage)} ${data[1]}% `
+ }
+ return ''
}
- return ''
}
-const getOption = (
+const useOption = (
statisticSecondaryIssuance: State.StatisticSecondaryIssuance[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -41,6 +53,7 @@ const getOption = (
bottom: '5%',
containLabel: true,
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.secondaryIssuanceColors,
tooltip: !isThumbnail
@@ -48,7 +61,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'), currentLanguage)} ${
dataList[0].data[0]
} `
list.forEach(data => {
@@ -63,13 +76,13 @@ const getOption = (
? []
: [
{
- name: i18n.t('nervos_dao.burnt'),
+ name: t('nervos_dao.burnt'),
},
{
- name: i18n.t('nervos_dao.mining_reward'),
+ name: t('nervos_dao.mining_reward'),
},
{
- name: i18n.t('nervos_dao.deposit_compensation'),
+ name: t('nervos_dao.deposit_compensation'),
},
],
},
@@ -77,7 +90,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -100,7 +113,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('nervos_dao.burnt'),
+ name: t('nervos_dao.burnt'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -113,7 +126,7 @@ const getOption = (
},
},
{
- name: i18n.t('nervos_dao.mining_reward'),
+ name: t('nervos_dao.mining_reward'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -126,7 +139,7 @@ const getOption = (
},
},
{
- name: i18n.t('nervos_dao.deposit_compensation'),
+ name: t('nervos_dao.deposit_compensation'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -169,7 +182,7 @@ export const SecondaryIssuanceChart = ({ isThumbnail = false }: { isThumbnail?:
description={t('statistic.secondary_issuance_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticSecondaryIssuance}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.SecondaryIssuance}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/monetary/TotalSupply.tsx b/src/pages/StatisticsChart/monetary/TotalSupply.tsx
index 6b187d07c..a67d40980 100644
--- a/src/pages/StatisticsChart/monetary/TotalSupply.tsx
+++ b/src/pages/StatisticsChart/monetary/TotalSupply.tsx
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, parseNumericAbbr } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../common'
@@ -8,30 +8,46 @@ import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 125 : 80)
+const widthSpan = (value: string, currentLanguage: LanuageType) =>
+ tooltipWidth(value, currentLanguage === 'en' ? 125 : 80)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
- if (seriesName === i18n.t('statistic.burnt')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.burnt'))} ${parseNumericAbbr(data[3], 2)} `
- }
- if (seriesName === i18n.t('statistic.locked')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.locked'))} ${parseNumericAbbr(data[2], 2)} `
- }
- if (seriesName === i18n.t('statistic.circulating_supply')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.circulating_supply'))} ${parseNumericAbbr(
- data[1],
- 2,
- )} `
+const useTooltip = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
+ return ({ seriesName, data, color }: SeriesItem & { data: [string, string, string, string] }): string => {
+ if (seriesName === t('statistic.burnt')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.burnt'), currentLanguage)} ${parseNumericAbbr(
+ data[3],
+ 2,
+ )} `
+ }
+ if (seriesName === t('statistic.locked')) {
+ return ` ${tooltipColor(color)}${widthSpan(t('statistic.locked'), currentLanguage)} ${parseNumericAbbr(
+ data[2],
+ 2,
+ )} `
+ }
+ if (seriesName === t('statistic.circulating_supply')) {
+ return ` ${tooltipColor(color)}${widthSpan(
+ t('statistic.circulating_supply'),
+ currentLanguage,
+ )} ${parseNumericAbbr(data[1], 2)} `
+ }
+ return ''
}
- return ''
}
-const getOption = (
+const useOption = (
statisticTotalSupplies: State.StatisticTotalSupply[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -46,6 +62,7 @@ const getOption = (
bottom: '5%',
containLabel: true,
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.totalSupplyColors,
tooltip: !isThumbnail
@@ -53,7 +70,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'), currentLanguage)} ${
list[0].data[0]
} `
list.forEach(data => {
@@ -68,13 +85,13 @@ const getOption = (
? []
: [
{
- name: i18n.t('statistic.circulating_supply'),
+ name: t('statistic.circulating_supply'),
},
{
- name: i18n.t('statistic.locked'),
+ name: t('statistic.locked'),
},
{
- name: i18n.t('statistic.burnt'),
+ name: t('statistic.burnt'),
},
],
},
@@ -82,7 +99,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -105,7 +122,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.circulating_supply'),
+ name: t('statistic.circulating_supply'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -120,7 +137,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.locked'),
+ name: t('statistic.locked'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -135,7 +152,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.burnt'),
+ name: t('statistic.burnt'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -180,7 +197,7 @@ export const TotalSupplyChart = ({ isThumbnail = false }: { isThumbnail?: boolea
description={t('statistic.total_supply_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticTotalSupply}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.TotalSupply}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx b/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx
index 635918e4c..afcacf9ee 100644
--- a/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx
+++ b/src/pages/StatisticsChart/nervosDao/CirculationRatio.tsx
@@ -1,17 +1,19 @@
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { useCurrentLanguage } from '../../../utils/i18n'
import { parseDateNoTime } from '../../../utils/date'
import { tooltipColor, tooltipWidth, SmartChartPage } from '../common'
import { DATA_ZOOM_CONFIG } from '../../../utils/chart'
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const getOption = (
+const useOption = (
statisticCirculationRatios: State.StatisticCirculationRatio[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -32,14 +34,12 @@ const getOption = (
? {
trigger: 'axis',
formatter: (dataList: any) => {
- const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 185 : 165)
- let result = ` ${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
- dataList[0].data[0]
- } `
+ const widthSpan = (value: string) => tooltipWidth(value, currentLanguage === 'en' ? 185 : 165)
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'))} ${dataList[0].data[0]} `
if (dataList[0].data) {
- result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(
- i18n.t('statistic.circulation_ratio'),
- )} ${dataList[0].data[1]}% `
+ result += ` ${tooltipColor(chartColor.colors[0])}${widthSpan(t('statistic.circulation_ratio'))} ${
+ dataList[0].data[1]
+ }% `
}
return result
},
@@ -49,7 +49,7 @@ const getOption = (
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -59,7 +59,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.circulation_ratio'),
+ name: isMobile || isThumbnail ? '' : t('statistic.circulation_ratio'),
nameTextStyle: {
align: 'left',
},
@@ -77,7 +77,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.circulation_ratio'),
+ name: t('statistic.circulation_ratio'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -106,7 +106,7 @@ export const CirculationRatioChart = ({ isThumbnail = false }: { isThumbnail?: b
description={t('statistic.deposit_to_circulation_ratio_description')}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticCirculationRatio}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.DepositCirculationRatio}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx b/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx
index 1f1fce355..e8bd4a41f 100644
--- a/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx
+++ b/src/pages/StatisticsChart/nervosDao/NewDaoDeposit.tsx
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, parseNumericAbbr } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util'
@@ -9,31 +9,37 @@ import { tooltipWidth, tooltipColor, SeriesItem, SmartChartPage } from '../commo
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 140 : 120)
+const widthSpan = (value: string, language: LanuageType) => tooltipWidth(value, language === 'en' ? 140 : 120)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, string, string] }): string => {
- if (seriesName === i18n.t('statistic.new_dao_deposit')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.new_dao_deposit'))} ${parseNumericAbbr(
- data[1],
- 2,
- )} `
- }
- if (seriesName === i18n.t('statistic.new_dao_depositor')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.new_dao_depositor'))} ${parseNumericAbbr(
- data[2],
- 2,
- true,
- )} `
+const useTooltip = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+
+ return ({ seriesName, data, color }: SeriesItem & { data: [string, string, string] }): string => {
+ if (seriesName === t('statistic.new_dao_deposit')) {
+ return ` ${tooltipColor(color)}${widthSpan(
+ t('statistic.new_dao_deposit'),
+ currentLanguage,
+ )} ${parseNumericAbbr(data[1], 2)} `
+ }
+ if (seriesName === t('statistic.new_dao_depositor')) {
+ return ` ${tooltipColor(color)}${widthSpan(
+ t('statistic.new_dao_depositor'),
+ currentLanguage,
+ )} ${parseNumericAbbr(data[2], 2, true)} `
+ }
+ return ''
}
- return ''
}
-const getOption = (
+const useOption = (
statisticNewDaoDeposits: State.StatisticNewDaoDeposit[],
chartColor: State.ChartColor,
isMobile: boolean,
isThumbnail = false,
): echarts.EChartOption => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
const gridThumbnail = {
left: '4%',
right: '10%',
@@ -48,6 +54,7 @@ const getOption = (
bottom: '5%',
containLabel: true,
}
+ const parseTooltip = useTooltip()
return {
color: chartColor.colors,
tooltip: !isThumbnail
@@ -55,7 +62,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as (SeriesItem & { data: [string, string, string] })[]
- let result = ` ${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'), currentLanguage)} ${
list[0].data[0]
} `
list.forEach(data => {
@@ -71,17 +78,17 @@ const getOption = (
? []
: [
{
- name: i18n.t('statistic.new_dao_deposit'),
+ name: t('statistic.new_dao_deposit'),
},
{
- name: i18n.t('statistic.new_dao_depositor'),
+ name: t('statistic.new_dao_depositor'),
},
],
},
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -91,7 +98,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.new_dao_deposit'),
+ name: isMobile || isThumbnail ? '' : t('statistic.new_dao_deposit'),
nameTextStyle: {
align: 'left',
},
@@ -108,7 +115,7 @@ const getOption = (
},
{
position: 'right',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.new_dao_depositor'),
+ name: isMobile || isThumbnail ? '' : t('statistic.new_dao_depositor'),
nameTextStyle: {
align: 'right',
},
@@ -126,7 +133,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.new_dao_deposit'),
+ name: t('statistic.new_dao_deposit'),
type: 'line',
yAxisIndex: 0,
areaStyle: {
@@ -140,7 +147,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.new_dao_depositor'),
+ name: t('statistic.new_dao_depositor'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
@@ -179,7 +186,7 @@ export const NewDaoDepositChart = ({ isThumbnail = false }: { isThumbnail?: bool
note={isMainnet() ? `${t('common.note')}1MB = 1,000,000 CKBytes` : undefined}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticNewDaoDeposit}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.DailyDeposit}
cacheMode="date"
diff --git a/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx b/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx
index bcea6e440..d809ea2bd 100644
--- a/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx
+++ b/src/pages/StatisticsChart/nervosDao/TotalDaoDeposit.tsx
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js'
import { useTranslation } from 'react-i18next'
-import i18n, { currentLanguage } from '../../../utils/i18n'
+import { LanuageType, useCurrentLanguage } from '../../../utils/i18n'
import { DATA_ZOOM_CONFIG, parseNumericAbbr } from '../../../utils/chart'
import { parseDateNoTime } from '../../../utils/date'
import { shannonToCkb, shannonToCkbDecimal } from '../../../utils/util'
@@ -9,29 +9,33 @@ import { tooltipColor, tooltipWidth, SeriesItem, SmartChartPage } from '../commo
import { ChartCachedKeys } from '../../../constants/cache'
import { explorerService } from '../../../services/ExplorerService'
-const widthSpan = (value: string) => tooltipWidth(value, currentLanguage() === 'en' ? 168 : 110)
+const widthSpan = (value: string, language: LanuageType) => tooltipWidth(value, language === 'en' ? 168 : 110)
-const parseTooltip = ({ seriesName, data, color }: SeriesItem & { data: [string, string, string] }): string => {
- if (seriesName === i18n.t('statistic.total_dao_deposit')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.total_dao_deposit'))} ${parseNumericAbbr(
- data[1],
- 2,
- )} `
+const useTooltip = () => {
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+ return ({ seriesName, data, color }: SeriesItem & { data: [string, string, string] }): string => {
+ if (seriesName === t('statistic.total_dao_deposit')) {
+ return ` ${tooltipColor(color)}${widthSpan(
+ t('statistic.total_dao_deposit'),
+ currentLanguage,
+ )} ${parseNumericAbbr(data[1], 2)} `
+ }
+ if (seriesName === t('statistic.total_dao_depositor')) {
+ return ` ${tooltipColor(color)}${widthSpan(
+ t('statistic.total_dao_depositor'),
+ currentLanguage,
+ )} ${parseNumericAbbr(data[2], 2, true)} `
+ }
+ return ''
}
- if (seriesName === i18n.t('statistic.total_dao_depositor')) {
- return ` ${tooltipColor(color)}${widthSpan(i18n.t('statistic.total_dao_depositor'))} ${parseNumericAbbr(
- data[2],
- 2,
- true,
- )} `
- }
- return ''
}
-const getOption = (
+const useOption = (
statisticTotalDaoDeposits: State.StatisticTotalDaoDeposit[],
chartColor: State.ChartColor,
isMobile: boolean,
+
isThumbnail = false,
): echarts.EChartOption => {
const gridThumbnail = {
@@ -48,6 +52,10 @@ const getOption = (
bottom: '5%',
containLabel: true,
}
+ const { t } = useTranslation()
+ const currentLanguage = useCurrentLanguage()
+ const parseTooltip = useTooltip()
+
return {
color: chartColor.colors,
tooltip: !isThumbnail
@@ -55,7 +63,7 @@ const getOption = (
trigger: 'axis',
formatter: (dataList: any) => {
const list = dataList as Array
- let result = `${tooltipColor('#333333')}${widthSpan(i18n.t('statistic.date'))} ${
+ let result = ` ${tooltipColor('#333333')}${widthSpan(t('statistic.date'), currentLanguage)} ${
list[0].data[0]
} `
list.forEach(data => {
@@ -71,17 +79,17 @@ const getOption = (
? []
: [
{
- name: i18n.t('statistic.total_dao_deposit'),
+ name: t('statistic.total_dao_deposit'),
},
{
- name: i18n.t('statistic.total_dao_depositor'),
+ name: t('statistic.total_dao_depositor'),
},
],
},
dataZoom: isThumbnail ? [] : DATA_ZOOM_CONFIG,
xAxis: [
{
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.date'),
+ name: isMobile || isThumbnail ? '' : t('statistic.date'),
nameLocation: 'middle',
nameGap: 30,
type: 'category',
@@ -91,7 +99,7 @@ const getOption = (
yAxis: [
{
position: 'left',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.total_dao_deposit'),
+ name: isMobile || isThumbnail ? '' : t('statistic.total_dao_deposit'),
nameTextStyle: {
align: 'left',
},
@@ -108,7 +116,7 @@ const getOption = (
},
{
position: 'right',
- name: isMobile || isThumbnail ? '' : i18n.t('statistic.total_dao_depositor'),
+ name: isMobile || isThumbnail ? '' : t('statistic.total_dao_depositor'),
nameTextStyle: {
align: 'right',
},
@@ -126,7 +134,7 @@ const getOption = (
],
series: [
{
- name: i18n.t('statistic.total_dao_deposit'),
+ name: t('statistic.total_dao_deposit'),
type: 'line',
yAxisIndex: 0,
symbol: isThumbnail ? 'none' : 'circle',
@@ -137,7 +145,7 @@ const getOption = (
},
},
{
- name: i18n.t('statistic.total_dao_depositor'),
+ name: t('statistic.total_dao_depositor'),
type: 'line',
yAxisIndex: 1,
symbol: isThumbnail ? 'none' : 'circle',
@@ -177,7 +185,7 @@ export const TotalDaoDepositChart = ({ isThumbnail = false }: { isThumbnail?: bo
note={isMainnet() ? `${t('common.note')}1GB = 1,000,000,000 CKBytes` : undefined}
isThumbnail={isThumbnail}
fetchData={explorerService.api.fetchStatisticTotalDaoDeposit}
- getEChartOption={getOption}
+ getEChartOption={useOption}
toCSV={toCSV}
cacheKey={ChartCachedKeys.TotalDeposit}
cacheMode="date"
diff --git a/src/pages/Tokens/index.tsx b/src/pages/Tokens/index.tsx
index ab19b3b95..3484bcddb 100644
--- a/src/pages/Tokens/index.tsx
+++ b/src/pages/Tokens/index.tsx
@@ -1,6 +1,7 @@
import { Tooltip } from 'antd'
import { Link, useHistory } from 'react-router-dom'
import { useQuery } from 'react-query'
+import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import Pagination from '../../components/Pagination'
import SortButton from '../../components/SortButton'
@@ -18,7 +19,6 @@ import HelpIcon from '../../assets/qa_help.png'
import { parseDateNoTime } from '../../utils/date'
import { localeNumberString } from '../../utils/number'
import SUDTTokenIcon from '../../assets/sudt_token.png'
-import i18n from '../../utils/i18n'
import Loading from '../../components/Loading'
import { udtSubmitEmail } from '../../utils/util'
import SmallLoading from '../../components/Loading/SmallLoading'
@@ -29,15 +29,16 @@ import { QueryResult } from '../../components/QueryResult'
const TokenItem = ({ token, isLast }: { token: State.UDT; isLast?: boolean }) => {
const { displayName, fullName, uan } = token
+ const { t } = useTranslation()
const name = displayName || fullName
const symbol = uan || token.symbol || `#${token.typeHash.substring(token.typeHash.length - 4)}`
- const defaultName = i18n.t('udt.unknown_token')
+ const defaultName = t('udt.unknown_token')
const isMobile = useIsMobile()
const transactions = isMobile ? (
- {`${i18n.t('udt.transactions')}:`}
+ {`${t('udt.transactions')}:`}
{localeNumberString(token.h24CkbTransactionsCount)}
) : (
@@ -45,7 +46,7 @@ const TokenItem = ({ token, isLast }: { token: State.UDT; isLast?: boolean }) =>
)
const addressCount = isMobile ? (
- {`${i18n.t('udt.address_count')}:`}
+ {`${t('udt.address_count')}:`}
{localeNumberString(token.addressesCount)}
) : (
@@ -73,7 +74,7 @@ const TokenItem = ({ token, isLast }: { token: State.UDT; isLast?: boolean }) =>
)}
{!isKnown && (
-
+
)}
@@ -94,6 +95,7 @@ const TokenItem = ({ token, isLast }: { token: State.UDT; isLast?: boolean }) =>
export default () => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const { currentPage, pageSize: _pageSize, setPage } = usePaginationParamsInPage()
const { location } = useHistory()
@@ -118,30 +120,30 @@ export default () => {
- {!isMobile && {i18n.t('udt.uan_name')}}
+ {!isMobile && {t('udt.uan_name')}}
- {i18n.t('udt.transactions')}
+ {t('udt.transactions')}
- {i18n.t('udt.address_count')}
+ {t('udt.address_count')}
- {i18n.t('udt.created_time')}
+ {t('udt.created_time')}
{i18n.t('udt.tokens_empty')}}
+ errorRender={() => {t('udt.tokens_empty')}}
loadingRender={() => (
{isMobile ? : }
)}
diff --git a/src/pages/Transaction/TransactionCell/index.tsx b/src/pages/Transaction/TransactionCell/index.tsx
index d2f9f548e..c75492f7c 100644
--- a/src/pages/Transaction/TransactionCell/index.tsx
+++ b/src/pages/Transaction/TransactionCell/index.tsx
@@ -1,8 +1,8 @@
import { useState, ReactNode, FC } from 'react'
import { Tooltip } from 'antd'
import { Link } from 'react-router-dom'
+import { useTranslation } from 'react-i18next'
import { CellType } from '../../../constants/common'
-import i18n from '../../../utils/i18n'
import { localeNumberString, parseUDTAmount } from '../../../utils/number'
import { parseSimpleDate } from '../../../utils/date'
import { sliceNftName } from '../../../utils/string'
@@ -45,6 +45,7 @@ import AddressText from '../../../components/AddressText'
const Addr: FC<{ address: string; isCellBase: boolean }> = ({ address, isCellBase }) => {
const alias = useDASAccount(address)
+ const { t } = useTranslation()
if (alias && address) {
return (
@@ -75,9 +76,7 @@ const Addr: FC<{ address: string; isCellBase: boolean }> = ({ address, isCellBas
)
}
return (
-
- {isCellBase ? 'Cellbase' : i18n.t('address.unable_decode_address')}
-
+ {isCellBase ? 'Cellbase' : t('address.unable_decode_address')}
)
}
@@ -92,6 +91,7 @@ const TransactionCellIndexAddress = ({
index: number
isAddrNew: boolean
}) => {
+ const { t } = useTranslation()
const deprecatedAddr = useDeprecatedAddr(cell.addressHash)!
const newAddr = useNewAddr(cell.addressHash)
const address = !isAddrNew ? deprecatedAddr : newAddr
@@ -127,7 +127,7 @@ const TransactionCellIndexAddress = ({
{since ? (
@@ -139,7 +139,8 @@ const TransactionCellIndexAddress = ({
)
}
-const parseNftInfo = (cell: State.Cell) => {
+const useParseNftInfo = (cell: State.Cell) => {
+ const { t } = useTranslation()
if (cell.cellType === 'nrc_721_token') {
const nftInfo = cell.extraInfo
return {`${nftInfo.symbol} #${nftInfo.amount}`}
@@ -150,83 +151,85 @@ const parseNftInfo = (cell: State.Cell) => {
if (nftInfo.issuerName) {
return sliceNftName(nftInfo.issuerName)
}
- return i18n.t('transaction.unknown_nft')
+ return t('transaction.unknown_nft')
}
if (cell.cellType === 'm_nft_class') {
const nftInfo = cell.extraInfo
- const className = nftInfo.className ? sliceNftName(nftInfo.className) : i18n.t('transaction.unknown_nft')
- const limit = nftInfo.total === '0' ? i18n.t('transaction.nft_unlimited') : i18n.t('transaction.nft_limited')
+ const className = nftInfo.className ? sliceNftName(nftInfo.className) : t('transaction.unknown_nft')
+ const limit = nftInfo.total === '0' ? t('transaction.nft_unlimited') : t('transaction.nft_limited')
const total = nftInfo.total === '0' ? '' : nftInfo.total
return {`${className}\n${limit} ${total}`}
}
if (cell.cellType === 'm_nft_token') {
const nftInfo = cell.extraInfo
- const className = nftInfo.className ? sliceNftName(nftInfo.className) : i18n.t('transaction.unknown_nft')
+ const className = nftInfo.className ? sliceNftName(nftInfo.className) : t('transaction.unknown_nft')
const total = nftInfo.total === '0' ? '' : ` / ${nftInfo.total}`
return {`${className}\n#${parseInt(nftInfo.tokenId, 16)}${total}`}
}
}
const TransactionCellDetail = ({ cell }: { cell: State.Cell }) => {
- let detailTitle = i18n.t('transaction.ckb_capacity')
+ const { t } = useTranslation()
+ let detailTitle = t('transaction.ckb_capacity')
let detailIcon
let tooltip: string | ReactNode = ''
+ const nftInfo = useParseNftInfo(cell)
switch (cell.cellType) {
case 'nervos_dao_deposit':
- detailTitle = i18n.t('transaction.nervos_dao_deposit')
+ detailTitle = t('transaction.nervos_dao_deposit')
detailIcon = NervosDAODepositIcon
break
case 'nervos_dao_withdrawing':
- detailTitle = i18n.t('transaction.nervos_dao_withdraw')
+ detailTitle = t('transaction.nervos_dao_withdraw')
detailIcon = NervosDAOWithdrawingIcon
break
case 'udt':
- detailTitle = i18n.t('transaction.udt_cell')
+ detailTitle = t('transaction.udt_cell')
detailIcon = UDTTokenIcon
tooltip = `Capacity: ${shannonToCkbDecimal(cell.capacity, 8)} CKB`
break
case 'm_nft_issuer':
- detailTitle = i18n.t('transaction.m_nft_issuer')
+ detailTitle = t('transaction.m_nft_issuer')
detailIcon = NFTIssuerIcon
- tooltip = parseNftInfo(cell)
+ tooltip = nftInfo
break
case 'm_nft_class':
- detailTitle = i18n.t('transaction.m_nft_class')
+ detailTitle = t('transaction.m_nft_class')
detailIcon = NFTClassIcon
- tooltip = parseNftInfo(cell)
+ tooltip = nftInfo
break
case 'm_nft_token':
- detailTitle = i18n.t('transaction.m_nft_token')
+ detailTitle = t('transaction.m_nft_token')
detailIcon = NFTTokenIcon
- tooltip = parseNftInfo(cell)
+ tooltip = nftInfo
break
case 'nrc_721_token':
- detailTitle = i18n.t('transaction.nrc_721_token')
+ detailTitle = t('transaction.nrc_721_token')
detailIcon = NFTTokenIcon
- tooltip = parseNftInfo(cell)
+ tooltip = nftInfo
break
case 'cota_registry': {
- detailTitle = i18n.t('transaction.cota_registry')
+ detailTitle = t('transaction.cota_registry')
detailIcon = CoTARegCellIcon
tooltip = detailTitle
break
}
case 'cota_regular': {
- detailTitle = i18n.t('transaction.cota')
+ detailTitle = t('transaction.cota')
detailIcon = CoTACellIcon
tooltip = detailTitle
break
}
case 'spore_cluster': {
- detailTitle = i18n.t('transaction.spore_cluster')
+ detailTitle = t('transaction.spore_cluster')
detailIcon = SporeCellIcon
tooltip = detailTitle
break
}
case 'spore_cell': {
- detailTitle = i18n.t('transaction.spore')
+ detailTitle = t('transaction.spore')
detailIcon = SporeCellIcon
tooltip = detailTitle
break
@@ -273,12 +276,13 @@ const TransactionCellInfo = ({ cell, children }: { cell: State.Cell; children: s
}
const TransactionCellCapacityAmount = ({ cell }: { cell: State.Cell }) => {
+ const { t } = useTranslation()
if (cell.cellType === 'udt') {
const udtInfo = cell.extraInfo
if (udtInfo.published) {
return {`${parseUDTAmount(udtInfo.amount, udtInfo.decimal)} ${udtInfo.uan || udtInfo.symbol}`}
}
- return {`${i18n.t('udt.unknown_token')} #${udtInfo.typeHash.substring(udtInfo.typeHash.length - 4)}`}
+ return {`${t('udt.unknown_token')} #${udtInfo.typeHash.substring(udtInfo.typeHash.length - 4)}`}
}
return
}
@@ -306,6 +310,8 @@ export default ({
isAddrNew: boolean
}) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
+
if (isMobile) {
return (
@@ -324,7 +330,7 @@ export default ({
) : (
<>
{!cell.fromCellbase && }
@@ -332,7 +338,7 @@ export default ({
}
/>
}
/>
>
diff --git a/src/pages/Transaction/TransactionCellList/index.tsx b/src/pages/Transaction/TransactionCellList/index.tsx
index 7204a0613..135f87336 100644
--- a/src/pages/Transaction/TransactionCellList/index.tsx
+++ b/src/pages/Transaction/TransactionCellList/index.tsx
@@ -1,7 +1,7 @@
import { useState, useCallback } from 'react'
import { Tooltip } from 'antd'
+import { useTranslation } from 'react-i18next'
import { CellType, PAGE_CELL_COUNT } from '../../../constants/common'
-import i18n from '../../../utils/i18n'
import TransactionCell from '../TransactionCell'
import { TransactionCellListPanel, TransactionCellListTitlePanel, TransactionCellsPanel } from './styled'
import SmallLoading from '../../../components/Loading/SmallLoading'
@@ -29,6 +29,7 @@ export default ({
setIsAddrNew: (is: boolean) => void
}
}) => {
+ const { t } = useTranslation()
const [offset, setOffset] = useState(PAGE_CELL_COUNT)
const [isEnd, setIsEnd] = useState(false)
const cells = inputs || outputs || []
@@ -64,17 +65,17 @@ export default ({
}
const cellTitle = () => {
- const title = inputs ? i18n.t('transaction.input') : i18n.t('transaction.output')
+ const title = inputs ? t('transaction.input') : t('transaction.output')
return (
{`${title} (${cellsCount()})`}
-
+
{isAddrNew ? : }
{isAddrNew ? null : (
-
+
)}
@@ -87,8 +88,8 @@ export default ({
{cellTitle()}
- {isCellbaseInput ? i18n.t('transaction.reward_info') : i18n.t('transaction.detail')}
- {isCellbaseInput ? '' : i18n.t('transaction.capacity_amount')}
+ {isCellbaseInput ? t('transaction.reward_info') : t('transaction.detail')}
+ {isCellbaseInput ? '' : t('transaction.capacity_amount')}
diff --git a/src/pages/Transaction/TransactionCellScript/index.tsx b/src/pages/Transaction/TransactionCellScript/index.tsx
index d58d052a4..6acf57507 100644
--- a/src/pages/Transaction/TransactionCellScript/index.tsx
+++ b/src/pages/Transaction/TransactionCellScript/index.tsx
@@ -1,6 +1,7 @@
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
import { useEffect, useState, ReactNode, useRef } from 'react'
import BigNumber from 'bignumber.js'
+import { TFunction, useTranslation } from 'react-i18next'
import { explorerService, Response } from '../../../services/ExplorerService'
import { CellState } from '../../../constants/common'
import { hexToUtf8 } from '../../../utils/string'
@@ -16,7 +17,6 @@ import {
TransactionCellScriptContentPanel,
TransactionDetailScriptButton,
} from './styled'
-import i18n from '../../../utils/i18n'
import SmallLoading from '../../../components/Loading/SmallLoading'
import CloseIcon from '../../../assets/modal_close.png'
import { getContractHashTag } from '../../../utils/util'
@@ -59,6 +59,7 @@ const handleFetchCellInfo = async (
setScriptFetchStatus: (val: boolean) => void,
setContent: Function,
setToast: ReturnType,
+ t: TFunction,
) => {
setScriptFetchStatus(false)
@@ -100,7 +101,7 @@ const handleFetchCellInfo = async (
const err = error.response.data[0]
if (err.status === 400 && err.code === 1022) {
setToast({
- message: i18n.t('toast.data_too_large'),
+ message: t('toast.data_too_large'),
type: 'warning',
})
return null
@@ -133,35 +134,16 @@ const handleFetchCellInfo = async (
})
break
case CellState.CAPACITY:
- setContent(null)
-
- Promise.all([fetchLock(), fetchType(), fetchData()]).then(([lock, type, data]) => {
+ {
setScriptFetchStatus(true)
const declared = new BigNumber(cell.capacity)
-
- if (!data) {
- setContent({
- declared: `${localeNumberString(declared.dividedBy(10 ** 8))} CKBytes`,
- occupied: null,
- })
- return
- }
-
- const CAPACITY_SIZE = 8
- const occupied = ([lock, type] as Array)
- .filter(s => s !== 'null')
- .map(
- script => Math.ceil(script.codeHash.slice(2).length / 2) + Math.ceil(script.args.slice(2).length / 2) + 1,
- )
- .reduce((acc, cur) => acc.plus(cur), new BigNumber(0))
- .plus(CAPACITY_SIZE)
- .plus(Math.ceil(data.data.slice(2).length / 2))
+ const occupied = new BigNumber(cell.occupiedCapacity)
setContent({
declared: `${localeNumberString(declared.dividedBy(10 ** 8))} CKBytes`,
- occupied: `${localeNumberString(occupied)} CKBytes`,
+ occupied: `${localeNumberString(occupied.dividedBy(10 ** 8))} CKBytes`,
})
- })
+ }
break
default:
@@ -183,6 +165,7 @@ const ScriptContent = ({
content: State.Script | State.Data | CapacityUsage | undefined
state: CellState
}) => {
+ const { t } = useTranslation()
const hashTag = getContractHashTag(content as State.Script)
const data = content as State.Data
const script = content as State.Script
@@ -196,7 +179,7 @@ const ScriptContent = ({
const v = capacities[key as keyof CapacityUsage]
if (!v) return null
- const field = i18n.t(`transaction.${key}_capacity`)
+ const field = t(`transaction.${key}_capacity`)
return
})}
>
@@ -205,7 +188,7 @@ const ScriptContent = ({
if (state === CellState.DATA) {
return (
)
@@ -215,7 +198,7 @@ const ScriptContent = ({
}
return (
<>
-
+
{hashTag && (
)}
-
-
+
+
>
)
}
@@ -247,6 +230,7 @@ const ScriptContentJson = ({
export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => {
const setToast = useSetToast()
+ const { t } = useTranslation()
const [scriptFetched, setScriptFetched] = useState(false)
const [content, setContent] = useState(null as State.Script | State.Data | CapacityUsage | null)
const [state, setState] = useState(CellState.LOCK as CellState)
@@ -257,13 +241,13 @@ export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => {
}
useEffect(() => {
- handleFetchCellInfo(cell, state, setScriptFetched, setContent, setToast)
- }, [cell, state, setToast])
+ handleFetchCellInfo(cell, state, setScriptFetched, setContent, setToast, t)
+ }, [cell, state, setToast, t])
const onClickCopy = () => {
navigator.clipboard.writeText(updateJsonFormat(content)).then(
() => {
- setToast({ message: i18n.t('common.copied') })
+ setToast({ message: t('common.copied') })
},
error => {
console.error(error)
@@ -275,22 +259,22 @@ export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => {
changeType(CellState.LOCK)}>
- {i18n.t('transaction.lock_script')}
-
+ {t('transaction.lock_script')}
+
changeType(CellState.TYPE)}>
- {i18n.t('transaction.type_script')}
-
+ {t('transaction.type_script')}
+
changeType(CellState.DATA)}>
- {i18n.t('transaction.data')}
+ {t('transaction.data')}
changeType(CellState.CAPACITY)}
>
- {i18n.t('transaction.capacity_usage')}
-
+ {t('transaction.capacity_usage')}
+
{}} onClick={() => onClose()} />
@@ -310,7 +294,7 @@ export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => {
{!content && scriptFetched ? null : (
- {i18n.t('common.copy')}
+ {t('common.copy')}
{(state === CellState.LOCK || state === CellState.TYPE) &&
@@ -319,7 +303,7 @@ export default ({ cell, onClose }: { cell: State.Cell; onClose: Function }) => {
'codeHash' in content &&
'hashType' in content ? (
- {i18n.t('scripts.script')}
+ {t('scripts.script')}
) : null}
diff --git a/src/pages/Transaction/TransactionComp.tsx b/src/pages/Transaction/TransactionComp.tsx
index c792e0015..9419bb5fe 100644
--- a/src/pages/Transaction/TransactionComp.tsx
+++ b/src/pages/Transaction/TransactionComp.tsx
@@ -2,12 +2,11 @@
import { useState, ReactNode, FC } from 'react'
import { Link } from 'react-router-dom'
import BigNumber from 'bignumber.js'
-import { Trans } from 'react-i18next'
+import { Trans, useTranslation } from 'react-i18next'
import OverviewCard, { OverviewItemData } from '../../components/Card/OverviewCard'
import { parseSimpleDate } from '../../utils/date'
-import i18n from '../../utils/i18n'
import { localeNumberString } from '../../utils/number'
-import { formatConfirmation, shannonToCkb, matchTxHash } from '../../utils/util'
+import { useFormatConfirmation, shannonToCkb, matchTxHash } from '../../utils/util'
import {
TransactionBlockHeightPanel,
TransactionInfoContentPanel,
@@ -126,7 +125,8 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
maxCyclesInEpoch,
maxCycles,
} = transaction
-
+ const { t } = useTranslation()
+ const parseFormatConfirmation = useFormatConfirmation()
let confirmation = 0
if (tipBlockNumber && blockNumber) {
confirmation = tipBlockNumber - blockNumber
@@ -134,8 +134,8 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
const OverviewItems: Array = [
{
- title: i18n.t('block.block_height'),
- tooltip: i18n.t('glossary.block_height'),
+ title: t('block.block_height'),
+ tooltip: t('glossary.block_height'),
content: ,
},
]
@@ -143,13 +143,13 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
if (confirmation >= 0) {
OverviewItems.push(
{
- title: i18n.t('block.timestamp'),
- tooltip: i18n.t('glossary.timestamp'),
+ title: t('block.timestamp'),
+ tooltip: t('glossary.timestamp'),
content: parseSimpleDate(blockTimestamp),
},
bytes
? {
- title: `${i18n.t('transaction.transaction_fee')} | ${i18n.t('transaction.fee_rate')}`,
+ title: `${t('transaction.transaction_fee')} | ${t('transaction.fee_rate')}`,
content: (
= ({ tr
),
}
: {
- title: i18n.t('transaction.transaction_fee'),
+ title: t('transaction.transaction_fee'),
content: ,
},
{
- title: i18n.t('transaction.status'),
- tooltip: i18n.t('glossary.transaction_status'),
- content: formatConfirmation(confirmation),
+ title: t('transaction.status'),
+ tooltip: t('glossary.transaction_status'),
+ content: parseFormatConfirmation(confirmation),
},
)
}
} else {
OverviewItems.push(
{
- title: i18n.t('block.timestamp'),
- tooltip: i18n.t('glossary.timestamp'),
+ title: t('block.timestamp'),
+ tooltip: t('glossary.timestamp'),
content: showTxStatus(txStatus),
},
{
- title: i18n.t('transaction.transaction_fee'),
+ title: t('transaction.transaction_fee'),
content: ,
},
{
- title: i18n.t('transaction.status'),
- tooltip: i18n.t('glossary.transaction_status'),
+ title: t('transaction.status'),
+ tooltip: t('glossary.transaction_status'),
content: showTxStatus(txStatus),
valueTooltip: txStatus === 'rejected' ? detailedMessage : undefined,
},
@@ -202,7 +202,7 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
OverviewItems.push(
{
- title: i18n.t('transaction.size'),
+ title: t('transaction.size'),
content: bytes ? (
= ({ tr
numerator={bytes}
maxInEpoch={largestTxInEpoch}
maxInChain={largestTx}
- titleInEpoch={i18n.t('transaction.compared_to_the_max_size_in_epoch')}
- titleInChain={i18n.t('transaction.compared_to_the_max_size_in_chain')}
+ titleInEpoch={t('transaction.compared_to_the_max_size_in_epoch')}
+ titleInChain={t('transaction.compared_to_the_max_size_in_chain')}
unit="Bytes"
>
- {i18n.t('transaction.size_in_block', {
+ {t('transaction.size_in_block', {
bytes: bytes.toLocaleString('en'),
})}
@@ -230,7 +230,7 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
},
null,
{
- title: i18n.t('transaction.cycles'),
+ title: t('transaction.cycles'),
content: cycles ? (
= ({ tr
numerator={cycles}
maxInEpoch={maxCyclesInEpoch}
maxInChain={maxCycles}
- titleInEpoch={i18n.t('transaction.compared_to_the_max_cycles_in_epoch')}
- titleInChain={i18n.t('transaction.compared_to_the_max_cycles_in_chain')}
+ titleInEpoch={t('transaction.compared_to_the_max_cycles_in_epoch')}
+ titleInChain={t('transaction.compared_to_the_max_cycles_in_chain')}
/>
) : (
@@ -255,7 +255,7 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
const TransactionParams = [
{
- title: i18n.t('transaction.cell_deps'),
+ title: t('transaction.cell_deps'),
tooltip: (
= ({ tr
return (
}
/>
)
@@ -307,37 +307,37 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
),
},
{
- title: i18n.t('transaction.header_deps'),
- tooltip: i18n.t('glossary.header_deps'),
+ title: t('transaction.header_deps'),
+ tooltip: t('glossary.header_deps'),
content:
headerDeps && headerDeps.length > 0 ? (
headerDeps.map(headerDep => (
))
) : (
-
+
),
},
{
- title: i18n.t('transaction.witnesses'),
- tooltip: i18n.t('glossary.witnesses'),
+ title: t('transaction.witnesses'),
+ tooltip: t('glossary.witnesses'),
content:
witnesses && witnesses.length > 0 ? (
witnesses.map((witness, index) => (
))
) : (
-
+
),
},
]
@@ -347,7 +347,7 @@ export const TransactionOverview: FC<{ transaction: State.Transaction }> = ({ tr
setShowParams(!showParams)}>
- {i18n.t('transaction.transaction_parameters')}
+ {t('transaction.transaction_parameters')}
{showParams && (
diff --git a/src/pages/Transaction/TransactionReward/index.tsx b/src/pages/Transaction/TransactionReward/index.tsx
index 82f742393..aa4c77e18 100644
--- a/src/pages/Transaction/TransactionReward/index.tsx
+++ b/src/pages/Transaction/TransactionReward/index.tsx
@@ -1,38 +1,43 @@
+import { useTranslation } from 'react-i18next'
import { shannonToCkb } from '../../../utils/util'
import { localeNumberString } from '../../../utils/number'
-import i18n from '../../../utils/i18n'
import DecimalCapacity from '../../../components/DecimalCapacity'
import { RewardPenal, RewardItemPenal } from './styled'
import { useIsMobile } from '../../../utils/hook'
-const Rewards = (cell: State.Cell, isMobile: boolean) => [
- {
- name: isMobile ? i18n.t('transaction.base') : i18n.t('transaction.base_reward'),
- capacity: cell.baseReward,
- },
- {
- name: isMobile ? i18n.t('transaction.secondary') : i18n.t('transaction.secondary_reward'),
- capacity: cell.secondaryReward,
- },
- {
- name: isMobile ? i18n.t('transaction.commit') : i18n.t('transaction.commit_reward'),
- capacity: cell.commitReward,
- },
- {
- name: isMobile ? i18n.t('transaction.proposal') : i18n.t('transaction.proposal_reward'),
- capacity: cell.proposalReward,
- },
-]
+const useRewards = (cell: State.Cell, isMobile: boolean) => {
+ const { t } = useTranslation()
+ return [
+ {
+ name: isMobile ? t('transaction.base') : t('transaction.base_reward'),
+ capacity: cell.baseReward,
+ },
+ {
+ name: isMobile ? t('transaction.secondary') : t('transaction.secondary_reward'),
+ capacity: cell.secondaryReward,
+ },
+ {
+ name: isMobile ? t('transaction.commit') : t('transaction.commit_reward'),
+ capacity: cell.commitReward,
+ },
+ {
+ name: isMobile ? t('transaction.proposal') : t('transaction.proposal_reward'),
+ capacity: cell.proposalReward,
+ },
+ ]
+}
const TransactionReward = ({ cell, showReward }: { cell: State.Cell; showReward?: boolean }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
// [0, 11] block doesn't show block reward and only cellbase show block reward
const showBlockReward = showReward && cell.targetBlockNumber > 0
+ const rewards = useRewards(cell, isMobile)
return showBlockReward ? (
- {i18n.t('transaction.reward_info')}
- {Rewards(cell, isMobile).map(reward => (
+ {t('transaction.reward_info')}
+ {rewards.map(reward => (
{reward.name}
diff --git a/src/pages/Transaction/index.tsx b/src/pages/Transaction/index.tsx
index 1f4046f18..4c4ef94d1 100644
--- a/src/pages/Transaction/index.tsx
+++ b/src/pages/Transaction/index.tsx
@@ -1,8 +1,8 @@
import { useParams } from 'react-router-dom'
import { useQuery } from 'react-query'
+import { useTranslation } from 'react-i18next'
import TransactionHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
-import i18n from '../../utils/i18n'
import { TransactionDiv as TransactionPanel } from './styled'
import TransactionComp, { TransactionOverview } from './TransactionComp'
import { explorerService } from '../../services/ExplorerService'
@@ -10,6 +10,7 @@ import { QueryResult } from '../../components/QueryResult'
import { defaultTransactionInfo } from './state'
export default () => {
+ const { t } = useTranslation()
const { hash: txHash } = useParams<{ hash: string }>()
const query = useQuery(['transaction', txHash], async () => {
@@ -26,7 +27,7 @@ export default () => {
return (
-
+
{txStatus !== 'committed' || blockTimestamp > 0 ? : null}
diff --git a/src/pages/TransactionList/index.tsx b/src/pages/TransactionList/index.tsx
index f3854cf9a..bf87919ed 100644
--- a/src/pages/TransactionList/index.tsx
+++ b/src/pages/TransactionList/index.tsx
@@ -6,7 +6,6 @@ import { parseSimpleDate } from '../../utils/date'
import Content from '../../components/Content'
import { shannonToCkb } from '../../utils/util'
import { localeNumberString } from '../../utils/number'
-import i18n from '../../utils/i18n'
import Pagination from '../../components/Pagination'
import DecimalCapacity from '../../components/DecimalCapacity'
import { ItemCardData, ItemCardGroup } from '../../components/Card/ItemCard'
@@ -36,8 +35,9 @@ const TransactionCardGroup: FC<{
type: TxStatus
sortButton: (sortRule?: ConfirmedSortByType | PendingSortByType) => ReactNode
}> = ({ transactions, type, sortButton }) => {
+ const { t } = useTranslation()
const itemHash: SortItemCardData = {
- title: i18n.t('transaction.transaction_hash'),
+ title: t('transaction.transaction_hash'),
render: transaction => (
= {
- title: i18n.t('transaction.capacity'),
+ title: t('transaction.capacity'),
sortRule: 'capacity',
render: transaction => (
@@ -62,7 +62,7 @@ const TransactionCardGroup: FC<{
const confirmedItems: SortItemCardData[] = [
itemHash,
{
- title: i18n.t('transaction.height'),
+ title: t('transaction.height'),
sortRule: 'height',
render: transaction => (
@@ -72,7 +72,7 @@ const TransactionCardGroup: FC<{
},
itemCapacity,
{
- title: i18n.t('transaction.time'),
+ title: t('transaction.time'),
render: transaction => parseSimpleDate(transaction.blockTimestamp),
},
]
@@ -81,7 +81,7 @@ const TransactionCardGroup: FC<{
itemHash,
itemCapacity,
{
- title: i18n.t('transaction.time'),
+ title: t('transaction.time'),
sortRule: 'time',
render: transaction => {
assert(transaction.createTimestamp != null)
@@ -89,7 +89,7 @@ const TransactionCardGroup: FC<{
},
},
{
- title: i18n.t('transaction.transaction_fee'),
+ title: t('transaction.transaction_fee'),
sortRule: 'fee',
render: transaction => ,
},
@@ -226,6 +226,7 @@ const TransactionTable: FC<{
const TransactionsPanel: FC<{ type: TxStatus }> = ({ type }) => {
const isMobile = useIsMobile()
+ const { t } = useTranslation()
const { currentPage, pageSize, setPage } = usePaginationParamsInListPage()
const { state } = useLocation()
const stateStaleTime = 3000
@@ -295,7 +296,7 @@ const TransactionsPanel: FC<{ type: TxStatus }> = ({ type }) => {
onChange={setPage}
annotation={
totalPages === MAX_PAGE_NUMBER
- ? i18n.t('pagination.only_first_pages_visible', { pages: MAX_PAGE_NUMBER })
+ ? t('pagination.only_first_pages_visible', { pages: MAX_PAGE_NUMBER })
: undefined
}
/>
diff --git a/src/services/ExplorerService/requester.ts b/src/services/ExplorerService/requester.ts
index 5d984e922..8a06de0b2 100644
--- a/src/services/ExplorerService/requester.ts
+++ b/src/services/ExplorerService/requester.ts
@@ -1,6 +1,5 @@
import axios, { AxiosError } from 'axios'
import CONFIG from '../../config'
-import i18n from '../../utils/i18n'
import { setNetworkErrMsgs } from '../../components/Sheet'
export const requesterV1 = axios.create({
@@ -32,7 +31,7 @@ const updateNetworkError = (errMessage = 'toast.invalid_network') => {
setNetworkErrMsgs([])
timeout = null
}, 2000)
- setNetworkErrMsgs([i18n.t(errMessage)])
+ setNetworkErrMsgs([errMessage])
}
requesterV1.interceptors.request.use(
diff --git a/src/types/index.d.ts b/src/types/index.d.ts
index d5aa7b43d..6ec2d61a2 100644
--- a/src/types/index.d.ts
+++ b/src/types/index.d.ts
@@ -66,6 +66,7 @@ declare namespace State {
id: number
addressHash: string
capacity: string
+ occupiedCapacity: string
fromCellbase: boolean
generatedTxHash: string
targetBlockNumber: number
diff --git a/src/utils/date.ts b/src/utils/date.ts
index d7804fae6..e5dcb7cd3 100644
--- a/src/utils/date.ts
+++ b/src/utils/date.ts
@@ -6,7 +6,7 @@ import 'dayjs/locale/en'
import BigNumber from 'bignumber.js'
import weekday from 'dayjs/plugin/weekday'
import localeData from 'dayjs/plugin/localeData'
-import i18n from './i18n'
+import { useTranslation } from 'react-i18next'
dayjs.extend(relativeTime)
dayjs.extend(updateLocale)
@@ -55,15 +55,18 @@ export const parseDateNoTime = (timestamp: number | string | Date, noYear = fals
return `${year}${formatData(date.getMonth() + 1)}${connector}${formatData(date.getDate())}`
}
-export const parseDate = (timestamp: number | string, now = new Date().getTime()) => {
- const diff = (now - Number(timestamp)) / 1000
- if (diff < 60) {
- return `${Math.floor(diff)}${i18n.t('common.second_ago')}`
+export const useParseDate = () => {
+ const { t } = useTranslation()
+ return (timestamp: number | string, now = new Date().getTime()) => {
+ const diff = (now - Number(timestamp)) / 1000
+ if (diff < 60) {
+ return `${Math.floor(diff)}${t('common.second_ago')}`
+ }
+ if (diff < 3600) {
+ return `${Math.floor(diff / 60)}${t('common.minute')} ${Math.floor(diff % 60)}${t('common.second_ago')}`
+ }
+ return parseSimpleDate(timestamp)
}
- if (diff < 3600) {
- return `${Math.floor(diff / 60)}${i18n.t('common.minute')} ${Math.floor(diff % 60)}${i18n.t('common.second_ago')}`
- }
- return parseSimpleDate(timestamp)
}
export const getCurrentYear = () => new Date().getFullYear()
diff --git a/src/utils/hook.ts b/src/utils/hook.ts
index bd58a5f52..38a6b9b4b 100644
--- a/src/utils/hook.ts
+++ b/src/utils/hook.ts
@@ -23,9 +23,9 @@ import {
storeDateChartCache,
storeEpochChartCache,
} from './cache'
-import { parseDate } from './date'
import { omit } from './object'
// TODO: This file depends on higher-level abstractions, so it should not be in the utils folder. It should be moved to `src/hooks/index.ts`.
+import { useParseDate } from './date'
import { Response, useStatistics } from '../services/ExplorerService'
/**
@@ -576,6 +576,7 @@ export function useTimestamp(): number {
}
export function useParsedDate(timestamp: number): string {
+ const parseDate = useParseDate()
const now = useTimestamp()
return parseDate(timestamp, now)
}
diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts
index d491ebbbf..0ec0b9f7f 100644
--- a/src/utils/i18n.ts
+++ b/src/utils/i18n.ts
@@ -1,30 +1,60 @@
import i18n from 'i18next'
-import { initReactI18next } from 'react-i18next'
+import { initReactI18next, useTranslation } from 'react-i18next'
import en from '../locales/en.json'
import zh from '../locales/zh.json'
import { storeCachedData, fetchCachedData } from './cache'
import { AppCachedKeys } from '../constants/cache'
+export type LanuageType = 'en' | 'zh'
+
+const getDefaultLanguage = () => fetchCachedData(AppCachedKeys.AppLanguage) ?? 'en'
+const setDefaultLanguage = (lng: LanuageType) => storeCachedData(AppCachedKeys.AppLanguage, lng)
+
i18n.use(initReactI18next).init({
resources: {
en,
zh,
},
- fallbackLng: 'en',
+ fallbackLng: getDefaultLanguage(),
interpolation: {
escapeValue: false,
},
})
-export const changeLanguage = (lan: 'en' | 'zh') => {
- if (lan.indexOf('zh') !== -1) {
- i18n.changeLanguage('zh')
- } else {
- i18n.changeLanguage('en')
+i18n.on('languageChanged', (lng: LanuageType) => {
+ setDefaultLanguage(lng)
+})
+
+export const useCurrentLanguage = (): LanuageType => {
+ const { i18n } = useTranslation()
+ const currentLanguage = i18n.language
+ if (currentLanguage !== 'en' && currentLanguage !== 'zh') {
+ throw new Error('Not supported language')
}
- storeCachedData(AppCachedKeys.AppLanguage, lan)
+ return currentLanguage
}
-export const currentLanguage = (): 'en' | 'zh' | null => fetchCachedData<'en' | 'zh'>(AppCachedKeys.AppLanguage)
+export const useToggleLanguage = () => {
+ const currentLanguage = useCurrentLanguage()
-export default i18n
+ return () => {
+ if (currentLanguage === 'zh') {
+ i18n.changeLanguage('en')
+ } else {
+ i18n.changeLanguage('zh')
+ }
+ }
+}
+
+export const useLanguageText = (payload?: { reverse: boolean }) => {
+ const currentLanguage = useCurrentLanguage()
+ const { t } = useTranslation()
+ if (payload?.reverse) {
+ return currentLanguage === 'zh' ? t('navbar.language_en') : t('navbar.language_zh')
+ }
+ return currentLanguage === 'en' ? t('navbar.language_en') : t('navbar.language_zh')
+}
+
+export const useOtherLanguageText = () => {
+ return useLanguageText({ reverse: true })
+}
diff --git a/src/utils/util.ts b/src/utils/util.ts
index 89b8c4bcc..bfb7c8214 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -3,6 +3,7 @@ import camelcaseKeys from 'camelcase-keys'
import JSBI from 'jsbi'
import BigNumber from 'bignumber.js'
import { scriptToAddress, addressToScript } from '@nervosnetwork/ckb-sdk-utils'
+import { useTranslation } from 'react-i18next'
import { MAX_CONFIRMATION, TOKEN_EMAIL_SUBJECT, TOKEN_EMAIL_BODY, TOKEN_EMAIL_ADDRESS } from '../constants/common'
import {
ContractHashTag,
@@ -10,7 +11,6 @@ import {
ScriptTagExtraRules,
TestnetContractHashTags,
} from '../constants/scripts'
-import i18n from './i18n'
import { isMainnet } from './chain'
export const copyElementValue = (component: any) => {
@@ -74,14 +74,17 @@ export const toCamelcase = (object: any): T => {
) as T
}
-export const formatConfirmation = (confirmation: number) => {
- if (confirmation > MAX_CONFIRMATION) {
- return `${MAX_CONFIRMATION}+ ${i18n.t('address.confirmations')}`
- }
- if (confirmation > 1) {
- return `${confirmation} ${i18n.t('address.confirmations')}`
+export const useFormatConfirmation = () => {
+ const { t } = useTranslation()
+ return (confirmation: number) => {
+ if (confirmation > MAX_CONFIRMATION) {
+ return `${MAX_CONFIRMATION}+ ${t('address.confirmations')}`
+ }
+ if (confirmation > 1) {
+ return `${confirmation} ${t('address.confirmations')}`
+ }
+ return `${confirmation} ${t('address.confirmation')}`
}
- return `${confirmation} ${i18n.t('address.confirmation')}`
}
export const isValidReactNode = (node: ReactNode) => {
@@ -333,7 +336,7 @@ export default {
copyElementValue,
shannonToCkb,
toCamelcase,
- formatConfirmation,
+ useFormatConfirmation,
isValidReactNode,
deprecatedAddrToNewAddr,
handleRedirectFromAggron,
diff --git a/yarn.lock b/yarn.lock
index 52552d3ee..858227f04 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -104,6 +104,14 @@
dependencies:
"@babel/highlight" "^7.18.6"
+"@babel/code-frame@^7.22.13":
+ version "7.22.13"
+ resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.13.tgz#e3c1c099402598483b7a8c46a721d1038803755e"
+ integrity sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==
+ dependencies:
+ "@babel/highlight" "^7.22.13"
+ chalk "^2.4.2"
+
"@babel/code-frame@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.8.3.tgz#33e25903d7481181534e12ec0a25f16b6fcf419e"
@@ -177,6 +185,16 @@
"@jridgewell/gen-mapping" "^0.3.2"
jsesc "^2.5.1"
+"@babel/generator@^7.23.0":
+ version "7.23.0"
+ resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.23.0.tgz#df5c386e2218be505b34837acbcb874d7a983420"
+ integrity sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==
+ dependencies:
+ "@babel/types" "^7.23.0"
+ "@jridgewell/gen-mapping" "^0.3.2"
+ "@jridgewell/trace-mapping" "^0.3.17"
+ jsesc "^2.5.1"
+
"@babel/generator@^7.9.0":
version "7.9.4"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.9.4.tgz#12441e90c3b3c4159cdecf312075bf1a8ce2dbce"
@@ -257,6 +275,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz#0c0cee9b35d2ca190478756865bb3528422f51be"
integrity sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==
+"@babel/helper-environment-visitor@^7.22.20":
+ version "7.22.20"
+ resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz#96159db61d34a29dba454c959f5ae4a649ba9167"
+ integrity sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==
+
"@babel/helper-explode-assignable-expression@^7.18.6":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.18.6.tgz#41f8228ef0a6f1a036b8dfdfec7ce94f9a6bc096"
@@ -272,21 +295,13 @@
"@babel/template" "^7.18.10"
"@babel/types" "^7.19.0"
-"@babel/helper-function-name@^7.8.3":
- version "7.8.3"
- resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.8.3.tgz#eeeb665a01b1f11068e9fb86ad56a1cb1a824cca"
- integrity sha512-BCxgX1BC2hD/oBlIFUgOCQDOPV8nSINxCwM3o93xP4P9Fq6aV5sgv2cOOITDMtCfQ+3PvHp3l689XZvAM9QyOA==
- dependencies:
- "@babel/helper-get-function-arity" "^7.8.3"
- "@babel/template" "^7.8.3"
- "@babel/types" "^7.8.3"
-
-"@babel/helper-get-function-arity@^7.8.3":
- version "7.8.3"
- resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.8.3.tgz#b894b947bd004381ce63ea1db9f08547e920abd5"
- integrity sha512-FVDR+Gd9iLjUMY1fzE2SR0IuaJToR4RkCDARVfsBBPSP53GEqSFjD8gNyxg246VUyc/ALRxFaAK8rVG7UT7xRA==
+"@babel/helper-function-name@^7.23.0":
+ version "7.23.0"
+ resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz#1f9a3cdbd5b2698a670c30d2735f9af95ed52759"
+ integrity sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==
dependencies:
- "@babel/types" "^7.8.3"
+ "@babel/template" "^7.22.15"
+ "@babel/types" "^7.23.0"
"@babel/helper-hoist-variables@^7.18.6":
version "7.18.6"
@@ -295,6 +310,13 @@
dependencies:
"@babel/types" "^7.18.6"
+"@babel/helper-hoist-variables@^7.22.5":
+ version "7.22.5"
+ resolved "https://registry.yarnpkg.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz#c01a007dac05c085914e8fb652b339db50d823bb"
+ integrity sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==
+ dependencies:
+ "@babel/types" "^7.22.5"
+
"@babel/helper-member-expression-to-functions@^7.18.9":
version "7.18.9"
resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.18.9.tgz#1531661e8375af843ad37ac692c132841e2fd815"
@@ -441,6 +463,13 @@
dependencies:
"@babel/types" "^7.18.6"
+"@babel/helper-split-export-declaration@^7.22.6":
+ version "7.22.6"
+ resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz#322c61b7310c0997fe4c323955667f18fcefb91c"
+ integrity sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==
+ dependencies:
+ "@babel/types" "^7.22.5"
+
"@babel/helper-split-export-declaration@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.8.3.tgz#31a9f30070f91368a7182cf05f831781065fc7a9"
@@ -453,6 +482,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz#38d3acb654b4701a9b77fb0615a96f775c3a9e63"
integrity sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==
+"@babel/helper-string-parser@^7.22.5":
+ version "7.22.5"
+ resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f"
+ integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==
+
"@babel/helper-validator-identifier@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.4.tgz#a78c7a7251e01f616512d31b10adcf52ada5e0d2"
@@ -463,6 +497,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2"
integrity sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==
+"@babel/helper-validator-identifier@^7.22.20":
+ version "7.22.20"
+ resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0"
+ integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==
+
"@babel/helper-validator-identifier@^7.22.5", "@babel/helper-validator-identifier@^7.9.0":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193"
@@ -528,11 +567,25 @@
chalk "^2.4.2"
js-tokens "^4.0.0"
+"@babel/highlight@^7.22.13":
+ version "7.22.20"
+ resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.22.20.tgz#4ca92b71d80554b01427815e06f2df965b9c1f54"
+ integrity sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==
+ dependencies:
+ "@babel/helper-validator-identifier" "^7.22.20"
+ chalk "^2.4.2"
+ js-tokens "^4.0.0"
+
"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.18.10", "@babel/parser@^7.20.5":
version "7.20.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.20.5.tgz#7f3c7335fe417665d929f34ae5dceae4c04015e8"
integrity sha512-r27t/cy/m9uKLXQNWWebeCUHgnAZq0CpG1OwKRxzJMP1vpSU4bSIK2hq+/cp0bQxetkXx38n09rNu8jVkcK/zA==
+"@babel/parser@^7.22.15", "@babel/parser@^7.23.0":
+ version "7.23.0"
+ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.0.tgz#da950e622420bf96ca0d0f2909cdddac3acd8719"
+ integrity sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==
+
"@babel/parser@^7.8.3", "@babel/parser@^7.8.6", "@babel/parser@^7.9.0":
version "7.9.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.4.tgz#68a35e6b0319bbc014465be43828300113f2f2e8"
@@ -1346,6 +1399,15 @@
"@babel/parser" "^7.18.10"
"@babel/types" "^7.18.10"
+"@babel/template@^7.22.15":
+ version "7.22.15"
+ resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
+ integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==
+ dependencies:
+ "@babel/code-frame" "^7.22.13"
+ "@babel/parser" "^7.22.15"
+ "@babel/types" "^7.22.15"
+
"@babel/template@^7.8.3", "@babel/template@^7.8.6":
version "7.8.6"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.8.6.tgz#86b22af15f828dfb086474f964dcc3e39c43ce2b"
@@ -1355,36 +1417,21 @@
"@babel/parser" "^7.8.6"
"@babel/types" "^7.8.6"
-"@babel/traverse@^7.19.1", "@babel/traverse@^7.20.1", "@babel/traverse@^7.20.5", "@babel/traverse@^7.7.2":
- version "7.20.5"
- resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.20.5.tgz#78eb244bea8270fdda1ef9af22a5d5e5b7e57133"
- integrity sha512-WM5ZNN3JITQIq9tFZaw1ojLU3WgWdtkxnhM1AegMS+PvHjkM5IXjmYEGY7yukz5XS4sJyEf2VzWjI8uAavhxBQ==
- dependencies:
- "@babel/code-frame" "^7.18.6"
- "@babel/generator" "^7.20.5"
- "@babel/helper-environment-visitor" "^7.18.9"
- "@babel/helper-function-name" "^7.19.0"
- "@babel/helper-hoist-variables" "^7.18.6"
- "@babel/helper-split-export-declaration" "^7.18.6"
- "@babel/parser" "^7.20.5"
- "@babel/types" "^7.20.5"
- debug "^4.1.0"
- globals "^11.1.0"
-
-"@babel/traverse@^7.4.5", "@babel/traverse@^7.8.3", "@babel/traverse@^7.8.6", "@babel/traverse@^7.9.0":
- version "7.9.0"
- resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.9.0.tgz#d3882c2830e513f4fe4cec9fe76ea1cc78747892"
- integrity sha512-jAZQj0+kn4WTHO5dUZkZKhbFrqZE7K5LAQ5JysMnmvGij+wOdr+8lWqPeW0BcF4wFwrEXXtdGO7wcV6YPJcf3w==
- dependencies:
- "@babel/code-frame" "^7.8.3"
- "@babel/generator" "^7.9.0"
- "@babel/helper-function-name" "^7.8.3"
- "@babel/helper-split-export-declaration" "^7.8.3"
- "@babel/parser" "^7.9.0"
- "@babel/types" "^7.9.0"
+"@babel/traverse@^7.19.1", "@babel/traverse@^7.20.1", "@babel/traverse@^7.20.5", "@babel/traverse@^7.4.5", "@babel/traverse@^7.7.2", "@babel/traverse@^7.8.3", "@babel/traverse@^7.8.6", "@babel/traverse@^7.9.0":
+ version "7.23.2"
+ resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.2.tgz#329c7a06735e144a506bdb2cad0268b7f46f4ad8"
+ integrity sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==
+ dependencies:
+ "@babel/code-frame" "^7.22.13"
+ "@babel/generator" "^7.23.0"
+ "@babel/helper-environment-visitor" "^7.22.20"
+ "@babel/helper-function-name" "^7.23.0"
+ "@babel/helper-hoist-variables" "^7.22.5"
+ "@babel/helper-split-export-declaration" "^7.22.6"
+ "@babel/parser" "^7.23.0"
+ "@babel/types" "^7.23.0"
debug "^4.1.0"
globals "^11.1.0"
- lodash "^4.17.13"
"@babel/types@^7.0.0", "@babel/types@^7.12.6", "@babel/types@^7.18.10", "@babel/types@^7.18.6", "@babel/types@^7.18.9", "@babel/types@^7.19.0", "@babel/types@^7.20.0", "@babel/types@^7.20.2", "@babel/types@^7.20.5", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
version "7.20.5"
@@ -1404,6 +1451,15 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"
+"@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0":
+ version "7.23.0"
+ resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.0.tgz#8c1f020c9df0e737e4e247c0619f58c68458aaeb"
+ integrity sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==
+ dependencies:
+ "@babel/helper-string-parser" "^7.22.5"
+ "@babel/helper-validator-identifier" "^7.22.20"
+ to-fast-properties "^2.0.0"
+
"@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.9.0":
version "7.9.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.9.0.tgz#00b064c3df83ad32b2dbf5ff07312b15c7f1efb5"
@@ -2032,6 +2088,11 @@
resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz#2203b118c157721addfe69d47b70465463066d78"
integrity sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==
+"@jridgewell/resolve-uri@^3.1.0":
+ version "3.1.1"
+ resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721"
+ integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==
+
"@jridgewell/set-array@^1.0.0", "@jridgewell/set-array@^1.0.1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@jridgewell/set-array/-/set-array-1.1.2.tgz#7c6cf998d6d20b914c0a55a91ae928ff25965e72"
@@ -2050,7 +2111,7 @@
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz#add4c98d341472a289190b424efbdb096991bb24"
integrity sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==
-"@jridgewell/sourcemap-codec@^1.4.13":
+"@jridgewell/sourcemap-codec@^1.4.13", "@jridgewell/sourcemap-codec@^1.4.14":
version "1.4.15"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==
@@ -2063,6 +2124,14 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"
+"@jridgewell/trace-mapping@^0.3.17":
+ version "0.3.20"
+ resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz#72e45707cf240fa6b081d0366f8265b0cd10197f"
+ integrity sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==
+ dependencies:
+ "@jridgewell/resolve-uri" "^3.1.0"
+ "@jridgewell/sourcemap-codec" "^1.4.14"
+
"@leichtgewicht/ip-codec@^2.0.1":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
@@ -4295,15 +4364,10 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"
-caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001426:
- version "1.0.30001441"
- resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001441.tgz#987437b266260b640a23cd18fbddb509d7f69f3e"
- integrity sha512-OyxRR4Vof59I3yGWXws6i908EtGbMzVUi3ganaZQHmydk1iwDhRnvaPG2WaR0KcqrDFKrxVZHULT396LEPhXfg==
-
-caniuse-lite@^1.0.30001487, caniuse-lite@^1.0.30001538:
- version "1.0.30001539"
- resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001539.tgz#325a387ab1ed236df2c12dc6cd43a4fff9903a44"
- integrity sha512-hfS5tE8bnNiNvEOEkm8HElUHroYwlqMMENEzELymy77+tJ6m+gA2krtHl5hxJaj71OlpC2cHZbdSMX1/YEqEkA==
+caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001426, caniuse-lite@^1.0.30001487, caniuse-lite@^1.0.30001538:
+ version "1.0.30001549"
+ resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001549.tgz"
+ integrity sha512-qRp48dPYSCYaP+KurZLhDYdVE+yEyht/3NlmcJgVQ2VMGt6JL36ndQ/7rgspdZsJuxDPFIo/OzBT2+GmIJ53BA==
case-sensitive-paths-webpack-plugin@^2.4.0:
version "2.4.0"
@@ -5778,7 +5842,26 @@ eslint-plugin-flowtype@^8.0.3:
lodash "^4.17.21"
string-natural-compare "^3.0.1"
-eslint-plugin-import@2.28.1:
+eslint-plugin-import@^2.25.3:
+ version "2.26.0"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz#f812dc47be4f2b72b478a021605a59fc6fe8b88b"
+ integrity sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==
+ dependencies:
+ array-includes "^3.1.4"
+ array.prototype.flat "^1.2.5"
+ debug "^2.6.9"
+ doctrine "^2.1.0"
+ eslint-import-resolver-node "^0.3.6"
+ eslint-module-utils "^2.7.3"
+ has "^1.0.3"
+ is-core-module "^2.8.1"
+ is-glob "^4.0.3"
+ minimatch "^3.1.2"
+ object.values "^1.1.5"
+ resolve "^1.22.0"
+ tsconfig-paths "^3.14.1"
+
+eslint-plugin-import@^2.28.1:
version "2.28.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.28.1.tgz#63b8b5b3c409bfc75ebaf8fb206b07ab435482c4"
integrity sha512-9I9hFlITvOV55alzoKBI+K9q74kv0iKMeY6av5+umsNwayt59fz692daGyjR+oStBQgx6nwR9rXldDev3Clw+A==
@@ -5801,25 +5884,6 @@ eslint-plugin-import@2.28.1:
semver "^6.3.1"
tsconfig-paths "^3.14.2"
-eslint-plugin-import@^2.25.3:
- version "2.26.0"
- resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.26.0.tgz#f812dc47be4f2b72b478a021605a59fc6fe8b88b"
- integrity sha512-hYfi3FXaM8WPLf4S1cikh/r4IxnO6zrhZbEGz2b660EJRbuxgpDS5gkCuYgGWg2xxh2rBuIr4Pvhve/7c31koA==
- dependencies:
- array-includes "^3.1.4"
- array.prototype.flat "^1.2.5"
- debug "^2.6.9"
- doctrine "^2.1.0"
- eslint-import-resolver-node "^0.3.6"
- eslint-module-utils "^2.7.3"
- has "^1.0.3"
- is-core-module "^2.8.1"
- is-glob "^4.0.3"
- minimatch "^3.1.2"
- object.values "^1.1.5"
- resolve "^1.22.0"
- tsconfig-paths "^3.14.1"
-
eslint-plugin-jest@^25.3.0:
version "25.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-25.7.0.tgz#ff4ac97520b53a96187bad9c9814e7d00de09a6a"
@@ -5908,6 +5972,18 @@ eslint-plugin-testing-library@^5.0.1:
dependencies:
"@typescript-eslint/utils" "^5.13.0"
+eslint-plugin-unused-imports@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.0.0.tgz#d25175b0072ff16a91892c3aa72a09ca3a9e69e7"
+ integrity sha512-sduiswLJfZHeeBJ+MQaG+xYzSWdRXoSw61DpU13mzWumCkR0ufD0HmO4kdNokjrkluMHpj/7PJeN35pgbhW3kw==
+ dependencies:
+ eslint-rule-composer "^0.3.0"
+
+eslint-rule-composer@^0.3.0:
+ version "0.3.0"
+ resolved "https://registry.yarnpkg.com/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz#79320c927b0c5c0d3d3d2b76c8b4a488f25bbaf9"
+ integrity sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==
+
eslint-scope@5.1.1, eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
|