From be89e940d5f2cbfef9da88b53a68a80586384ee4 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 27 Aug 2024 14:45:50 +0300 Subject: [PATCH 01/28] Actualize sync constants --- src/state/sync/constants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/state/sync/constants.js b/src/state/sync/constants.js index b1b7b691a..c01b498df 100644 --- a/src/state/sync/constants.js +++ b/src/state/sync/constants.js @@ -16,6 +16,7 @@ export default { SET_IS_SYNC_REQUIRED: 'BITFINEX/SYNC/IS_SYNC_REQUIRED/SET', SET_IS_LONG_SYNC: 'BITFINEX/SYNC/IS_LONG_SYNC/SET', SHOW_INIT_SYNC_POPUP: 'BITFINEX/SYNC/IS_SYNC_POPUP/SHOW', + SET_LAST_SYNC_TIME: 'BITFINEX/SYNC/LAST_SYNC_TIME/SET', EDIT_PUBLIC_TRADES_PREF: 'BITFINEX/SYNC/PREF/EDIT/PUBLIC_TRADES', EDIT_PUBLIC_FUNDING_PREF: 'BITFINEX/SYNC/PREF/EDIT/PUBLIC_FUNDING', From 4a2a991031b977fb189bf4a7a6f6852b64abeeb7 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 27 Aug 2024 14:46:12 +0300 Subject: [PATCH 02/28] Add setLastSyncTime action --- src/state/sync/actions.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/state/sync/actions.js b/src/state/sync/actions.js index 1412dfd35..0fb37bae4 100644 --- a/src/state/sync/actions.js +++ b/src/state/sync/actions.js @@ -213,6 +213,13 @@ export function setIsLongSync(payload) { } } +export function setLastSyncTime(payload) { + return { + type: types.SET_LAST_SYNC_TIME, + payload, + } +} + export default { editPublicTradesPref, editPublicTradesSymbolPref, @@ -233,4 +240,5 @@ export default { stopSyncNow, setIsSyncRequired, showInitSyncPopup, + setLastSyncTime, } From 14d2a68cb71394250023a6d1b688434e9ef269b1 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 27 Aug 2024 14:54:22 +0300 Subject: [PATCH 03/28] Update sync reducers and initial state entries --- src/state/sync/reducer.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/state/sync/reducer.js b/src/state/sync/reducer.js index 51ccffab3..9728ce293 100644 --- a/src/state/sync/reducer.js +++ b/src/state/sync/reducer.js @@ -23,6 +23,7 @@ const initialState = { isSyncRequired: true, isLongSync: false, showInitSyncPopup: false, + lastSyncMts: null, } export function syncReducer(state = initialState, action) { @@ -142,6 +143,12 @@ export function syncReducer(state = initialState, action) { isLongSync: payload, } } + case types.SET_LAST_SYNC_TIME: { + return { + ...state, + lastSyncMts: payload, + } + } default: { return state } From cb8c96e03a80d19b7710600e3a4997a501d037bf Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 27 Aug 2024 14:55:47 +0300 Subject: [PATCH 04/28] Implement getLastSyncTime selector --- src/state/sync/selectors.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/state/sync/selectors.js b/src/state/sync/selectors.js index fc321cb01..76b538a07 100644 --- a/src/state/sync/selectors.js +++ b/src/state/sync/selectors.js @@ -24,6 +24,7 @@ export const getIsSyncRequired = state => getSync(state)?.isSyncRequired ?? fals export const getIsInitSyncPopupOpen = state => getSync(state)?.showInitSyncPopup ?? false export const getIsLongSync = state => getSync(state)?.isLongSync ?? false export const getIsFirstSyncing = state => (getIsSyncRequired(state) && getIsSyncing(state)) ?? false +export const getLastSyncTime = state => getSync(state)?.lastSyncMts ?? null export default { getSyncMode, @@ -45,4 +46,5 @@ export default { getIsInitSyncPopupOpen, getIsLongSync, getIsFirstSyncing, + getLastSyncTime, } From a9b38f50c5844682c83dc3cf55dc9d730edb0997 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 10 Sep 2024 12:21:55 +0300 Subject: [PATCH 05/28] Implement getLastFinishedSyncMts method --- src/state/sync/saga.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index e2e024ca6..85edc258c 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -31,6 +31,7 @@ const disableSyncMode = () => makeFetchCall('disableSyncMode') const haveCollsBeenSyncedAtLeastOnce = () => makeFetchCall('haveCollsBeenSyncedAtLeastOnce') const syncNow = () => makeFetchCall('syncNow') const syncNowStop = () => makeFetchCall('stopSyncNow') +const getLastFinishedSyncMts = () => makeFetchCall('getLastFinishedSyncMts') const updateSyncErrorStatus = msg => updateErrorStatus({ id: 'status.request.error', topic: 'sync.title', From 77ec08caa0f1853b7961253dcf719f7b4308ffc9 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 10 Sep 2024 12:41:16 +0300 Subject: [PATCH 06/28] Implement refreshLastFinishedSyncMts saga --- src/state/sync/saga.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index 85edc258c..4fc615fa8 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -132,11 +132,30 @@ function* switchSyncMode({ mode }) { } } +function* refreshLastFinishedSyncMts() { + try { + const { result } = yield call(getLastFinishedSyncMts) + if (result) { + const { lastSyncMts } = result + yield put(actions.setLastSyncTime(lastSyncMts)) + } + } catch (fail) { + yield put(updateErrorStatus({ + id: 'status.request.error', + topic: 'symbols.title', + detail: JSON.stringify(fail), + })) + } +} + + function* forceQueryFromDb() { const syncProgress = yield select(getSyncProgress) if (syncProgress === 100) { yield put(updateStatus({ id: 'sync.sync-done' })) } + yield call(refreshLastFinishedSyncMts) + console.log('++1') yield put(actions.setIsSyncing(false)) yield put(actions.setIsSyncRequired(false)) yield put(actions.showInitSyncPopup(false)) @@ -229,6 +248,8 @@ function* requestsRedirectUpdate({ payload }) { yield put(actions.setSyncMode(types.MODE_ONLINE)) yield put(actions.setIsSyncing(false)) yield put(actions.showInitSyncPopup(false)) + console.log('+++') + yield call(refreshLastFinishedSyncMts) } else { yield put(actions.setSyncMode(types.MODE_OFFLINE)) yield put(actions.forceQueryFromDb()) From 56edeb8b1cda96a699493022c7c2733627542f23 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 10 Sep 2024 12:42:43 +0300 Subject: [PATCH 07/28] Cleanup --- src/state/sync/saga.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index 4fc615fa8..d513794e3 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -154,11 +154,10 @@ function* forceQueryFromDb() { if (syncProgress === 100) { yield put(updateStatus({ id: 'sync.sync-done' })) } - yield call(refreshLastFinishedSyncMts) - console.log('++1') yield put(actions.setIsSyncing(false)) yield put(actions.setIsSyncRequired(false)) yield put(actions.showInitSyncPopup(false)) + yield call(refreshLastFinishedSyncMts) } function* syncLogout() { @@ -248,7 +247,6 @@ function* requestsRedirectUpdate({ payload }) { yield put(actions.setSyncMode(types.MODE_ONLINE)) yield put(actions.setIsSyncing(false)) yield put(actions.showInitSyncPopup(false)) - console.log('+++') yield call(refreshLastFinishedSyncMts) } else { yield put(actions.setSyncMode(types.MODE_OFFLINE)) From d4711c6c977ade61e8f675721972c93dbe6c9635 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 10 Sep 2024 12:51:11 +0300 Subject: [PATCH 08/28] Add last sync time keys/descriptions --- public/locales/en/translations.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 37e365b7c..8509d94a6 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -712,6 +712,9 @@ "message": { "canceled": "Canceled old Sync Watcher" }, + "last-sync-time": { + "fail": "Failed to get last sync time" + }, "init-sync-info": { "main": "Welcome to the Bitfinex Reports App. Your trading history is currently synchronizing, please wait until it's finished in order to view your reports.", "additional": "Syncing is still in progress, this might take several minutes. Keep this window open until it's finished in case you have a large history." From 201dd359fdcde1f9684d87ebd84b3726d8a69d34 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 10 Sep 2024 12:51:32 +0300 Subject: [PATCH 09/28] Improve refreshLastFinishedSyncMts saga errors handling --- src/state/sync/saga.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/state/sync/saga.js b/src/state/sync/saga.js index d513794e3..f8aca0647 100644 --- a/src/state/sync/saga.js +++ b/src/state/sync/saga.js @@ -134,15 +134,22 @@ function* switchSyncMode({ mode }) { function* refreshLastFinishedSyncMts() { try { - const { result } = yield call(getLastFinishedSyncMts) + const { result, error } = yield call(getLastFinishedSyncMts) if (result) { const { lastSyncMts } = result yield put(actions.setLastSyncTime(lastSyncMts)) } + if (error) { + yield put(updateErrorStatus({ + id: 'status.fail', + topic: 'sync.last-sync-time.fail', + detail: error?.message ?? JSON.stringify(error), + })) + } } catch (fail) { yield put(updateErrorStatus({ id: 'status.request.error', - topic: 'symbols.title', + topic: 'sync.last-sync-time.fail', detail: JSON.stringify(fail), })) } From 5dcab300ad7241aa7efeb7321c22c6b81eb09166 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Tue, 10 Sep 2024 13:13:49 +0300 Subject: [PATCH 10/28] Implement last sync time handling on auth success --- src/state/auth/saga.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/state/auth/saga.js b/src/state/auth/saga.js index a04aad811..fb8328f36 100644 --- a/src/state/auth/saga.js +++ b/src/state/auth/saga.js @@ -28,7 +28,7 @@ import tokenRefreshSaga from 'state/auth/tokenRefresh/saga' import { togglePreferencesDialog } from 'state/ui/actions' import { updateErrorStatus, updateSuccessStatus, updateWarningStatus } from 'state/status/actions' import { fetchSymbols } from 'state/symbols/actions' -import { setIsSyncRequired } from 'state/sync/actions' +import { setIsSyncRequired, setLastSyncTime } from 'state/sync/actions' import { refreshToken, tokenRefreshStart, tokenRefreshStop } from 'state/auth/tokenRefresh/actions' import config from 'config' @@ -45,6 +45,8 @@ const updateAuthErrorStatus = msg => updateErrorStatus({ function* onAuthSuccess(result) { try { + const { lastSyncMts } = result + yield put(setLastSyncTime(lastSyncMts)) yield put(actions.updateAuth(result)) yield put(fetchSymbols()) From 71ee2fea80e18384849c5ce2185fac3e159b51dc Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:16:25 +0300 Subject: [PATCH 11/28] [wip] Last sync time header section --- .../Header/LastSyncTime/LastSyncTime.js | 17 +++++++++++++++++ src/components/Header/LastSyncTime/index.js | 1 + 2 files changed, 18 insertions(+) create mode 100644 src/components/Header/LastSyncTime/LastSyncTime.js create mode 100644 src/components/Header/LastSyncTime/index.js diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js new file mode 100644 index 000000000..57558b9ae --- /dev/null +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -0,0 +1,17 @@ +import React from 'react' +import { useSelector } from 'react-redux' + +import { getLastSyncTime } from 'state/sync/selectors' + +const LastSyncTime = () => { + const lasSyncTime = useSelector(getLastSyncTime) + console.log('+++lasSyncTime', lasSyncTime) + + return ( +

+ Last sync was 3 hours ago +

+ ) +} + +export default LastSyncTime diff --git a/src/components/Header/LastSyncTime/index.js b/src/components/Header/LastSyncTime/index.js new file mode 100644 index 000000000..6c331706b --- /dev/null +++ b/src/components/Header/LastSyncTime/index.js @@ -0,0 +1 @@ +export { default } from './LastSyncTime' From e31f6e6d7a878afa7a91faf58fa773c0b7847548 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:17:46 +0300 Subject: [PATCH 12/28] Add last sync time styling --- src/components/Header/LastSyncTime/_LastSyncTime.scss | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/components/Header/LastSyncTime/_LastSyncTime.scss diff --git a/src/components/Header/LastSyncTime/_LastSyncTime.scss b/src/components/Header/LastSyncTime/_LastSyncTime.scss new file mode 100644 index 000000000..f936ac80c --- /dev/null +++ b/src/components/Header/LastSyncTime/_LastSyncTime.scss @@ -0,0 +1,3 @@ +.last-sync-time { + color: var(--color2) +} \ No newline at end of file From 115f3c344cd3e1396fbd28d628b9e5bd96bbd0e8 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:18:09 +0300 Subject: [PATCH 13/28] Actualize header styles export --- src/components/Header/_Header.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Header/_Header.scss b/src/components/Header/_Header.scss index e36bf518e..b9da7ef0d 100644 --- a/src/components/Header/_Header.scss +++ b/src/components/Header/_Header.scss @@ -2,6 +2,7 @@ @import './TopNavigation/_TopNavigation.scss'; @import './SyncMode/_SyncMode.scss'; @import './QueryMode/_QueryMode.scss'; +@import './LastSyncTime/_LastSyncTime.scss'; .header { width: 100%; From ba8ab90767d9d474d45c76a5345a21fd24c90d53 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:19:27 +0300 Subject: [PATCH 14/28] Add last sync time to the header --- src/components/Header/Header.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Header/Header.js b/src/components/Header/Header.js index 0e998dbfb..7ce5feb2a 100644 --- a/src/components/Header/Header.js +++ b/src/components/Header/Header.js @@ -9,6 +9,7 @@ import Export from './Export' import SyncMode from './SyncMode' import QueryMode from './QueryMode' import AccountMenu from './AccountMenu' +import LastSyncTime from './LastSyncTime' import TopNavigation from './TopNavigation' const Header = () => { @@ -23,6 +24,7 @@ const Header = () => {
+ From c9c9749e37bcf197dfcc05fc10a0e0aebc312126 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:25:45 +0300 Subject: [PATCH 15/28] Improve last sync time styling --- src/components/Header/LastSyncTime/_LastSyncTime.scss | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Header/LastSyncTime/_LastSyncTime.scss b/src/components/Header/LastSyncTime/_LastSyncTime.scss index f936ac80c..196cb10fa 100644 --- a/src/components/Header/LastSyncTime/_LastSyncTime.scss +++ b/src/components/Header/LastSyncTime/_LastSyncTime.scss @@ -1,3 +1,6 @@ .last-sync-time { - color: var(--color2) + display: flex; + align-items: center; + margin-right: 20px; + color: var(--color2); } \ No newline at end of file From 868ba8e0a6e39668dce111c097ba8eb05a5a357b Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:31:22 +0300 Subject: [PATCH 16/28] Update last sync keys/descriptions --- public/locales/en/translations.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 8509d94a6..ff25c6627 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -713,7 +713,10 @@ "canceled": "Canceled old Sync Watcher" }, "last-sync-time": { - "fail": "Failed to get last sync time" + "fail": "Failed to get last sync time", + "syncing": "Syncing...", + "sync-was-less-than-hour": "Last sync was less than a hour ago", + "sync-was":"Last sync was {{hours}} ago" }, "init-sync-info": { "main": "Welcome to the Bitfinex Reports App. Your trading history is currently synchronizing, please wait until it's finished in order to view your reports.", From c4402b269773d489b795fad2250744373555cd46 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:35:23 +0300 Subject: [PATCH 17/28] Implement syncing state representation --- src/components/Header/LastSyncTime/LastSyncTime.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js index 57558b9ae..ce4431b18 100644 --- a/src/components/Header/LastSyncTime/LastSyncTime.js +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -1,16 +1,21 @@ import React from 'react' import { useSelector } from 'react-redux' -import { getLastSyncTime } from 'state/sync/selectors' +import { getIsSyncing, getLastSyncTime } from 'state/sync/selectors' const LastSyncTime = () => { + const isSyncing = useSelector(getIsSyncing) const lasSyncTime = useSelector(getLastSyncTime) console.log('+++lasSyncTime', lasSyncTime) + const content = isSyncing + ? 'Syncing...' + : 'Last Sync was 3 hours ago' + return ( -

- Last sync was 3 hours ago -

+
+ {content} +
) } From 1f802991efac4a21450aa8a287c4118cd9904291 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Fri, 13 Sep 2024 14:35:38 +0300 Subject: [PATCH 18/28] Update locales --- public/locales/en/translations.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index ff25c6627..02d36ac63 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -715,8 +715,8 @@ "last-sync-time": { "fail": "Failed to get last sync time", "syncing": "Syncing...", - "sync-was-less-than-hour": "Last sync was less than a hour ago", - "sync-was":"Last sync was {{hours}} ago" + "sync-was-less-than-hour": "Last Sync was less than a hour ago", + "sync-was":"Last Sync was {{hours}} ago" }, "init-sync-info": { "main": "Welcome to the Bitfinex Reports App. Your trading history is currently synchronizing, please wait until it's finished in order to view your reports.", From 5f96667ef044b99192155cccb420bf4dbe88e19f Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 14:53:37 +0300 Subject: [PATCH 19/28] Minor tweak --- public/locales/en/translations.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 02d36ac63..43b586e67 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -715,7 +715,7 @@ "last-sync-time": { "fail": "Failed to get last sync time", "syncing": "Syncing...", - "sync-was-less-than-hour": "Last Sync was less than a hour ago", + "sync-was-less-than-hour": "Last Sync was less than an hour ago", "sync-was":"Last Sync was {{hours}} ago" }, "init-sync-info": { From 8d7a3d294fa5ed09c0c1ba229336112aca39ef44 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:39:45 +0300 Subject: [PATCH 20/28] Implement getLastSyncLabel helper --- .../Header/LastSyncTime/LastSyncTime.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js index ce4431b18..5ad6ba15f 100644 --- a/src/components/Header/LastSyncTime/LastSyncTime.js +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -1,16 +1,30 @@ import React from 'react' import { useSelector } from 'react-redux' +import { useTranslation } from 'react-i18next' +import _floor from 'lodash/floor' import { getIsSyncing, getLastSyncTime } from 'state/sync/selectors' +const getLastSyncLabel = (lastSyncTime, t) => { + const now = Date.now() + const duration = now - lastSyncTime + const hours = _floor(duration / 3600000) + const label = hours > 1 + ? t('sync.last-sync-time.sync-was', { hours }) + : t('sync.last-sync-time.sync-was-less-than-hour') + return label +} + const LastSyncTime = () => { + const { t } = useTranslation() const isSyncing = useSelector(getIsSyncing) const lasSyncTime = useSelector(getLastSyncTime) console.log('+++lasSyncTime', lasSyncTime) + const lastSyncLabel = getLastSyncLabel(lasSyncTime, t) const content = isSyncing ? 'Syncing...' - : 'Last Sync was 3 hours ago' + : lastSyncLabel return (
From 00ef4e9703a71a1f9bd6c2135a54acb3a98455a8 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:40:02 +0300 Subject: [PATCH 21/28] Update locales --- public/locales/en/translations.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 43b586e67..d41c2b7e6 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -716,7 +716,7 @@ "fail": "Failed to get last sync time", "syncing": "Syncing...", "sync-was-less-than-hour": "Last Sync was less than an hour ago", - "sync-was":"Last Sync was {{hours}} ago" + "sync-was":"Last Sync was {{hours}} hours ago" }, "init-sync-info": { "main": "Welcome to the Bitfinex Reports App. Your trading history is currently synchronizing, please wait until it's finished in order to view your reports.", From cb8840f86830416e84e8ca7b381ab9bfb788d480 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:44:27 +0300 Subject: [PATCH 22/28] Optimize getLastSyncLabel helper --- src/components/Header/LastSyncTime/LastSyncTime.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js index 5ad6ba15f..d2682f483 100644 --- a/src/components/Header/LastSyncTime/LastSyncTime.js +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -7,12 +7,10 @@ import { getIsSyncing, getLastSyncTime } from 'state/sync/selectors' const getLastSyncLabel = (lastSyncTime, t) => { const now = Date.now() - const duration = now - lastSyncTime - const hours = _floor(duration / 3600000) - const label = hours > 1 + const hours = _floor((now - lastSyncTime) / 3600000) + return hours > 1 ? t('sync.last-sync-time.sync-was', { hours }) : t('sync.last-sync-time.sync-was-less-than-hour') - return label } const LastSyncTime = () => { From c7c6fd34b725b64606036c0579a1f8939b3e9563 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:46:11 +0300 Subject: [PATCH 23/28] Improve syncing state label representation --- src/components/Header/LastSyncTime/LastSyncTime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js index d2682f483..b66d477cf 100644 --- a/src/components/Header/LastSyncTime/LastSyncTime.js +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -21,7 +21,7 @@ const LastSyncTime = () => { const lastSyncLabel = getLastSyncLabel(lasSyncTime, t) const content = isSyncing - ? 'Syncing...' + ? t('sync.last-sync-time.syncing') : lastSyncLabel return ( From bd626a0c65a64707fa2cbcd32298de87b7b3ada6 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:50:04 +0300 Subject: [PATCH 24/28] Add last sync mts validation check --- src/components/Header/LastSyncTime/LastSyncTime.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js index b66d477cf..eb33894ec 100644 --- a/src/components/Header/LastSyncTime/LastSyncTime.js +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -2,10 +2,12 @@ import React from 'react' import { useSelector } from 'react-redux' import { useTranslation } from 'react-i18next' import _floor from 'lodash/floor' +import { isNil } from '@bitfinex/lib-js-util-base' import { getIsSyncing, getLastSyncTime } from 'state/sync/selectors' const getLastSyncLabel = (lastSyncTime, t) => { + if (isNil(lastSyncTime)) return '' const now = Date.now() const hours = _floor((now - lastSyncTime) / 3600000) return hours > 1 From f751adbafb9c0f096539231a8f41d084ddab3e42 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:54:40 +0300 Subject: [PATCH 25/28] Optimize sync label getter, cleanup --- src/components/Header/LastSyncTime/LastSyncTime.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Header/LastSyncTime/LastSyncTime.js b/src/components/Header/LastSyncTime/LastSyncTime.js index eb33894ec..770b93351 100644 --- a/src/components/Header/LastSyncTime/LastSyncTime.js +++ b/src/components/Header/LastSyncTime/LastSyncTime.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useMemo } from 'react' import { useSelector } from 'react-redux' import { useTranslation } from 'react-i18next' import _floor from 'lodash/floor' @@ -18,9 +18,12 @@ const getLastSyncLabel = (lastSyncTime, t) => { const LastSyncTime = () => { const { t } = useTranslation() const isSyncing = useSelector(getIsSyncing) - const lasSyncTime = useSelector(getLastSyncTime) - console.log('+++lasSyncTime', lasSyncTime) - const lastSyncLabel = getLastSyncLabel(lasSyncTime, t) + const lastSyncTime = useSelector(getLastSyncTime) + + const lastSyncLabel = useMemo( + () => getLastSyncLabel(lastSyncTime, t), + [lastSyncTime, t], + ) const content = isSyncing ? t('sync.last-sync-time.syncing') From 6fbc2befb77ae3031c1137da5b17a6dd344bc042 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 15:57:43 +0300 Subject: [PATCH 26/28] Adjust sync label styling --- src/components/Header/LastSyncTime/_LastSyncTime.scss | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/Header/LastSyncTime/_LastSyncTime.scss b/src/components/Header/LastSyncTime/_LastSyncTime.scss index 196cb10fa..b868b1ee6 100644 --- a/src/components/Header/LastSyncTime/_LastSyncTime.scss +++ b/src/components/Header/LastSyncTime/_LastSyncTime.scss @@ -3,4 +3,10 @@ align-items: center; margin-right: 20px; color: var(--color2); -} \ No newline at end of file +} + +@media screen and (max-width: 580px) { + .last-sync-time { + display: none; + } +} From 64045fa51c564959fa89998ef0295235f50605dd Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 16:00:54 +0300 Subject: [PATCH 27/28] Show last sync time only for the framework mode --- src/components/Header/Header.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Header/Header.js b/src/components/Header/Header.js index 7ce5feb2a..b7c1301c5 100644 --- a/src/components/Header/Header.js +++ b/src/components/Header/Header.js @@ -12,6 +12,8 @@ import AccountMenu from './AccountMenu' import LastSyncTime from './LastSyncTime' import TopNavigation from './TopNavigation' +const { showFrameworkMode } = config + const Header = () => { const HOME_URL = config.isElectronApp ? '/' : config.HOME_URL @@ -24,7 +26,7 @@ const Header = () => {
- + { showFrameworkMode && ()} From 7434a31453ed3cfd3a21c1faf456e8c017ab95a1 Mon Sep 17 00:00:00 2001 From: alexstotsky Date: Sat, 14 Sep 2024 16:03:12 +0300 Subject: [PATCH 28/28] Lint fix --- src/components/Header/Header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Header/Header.js b/src/components/Header/Header.js index b7c1301c5..07829c777 100644 --- a/src/components/Header/Header.js +++ b/src/components/Header/Header.js @@ -26,7 +26,7 @@ const Header = () => {
- { showFrameworkMode && ()} + {showFrameworkMode && ()}