Skip to content

Commit

Permalink
add tooltip and default to portoflio when dex disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
smk762 committed Aug 22, 2024
1 parent c20f43a commit 90b1d02
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
4 changes: 2 additions & 2 deletions atomic_defi_design/Dex/Exchange/Trade/FeeIcon.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 23 additions & 1 deletion atomic_defi_design/Dex/Sidebar/Center.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions atomic_defi_design/Dex/Sidebar/FigurativeLine.qml
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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
}
}
34 changes: 18 additions & 16 deletions src/core/atomicdex/services/sync/timesync.checker.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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::seconds>(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::seconds>(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;
}
Expand All @@ -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<std::chrono::seconds>(now - m_timesync_clock);
if (s >= 1min)
int64_t m_timesync_clock_ts = std::chrono::duration_cast<std::chrono::seconds>(m_timesync_clock.time_since_epoch()).count();
int64_t now_ts = std::chrono::duration_cast<std::chrono::seconds>(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
Expand Down
4 changes: 2 additions & 2 deletions src/core/atomicdex/services/sync/timesync.checker.service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>;

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);
Expand Down

0 comments on commit 90b1d02

Please sign in to comment.