Fix accounts

This commit is contained in:
Daniel 2026-06-19 17:21:24 +02:00
parent 7d849653fa
commit 4ab800bf4a
4 changed files with 70 additions and 12 deletions

View File

@ -4,6 +4,7 @@
#include <QByteArray>
#include <QClipboard>
#include <QCoreApplication>
#include <QDateTime>
#include <QDebug>
#include <QDir>
@ -205,9 +206,28 @@ void BlockchainBackend::refreshAccounts()
const LogosResult result = toLogosResult(m_blockchainClient->invokeRemoteMethod(
BLOCKCHAIN_MODULE_NAME, "wallet_get_known_addresses"));
if (!result.success) {
qWarning() << "refreshAccounts: failed:" << result.error.toString();
return;
}
// The SDK marshals the JSON array into a QVariantList; rely on toList()
// rather than canConvert<QStringList>() (which is unreliable for a
// QVariantList under Qt6), and fall back to toStringList() for the rare
// case where the value already arrives as a QStringList.
QStringList list;
if (result.success && result.value.canConvert<QStringList>())
const QVariantList items = result.value.toList();
if (!items.isEmpty()) {
for (const QVariant& item : items) {
const QString addr = item.toString();
if (!addr.isEmpty())
list << addr;
}
} else {
list = result.value.toStringList();
}
qDebug() << "refreshAccounts: loaded" << list.size() << "addresses";
m_accountsModel->setAddresses(list);
@ -346,6 +366,14 @@ void BlockchainBackend::clearLogs()
void BlockchainBackend::copyToClipboard(QString text)
{
if (QGuiApplication::clipboard())
QGuiApplication::clipboard()->setText(text);
// The backend runs in a non-GUI ViewModuleHost subprocess, where there is
// no QGuiApplication and accessing the clipboard segfaults. Clipboard is
// handled QML-side (see BlockchainView.copyText); guard here so any stray
// call is a no-op rather than a crash.
if (!qobject_cast<QGuiApplication*>(QCoreApplication::instance())) {
qWarning() << "copyToClipboard: no GUI application; ignoring";
return;
}
if (QClipboard* clipboard = QGuiApplication::clipboard())
clipboard->setText(text);
}

View File

@ -40,6 +40,23 @@ Rectangle {
readonly property var accountsModel: logos.model("blockchain_ui", "accounts")
readonly property var logModel: logos.model("blockchain_ui", "logs")
// Clipboard must be handled here in the UI-host (GUI) process. The backend
// .rep source runs in a separate, non-GUI ViewModuleHost subprocess where
// QGuiApplication::clipboard() segfaults (process exits with code 11), so
// we copy from QML via a hidden TextEdit instead of calling the backend.
function copyText(text) {
clipboardHelper.text = text || ""
clipboardHelper.selectAll()
clipboardHelper.copy()
clipboardHelper.deselect()
clipboardHelper.text = ""
}
TextEdit {
id: clipboardHelper
visible: false
}
QtObject {
id: _d
function getStatusString(s) {
@ -228,7 +245,7 @@ Rectangle {
)
}
onCopyToClipboard: (text) => {
if (root.backend) root.backend.copyToClipboard(text)
root.copyText(text)
}
onTransferRequested: function(fromKeyHex, toKeyHex, amount) {
if (!root.backend) return
@ -246,6 +263,7 @@ Rectangle {
function(error) { walletView.setLeaderClaimResult("Error: " + error) }
)
}
onRefreshAccountsRequested: if (root.backend) root.backend.refreshAccounts()
}
Item {
@ -260,7 +278,7 @@ Rectangle {
logModel: root.logModel
onClearRequested: if (root.backend) root.backend.clearLogs()
onCopyToClipboard: (text) => {
if (root.backend) root.backend.copyToClipboard(text)
root.copyText(text)
}
}
}
@ -291,7 +309,7 @@ Rectangle {
)
}
onCopyToClipboard: (text) => {
if (root.backend) root.backend.copyToClipboard(text)
root.copyText(text)
}
}
}

View File

@ -70,7 +70,9 @@ Control {
delegate: ItemDelegate{
width: ListView.view.width
contentItem: LogosText {
text: model.text
// The remoted log model can briefly report an undefined
// "text" role while the replica syncs coerce to "".
text: model.text || ""
font.pixelSize: Theme.typography.secondaryText
wrapMode: Text.Wrap
}
@ -78,7 +80,7 @@ Control {
color: hovered ? Theme.palette.background: "transparent"
radius: 2
}
onClicked: root.copyToClipboard(model.text)
onClicked: root.copyToClipboard(model.text || "")
}
LogosText {

View File

@ -16,6 +16,7 @@ RowLayout {
property string lastBalanceErrorAddress: ""
signal getBalanceRequested(string addressHex)
signal refreshAccountsRequested()
signal transferRequested(string fromKeyHex, string toKeyHex, string amount)
signal claimLeaderRewardsRequested()
signal copyToClipboard(string text)
@ -48,10 +49,19 @@ RowLayout {
anchors.margins: Theme.spacing.large
spacing: Theme.spacing.large
LogosText {
text: qsTr("Accounts")
font.pixelSize: Theme.typography.secondaryText
font.bold: true
RowLayout {
Layout.fillWidth: true
LogosText {
text: qsTr("Accounts")
font.pixelSize: Theme.typography.secondaryText
font.bold: true
}
Item { Layout.fillWidth: true }
LogosButton {
text: qsTr("Refresh")
padding: Theme.spacing.small
onClicked: root.refreshAccountsRequested()
}
}
LogosText {