Skip to content

Commit 070cf55

Browse files
authored
Merge pull request #2474 from KomodoPlatform/fix/timesync-checker
Fix/timesync checker
2 parents 7a6e41d + b5ea876 commit 070cf55

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

atomic_defi_design/Dex/Constants/General.qml

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ QtObject {
2525

2626
function coinIcon(ticker)
2727
{
28+
if (ticker.toLowerCase() == "smart chain")
29+
{
30+
return coin_icons_path + "smart_chain.png"
31+
}
32+
if (ticker.toLowerCase() == "avx")
33+
{
34+
return coin_icons_path + "avax.png"
35+
}
2836
if (ticker === "" || ticker === "All" || ticker===undefined)
2937
{
3038
return ""
@@ -458,7 +466,7 @@ QtObject {
458466
}
459467
if (sell_ticker_balance == 0)
460468
{
461-
return qsTr("%1 balance is zero").arg(selectedTicker)
469+
return qsTr("Balance is zero!")
462470
}
463471
if (!isZhtlcReady(selectedTicker))
464472
{

src/core/atomicdex/services/sync/timesync.checker.service.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,22 @@ namespace
4444
{
4545
using namespace std::string_literals;
4646
nlohmann::json resp;
47-
bool sync_ok = false;
47+
bool sync_ok = true;
4848
std::string resp_str = TO_STD_STR(resp_http.extract_string(true).get());
4949
if (resp_http.status_code() != 200)
5050
{
51-
SPDLOG_ERROR("Cannot reach the endpoint [{}]: {}", g_timesync_endpoint);
51+
SPDLOG_ERROR("Cannot reach the endpoint [{}]: {}", g_timesync_endpoint, resp_str);
5252
}
5353
else
5454
{
5555
resp = nlohmann::json::parse(resp_str);
5656
int64_t epoch_ts = resp["unixtime"];
5757
int64_t current_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
5858
int64_t ts_diff = epoch_ts - current_ts;
59-
if (abs(ts_diff) < 60)
59+
if (abs(ts_diff) > 60)
6060
{
61-
sync_ok = true;
61+
SPDLOG_WARN("Time sync failed! Actual: {}, System: {}, Diff: {}", epoch_ts, current_ts, ts_diff);
62+
sync_ok = false;
6263
}
6364
}
6465
return sync_ok;
@@ -82,7 +83,7 @@ namespace atomic_dex
8283
int64_t m_timesync_clock_ts = std::chrono::duration_cast<std::chrono::seconds>(m_timesync_clock.time_since_epoch()).count();
8384
int64_t now_ts = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
8485
int64_t ts_diff = now_ts - m_timesync_clock_ts;
85-
if (abs(ts_diff) >= 60)
86+
if (abs(ts_diff) > 300)
8687
{
8788
fetch_timesync_status();
8889
m_timesync_clock = std::chrono::high_resolution_clock::now();
@@ -91,21 +92,28 @@ namespace atomic_dex
9192

9293
void timesync_checker_service::fetch_timesync_status()
9394
{
95+
SPDLOG_INFO("Checking system time is in sync...");
9496
if (is_timesync_fetching)
9597
{
98+
SPDLOG_WARN("Already checking timesync, returning");
9699
return;
97100
}
98101
is_timesync_fetching = true;
99102
emit isTimesyncFetchingChanged();
100103
async_fetch_timesync()
101104
.then([this](web::http::http_response resp) {
102-
this->m_timesync_status = get_timesync_info_rpc(resp);
103-
emit timesyncInfoChanged();
105+
bool is_timesync_ok = get_timesync_info_rpc(resp);
106+
SPDLOG_INFO("System time is in sync: {}", is_timesync_ok);
107+
108+
if (is_timesync_ok != *m_timesync_status)
109+
{
110+
this->m_timesync_status = is_timesync_ok;
111+
emit timesyncInfoChanged();
112+
}
104113
})
105114
.then(&handle_exception_pplx_task);
106115
is_timesync_fetching = false;
107116
emit isTimesyncFetchingChanged();
108-
109117
}
110118

111119
bool timesync_checker_service::get_timesync_info() const
@@ -115,4 +123,5 @@ namespace atomic_dex
115123

116124
} // namespace atomic_dex
117125

126+
118127

0 commit comments

Comments
 (0)