From 5285074b73724ff1db26b7c8f54eec7f1596c295 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Wed, 10 Jan 2024 10:23:23 +0800 Subject: [PATCH] feat: Add left time. 1. Add left time for sync 2. Move global loading to button when clear cache. --- .../ClearCache/clearCache.module.scss | 24 +++++++---------- .../src/components/ClearCache/index.tsx | 24 ++++++++--------- .../src/components/PageContainer/index.tsx | 3 ++- .../src/components/SyncStatus/index.tsx | 13 ++++++++-- .../SyncStatus/syncStatus.module.scss | 4 ++- packages/neuron-ui/src/locales/en.json | 3 ++- packages/neuron-ui/src/locales/es.json | 3 ++- packages/neuron-ui/src/locales/fr.json | 3 ++- packages/neuron-ui/src/locales/zh-tw.json | 3 ++- packages/neuron-ui/src/locales/zh.json | 3 ++- .../src/tests/getSyncLeftTime/fixtures.json | 26 ++++++++++++++----- .../neuron-ui/src/utils/getSyncLeftTime.ts | 8 +++--- 12 files changed, 72 insertions(+), 45 deletions(-) diff --git a/packages/neuron-ui/src/components/ClearCache/clearCache.module.scss b/packages/neuron-ui/src/components/ClearCache/clearCache.module.scss index 807b9ad684..fbcb1ca54e 100644 --- a/packages/neuron-ui/src/components/ClearCache/clearCache.module.scss +++ b/packages/neuron-ui/src/components/ClearCache/clearCache.module.scss @@ -5,26 +5,22 @@ font-size: 12px; } -.clearDialog { - height: 180px; - width: 360px; - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - p { - font-weight: 500; - font-size: 16px; - color: var(--main-text-color); - } -} - .clearBtn { &[disabled] { opacity: 0.5; box-shadow: none !important; cursor: not-allowed; } + + .spinner { + width: 16px; + height: 16px; + vertical-align: sub; + margin-left: 4px; + & > path { + fill: var(--secondary-text-color); + } + } } .options { diff --git a/packages/neuron-ui/src/components/ClearCache/index.tsx b/packages/neuron-ui/src/components/ClearCache/index.tsx index 1007687528..1788620ef4 100644 --- a/packages/neuron-ui/src/components/ClearCache/index.tsx +++ b/packages/neuron-ui/src/components/ClearCache/index.tsx @@ -1,7 +1,6 @@ import React, { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import Spinner from 'widgets/Spinner' -import Dialog from 'widgets/Dialog' import Toast from 'widgets/Toast' import { StateDispatch, addPopup } from 'states' import { clearCellCache } from 'services/remote' @@ -9,7 +8,7 @@ import { cacheClearDate } from 'services/localCache' import { isSuccessResponse, uniformTimeFormatter } from 'utils' import styles from './clearCache.module.scss' -const ClearCacheDialog = ({ +const ClearCache = ({ dispatch, className, btnClassName, @@ -50,20 +49,21 @@ const ClearCacheDialog = ({ onClick={handleSubmit} disabled={isClearing} > - {t('settings.data.refresh')} + {isClearing ? ( + <> + +    + {t('settings.data.clearing-cache')} + + ) : ( + t('settings.data.refresh') + )} - - -
- -

{t('settings.data.clearing-cache')}

-
-
setNotice('')} /> ) } -ClearCacheDialog.displayName = 'ClearCacheDialog' -export default ClearCacheDialog +ClearCache.displayName = 'ClearCache' +export default ClearCache diff --git a/packages/neuron-ui/src/components/PageContainer/index.tsx b/packages/neuron-ui/src/components/PageContainer/index.tsx index 7ee23aad18..8a665470e2 100755 --- a/packages/neuron-ui/src/components/PageContainer/index.tsx +++ b/packages/neuron-ui/src/components/PageContainer/index.tsx @@ -41,7 +41,7 @@ const PageContainer: React.FC = props => { const { app: { showWaitForFullySynced }, chain: { - syncState: { bestKnownBlockNumber, cacheTipBlockNumber, syncStatus, isLookingValidTarget, validTarget }, + syncState: { bestKnownBlockNumber, cacheTipBlockNumber, syncStatus, isLookingValidTarget, validTarget, estimate }, connectionStatus, networkID, }, @@ -141,6 +141,7 @@ const PageContainer: React.FC = props => { isLightClient={isLightClient} onOpenSetStartBlock={openDialog} startBlockNumber={walletStartBlockNumber} + estimate={estimate} /> diff --git a/packages/neuron-ui/src/components/SyncStatus/index.tsx b/packages/neuron-ui/src/components/SyncStatus/index.tsx index 01a7d4ccac..5735881e07 100644 --- a/packages/neuron-ui/src/components/SyncStatus/index.tsx +++ b/packages/neuron-ui/src/components/SyncStatus/index.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' -import { SyncStatus as SyncStatusEnum, ConnectionStatus, clsx, localNumberFormatter } from 'utils' +import { SyncStatus as SyncStatusEnum, ConnectionStatus, clsx, localNumberFormatter, getSyncLeftTime } from 'utils' import { Confirming, NewTab } from 'widgets/Icons/icon' import { ReactComponent as UnexpandStatus } from 'widgets/Icons/UnexpandStatus.svg' import { ReactComponent as StartBlock } from 'widgets/Icons/StartBlock.svg' @@ -14,6 +14,7 @@ const SyncDetail = ({ isLightClient, onOpenSetStartBlock, startBlockNumber, + estimate, }: { syncBlockNumbers: string isLookingValidTarget: boolean @@ -21,6 +22,7 @@ const SyncDetail = ({ isLightClient: boolean onOpenSetStartBlock: () => void startBlockNumber?: string + estimate?: number }) => { const [t] = useTranslation() return ( @@ -45,11 +47,15 @@ const SyncDetail = ({ )} {isLightClient && startBlockNumber ? ( -
+
{t('network-status.tooltip.start-block-number')}:
{localNumberFormatter(startBlockNumber)}
) : null} +
+
{t('network-status.left-time')}
+
{getSyncLeftTime(estimate)}
+
{isLightClient && (
void startBlockNumber?: string + estimate?: number }>) => { const [t] = useTranslation() const [isOpen, setIsOpen] = useState(false) @@ -127,6 +135,7 @@ const SyncStatus = ({ isLightClient={isLightClient} onOpenSetStartBlock={onOpenSetStartBlock} startBlockNumber={startBlockNumber} + estimate={estimate} /> } trigger="click" diff --git a/packages/neuron-ui/src/components/SyncStatus/syncStatus.module.scss b/packages/neuron-ui/src/components/SyncStatus/syncStatus.module.scss index 9afd0e19e6..0392091b75 100755 --- a/packages/neuron-ui/src/components/SyncStatus/syncStatus.module.scss +++ b/packages/neuron-ui/src/components/SyncStatus/syncStatus.module.scss @@ -46,6 +46,8 @@ .tipContainer { .tip { padding: 12px; + // set left 40% to avoid horizontal scroll bar when find valid target + left: 40% !important; } .blockSynced { font-size: 12px; @@ -92,7 +94,7 @@ } } - .startBlockNumber { + .item { margin-top: 8px; .title { font-size: 12px; diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 338f714db6..c16a08204d 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -35,7 +35,8 @@ "start-block-number": "Start block number", "set-start-block-number": "Set start block number" }, - "migrating": "migrating..." + "migrating": "migrating...", + "left-time": "Left Time" }, "import-hardware": { "title": { diff --git a/packages/neuron-ui/src/locales/es.json b/packages/neuron-ui/src/locales/es.json index 9909598ea0..e8a8b80408 100644 --- a/packages/neuron-ui/src/locales/es.json +++ b/packages/neuron-ui/src/locales/es.json @@ -34,7 +34,8 @@ "looking-valid-target": "Buscando objetivo válido asumido", "set-start-block-number": "Establecer el número de bloque inicial" }, - "migrating": "migrando..." + "migrating": "migrando...", + "left-time": "Tiempo restante" }, "import-hardware": { "title": { diff --git a/packages/neuron-ui/src/locales/fr.json b/packages/neuron-ui/src/locales/fr.json index a4fcb7e2c9..02e4fd1cc2 100644 --- a/packages/neuron-ui/src/locales/fr.json +++ b/packages/neuron-ui/src/locales/fr.json @@ -35,7 +35,8 @@ "start-block-number": "bloc de départ", "set-start-block-number": "Définir le numéro de bloc de départ" }, - "migrating": "migration en cours..." + "migrating": "migration en cours...", + "left-time": "Temps restant" }, "import-hardware": { "title": { diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index 151d07d7dd..c953a9676b 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -35,7 +35,8 @@ "start-block-number": "起始區塊", "set-start-block-number": "設置同步起始區塊" }, - "migrating": "正在數據遷移..." + "migrating": "正在數據遷移...", + "left-time": "剩余時間" }, "import-hardware": { "title": { diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 05fdaf61bd..88b3e02af7 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -35,7 +35,8 @@ "start-block-number": "起始区块", "set-start-block-number": "设置同步起始区块" }, - "migrating": "正在数据迁移..." + "migrating": "正在数据迁移...", + "left-time": "剩余时间" }, "import-hardware": { "title": { diff --git a/packages/neuron-ui/src/tests/getSyncLeftTime/fixtures.json b/packages/neuron-ui/src/tests/getSyncLeftTime/fixtures.json index b677363a57..85cc88cb20 100644 --- a/packages/neuron-ui/src/tests/getSyncLeftTime/fixtures.json +++ b/packages/neuron-ui/src/tests/getSyncLeftTime/fixtures.json @@ -3,20 +3,32 @@ "estimate": null, "expected": "-" }, - "should return 00:01 when estimate is 60_000": { + "should return 00:00:00 when estimate is less than 1_000": { + "estimate": 999, + "expected": "00:00:00" + }, + "should return 00:00:01 when estimate is 1_000": { + "estimate": 1000, + "expected": "00:00:01" + }, + "should return 00:01:00 when estimate is 60_000": { "estimate": 60000, - "expected": "00:01" + "expected": "00:01:00" + }, + "should return 00:01:59 when estimate is 119_999": { + "estimate": 119999, + "expected": "00:01:59" }, "should return 01:00 when estimate is 60 * 60_000": { "estimate": 3600000, - "expected": "01:00" + "expected": "01:00:00" }, - "should return 00:00 when estimate is less than 30_000": { - "estimate": 29999, - "expected": "00:00" + "should return 01:59:59 when estimate is 60 * 60_000 + 59 * 60_000 + 59 * 1_000": { + "estimate": 7199000, + "expected": "01:59:59" }, "should return 00:01 when estimate is less than 60_000 but greater than 30_000": { "estimate": 30001, - "expected": "00:01" + "expected": "00:00:30" } } diff --git a/packages/neuron-ui/src/utils/getSyncLeftTime.ts b/packages/neuron-ui/src/utils/getSyncLeftTime.ts index c717f0a300..9b45a9f274 100644 --- a/packages/neuron-ui/src/utils/getSyncLeftTime.ts +++ b/packages/neuron-ui/src/utils/getSyncLeftTime.ts @@ -1,4 +1,5 @@ -const MINS_PER_HOUR = 60 +const MILLISECS_PER_SEC = 1_000 +const MILLISECS_PER_MIN = 60_000 const MILLISECS_PER_HOUR = 3600_000 export const getSyncLeftTime = (estimate: number | undefined) => { @@ -6,8 +7,9 @@ export const getSyncLeftTime = (estimate: number | undefined) => { if (typeof estimate === 'number') { const time = estimate / MILLISECS_PER_HOUR const hrs = Math.floor(time) - const mins = Math.round((time - hrs) * MINS_PER_HOUR) - leftTime = `${hrs.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}` + const mins = Math.floor((estimate - hrs * MILLISECS_PER_HOUR) / MILLISECS_PER_MIN) + const secs = Math.floor((estimate - hrs * MILLISECS_PER_HOUR - mins * MILLISECS_PER_MIN) / MILLISECS_PER_SEC) + leftTime = [hrs, mins, secs].map(v => v.toString().padStart(2, '0')).join(':') } return leftTime }