diff --git a/atomic_defi_design/Dex/Exchange/Trade/FeeIcon.qml b/atomic_defi_design/Dex/Exchange/Trade/FeeIcon.qml index a5f65a9ba9..883e5e13d1 100644 --- a/atomic_defi_design/Dex/Exchange/Trade/FeeIcon.qml +++ b/atomic_defi_design/Dex/Exchange/Trade/FeeIcon.qml @@ -24,12 +24,12 @@ DefaultText { visible: mouse_area.containsMouse contentItem: ColumnLayout { - DefaultText { + DexLabel { id: tx_fee_text text_value: General.txFeeText(trade_info, base, false) font.pixelSize: Style.textSizeSmall4 } - DefaultText { + DexLabel { text_value: General.tradingFeeText(trade_info, base, false) font.pixelSize: tx_fee_text.font.pixelSize } diff --git a/atomic_defi_design/Dex/Sidebar/Center.qml b/atomic_defi_design/Dex/Sidebar/Center.qml index 89ab94df97..a3e2586d90 100644 --- a/atomic_defi_design/Dex/Sidebar/Center.qml +++ b/atomic_defi_design/Dex/Sidebar/Center.qml @@ -15,6 +15,25 @@ MouseArea height: lineHeight * 5 hoverEnabled: true + Connections + { + target: API.app.timesyncCheckerService + + function onTimesyncInfoChanged() + { + if (!API.app.timesyncCheckerService.timesyncInfo) + { + _dexLine.timesyncInfo = false + if (currentLineType === Main.LineType.DEX) currentLineType = Main.LineType.Portfolio + root.lineSelected(Main.LineType.Portfolio); + } + else + { + _dexLine.timesyncInfo = true + } + } + } + Connections { target: parent.parent @@ -84,12 +103,15 @@ MouseArea FigurativeLine { id: _dexLine + property var timesyncInfo: API.app.timesyncCheckerService.timesyncInfo Layout.fillWidth: true type: Main.LineType.DEX + label.color: timesyncInfo ? Dex.CurrentTheme.foregroundColor : Dex.CurrentTheme.textDisabledColor label.text: qsTr("DEX") // isExpanded ? qsTr("DEX") : "" icon.source: General.image_path + "menu-exchange-white.svg" - onClicked: lineSelected(type) + onClicked: timesyncInfo ? lineSelected(type) : null + disabled_tt_text: timesyncInfo ? "" : qsTr("DEX is disabled due to system clock synchronization issues. Please check your device time settings.") } FigurativeLine diff --git a/atomic_defi_design/Dex/Sidebar/FigurativeLine.qml b/atomic_defi_design/Dex/Sidebar/FigurativeLine.qml index 540ca6e11b..a747a36e7f 100644 --- a/atomic_defi_design/Dex/Sidebar/FigurativeLine.qml +++ b/atomic_defi_design/Dex/Sidebar/FigurativeLine.qml @@ -1,12 +1,14 @@ import QtQuick 2.12 import "../Components" +import "../Constants" import Dex.Themes 1.0 as Dex // FigurativeLine acts the same as Line but contains a figurative icon on the left of its label Line { property alias icon: _icon + property string disabled_tt_text: "" DefaultImage { @@ -26,4 +28,13 @@ Line currentLineType === type && type != Main.LineType.Support ? Dex.CurrentTheme.sidebarLineTextSelected : Dex.CurrentTheme.foregroundColor } + + DexTooltip + { + visible: mouseArea.containsMouse && disabled_tt_text + delay: 500 + timeout: 5000 + text: disabled_tt_text + font.pixelSize: Style.textSizeSmall4 + } } diff --git a/src/core/atomicdex/services/sync/timesync.checker.service.cpp b/src/core/atomicdex/services/sync/timesync.checker.service.cpp index b74efa0927..2909368a4e 100644 --- a/src/core/atomicdex/services/sync/timesync.checker.service.cpp +++ b/src/core/atomicdex/services/sync/timesync.checker.service.cpp @@ -37,7 +37,6 @@ namespace web::http::http_request req; req.set_method(web::http::methods::GET); req.set_request_uri(FROM_STD_STR("api/timezone/UTC")); - SPDLOG_INFO("req: {}", TO_STD_STR(req.to_string())); return g_timesync_client->request(req, g_synctoken_source.get_token()); } @@ -54,14 +53,13 @@ namespace else { resp = nlohmann::json::parse(resp_str); - int8_t epoch_ts = resp["unixtime"]; - int8_t current_ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - int8_t ts_diff = epoch_ts - current_ts; + int64_t epoch_ts = resp["unixtime"]; + int64_t current_ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + int64_t ts_diff = epoch_ts - current_ts; if (abs(ts_diff) < 60) { sync_ok = true; } - SPDLOG_WARN("TIME SYNC STATUS [{}]", sync_ok); } return sync_ok; } @@ -73,42 +71,46 @@ namespace atomic_dex timesync_checker_service::timesync_checker_service(entt::registry& registry, QObject* parent) : QObject(parent), system(registry) { m_timesync_clock = std::chrono::high_resolution_clock::now(); - fetch_timesync_info(); + m_timesync_status = true; + fetch_timesync_status(); } void timesync_checker_service::update() { using namespace std::chrono_literals; - const auto now = std::chrono::high_resolution_clock::now(); - const auto s = std::chrono::duration_cast(now - m_timesync_clock); - if (s >= 1min) + int64_t m_timesync_clock_ts = std::chrono::duration_cast(m_timesync_clock.time_since_epoch()).count(); + int64_t now_ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + int64_t ts_diff = now_ts - m_timesync_clock_ts; + if (abs(ts_diff) >= 60) { - fetch_timesync_info(); + fetch_timesync_status(); m_timesync_clock = std::chrono::high_resolution_clock::now(); } } - void timesync_checker_service::fetch_timesync_info() + void timesync_checker_service::fetch_timesync_status() { if (is_timesync_fetching) + { return; + } is_timesync_fetching = true; emit isTimesyncFetchingChanged(); async_fetch_timesync() .then([this](web::http::http_response resp) { - - this->m_timesync_info = get_timesync_info_rpc(resp); - is_timesync_fetching = false; - emit isTimesyncFetchingChanged(); + this->m_timesync_status = get_timesync_info_rpc(resp); emit timesyncInfoChanged(); }) .then(&handle_exception_pplx_task); + is_timesync_fetching = false; + emit isTimesyncFetchingChanged(); + } bool timesync_checker_service::get_timesync_info() const { - return *m_timesync_info; + return *m_timesync_status; } } // namespace atomic_dex diff --git a/src/core/atomicdex/services/sync/timesync.checker.service.hpp b/src/core/atomicdex/services/sync/timesync.checker.service.hpp index e3ccb86eea..54b3f73bf5 100644 --- a/src/core/atomicdex/services/sync/timesync.checker.service.hpp +++ b/src/core/atomicdex/services/sync/timesync.checker.service.hpp @@ -36,11 +36,11 @@ namespace atomic_dex using t_timesync_time_point = std::chrono::high_resolution_clock::time_point; using t_bool_synchronized = boost::synchronized_value; - t_bool_synchronized m_timesync_info; + t_bool_synchronized m_timesync_status; t_timesync_time_point m_timesync_clock; t_bool_synchronized is_timesync_fetching; - void fetch_timesync_info(); + void fetch_timesync_status(); public: explicit timesync_checker_service(entt::registry& registry, QObject* parent = nullptr);