diff --git a/src/ui/windows/about_dialog.cpp b/src/ui/windows/about_dialog.cpp index 0b48ae5..49b75d2 100644 --- a/src/ui/windows/about_dialog.cpp +++ b/src/ui/windows/about_dialog.cpp @@ -97,7 +97,7 @@ void RenderAboutDialog(App* app, bool* p_open) const auto& state = app->getWalletState(); ImGui::Text("%s", TR("about_chain")); ImGui::SameLine(valX); - ImGui::Text("ObsidianDragon"); + ImGui::Text("%s", "DragonX (DRGX)"); ImGui::Text("%s", TR("about_block_height")); ImGui::SameLine(valX); @@ -116,11 +116,11 @@ void RenderAboutDialog(App* app, bool* p_open) ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(material::OnSurfaceMedium()), "%s", TR("about_credits")); ImGui::Spacing(); - ImGui::BulletText("The Hush Developers"); - ImGui::BulletText("ObsidianDragon Community"); - ImGui::BulletText("Dear ImGui by Omar Cornut"); - ImGui::BulletText("ImPlot by Evan Pezent"); - ImGui::BulletText("SDL3 by Sam Lantinga"); + ImGui::BulletText("%s", "The Hush Developers"); + ImGui::BulletText("%s", "ObsidianDragon Community"); + ImGui::BulletText(TR("about_credit_by"), "Dear ImGui", "Omar Cornut"); + ImGui::BulletText(TR("about_credit_by"), "ImPlot", "Evan Pezent"); + ImGui::BulletText(TR("about_credit_by"), "SDL3", "Sam Lantinga"); ImGui::Spacing(); ImGui::Separator(); diff --git a/src/ui/windows/block_info_dialog.cpp b/src/ui/windows/block_info_dialog.cpp index 2a661ca..298427e 100644 --- a/src/ui/windows/block_info_dialog.cpp +++ b/src/ui/windows/block_info_dialog.cpp @@ -15,6 +15,7 @@ #include #include +#include #include namespace dragonx { @@ -59,7 +60,9 @@ static void handleBlockResponseUnified(const json& result, const std::string& er s_loading = false; if (!error.empty()) { + // `error` is already user-facing (friendlyRpcError / out-of-range message, built on the worker). s_error = std::string(TR("grpa_error_prefix")) + error; + s_has_data = false; // don't leave stale data on screen beside a failure return; } @@ -88,6 +91,49 @@ static void handleBlockResponseUnified(const json& result, const std::string& er } } +// Fetch s_height (getblockhash -> getblock) on the worker. Shared by the Get Info button, the +// Prev/Next buttons and the Prev/Next hash links. keepData=true leaves the currently displayed +// block visible (with the "Loading..." indicator) until the new block arrives. +static void startBlockFetch(App* app, bool keepData) +{ + auto* rpc = app->rpc(); + if (s_loading || !rpc || !rpc->isConnected() || !app->worker()) return; + + s_loading = true; + s_error.clear(); + if (!keepData) s_has_data = false; + s_pending_app = app; + + // Run the two chained RPCs (getblockhash -> getblock) on the worker thread; + // doing them inline froze the UI for two round-trips. Guard the hash type. + int height = s_height; + int tip = app->getWalletState().sync.blocks; + app->worker()->post([rpc, height, tip]() -> rpc::RPCWorker::MainCb { + json block; + std::string error; + try { + rpc::RPCClient::TraceScope trace("Explorer / Block info"); + auto hashResult = rpc->call("getblockhash", {height}); + if (!hashResult.is_string()) { + error = TR("grpa_unexpected_getblockhash_result"); + } else { + block = rpc->call("getblock", {hashResult.get()}); + } + } catch (const std::exception& e) { + std::string raw = e.what(); + if (tip > 0 && height > tip && + (raw.find("out of range") != std::string::npos || raw.find("Out of range") != std::string::npos)) { + char buf[256]; + std::snprintf(buf, sizeof(buf), TR("block_info_not_exist"), height, tip); + error = buf; + } else { + error = util::friendlyRpcError(raw); + } + } + return [block, error]() { handleBlockResponseUnified(block, error); }; + }); +} + void BlockInfoDialog::render(App* app) { if (!s_open) return; @@ -131,41 +177,28 @@ void BlockInfoDialog::render(App* app) ImGui::SameLine(); // Fetch button - if (s_loading) { + const bool connected = rpc && rpc->isConnected() && app->worker(); + const bool fetchDisabled = s_loading || !connected; + if (fetchDisabled) { ImGui::BeginDisabled(); } if (material::TactileButton(TR("block_get_info"), ImVec2(0,0), S.resolveFont(closeBtn.font))) { - if (rpc && rpc->isConnected() && app->worker()) { - s_loading = true; - s_error.clear(); - s_has_data = false; - s_pending_app = app; - - // Run the two chained RPCs (getblockhash → getblock) on the worker thread; - // doing them inline froze the UI for two round-trips. Guard the hash type. - int height = s_height; - app->worker()->post([rpc, height]() -> rpc::RPCWorker::MainCb { - json block; - std::string error; - try { - rpc::RPCClient::TraceScope trace("Explorer / Block info"); - auto hashResult = rpc->call("getblockhash", {height}); - if (!hashResult.is_string()) { - error = TR("grpa_unexpected_getblockhash_result"); - } else { - block = rpc->call("getblock", {hashResult.get()}); - } - } catch (const std::exception& e) { - error = e.what(); - } - return [block, error]() { handleBlockResponseUnified(block, error); }; - }); - } + startBlockFetch(app, /*keepData=*/false); } - - if (s_loading) { + if (!connected && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) { + material::Tooltip("%s", TR("block_info_not_connected")); + } + + if (fetchDisabled) { ImGui::EndDisabled(); + } + if (!connected) { + ImGui::SameLine(); + ImGui::PushStyleColor(ImGuiCol_Text, material::OnSurfaceMedium()); + ImGui::TextUnformatted(TR("block_info_not_connected")); + ImGui::PopStyleColor(); + } else if (s_loading) { ImGui::SameLine(); ImGui::TextDisabled("%s", TR("loading")); } @@ -176,7 +209,7 @@ void BlockInfoDialog::render(App* app) // Error display if (!s_error.empty()) { - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_Text, material::Error()); ImGui::TextWrapped("%s", s_error.c_str()); ImGui::PopStyleColor(); } @@ -185,7 +218,7 @@ void BlockInfoDialog::render(App* app) if (s_has_data) { // Block hash ImGui::Text("%s", TR("block_hash")); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.6f, 0.8f, 1.0f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_Text, material::Primary()); ImGui::TextWrapped("%s", s_block_hash.c_str()); ImGui::PopStyleColor(); @@ -222,11 +255,11 @@ void BlockInfoDialog::render(App* app) ImGui::Text("%s", TR("block_size")); ImGui::SameLine(lbl.position); if (s_block_size > 1024 * 1024) { - ImGui::Text("%.2f MB", s_block_size / (1024.0 * 1024.0)); + ImGui::Text(TR("block_size_mb"), s_block_size / (1024.0 * 1024.0)); } else if (s_block_size > 1024) { - ImGui::Text("%.2f KB", s_block_size / 1024.0); + ImGui::Text(TR("block_size_kb"), s_block_size / 1024.0); } else { - ImGui::Text("%d bytes", s_block_size); + ImGui::Text(TR("block_size_bytes"), s_block_size); } // Difficulty @@ -245,7 +278,7 @@ void BlockInfoDialog::render(App* app) // Merkle root ImGui::Text("%s", TR("block_merkle_root")); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.7f, 0.7f, 0.7f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_Text, material::OnSurfaceMedium()); ImGui::TextWrapped("%s", s_merkle_root.c_str()); ImGui::PopStyleColor(); @@ -254,7 +287,7 @@ void BlockInfoDialog::render(App* app) // Previous block if (!s_prev_hash.empty()) { ImGui::Text("%s", TR("block_previous")); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.6f, 0.8f, 1.0f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_Text, material::Primary()); // Truncate for display std::string prev_short = s_prev_hash; @@ -265,18 +298,19 @@ void BlockInfoDialog::render(App* app) ImGui::PopStyleColor(); if (ImGui::IsItemHovered()) { + ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); material::Tooltip("%s", TR("block_click_prev")); } - if (ImGui::IsItemClicked() && s_height > 1) { + if (ImGui::IsItemClicked() && s_height > 1 && !s_loading) { s_height--; - s_has_data = false; + startBlockFetch(app, /*keepData=*/true); } } // Next block if (!s_next_hash.empty()) { ImGui::Text("%s", TR("block_next")); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.6f, 0.8f, 1.0f, 1.0f)); + ImGui::PushStyleColor(ImGuiCol_Text, material::Primary()); // Truncate for display std::string next_short = s_next_hash; @@ -287,12 +321,13 @@ void BlockInfoDialog::render(App* app) ImGui::PopStyleColor(); if (ImGui::IsItemHovered()) { + ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); material::Tooltip("%s", TR("block_click_next")); } - if (ImGui::IsItemClicked() && + if (ImGui::IsItemClicked() && !s_loading && (state.sync.blocks <= 0 || s_height < state.sync.blocks)) { s_height++; - s_has_data = false; + startBlockFetch(app, /*keepData=*/true); } } } @@ -303,10 +338,9 @@ void BlockInfoDialog::render(App* app) // Navigation buttons if (s_has_data) { if (s_height > 1) { - if (material::TactileButton(TR("block_nav_prev"), ImVec2(0,0), S.resolveFont(closeBtn.font))) { + if (material::TactileButton(TR("block_nav_prev"), ImVec2(0,0), S.resolveFont(closeBtn.font)) && !s_loading) { s_height--; - s_has_data = false; - s_error.clear(); + startBlockFetch(app, /*keepData=*/true); } ImGui::SameLine(); } @@ -315,10 +349,9 @@ void BlockInfoDialog::render(App* app) // nextblockhash, so this stays hidden there). if (!s_next_hash.empty() && (state.sync.blocks <= 0 || s_height < state.sync.blocks)) { - if (material::TactileButton(TR("block_nav_next"), ImVec2(0,0), S.resolveFont(closeBtn.font))) { + if (material::TactileButton(TR("block_nav_next"), ImVec2(0,0), S.resolveFont(closeBtn.font)) && !s_loading) { s_height++; - s_has_data = false; - s_error.clear(); + startBlockFetch(app, /*keepData=*/true); } } } diff --git a/src/ui/windows/peers_tab.cpp b/src/ui/windows/peers_tab.cpp index 61d4795..3d83873 100644 --- a/src/ui/windows/peers_tab.cpp +++ b/src/ui/windows/peers_tab.cpp @@ -375,6 +375,13 @@ void RenderPeersTab(App* app) // TLS — bespoke: appends a check icon when every peer is TLS float cx = leftX; dl->AddText(capFont, capFont->LegacySize, ImVec2(cx, ry), OnSurfaceMedium(), "TLS"); + { + ImVec2 tlsLblSz = capFont->CalcTextSizeA(capFont->LegacySize, FLT_MAX, 0, "TLS"); + ImVec2 tlsLblMin(cx, ry); + ImVec2 tlsLblMax(cx + tlsLblSz.x, ry + tlsLblSz.y); + if (ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect(tlsLblMin, tlsLblMax)) + material::Tooltip("%s", TR("peers_tls_badge_tip")); + } float valY = ry + capFont->LegacySize + Layout::spacingXs(); if (totalPeers > 0) { snprintf(buf, sizeof(buf), "%d / %d", tlsCount, totalPeers); @@ -748,6 +755,7 @@ void RenderPeersTab(App* app) // Pin the badge just after the (clipped) subver, but never past the reserved zone. float badgeX = std::min(subverX + verW + Layout::spacingSm(), subverMaxX + Layout::spacingSm()); + bool badgeHovered = false; if (!peer.tls_cipher.empty()) { ImU32 tlsBg = WithAlpha(Success(), 25); ImU32 tlsFg = WithAlpha(Success(), 200); @@ -755,9 +763,17 @@ void RenderPeersTab(App* app) ImVec2 tlsMax(tlsMin.x + tlsBadgeW, tlsMin.y + capFont->LegacySize + 2 * dp); dl->AddRectFilled(tlsMin, tlsMax, tlsBg, S.drawElement("tabs.peers", "tls-badge-rounding").size * dp); dl->AddText(capFont, capFont->LegacySize, ImVec2(tlsMin.x + 4 * dp, cy2 + 1 * dp), tlsFg, "TLS"); + badgeHovered = ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect(tlsMin, tlsMax); + if (badgeHovered) + material::Tooltip("%s", TR("peers_tls_badge_tip")); } else { dl->AddText(capFont, capFont->LegacySize, ImVec2(badgeX, cy2), WithAlpha(Error(), 140), TR("peers_no_tls")); + badgeHovered = ImGui::IsWindowHovered() && + ImGui::IsMouseHoveringRect(ImVec2(badgeX, cy2), + ImVec2(badgeX + noTlsW, cy2 + capFont->LegacySize + 2 * dp)); + if (badgeHovered) + material::Tooltip("%s", TR("peers_no_tls_badge_tip")); } if (haveBanScore) { @@ -789,7 +805,7 @@ void RenderPeersTab(App* app) effects::ImGuiAcrylic::EndAcrylicPopup(); } - if (ImGui::IsItemHovered()) { + if (ImGui::IsItemHovered() && !badgeHovered) { material::BeginTooltip(); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(8, 3)); if (ImGui::BeginTable("##PeerTT", 2, ImGuiTableFlags_SizingFixedFit)) { diff --git a/src/util/i18n.cpp b/src/util/i18n.cpp index e95330a..94842a0 100644 --- a/src/util/i18n.cpp +++ b/src/util/i18n.cpp @@ -1843,6 +1843,7 @@ void I18n::loadBuiltinEnglish() // --- About Dialog --- strings_["about_block_explorer"] = "Block Explorer"; strings_["about_block_height"] = "Block Height:"; + strings_["about_credit_by"] = "%s by %s"; strings_["about_build_date"] = "Build Date:"; strings_["about_build_type"] = "Build Type:"; strings_["about_chain"] = "Chain:"; @@ -2107,6 +2108,11 @@ void I18n::loadBuiltinEnglish() strings_["block_click_next"] = "Click to view next block"; strings_["block_click_prev"] = "Click to view previous block"; strings_["block_get_info"] = "Get Block Info"; + strings_["block_info_not_connected"] = "Not connected to the node"; + strings_["block_info_not_exist"] = "Block %d does not exist yet (tip is %d)"; + strings_["block_size_mb"] = "%.2f MB"; + strings_["block_size_kb"] = "%.2f KB"; + strings_["block_size_bytes"] = "%d bytes"; strings_["block_hash"] = "Block Hash:"; strings_["block_height"] = "Block Height:"; strings_["block_info_title"] = "Block Information"; @@ -2751,6 +2757,8 @@ void I18n::loadBuiltinEnglish() strings_["peers_click_copy"] = "Click to copy"; strings_["peers_connected"] = "Connected"; strings_["peers_connected_count"] = "Connected: %d"; + strings_["peers_tls_badge_tip"] = "Encrypted peer connection (TLS)"; + strings_["peers_no_tls_badge_tip"] = "Unencrypted peer connection"; strings_["peers_copy_ip"] = "Copy IP"; strings_["peers_dir_in"] = "In"; strings_["peers_dir_out"] = "Out";