diff --git a/CellFrameDashboardGUI/DapChainWalletsModel.cpp b/CellFrameDashboardGUI/DapChainWalletsModel.cpp index ad72f4ef71480dc16a7c61151bc843551aa82715..86d4815bf87c97a026390d0487193dac5c7b69f8 100755 --- a/CellFrameDashboardGUI/DapChainWalletsModel.cpp +++ b/CellFrameDashboardGUI/DapChainWalletsModel.cpp @@ -1,7 +1,7 @@ #include "DapChainWalletsModel.h" -DapChainWalletsModel::DapChainWalletsModel(QObject *parent) +DapChainWalletsModel::DapChainWalletsModel(QObject *parent) : QAbstractListModel(parent) { } diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp index 2bdd5a377bff6f669c51664a1a4c867a73789c18..e3f4591996bb3b07cdd4669fb4a95d206812742a 100755 --- a/CellFrameDashboardGUI/DapCommandController.cpp +++ b/CellFrameDashboardGUI/DapCommandController.cpp @@ -153,23 +153,9 @@ void DapCommandController::processGetWalletInfo() QString name = reply->response().toJsonValue().toVariant().toStringList().at(0); QString address = reply->response().toJsonValue().toVariant().toStringList().at(1); QStringList temp = reply->response().toJsonValue().toVariant().toStringList(); - QStringList tokens; - QStringList balance; - for(int x{2}; x < temp.count(); x++) - { - if(x%2) - { - tokens.append(temp[x]); - qDebug() << "TOKKEN " << temp[x]; - } - else - { - balance.append(temp[x]); - qDebug() << "BALANCE " << temp[x]; - } - } + QStringList tokens = temp.mid(3, temp.count()); - emit sigWalletInfoChanged(name, address, balance, tokens); + emit sigWalletInfoChanged(name, address, QStringList(), tokens); } void DapCommandController::processGetNodeNetwork() diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml index e6fa4db7f7e781fd8c9d5c0fd95f25c453ddc182..4f9e0f595eee3434940084a584a5daccbf677211 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxToken.qml @@ -28,7 +28,7 @@ DapUiQmlWidgetStatusBarComboBoxTokenForm { fieldBalance.text = 0; else { - var money = dapChainWalletsModel.get(comboboxWallet.currentIndex).tokens[currentIndex * 2]; + var money = dapChainWalletsModel.get(comboboxWallet.currentIndex).tokens[currentIndex * 3]; fieldBalance.text = dapChainConvertor.toConvertCurrency(money); } } diff --git a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml index f6899f524c1ad8712ffa559acc4e9d0a199f26c1..d294cc0cb9bd2502a0eb0e5f00798b9c3edb7979 100644 --- a/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml +++ b/CellFrameDashboardGUI/DapUiQmlWidgetStatusBarComboBoxWallet.qml @@ -26,8 +26,8 @@ DapUiQmlWidgetStatusBarComboBoxWalletForm { onCurrentIndexChanged: { listToken.model.clear(); - for(var i = 0; i < dapChainWalletsModel.get(currentIndex).count; i++) - listToken.model.append({"tokenName": dapChainWalletsModel.get(currentIndex).tokens[++i]}); + for(var i = 2; i < dapChainWalletsModel.get(currentIndex).count; i += 3) + listToken.model.append({"tokenName": dapChainWalletsModel.get(currentIndex).tokens[i]}); if(listToken.model.count) listToken.currentIndex = 0; } diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp index 42f14936bb9c8eec85cd81110b2b27dd345a7548..4b4dbda508e94f6a3470b2cb7df74edddfde5a4c 100755 --- a/CellFrameDashboardService/DapChainDashboardService.cpp +++ b/CellFrameDashboardService/DapChainDashboardService.cpp @@ -119,7 +119,12 @@ void DapChainDashboardService::changeCurrentNetwork(const QString& aNetwork) void DapChainDashboardService::doRequestWallets() { - m_pDapChainHistoryHandler->onRequestNewHistory(m_pDapChainWalletHandler->getWallets()); + QMap<QString, QVariant> wallets = m_pDapChainWalletHandler->getWallets(); + m_pDapChainHistoryHandler->onRequestNewHistory(wallets); + /// TODO: for future +// QVariantList params = QVariantList() << wallets; +// DapRpcMessage request = DapRpcMessage::createRequest("RPCClient.setNewWallets", QJsonArray::fromVariantList(params)); +// m_pServer->notifyConnectedClients(request); } void DapChainDashboardService::doSendNewHistory(const QVariant& aData) diff --git a/CellFrameDashboardService/DapChainWalletHandler.cpp b/CellFrameDashboardService/DapChainWalletHandler.cpp index 4da008ac980a5c0b0b36a7d7f7c5ae45b89b76c1..309c0988d1ddd7e3cf065f0313361509f010d1a4 100755 --- a/CellFrameDashboardService/DapChainWalletHandler.cpp +++ b/CellFrameDashboardService/DapChainWalletHandler.cpp @@ -1,5 +1,6 @@ #include "DapChainWalletHandler.h" #include <QDebug> +#include <QRegularExpression> DapChainWalletHandler::DapChainWalletHandler(QObject *parent) : QObject(parent) { @@ -42,25 +43,12 @@ QMap<QString, QVariant> DapChainWalletHandler::getWallets() QProcess process; process.start(QString("%1 wallet list").arg(CLI_PATH)); process.waitForFinished(-1); - QString str = QString::fromLatin1(process.readAll()); - QRegExp rx(":{1,1}([\\s\\w\\W]+)(\\n|\\r){1,1}" ); - rx.setMinimal(true); - int pos = 0; - int x {0}; - QString tempName; - while ((pos = rx.indexIn(str, pos)) != -1) - { - if(x == 0) - { - tempName = rx.cap(1); - ++x; - } - else - { - map.insert(tempName, rx.cap(1)); - x = 0; - } - pos += rx.matchedLength(); + QByteArray result = process.readAll(); + QRegularExpression rx("wallet:\\s(.+)\\s+addr:\\s(.+)", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator itr = rx.globalMatch(result); + while (itr.hasNext()) { + QRegularExpressionMatch match = itr.next(); + map[match.captured(1)] = match.captured(2); } return map; @@ -72,7 +60,7 @@ QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet) process.start(QString("%1 wallet info -w %2 -net private").arg(CLI_PATH).arg(asNameWallet)); process.waitForFinished(-1); QByteArray result = process.readAll(); - QRegExp rx("wallet: (\\w+)\\s+addr:\\s+(\\w+)\\s+(balance)|(\\d+.\\d+)\\s(\\(\\d+\\))\\s(\\w+)"); + QRegExp rx("wallet: (.+)\\s+addr:\\s+(\\w+)\\s+(balance)|(\\d+.\\d+)\\s(\\(\\d+\\))\\s(\\w+)"); QStringList list; int pos = 0;