diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index 22052a2d7b1ec6dc927d7a4c09831e9cecbec75b..6027ab04ec2e0ca5464461519913b42ed76ee547 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -69,7 +69,7 @@ SOURCES += \ $$PWD/DapServiceClientNativeAbstract.cpp \ $$PWD/DapServiceClientNativeLinux.cpp \ $$PWD/DapServiceClientNativeWin.cpp \ - $$PWD/DapServiceClientNativeMacOS.cpp \ + $$PWD/DapServiceClientNativeMacOS.cpp RESOURCES += $$PWD/qml.qrc @@ -83,7 +83,7 @@ HEADERS += \ $$PWD/DapServiceController.h \ $$PWD/DapServiceClientNativeAbstract.h \ $$PWD/DapServiceClientNativeLinux.h \ - $$PWD/DapServiceClientNativeWin.h \ + $$PWD/DapServiceClientNativeWin.h include (../libdap/libdap.pri) include (../libdap-crypto/libdap-crypto.pri) diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index 2f7b61a7f20c974128f35becb6ef6630c254f510..5502b5a01717b571477e9f5db7d7c259225db5e9 100644 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -33,6 +33,30 @@ QString DapServiceController::getVersion() const return m_sVersion; } +QString DapServiceController::getCurrentNetwork() const +{ + return m_sCurrentNetwork; +} + +void DapServiceController::setCurrentNetwork(const QString &sCurrentNetwork) +{ + m_sCurrentNetwork = sCurrentNetwork; + + emit currentNetworkChanged(m_sCurrentNetwork); +} + +int DapServiceController::getIndexCurrentNetwork() const +{ + return m_iIndexCurrentNetwork; +} + +void DapServiceController::setIndexCurrentNetwork(int iIndexCurrentNetwork) +{ + m_iIndexCurrentNetwork = iIndexCurrentNetwork; + + emit indexCurrentNetworkChanged(m_iIndexCurrentNetwork); +} + /// Get an instance of a class. /// @return Instance of a class. DapServiceController &DapServiceController::getInstance() @@ -81,13 +105,44 @@ void DapServiceController::registerCommand() m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapActivateClientCommand("DapActivateClientCommand", m_DAPRpcSocket))), QString("clientActivated"))); // Log update command on the Logs tab m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_DAPRpcSocket))), QString("logUpdated"))); + // The team to create a new wallet on the Dashboard tab + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapAddWalletCommand("DapAddWalletCommand", m_DAPRpcSocket))), QString("walletCreated"))); + // The command to get a list of available wallets + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetListWalletsCommand("DapGetListWalletsCommand", m_DAPRpcSocket))), QString("walletsListReceived"))); // Command to save data from the Logs tab m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapExportLogCommand("DapExportLogCommand",m_DAPRpcSocket))), QString("exportLogs"))); + // The command to get a list of available networks + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetListNetworksCommand("DapGetListNetworksCommand", m_DAPRpcSocket))), QString("networksListReceived"))); + + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetWalletAddressesCommand("DapGetWalletAddressesCommand", m_DAPRpcSocket))), QString("walletAddressesReceived"))); + + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetWalletTokenInfoCommand("DapGetWalletTokenInfoCommand", m_DAPRpcSocket))), QString("walletTokensReceived"))); // Creating a token transfer transaction between wallets m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapCreateTransactionCommand("DapCreateTransactionCommand",m_DAPRpcSocket))), QString("transactionCreated"))); // Transaction confirmation m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapMempoolProcessCommand("DapMempoolProcessCommand",m_DAPRpcSocket))), QString("mempoolProcessed"))); + connect(this, &DapServiceController::walletsListReceived, [=] (const QVariant& walletList) + { + QByteArray array = QByteArray::fromHex(walletList.toByteArray()); + QList<DapWallet> tempWallets; + + QDataStream in(&array, QIODevice::ReadOnly); + in >> tempWallets; + + QList<QObject*> wallets; + auto begin = tempWallets.begin(); + auto end = tempWallets.end(); + DapWallet * wallet = nullptr; + for(;begin != end; ++begin) + { + wallet = new DapWallet(*begin); + wallets.append(wallet); + } + + emit walletsReceived(wallets); + }); + registerEmmitedSignal(); } @@ -96,7 +151,7 @@ void DapServiceController::registerCommand() void DapServiceController::findEmittedSignal(const QVariant &aValue) { DapAbstractCommand * transceiver = dynamic_cast<DapAbstractCommand *>(sender()); - + disconnect(transceiver, SIGNAL(serviceResponded(QVariant)), this, SLOT(findEmittedSignal(QVariant))); Q_ASSERT(transceiver); auto service = std::find_if(m_transceivers.begin(), m_transceivers.end(), [=] (const QPair<DapAbstractCommand*, QString>& it) { diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index 6c834ea4f807cf59af6809adce488a25430a7b8f..93c7c971d2a21c2b70007373e43b3998a705a50a 100644 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -7,13 +7,21 @@ #include <QJSEngine> #include <QVector> #include <algorithm> +#include <QDataStream> #include "DapServiceClient.h" +#include "DapWallet.h" #include "Handlers/DapAbstractCommand.h" #include "Handlers/DapQuitApplicationCommand.h" #include "Handlers/DapActivateClientCommand.h" #include "Handlers/DapUpdateLogsCommand.h" +#include "Handlers/DapAddWalletCommand.h" +#include "Handlers/DapGetListWalletsCommand.h" +#include "Handlers/DapGetListNetworksCommand.h" #include "Handlers/DapExportLogCommand.h" +#include "Handlers/DapGetWalletAddressesCommand.h" +#include "Handlers/DapGetWalletTokenInfoCommand.h" +#include "Models/DapWalletModel.h" #include "Handlers/DapCreateTransactionCommand.h" #include "Handlers/DapMempoolProcessCommand.h" @@ -25,6 +33,10 @@ class DapServiceController : public QObject QString m_sBrand {DAP_BRAND}; /// Application version. QString m_sVersion {DAP_VERSION}; + + QString m_sCurrentNetwork; + + int m_iIndexCurrentNetwork; /// Service connection management service. DapServiceClient *m_pDapServiceClient {nullptr}; /// Command manager. @@ -64,6 +76,10 @@ public: Q_PROPERTY(QString Brand MEMBER m_sBrand READ getBrand NOTIFY brandChanged) /// Application version. Q_PROPERTY(QString Version MEMBER m_sVersion READ getVersion NOTIFY versionChanged) + + Q_PROPERTY(QString CurrentNetwork MEMBER m_sVersion READ getCurrentNetwork WRITE setCurrentNetwork NOTIFY currentNetworkChanged) + + Q_PROPERTY(int IndexCurrentNetwork MEMBER m_iIndexCurrentNetwork READ getIndexCurrentNetwork WRITE setIndexCurrentNetwork NOTIFY indexCurrentNetworkChanged) /// Client controller initialization. /// @param apDapServiceClient Network connection controller. @@ -75,6 +91,14 @@ public: /// @return Application version. QString getVersion() const; + QString getCurrentNetwork() const; + + Q_INVOKABLE void setCurrentNetwork(const QString &sCurrentNetwork); + + int getIndexCurrentNetwork() const; + + Q_INVOKABLE void setIndexCurrentNetwork(int iIndexCurrentNetwork); + signals: /// The signal is emitted when the Brand company property changes. /// @param asBrand Brand @@ -82,6 +106,8 @@ signals: /// The signal is emitted when the Application version property changes. /// @param version Version void versionChanged(const QString &version); + + void currentNetworkChanged(const QString &asCurrentNetwork); /// The signal is emitted when a command to activate a client is received. void clientActivated(); ///This signal sends data about saving a file from the Logs tab @@ -97,6 +123,19 @@ signals: /// @param aResult Mempool processing result. void mempoolProcessed(const QVariant& aResult); + void walletCreated(const QVariant& wallet); + + void walletsListReceived(const QVariant& walletList); + + void walletsReceived(const QList<QObject*>& walletList); + + void networksListReceived(const QVariant& networkList); + + void walletAddressesReceived(const QVariant& walletAddresses); + + void walletTokensReceived(const QVariant& walletTokens); + + void indexCurrentNetworkChanged(int iIndexCurrentNetwork); private slots: /// Register command. diff --git a/CellFrameDashboardGUI/main.cpp b/CellFrameDashboardGUI/main.cpp index 6112b12ef6eeafdb3ad864c5edd3bf38610393cb..c757d815295dca6b19cc6035654898da59441993 100644 --- a/CellFrameDashboardGUI/main.cpp +++ b/CellFrameDashboardGUI/main.cpp @@ -13,6 +13,7 @@ #include "DapServiceController.h" #include "DapLogger.h" #include "DapLogMessage.h" +#include "DapWallet.h" #include <sys/stat.h> @@ -40,14 +41,19 @@ int main(int argc, char *argv[]) #endif //#endif + + /// Local client. DapServiceClient dapServiceClient; // Creating a service controller DapServiceController &controller = DapServiceController::getInstance(); controller.init(&dapServiceClient); dapServiceClient.init(); - qmlRegisterType<DapLogMessage>("LogMessage", 1, 0, "DapLogMessage"); - + qmlRegisterType<DapLogMessage>("Demlabs", 1, 0, "DapLogMessage"); + qmlRegisterType<DapWallet>("Demlabs", 1, 0, "DapWallet"); + qmlRegisterType<DapWalletToken>("Demlabs", 1, 0, "DapWalletToken"); + qRegisterMetaType<DapWallet>(); + qRegisterMetaType<DapWalletToken>(); QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance()); engine.rootContext()->setContextProperty("pt", 1); diff --git a/CellFrameDashboardGUI/qml.qrc b/CellFrameDashboardGUI/qml.qrc index 935a1a8fcf32c8c4307b8693261db5d08e8618a6..5bc6b7bf37beed7369a9a617af4ff19f64540e1b 100755 --- a/CellFrameDashboardGUI/qml.qrc +++ b/CellFrameDashboardGUI/qml.qrc @@ -136,12 +136,13 @@ <file>res/icons/ic_edit_hover.png</file> <file>res/icons/ic_klvn.png</file> <file>res/icons/new-payment_icon.png</file> - <file>res/icons/ng_icon.png</file> - <file>res/icons/tkn1_icon_light.png</file> <file>res/icons/tkn2_icon.png</file> + <file>res/icons/tkn1_icon_light.png</file> + <file>res/icons/ng_icon.png</file> <file>screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanel.qml</file> <file>screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanelForm.ui.qml</file> <file>screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanel.qml</file> <file>screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanelForm.ui.qml</file> + <file>res/icons/ic_cellframe.png</file> </qresource> </RCC> diff --git a/CellFrameDashboardGUI/res/icons/ic_cellframe.png b/CellFrameDashboardGUI/res/icons/ic_cellframe.png new file mode 100644 index 0000000000000000000000000000000000000000..808b85e4d830a9e1a476ca60a551a738eb48b8f4 Binary files /dev/null and b/CellFrameDashboardGUI/res/icons/ic_cellframe.png differ diff --git a/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml b/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml index 73e879aae951404f95164cb8539956acc544e601..b17d786ef8a36192aae9b33ee7d089ba5340500d 100644 --- a/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml +++ b/CellFrameDashboardGUI/screen/DapMainApplicationWindow.qml @@ -2,6 +2,7 @@ import QtQuick 2.4 DapMainApplicationWindowForm { + id: dapMainWindow ///@detalis Path to the dashboard tab. readonly property string dashboardScreen: "qrc:/screen/" + device + "/Dashboard/DapDashboardTab.qml" ///@detalis Path to the exchange tab. @@ -15,8 +16,19 @@ DapMainApplicationWindowForm ///@detalis Path to the console tab. readonly property string consoleScreen: "qrc:/screen/" + device + "/Console/DapConsoleTab.qml" + property var dapWallets: [] + signal modelWalletsUpdated() + ListModel + { + id: dapNetworkModel + } + + ListModel + { + id: dapModelWallets + } // Menu bar tab model ListModel @@ -75,6 +87,68 @@ DapMainApplicationWindowForm { dapScreenLoader.setSource(Qt.resolvedUrl(dapMenuTabWidget.pathScreen)) } + + Component.onCompleted: + { + dapServiceController.requestToService("DapGetListNetworksCommand"); + dapServiceController.requestToService("DapGetListWalletsCommand"); + } + + Connections + { + target: dapServiceController + onNetworksListReceived: + { + for(var n=0; n < Object.keys(networkList).length; ++n) + { + dapServiceController.CurrentNetwork = networkList[0]; + dapServiceController.IndexCurrentNetwork = 0; + dapNetworkModel.append({name: networkList[n]}) + } + } + + onWalletsReceived: + { + console.log(walletList.length) + console.log(dapWallets.length) + console.log(dapModelWallets.count) + for (var q = 0; q < walletList.length; ++q) + { + dapWallets.push(walletList[q]) + } + for (var i = 0; i < dapWallets.length; ++i) + { + console.log(dapWallets[i].Name) + dapModelWallets.append({ "name" : dapWallets[i].Name, + "balance" : dapWallets[i].Balance, + "icon" : dapWallets[i].Icon, + "address" : dapWallets[i].Address, + "networks" : []}) + console.log(Object.keys(dapWallets[i].Networks).length) + for (var n = 0; n < Object.keys(dapWallets[i].Networks).length; ++n) + { + dapModelWallets.get(i).networks.append({"name": dapWallets[i].Networks[n], + "address": dapWallets[i].findAddress(dapWallets[i].Networks[n]), + "tokens": []}) + console.log(Object.keys(dapWallets[i].Tokens).length) + for (var t = 0; t < Object.keys(dapWallets[i].Tokens).length; ++t) + { + console.log(dapWallets[i].Tokens[t].Network + " === " + dapWallets[i].Networks[n]) + if(dapWallets[i].Tokens[t].Network === dapWallets[i].Networks[n]) + { + dapModelWallets.get(i).networks.get(n).tokens.append({"name": dapWallets[i].Tokens[t].Name, + "balance": dapWallets[i].Tokens[t].Balance, + "emission": dapWallets[i].Tokens[t].Emission, + "network": dapWallets[i].Tokens[t].Network}) + } + } + + } + + } + modelWalletsUpdated() + } + } } /*##^## Designer { diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml index d38bc0e7a9168e7d6ed07f83a5a2bf92a5937b24..6fed35f286fa51eb902349e046cbf4df95ebab32 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml @@ -1,6 +1,221 @@ import QtQuick 2.4 +import QtQuick.Layouts 1.2 +import "qrc:/widgets" DapDashboardScreenForm { + Component + { + id: delegateTokenView + Column + { + width: parent.width + Rectangle + { + id: stockNameBlock + height: 30 * pt + width: parent.width + color: "#908D9D" + + Text + { + id: stockNameText + anchors.left: parent.left + anchors.leftMargin: 16 * pt + anchors.verticalCenter: parent.verticalCenter + font.pixelSize: 12 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#FFFFFF" + verticalAlignment: Qt.AlignVCenter + text: name + } + } + + Rectangle + { + id: networkAddressBlock + height: 40 * pt + width: parent.width + + Text + { + id: networkAddressLabel + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 16 * pt + font.pixelSize: 12 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#908D9D" + text: qsTr("Network address") + width: 92 * pt + } + + DapText + { + id: textMetworkAddress + anchors.verticalCenter: parent.verticalCenter + anchors.left: networkAddressLabel.right + anchors.leftMargin: 36 * pt + width: 172 * pt + font.pixelSize: 10 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#908D9D" + text: address + elide: Text.ElideRight + } + + + + MouseArea + { + id: networkAddressCopyButton + anchors.verticalCenter: parent.verticalCenter + anchors.left: textMetworkAddress.right + anchors.leftMargin: 4 * pt + width: 16 * pt + height: 16 * pt + hoverEnabled: true + + onClicked: textMetworkAddress.copy() + + + Image + { + id: networkAddressCopyButtonImage + anchors.fill: parent + source: parent.containsMouse ? "qrc:/res/icons/ic_copy_hover.png" : "qrc:/res/icons/ic_copy.png" + sourceSize.width: parent.width + sourceSize.height: parent.height + + } + } + } + + Repeater + { + width: parent.width + model: tokens + + Rectangle + { + anchors.left: parent.left + anchors.leftMargin: 16 * pt + anchors.right: parent.right + anchors.rightMargin: 16 * pt + height: 67 * pt + + Rectangle + { + id: lineBalance + anchors.top: parent.top + width: parent.width + height: 1 * pt + color: "#908D9D" + } + + Rectangle + { + anchors.top: lineBalance.bottom + anchors.topMargin: 24 * pt + anchors.bottom: parent.bottom + anchors.bottomMargin: 12 * pt + color: "transparent" + + Image + { + id: currencyIcon + anchors.left: parent.left + height: 30 * pt + width: 30 * pt + source: "qrc:/res/icons/ic_cellframe.png" + sourceSize.width: width + sourceSize.height: height + anchors.verticalCenter: parent.verticalCenter + } + + Text + { + id: currencyName + anchors.verticalCenter: parent.verticalCenter + anchors.left: currencyIcon.right + anchors.leftMargin: 10 * pt + font.pixelSize: 18 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#070023" + text: name + width: 172 * pt + horizontalAlignment: Text.AlignLeft + + } + + Rectangle + { + id: frameBalance + anchors.verticalCenter: parent.verticalCenter + color: "transparent" + width: 188 * pt + anchors.left: currencyName.right + anchors.leftMargin: 16 * pt + Text + { + id: currencySum + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + font.pixelSize: 12 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#070023" + text: balance + " " + horizontalAlignment: Text.AlignLeft + + } + + Text + { + id: currencyCode + anchors.verticalCenter: parent.verticalCenter + anchors.left: currencySum.right + anchors.right: parent.right + font.pixelSize: 12 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#070023" + text: name + horizontalAlignment: Text.AlignLeft + } + } + + Text + { + id: currencyDollarEqv + anchors.verticalCenter: parent.verticalCenter + anchors.left: frameBalance.right + anchors.leftMargin: 16 * pt + anchors.right: parent.right + anchors.rightMargin: 16 * pt + font.pixelSize: 12 * pt + font.family: "Roboto" + font.styleName: "Normal" + font.weight: Font.Normal + color: "#070023" + text: "$" + emission + " USD" + width: 188 * pt + horizontalAlignment: Text.AlignLeft + } + } + } + } + } + } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml index 6c2b6ca5d7f4314035741422e38eb2842618d383..e96b43ce7eee36fc5deda2faf60dd667628ff02c 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml @@ -8,7 +8,6 @@ DapAbstractScreen { id: dapDashboardScreen dapFrame.color: "#FFFFFF" - textTest.text: "Here text" // Delete it? anchors.fill: parent anchors.leftMargin: 24 * pt anchors.rightMargin: 24 * pt @@ -21,6 +20,8 @@ DapAbstractScreen ///@param dapButtonNewPayment Button to create a new payment. property alias dapButtonNewPayment: buttonNewPayment + property alias dapListViewWallet: listViewWallet + Rectangle { id: titleBlock @@ -37,11 +38,13 @@ DapAbstractScreen Text { + id: titleText font.pixelSize: 20 * pt font.family: "Roboto" font.styleName: "Normal" font.weight: Font.Normal - text: "My first wallet" + text: "My first crypto wallet" + width: 185 * pt } MouseArea @@ -50,6 +53,8 @@ DapAbstractScreen width: 20 * pt height: 20 * pt hoverEnabled: true + anchors.left: titleText.right + anchors.leftMargin: 12 * pt Image { @@ -90,282 +95,14 @@ DapAbstractScreen ListView { + id: listViewWallet anchors.top: titleBlock.bottom anchors.topMargin: 20 * pt anchors.bottom: parent.bottom width: parent.width spacing: 5 * pt clip: true - model: - ListModel - { - ListElement - { - name: "Kelvin Testnet" - address: "KLJHuhlkjshfausdh7865lksfahHKLUIHKJFHKLUESAHFILKUHEWKUAFHjkhfdkslusfkhgs" - money: [ - ListElement - { - type: "bitCoin" - sum: 3487256 - eq: "$ 3498750" - }, - ListElement - { - type: "ether" - sum: 67896 - eq: "$ 78687" - }, - ListElement - { - type: "newGold" - sum: 675573 - eq: "$ 987978" - } - ] - } - - ListElement - { - name: "Marketnet" - address: "lkajdsfeislsaIJEUfesIJEFHJISEFIsdfLIJFEISHFUSKEIEWEQLIJSlijfsfjlijeIEJJE" - money: [ - ListElement - { - type: "bitCoin" - sum: 3487256 - eq: "$ 3498750" - }, - ListElement - { - type: "ether" - sum: 67896 - eq: "$ 78687" - }, - ListElement - { - type: "newGold" - sum: 675573 - eq: "$ 987978" - }, - ListElement - { - type: "ether" - sum: 6743896 - eq: "$ 7843687" - } - ] - } - } - - delegate: - Column - { - width: parent.width - - Rectangle - { - id: stockNameBlock - height: 30 * pt - width: parent.width - color: "#908D9D" - - Text - { - id: stockNameText - anchors.left: parent.left - anchors.leftMargin: 16 * pt - anchors.verticalCenter: parent.verticalCenter - font.pixelSize: 12 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#FFFFFF" - verticalAlignment: Qt.AlignVCenter - text: name - } - } - - Row - { - id: networkAddressBlock - height: 40 * pt - width: parent.width - - Item - { - width: 16 * pt - height: parent.height - } - - Text - { - id: networkAddressLabel - anchors.verticalCenter: parent.verticalCenter - font.pixelSize: 12 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#908D9D" - text: qsTr("Network address") - } - - Item - { - width: 36 * pt - height: parent.height - } - - Text - { - id: networkAddressValue - anchors.verticalCenter: parent.verticalCenter - width: 200 * pt - font.pixelSize: 12 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#908D9D" - text: address - elide: Text.ElideRight - } - - MouseArea - { - id: networkAddressCopyButton - anchors.verticalCenter: parent.verticalCenter - width: 20 * pt - height: 20 * pt - hoverEnabled: true - Image - { - id: networkAddressCopyButtonImage - anchors.fill: parent - source: parent.containsMouse ? "qrc:/res/icons/ic_copy_hover.png" : "qrc:/res/icons/ic_copy.png" - sourceSize.width: width - sourceSize.height: height - - } - } - } - - Repeater - { - width: parent.width - model: money - - Rectangle - { - anchors.left: parent.left - anchors.leftMargin: 16 * pt - anchors.right: parent.right - anchors.rightMargin: 16 * pt - height: 56 * pt - - Rectangle - { - anchors.top: parent.top - width: parent.width - height: 1 * pt - color: "#908D9D" - } - - RowLayout - { - anchors.fill: parent - - Image - { - id: currencyIcon - height: 40 * pt - width: 40 * pt - Layout.alignment: Qt.AlignLeft - source: (type === "bitCoin") ? bitCoinImagePath : (type === "ether") ? ethereumImagePath : newGoldImagePath // Don't know how to deal with it yet - sourceSize.width: width - sourceSize.height: height - } - - Item - { - height: parent.height - width: 10 * pt - Layout.alignment: Qt.AlignLeft - } - - Text - { - id: currencyName - Layout.alignment: Qt.AlignLeft - font.pixelSize: 18 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#070023" - text: type - } - // Delimiters - see design - Item - { - height: parent.height - width: 16 * pt - } - - - Item - { - Layout.fillWidth: true - } - - - Item - { - height: parent.height - width: 16 * pt - } - - Text - { - id: currencySum - Layout.alignment: Qt.AlignHCenter - font.pixelSize: 18 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#070023" - text: sum - } - - Text - { - id: currencyCode - font.pixelSize: 18 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#070023" - text: (type === "bitCoin") ? "BTC" : (type === "ether") ? "ETH" : (type === "newGold") ? "NGD" : "KLVN" - } - - Item - { - Layout.fillWidth: true - } - - Text - { - id: currencyDollarEqv - Layout.alignment: Qt.AlignRight - font.pixelSize: 18 * pt - font.family: "Roboto" - font.styleName: "Normal" - font.weight: Font.Normal - color: "#070023" - text: eq - } - } - } - } - } + delegate: delegateTokenView } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml index 6682466647cb8693274c448a7140936b8430accd..e39539879b4e4c71aae8350ae0d0f3ed5352e33b 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml @@ -1,4 +1,5 @@ import QtQuick 2.4 +import "qrc:/" import "../../" DapDashboardTabForm @@ -21,6 +22,13 @@ DapDashboardTabForm // Setting the right pane by default dapDashboardRightPanel.initialItem: Qt.resolvedUrl(lastActionsWallet); + property int dapIndexCurrentWallet: -1 + + dapDashboardTopPanel.dapComboboxWallet.onCurrentIndexChanged: + { + dapDashboardScreen.dapListViewWallet.model = dapModelWallets.get(dapDashboardTopPanel.dapComboboxWallet.currentIndex).networks + } + // Signal-slot connection realizing panel switching depending on predefined rules Connections { @@ -29,14 +37,58 @@ DapDashboardTabForm { currentRightPanel = dapDashboardRightPanel.push(currentRightPanel.dapNextRightPanel); } + onPreviousActivated: + { + currentRightPanel = dapDashboardRightPanel.push(currentRightPanel.dapPreviousRightPanel); + } } - // When you click on the button for creating a new payment, open the form to fill in the payment data - dapDashboardScreen.dapButtonNewPayment.onClicked: + Connections + { + target: dapMainWindow + onModelWalletsUpdated: + { + console.log(dapIndexCurrentWallet) + dapDashboardTopPanel.dapComboboxWallet.currentIndex = dapIndexCurrentWallet + } + } + + Connections { - if(dapDashboardRightPanel.currentItem !== currentRightPanel) + target: dapServiceController + onMempoolProcessed: + { + update() + } + onWalletCreated: { - currentRightPanel = dapDashboardRightPanel.push(Qt.resolvedUrl(newPaymentMain)); + if(wallet[0]) + { + update() + } } } + + dapDashboardTopPanel.dapAddWalletButton.onClicked: + { + currentRightPanel = dapDashboardRightPanel.push({item:Qt.resolvedUrl(inputNameWallet)}); + } + + // When you click on the button for creating a new payment, open the form to fill in the payment data + dapDashboardScreen.dapButtonNewPayment.onClicked: + { + currentRightPanel = dapDashboardRightPanel.push({item:Qt.resolvedUrl(newPaymentMain), + properties: {dapCmboBoxTokenModel: dapModelWallets.get(dapDashboardTopPanel.dapComboboxWallet.currentIndex).networks, + dapCurrentWallet: dapDashboardTopPanel.dapComboboxWallet.currentText, + dapCmboBoxTokenModel: dapModelWallets.get(dapDashboardTopPanel.dapComboboxWallet.currentIndex).networks.get(dapServiceController.IndexCurrentNetwork).tokens, + dapTextSenderWalletAddress: dapWallets[dapDashboardTopPanel.dapComboboxWallet.currentIndex].findAddress(dapServiceController.CurrentNetwork)}}); + } + + function update() + { + dapIndexCurrentWallet = dapDashboardTopPanel.dapComboboxWallet.currentIndex + dapWallets.length = 0 + dapModelWallets.clear() + dapServiceController.requestToService("DapGetListWalletsCommand"); + } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml index 57d0ed84e19492ccd2fdae2ff3ad3983243cc28d..81c8945d204a4f55c378d468c687ffe895e28f82 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml @@ -7,7 +7,7 @@ DapAbstractTab { id: dashboardTab - property alias dapDashboardRightPanel: rightPanelLoader + property alias dapDashboardRightPanel: stackViewRightPanel property alias dapDashboardTopPanel: dashboardTopPanel property alias dapDashboardScreen: dashboardScreen @@ -26,7 +26,7 @@ DapAbstractTab dapRightPanel: StackView { - id: rightPanelLoader + id: stackViewRightPanel anchors.fill: parent width: 400 delegate: diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml index 0546d724dbaf5a6118a998ba1056b28338ed228e..eda858dac7667a180d4c63b15ba7b4c52ba48eef 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml @@ -1,26 +1,17 @@ import QtQuick 2.4 +import Demlabs 1.0 DapDashboardTopPanelForm { - ListModel + Connections { - id: modelWallets - } - - ListModel - { - id: modelTokens - } - - function updateModel(wallet) - { - console.log(wallet) - if(wallet[1] === "created") - modelWallets.append({ "name" : wallet[0] }) - } - - dapAddWalletButton.onClicked: - { - dapServiceController.requestToService("ADD", "MYNEWWALLET"); + target: dapServiceController + onWalletCreated: + { + if(wallet[0] === true) + updateModel(wallet) + else + console.log(wallet[1]) + } } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml index 1a41f58423b1775a93834dfd3c54a0d4276f4405..15368001fc33290bc95f5d45925c2a5776e99f84 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml @@ -6,7 +6,8 @@ import "../../" DapAbstractTopPanel { property alias dapAddWalletButton: addWalletButton - + property alias dapComboboxWallet: comboboxWallet + anchors.fill: parent // Static text "Wallet" @@ -17,7 +18,7 @@ DapAbstractTopPanel anchors.left: parent.left anchors.leftMargin: 24 * pt anchors.verticalCenter: parent.verticalCenter - font.family: DapMainApplicationWindow.dapFontRobotoRegular.name + font.family: dapFontRobotoRegular.name font.pixelSize: 12 * pt color: "#ACAAB5" } @@ -36,7 +37,8 @@ DapAbstractTopPanel DapComboBox { id: comboboxWallet - model: modelWallets + model: dapModelWallets + comboBoxTextRole: "name" mainLineText: "all wallets" indicatorImageNormal: "qrc:/res/icons/ic_arrow_drop_down.png" indicatorImageActive: "qrc:/res/icons/ic_arrow_drop_up.png" @@ -70,63 +72,15 @@ DapAbstractTopPanel } } - // Token selection combo box - Rectangle - { - id: frameComboBoxToken - - anchors.left: frameComboBoxWallet.right - anchors.verticalCenter: parent.verticalCenter - anchors.leftMargin: 70 * pt - width: 148 * pt - color: "transparent" - - DapComboBox - { - id: comboboxToken - model: modelTokens - mainLineText: "all tokens" - indicatorImageNormal: "qrc:/res/icons/ic_arrow_drop_down.png" - indicatorImageActive: "qrc:/res/icons/ic_arrow_drop_up.png" - sidePaddingNormal: 0 * pt - sidePaddingActive: 16 * pt - normalColorText: "#070023" - hilightColorText: "#FFFFFF" - normalColorTopText: "#FFFFFF" - hilightColorTopText: "#070023" - hilightColor: "#330F54" - normalTopColor: "#070023" - widthPopupComboBoxNormal: 148 * pt - widthPopupComboBoxActive: 180 * pt - heightComboBoxNormal: 24 * pt - heightComboBoxActive: 44 * pt - bottomIntervalListElement: 8 * pt - topEffect: false - x: popup.visible ? sidePaddingActive * (-1) : sidePaddingNormal - normalColor: "#FFFFFF" - hilightTopColor: normalColor - paddingTopItemDelegate: 8 * pt - heightListElement: 32 * pt - intervalListElement: 10 * pt - indicatorWidth: 24 * pt - indicatorHeight: indicatorWidth - indicatorLeftInterval: 8 * pt - colorTopNormalDropShadow: "#00000000" - colorDropShadow: "#40ABABAB" - fontComboBox.pixelSize: 14 * pt - fontComboBox.family: "Roboto" - } - } - // Static wallet balance text "Wallet balance" Label { id: headerWalletBalance text: qsTr("Wallet balance") - anchors.left: frameComboBoxToken.right + anchors.left: frameComboBoxWallet.right anchors.leftMargin: 70 * pt anchors.verticalCenter: parent.verticalCenter - font.family: DapMainApplicationWindow.dapFontRobotoRegular.name + font.family: dapFontRobotoRegular.name font.pixelSize: 12 * pt color: "#ACAAB5" } @@ -139,7 +93,7 @@ DapAbstractTopPanel anchors.left: headerWalletBalance.right anchors.leftMargin: 18 * pt anchors.verticalCenter: parent.verticalCenter - font.family: DapMainApplicationWindow.dapFontRobotoRegular.name + font.family: dapFontRobotoRegular.name font.pixelSize: 16 * pt color: "#FFFFFF" } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanel.qml index 01b96efde04f495beb991b2688fca72fb93fa450..36ae060f2f4714246183850878085317e55043c9 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanel.qml @@ -2,5 +2,13 @@ import QtQuick 2.4 DapDoneWalletRightPanelForm { + dapButtonDone.onClicked: + { + nextActivated(lastActionsWallet) + } + dapButtonClose.onClicked: + { + previousActivated(lastActionsWallet) + } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanelForm.ui.qml index 0cb2560afb9a71a5f42bc59ebf409b583c8599fa..7bc5a82a5644613693defab9cee617ce5c7315a3 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapDoneWalletRightPanelForm.ui.qml @@ -4,6 +4,11 @@ import "../../../" DapAbstractRightPanel { + dapNextRightPanel: lastActionsWallet + dapPreviousRightPanel: lastActionsWallet + + property alias dapButtonDone: buttonDone + dapButtonClose.height: 16 * pt dapButtonClose.width: 16 * pt dapButtonClose.heightImageButton: 16 * pt diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanel.qml index 518af912ef583326cc25091609ef08f7611999d1..c09c1ca693c7d6399c11c306102b83f69d37565b 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanel.qml @@ -2,5 +2,36 @@ import QtQuick 2.4 DapInputNewWalletNameRightPanelForm { + property string dapSignatureTypeWallet + + dapComboBoxSignatureTypeWallet.onCurrentIndexChanged: + { + dapSignatureTypeWallet = dapSignatureTypeWalletModel.get(dapComboBoxSignatureTypeWallet.currentIndex).sign + } + + dapButtonNext.onClicked: + { + console.log(dapTextInputNameWallet.text) + console.log(dapSignatureTypeWallet) + console.log(dapServiceController.CurrentNetwork) + dapServiceController.requestToService("DapAddWalletCommand", dapTextInputNameWallet.text, dapSignatureTypeWallet, dapServiceController.CurrentNetwork, "0xad12dec5ab4f"); + } + + dapButtonClose.onClicked: + { + previousActivated(lastActionsWallet) + } + + Connections + { + target: dapServiceController + onWalletCreated: + { + if(wallet[0]) + { + nextActivated("doneWallet") + } + } + } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanelForm.ui.qml index c691075db67f66d0af656a1723faeff2f26415af..4a9ab6d370b4c6b88b15becd48ff968a61c32fa4 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapInputNewWalletNameRightPanelForm.ui.qml @@ -7,6 +7,39 @@ import "../../../" DapAbstractRightPanel { + property alias dapTextInputNameWallet: textInputNameWallet + property alias dapComboBoxSignatureTypeWallet: comboBoxSignatureTypeWallet + property alias dapButtonNext: buttonNext + property alias dapSignatureTypeWalletModel: signatureTypeWallet + + dapNextRightPanel: doneWallet + dapPreviousRightPanel: lastActionsWallet + + ListModel + { + id: signatureTypeWallet + ListElement + { + name: "Dilithium" + sign: "sig_dil" + } + ListElement + { + name: "Bliss" + sign: "sig_bliss" + } + ListElement + { + name: "Picnic" + sign: " sig_picnic" + } + ListElement + { + name: "Tesla" + sign: " sig_tesla" + } + } + dapHeaderData: Row { @@ -140,29 +173,9 @@ DapAbstractRightPanel anchors.rightMargin: 16 * pt DapComboBox { - property Label fieldBalance: Label {} - - model: - ListModel - { - id: signatureType - ListElement - { - signatureName: "Dilithium" - } - ListElement - { - signatureName: "Bliss" - } - ListElement - { - signatureName: "Picnic" - } - ListElement - { - signatureName: "Tesla" - } - } + id: comboBoxSignatureTypeWallet + model: signatureTypeWallet + comboBoxTextRole: "name" anchors.left: parent.left anchors.right: parent.right anchors.leftMargin: 20 * pt diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanel.qml index 1f044c23d8747c06d5d09fb1e28693f4ff0be1a8..c1d95241c0def92a8cc984b2be123b3b9552139e 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanel.qml @@ -4,6 +4,14 @@ DapNewPaymentDoneRightPanelForm { dapButtonSend.onClicked: { - dapServiceController.requestToService("DapMempoolProcessCommand", "private", "gdb") + var chain = dapServiceController.CurrentNetwork === "private" ? "gdb": "plasma" + dapServiceController.requestToService("DapMempoolProcessCommand", dapServiceController.CurrentNetwork, chain) + + nextActivated("transaction done") + } + + dapButtonClose.onClicked: + { + previousActivated(lastActionsWallet) } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanelForm.ui.qml index 3330f13f70299d57393977f5ef2ef67fc92fbe1e..5d2319e403621f3a8c9d11340aff8a2efc610697 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentDoneRightPanelForm.ui.qml @@ -9,6 +9,9 @@ DapAbstractRightPanel /// @param dapButtonSend Send button. property alias dapButtonSend: buttonSend + dapNextRightPanel: lastActionsWallet + dapPreviousRightPanel: lastActionsWallet + dapHeaderData: Row { diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanel.qml index 7e49160af9ba70b04402fd73a8bd68459f545f2a..4ee51ff7c5ccaf5b0e9eeb6bdbc19dd4c741a6d6 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanel.qml @@ -4,10 +4,18 @@ DapNewPaymentMainRightPanelForm { // The form displayed after clicking on the "Send" button dapNextRightPanel: newPaymentDone + dapPreviousRightPanel: lastActionsWallet + + dapButtonClose.onClicked: + { + previousActivated(lastActionsWallet) + } dapButtonSend.onClicked: { - nextActivated() - dapServiceController.requestToService("DapCreateTransactionCommand", "private", "gdb", "MyWallet", dapTextInputRecipientWalletAddress.text, dapCmboBoxToken.currentText, dapTextInputAmountPayment.text) + var chain = dapServiceController.CurrentNetwork === "private" ? "gdb": "plasma" + dapServiceController.requestToService("DapCreateTransactionCommand", dapServiceController.CurrentNetwork, chain, dapCurrentWallet, dapTextInputRecipientWalletAddress.text, dapCmboBoxToken.currentText, dapTextInputAmountPayment.text) + + nextActivated("transaction created") } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanelForm.ui.qml index e71f0afc96238316520ca7ed99a9eaf1ff431956..6956beae2b6d14d2cade813c6d440f4b00d8f575 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/RightPanel/DapNewPaymentMainRightPanelForm.ui.qml @@ -10,8 +10,15 @@ DapAbstractRightPanel property alias dapButtonSend: buttonSend /// @param dapTextInputAmountPayment Input field for transfer amount. property alias dapTextInputAmountPayment: textInputAmountPayment - /// @param dapCmboBoxToken Token combobox. - property alias dapCmboBoxToken: comboBoxToken + /// @param dapCmboBoxTokenModel Token combobox model. + property alias dapCmboBoxTokenModel: comboboxToken.model + + property alias dapCmboBoxToken: comboboxToken + + + property string dapCurrentWallet + + property alias dapTextSenderWalletAddress: textSenderWalletAddress.text /// @param dapTextInputRecipientWalletAddress Recipient wallet address input field. property alias dapTextInputRecipientWalletAddress: textInputRecipientWalletAddress @@ -75,29 +82,6 @@ DapAbstractRightPanel } } - - - ListModel - { - id: tokenModel - ListElement - { - signatureName: "Kelvin" - } - ListElement - { - signatureName: "Token 1" - } - ListElement - { - signatureName: "Token 2" - } - ListElement - { - signatureName: "NewGold" - } - } - Rectangle { id: frameSenderWalletAddress @@ -119,24 +103,23 @@ DapAbstractRightPanel anchors.topMargin: 20 * pt anchors.leftMargin: 16 * pt anchors.rightMargin: 16 * pt - height: comboBoxToken.height + height: 40 * pt DapComboBox { - id: comboBoxToken - model: tokenModel - anchors.top: parent.top + id: comboboxToken anchors.left: parent.left anchors.right: parent.right - indicatorImageNormal: "qrc:/res/icons/ic_arrow_drop_down_dark.png" + comboBoxTextRole: "name" + indicatorImageNormal: "qrc:/res/icons/ic_arrow_drop_down.png" indicatorImageActive: "qrc:/res/icons/ic_arrow_drop_up.png" sidePaddingNormal: 0 * pt - sidePaddingActive: 0 * pt + sidePaddingActive: 16 * pt normalColorText: "#070023" - hilightColorText: "#transparent" - normalColorTopText: "#070023" + hilightColorText: "#FFFFFF" + normalColorTopText: "#FFFFFF" hilightColorTopText: "#070023" hilightColor: "#330F54" - normalTopColor: "transparent" + normalTopColor: "#070023" widthPopupComboBoxNormal: 148 * pt widthPopupComboBoxActive: 180 * pt heightComboBoxNormal: 24 * pt @@ -149,12 +132,12 @@ DapAbstractRightPanel paddingTopItemDelegate: 8 * pt heightListElement: 32 * pt intervalListElement: 10 * pt - indicatorWidth: 20 * pt + indicatorWidth: 24 * pt indicatorHeight: indicatorWidth indicatorLeftInterval: 8 * pt colorTopNormalDropShadow: "#00000000" colorDropShadow: "#40ABABAB" - fontComboBox.pixelSize: 16 * pt + fontComboBox.pixelSize: 14 * pt fontComboBox.family: "Roboto" } } @@ -186,7 +169,6 @@ DapAbstractRightPanel font.styleName: "Normal" font.weight: Font.Normal color: "#757184" - text: "dsgfsghdfsht5y5wv546v76b67v66354c6565v576764657676767f5f46" elide: Text.ElideRight } } diff --git a/CellFrameDashboardGUI/screen/desktop/Settings/DapSettingsScreen.qml b/CellFrameDashboardGUI/screen/desktop/Settings/DapSettingsScreen.qml index 60f961bc4483e144d6247e96e7f3c9836c657c88..e64d6f4a8d5aa435f17aa728b9be99f30506964e 100644 --- a/CellFrameDashboardGUI/screen/desktop/Settings/DapSettingsScreen.qml +++ b/CellFrameDashboardGUI/screen/desktop/Settings/DapSettingsScreen.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 2.0 DapSettingsScreenForm { + ///@detalis Settings item model. VisualItemModel { @@ -47,6 +48,7 @@ DapSettingsScreenForm height: 60 * pt ComboBox { + id: comboBoxNetwork width: 150 anchors.left: parent.left anchors.top: parent.top @@ -54,18 +56,12 @@ DapSettingsScreenForm anchors.leftMargin: 18 * pt anchors.topMargin: 10 * pt anchors.bottomMargin: 10 * pt - model: - ListModel - { - ListElement - { - text: "one" - } - ListElement - { - text: "two" - } - } + model: dapNetworkModel + onCurrentTextChanged: + { + dapServiceController.CurrentNetwork = currentText + dapServiceController.IndexCurrentNetwork = currentIndex + } } } } diff --git a/CellFrameDashboardService/DapServiceController.cpp b/CellFrameDashboardService/DapServiceController.cpp index a7553b32aac6eff67a5c06618cf0638772b9f39e..90901c36ff0ae9c8eeb5af14eb1540d88a25420b 100755 --- a/CellFrameDashboardService/DapServiceController.cpp +++ b/CellFrameDashboardService/DapServiceController.cpp @@ -50,8 +50,18 @@ void DapServiceController::registerCommand() m_pServer->addService(new DapActivateClientCommand("DapActivateClientCommand", m_pServer)); // Log update command on the Logs tab m_pServer->addService(new DapUpdateLogsCommand("DapUpdateLogsCommand", m_pServer, LOG_FILE)); + // The team to create a new wallet on the Dashboard tab + m_pServer->addService(new DapAddWalletCommand("DapAddWalletCommand", m_pServer)); + // The command to get a list of available wallets + m_pServer->addService(new DapGetListWalletsCommand("DapGetListWalletsCommand", m_pServer, CLI_PATH)); + // The command to get a list of available networks + m_pServer->addService(new DapGetListNetworksCommand("DapGetListNetworksCommand", m_pServer, CLI_PATH)); // Saving the file with the logs m_pServer->addService(new DapExportLogCommand("DapExportLogCommand", m_pServer)); + + m_pServer->addService(new DapGetWalletAddressesCommand("DapGetWalletAddressesCommand", m_pServer)); + + m_pServer->addService(new DapGetWalletTokenInfoCommand("DapGetWalletTokenInfoCommand", m_pServer)); // Creating a token transfer transaction between wallets m_pServer->addService(new DapCreateTransactionCommand("DapCreateTransactionCommand", m_pServer, CLI_PATH)); // Transaction confirmation diff --git a/CellFrameDashboardService/DapServiceController.h b/CellFrameDashboardService/DapServiceController.h index 3d510f65097c7c87a07ad7e163fff572816e6767..f48be4eac4e2865deeac2dcf144e3e1962613b1a 100755 --- a/CellFrameDashboardService/DapServiceController.h +++ b/CellFrameDashboardService/DapServiceController.h @@ -27,7 +27,12 @@ typedef class DapRpcLocalServer DapUiService; #include "Handlers/DapQuitApplicationCommand.h" #include "Handlers/DapActivateClientCommand.h" #include "Handlers/DapUpdateLogsCommand.h" +#include "Handlers/DapAddWalletCommand.h" +#include "Handlers/DapGetListWalletsCommand.h" +#include "Handlers/DapGetListNetworksCommand.h" +#include "Handlers/DapGetWalletAddressesCommand.h" #include "Handlers/DapExportLogCommand.h" +#include "Handlers/DapGetWalletTokenInfoCommand.h" #include "Handlers/DapCreateTransactionCommand.h" #include "Handlers/DapMempoolProcessCommand.h" #include "DapSystemTrayIcon.h" diff --git a/DapRPCProtocol/DapRpcService.cpp b/DapRPCProtocol/DapRpcService.cpp index d4c22849c324bce93b225bb5ddc61d5c9dff2bd7..05826c00e3912ac73ce224243355702241829ee8 100644 --- a/DapRPCProtocol/DapRpcService.cpp +++ b/DapRPCProtocol/DapRpcService.cpp @@ -235,7 +235,10 @@ QJsonValue DapRpcService::convertReturnValue(QVariant &aReturnValue) case QMetaType::QVariantMap: return QJsonValue::fromVariant(aReturnValue); case QMetaType::QByteArray: - return QJsonValue::fromVariant(aReturnValue.toByteArray().toHex()); + { + QJsonValue var = QJsonValue::fromVariant(aReturnValue); + return var; + } default: // if a conversion operator was registered it will be used if (aReturnValue.convert(QMetaType::QJsonValue)) diff --git a/libCellFrameDashboardCommon/DapChainWallet.cpp b/libCellFrameDashboardCommon/DapChainWallet.cpp deleted file mode 100755 index 2fa9c8c972e2623a3dd12fe6fd3196a5ececc26d..0000000000000000000000000000000000000000 --- a/libCellFrameDashboardCommon/DapChainWallet.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#include "DapChainWallet.h" - -DapChainWalletTokenItem::DapChainWalletTokenItem(const QString& aWalletAddress, QObject* parent) : - QObject(parent), - m_wallet(aWalletAddress) -{ - -} - -DapChainWalletTokenItem::DapChainWalletTokenItem(const QString& aWalletAddress, const DapChainWalletTokenData& aData, QObject* parent) : - QObject(parent) -{ - m_wallet = aWalletAddress; - m_name = aData.Name; - m_balance = aData.Balance; - m_emission = aData.Emission; -} - -QString DapChainWalletTokenItem::name() const -{ - return m_name; -} - -double DapChainWalletTokenItem::balance() const -{ - return m_balance; -} - -quint64 DapChainWalletTokenItem::emission() const -{ - return m_emission; -} - -QString DapChainWalletTokenItem::wallet() const -{ - return m_wallet; -} - -void DapChainWalletTokenItem::setName(const QString& aName) -{ - if (m_name == aName) return; - m_name = aName; - emit nameChanged(aName); -} - -void DapChainWalletTokenItem::setBalance(const double aBalance) -{ - qWarning("Floating point comparison needs context sanity check"); - if (qFuzzyCompare(m_balance, aBalance)) - return; - - m_balance = aBalance; - emit balanceChanged(m_balance); -} - -void DapChainWalletTokenItem::setEmission(const quint64 aEmission) -{ - if (m_emission == aEmission) - return; - - m_emission = aEmission; - emit emissionChanged(m_emission); -} - -void DapChainWalletTokenItem::setData(const DapChainWalletTokenData& aData) -{ - setName(aData.Name); - setBalance(aData.Balance); - setEmission(aData.Emission); -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList &aTokens, QObject *parent) - : QObject(parent), m_sIconPath(asIconPath), m_sName(asName), m_sAddress(asAddress), m_balance(aBalance), m_tokens(aTokens) -{ - -} - -DapChainWallet::DapChainWallet(const QString &asIconPath, const QString &asName, const QString &asAddress, QObject *parent) - : DapChainWallet(asIconPath, asName, asAddress, QStringList(), QStringList(), parent) -{ - -} - -QString DapChainWallet::getIconPath() const -{ - return m_sIconPath; -} - -void DapChainWallet::setIconPath(const QString &asIconPath) -{ - m_sIconPath = asIconPath; - - emit iconPathChanged(m_sIconPath); -} - -QString DapChainWallet::getName() const -{ - return m_sName; -} - -void DapChainWallet::setName(const QString &asName) -{ - m_sName = asName; - - emit nameChanged(m_sName); -} - -QString DapChainWallet::getAddress() const -{ - return m_sAddress; -} - -void DapChainWallet::setAddress(const QString &asAddress) -{ - m_sAddress = asAddress; - - emit addressChanged(m_sAddress); -} - -QStringList DapChainWallet::getBalance() const -{ - return m_balance; -} - -void DapChainWallet::setBalance(const QStringList &aBalance) -{ - m_balance = aBalance; - - emit balanceChanged(m_balance); -} - -QStringList DapChainWallet::getTokens() const -{ - return m_tokens; -} - -void DapChainWallet::setTokens(const QStringList &aTokens) -{ - m_tokens = aTokens; - - emit tokensChanged(m_tokens); -} - -int DapChainWallet::getCount() const -{ - return m_tokens.count(); -} - - diff --git a/libCellFrameDashboardCommon/DapChainWallet.h b/libCellFrameDashboardCommon/DapChainWallet.h deleted file mode 100755 index cab79e5522c791d755aa3d86563670da34359ffe..0000000000000000000000000000000000000000 --- a/libCellFrameDashboardCommon/DapChainWallet.h +++ /dev/null @@ -1,228 +0,0 @@ -#ifndef DAPCHAINWALLET_H -#define DAPCHAINWALLET_H - -#include <QObject> -#include <QString> -#include <QList> -#include <QDataStream> - -struct DapChainWalletData -{ - QString IconPath; - QString Name; - QString Address; - QString Network; - - friend QDataStream& operator << (QDataStream& aOut, const DapChainWalletData& aData) - { - aOut << aData.IconPath - << aData.Name - << aData.Address - << aData.Network; - return aOut; - } - - friend QDataStream& operator >> (QDataStream& aOut, DapChainWalletData& aData) - { - aOut >> aData.IconPath - >> aData.Name - >> aData.Address - >> aData.Network; - return aOut; - } - - DapChainWalletData& operator = (const DapChainWalletData& aData) - { - IconPath = aData.IconPath; - Name = aData.Name; - Address = aData.Address; - Network = aData.Network; - return *this; - } - - bool operator == (const DapChainWalletData& aData) const { - return IconPath == aData.IconPath && - Name == aData.Name && - Address == aData.Address && - Network == aData.Network; - } -}; - -struct DapChainWalletTokenData { - QString Name; - double Balance; - quint64 Emission; - - friend QDataStream& operator << (QDataStream& aOut, const DapChainWalletTokenData& aData) - { - aOut << aData.Name - << aData.Balance - << aData.Emission; - return aOut; - } - - friend QDataStream& operator >> (QDataStream& aOut, DapChainWalletTokenData& aData) - { - aOut >> aData.Name - >> aData.Balance - >> aData.Emission; - return aOut; - } - - DapChainWalletTokenData& operator = (const DapChainWalletTokenData& aData) - { - Name = aData.Name; - Balance = aData.Balance; - Emission = aData.Emission; - return *this; - } - - bool operator == (const DapChainWalletTokenData& aData) const { - return Name == aData.Name; - } -}; - -class DapChainWalletTokenItem : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(double balance READ balance WRITE setBalance NOTIFY balanceChanged) - Q_PROPERTY(quint64 emission READ emission WRITE setEmission NOTIFY emissionChanged) - Q_PROPERTY(QString wallet READ wallet) - -private: - QString m_wallet; - QString m_name; - double m_balance; - quint64 m_emission; - -public: - explicit DapChainWalletTokenItem(const QString& aWalletAddress, QObject *parent = nullptr); - explicit DapChainWalletTokenItem(const QString& aWalletAddress, const DapChainWalletTokenData& aData, QObject *parent = nullptr); - - QString name() const; - double balance() const; - quint64 emission() const; - QString wallet() const; - -public slots: - void setName(const QString& aName); - void setBalance(const double aBalance); - void setEmission(const quint64 aEmission); - void setData(const DapChainWalletTokenData& aData); - -signals: - void nameChanged(QString name); - void balanceChanged(double balance); - void emissionChanged(quint64 emission); -}; - -typedef QList<DapChainWalletTokenItem*> DapChainWalletTokenItemList; -typedef QList<DapChainWalletTokenData> DapChainWalletTokenList; -typedef QPair<DapChainWalletData, DapChainWalletTokenItemList> DapChainWalletPair; - - - - - - - - -class DapChainWallet : public QObject -{ - Q_OBJECT - - /// Icon path - QString m_sIconPath; - /// Name of wallet - QString m_sName; - /// Address of wallet - QString m_sAddress; - /// Balance - QStringList m_balance; - /// Tokens name - QStringList m_tokens; - /// number of tokens - int m_iCount; - -public: - /// Standard constructor - DapChainWallet(QObject *parent = nullptr) { Q_UNUSED(parent)} - /// overloaded constructor - /// @param asIconPath Path icon - /// @param asName Name of wallet - /// @param asAddresss Address for wallet - /// @param aBalance Balance - /// @param aTokens Tokens name - DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddress, const QStringList &aBalance, const QStringList& aTokens, QObject * parent = nullptr); - /// overloaded constructor - /// @param asIconPath Path icon - /// @param asName Name of wallet - /// @param asAddresss Address for wallet - DapChainWallet(const QString& asIconPath, const QString &asName, const QString &asAddress, QObject * parent = nullptr); - - - Q_PROPERTY(QString iconPath MEMBER m_sIconPath READ getIconPath WRITE setIconPath NOTIFY iconPathChanged) - Q_PROPERTY(QString name MEMBER m_sName READ getName WRITE setName NOTIFY nameChanged) - Q_PROPERTY(QString address MEMBER m_sAddress READ getAddress WRITE setAddress NOTIFY addressChanged) - Q_PROPERTY(QStringList balance MEMBER m_balance READ getBalance WRITE setBalance NOTIFY balanceChanged) - Q_PROPERTY(QStringList tokens MEMBER m_tokens READ getTokens WRITE setTokens NOTIFY tokensChanged) - Q_PROPERTY(int count MEMBER m_iCount READ getCount) - - /// Get name of wallet - /// @return name of wallet - QString getName() const; - /// Set name of wallet - /// @param asName name of wallet - void setName(const QString &asName); - /// Get address of wallet - /// @return Address of wallet - QString getAddress() const; - /// Set address for wallet - /// @param asAddress address for wallet - void setAddress(const QString &asAddress); - - /// Get icon path - /// @return Icon path - QString getIconPath() const; - /// Set icon path - /// @param asIconPath Icon path - void setIconPath(const QString &asIconPath); - - /// Get balance - QStringList getBalance() const; - /// Set balance - void setBalance(const QStringList& aBalance); - - /// Get tokens name - /// @return tokens name - QStringList getTokens() const; - /// Set tokens name - /// @param aTokens tokens name - void setTokens(const QStringList& aTokens); - - /// get number of tokens - /// @return number of tokens - int getCount() const; - -signals: - /// Signal changes for icon path - /// @param asIconPath Icon path - void iconPathChanged(const QString& asIconPath); - /// Signal changes for name of wallet - /// @param asName name of wallet - void nameChanged(const QString& asName); - /// Signal changes for address of wallet - /// @param asAddress address of wallet - void addressChanged(const QString& asAddress); - /// Signal changes for balance - /// @param aBalance balance - void balanceChanged(const QStringList& aBalance); - /// Signal changes for tokens - /// @param aTokens tokens name - void tokensChanged(const QStringList& aTokens); - -}; - -#endif // DAPCHAINWALLET_H diff --git a/libCellFrameDashboardCommon/DapWallet.cpp b/libCellFrameDashboardCommon/DapWallet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..305fb38a5337bc3d34fbf6928185d06cbc17489e --- /dev/null +++ b/libCellFrameDashboardCommon/DapWallet.cpp @@ -0,0 +1,200 @@ +#include "DapWallet.h" + +DapWallet::DapWallet(QObject * parent) + : QObject(parent) +{ + +} + +DapWallet::DapWallet(const DapWallet &aWallet) + : m_sName(aWallet.m_sName), m_dBalance(aWallet.m_dBalance), m_sIcon(aWallet.m_sIcon), m_sAddress(aWallet.m_sAddress), + m_aNetworks(aWallet.m_aNetworks), m_aAddresses(aWallet.m_aAddresses), m_aTokens(aWallet.m_aTokens) +{ + +} + +DapWallet &DapWallet::operator=(const DapWallet &aWallet) +{ + m_sName = aWallet.m_sName; + m_dBalance = aWallet.m_dBalance; + m_sIcon = aWallet.m_sIcon; + m_sAddress = aWallet.m_sAddress; + m_aNetworks = aWallet.m_aNetworks; + m_aAddresses = aWallet.m_aAddresses; + m_aTokens = aWallet.m_aTokens; + return (*this); +} + +QString DapWallet::getName() const +{ + return m_sName; +} + +void DapWallet::setName(const QString &asName) +{ + m_sName = asName; + + emit nameChanged(m_sName); +} + +double DapWallet::getBalance() const +{ + return m_dBalance; +} + +void DapWallet::setBalance(const double& adBalance) +{ + m_dBalance = adBalance; + + emit balanceChanged(m_dBalance); +} + +QString DapWallet::getIcon() const +{ + return m_sIcon; +} + +void DapWallet::setIcon(const QString &sIcon) +{ + m_sIcon = sIcon; + + emit iconChanged(m_sIcon); +} + +void DapWallet::addNetwork(const QString &asNetwork) +{ + m_aNetworks.append(asNetwork); + + emit networkAdded(asNetwork); + emit networksChanged(m_aNetworks); +} + +QStringList DapWallet::getNetworks() const +{ + return m_aNetworks; +} + +void DapWallet::setAddress(const QString &asNetwork) +{ + m_sAddress = m_aAddresses.find(asNetwork).value(); + + emit addressChanged(m_sAddress); +} + +QString DapWallet::getAddress() const +{ + return m_sAddress; +} + +void DapWallet::addAddress(const QString& aiAddress, const QString &asNetwork) +{ + m_aAddresses.insert(asNetwork, aiAddress); +} + +QString DapWallet::findAddress(const QString &asNetwork) const +{ + QString s=m_aAddresses.find(asNetwork).value(); + return m_aAddresses.find(asNetwork) != m_aAddresses.end() ? m_aAddresses.find(asNetwork).value() : QString(); +} + +QMap<QString, QString> DapWallet::getAddresses() const +{ + return m_aAddresses; +} + +void DapWallet::addToken(DapWalletToken *asToken) +{ + m_aTokens.append(asToken); + + emit tokenAdded(*asToken); + + QList<QObject*> tokens; + auto begin = m_aTokens.begin(); + auto end = m_aTokens.end(); + for(;begin != end; ++begin) + { + tokens.append(*begin); + } + emit tokensChanged(tokens); +} + +QList<DapWalletToken*> DapWallet::findTokens(const QString &asNetwork) +{ + QList<DapWalletToken*> tokens; + auto begin = m_aTokens.begin(); + auto end = m_aTokens.end(); + for(;begin != end; ++begin) + { + if((*begin)->getNetwork() == asNetwork) + { + tokens.append(*begin); + } + } + return tokens; +} + +QList<QObject *> DapWallet::getTokens() const +{ + QList<QObject*> tokens; + auto begin = m_aTokens.begin(); + auto end = m_aTokens.end(); + for(;begin != end; ++begin) + { + tokens.append(*begin); + } + return tokens; +} + +DapWallet DapWallet::fromVariant(const QVariant &aWallet) +{ + DapWallet wallet; + QByteArray data = QByteArray::fromStdString(aWallet.toString().toStdString()); + QDataStream in(&data, QIODevice::ReadOnly); + in >> wallet; + return wallet; +} + +QDataStream& operator << (QDataStream& aOut, const DapWallet& aWallet) +{ + QList<DapWalletToken> tokens; + for(int x{0}; x < aWallet.m_aTokens.size(); ++x) + { + tokens.append(*aWallet.m_aTokens.at(x)); + } + + aOut << aWallet.m_sName + << aWallet.m_dBalance + << aWallet.m_sIcon + << aWallet.m_sAddress + << aWallet.m_aNetworks + << aWallet.m_aAddresses + << tokens; + + return aOut; +} + +QDataStream& operator >> (QDataStream& aIn, DapWallet& aWallet) +{ + QList<DapWalletToken> tokens; + + aIn >> aWallet.m_sName; + aIn.setFloatingPointPrecision(QDataStream::DoublePrecision); + aIn >> aWallet.m_dBalance + >> aWallet.m_sIcon + >> aWallet.m_sAddress + >> aWallet.m_aNetworks + >> aWallet.m_aAddresses + >> tokens; + + + auto begin = tokens.begin(); + auto end = tokens.end(); + for(;begin != end; ++begin) + aWallet.addToken(new DapWalletToken(*begin)); + return aIn; +} + +bool operator ==(const DapWallet &aWalletFirst, const DapWallet &aWalletSecond) +{ + return aWalletFirst.m_sName == aWalletSecond.m_sName; +} diff --git a/libCellFrameDashboardCommon/DapWallet.h b/libCellFrameDashboardCommon/DapWallet.h new file mode 100644 index 0000000000000000000000000000000000000000..1cdcf71cb14cd895c911ea3d8c7e76de74d8fd30 --- /dev/null +++ b/libCellFrameDashboardCommon/DapWallet.h @@ -0,0 +1,75 @@ +#ifndef DAPWALLET_H +#define DAPWALLET_H + +#include <QObject> +#include <QString> +#include <QList> +#include <QQmlEngine> + +#include "DapWalletToken.h" + +class DapWallet : public QObject +{ + Q_OBJECT + + QString m_sName; + double m_dBalance {0.0}; + QString m_sIcon; + QString m_sAddress = "private"; + QStringList m_aNetworks; + QMap<QString, QString> m_aAddresses; + mutable QList<DapWalletToken*> m_aTokens; + +public: + Q_INVOKABLE explicit DapWallet(QObject * parent = nullptr); + Q_INVOKABLE DapWallet(const DapWallet& aWallet); + Q_INVOKABLE DapWallet& operator=(const DapWallet& aToken); + + + Q_PROPERTY(QString Name MEMBER m_sName READ getName WRITE setName NOTIFY nameChanged) + Q_PROPERTY(double Balance MEMBER m_dBalance READ getBalance WRITE setBalance NOTIFY balanceChanged) + Q_PROPERTY(QString Icon MEMBER m_sIcon READ getIcon WRITE setIcon NOTIFY iconChanged) + Q_PROPERTY(QString Address MEMBER m_sAddress READ getAddress NOTIFY addressChanged) + Q_PROPERTY(QStringList Networks MEMBER m_aNetworks READ getNetworks NOTIFY networksChanged) + Q_PROPERTY(QList<QObject*> Tokens READ getTokens NOTIFY tokensChanged) + + + friend QDataStream& operator << (QDataStream& aOut, const DapWallet& aToken); + friend QDataStream& operator >> (QDataStream& aOut, DapWallet& aToken); + friend bool operator == (const DapWallet &aWalletFirst, const DapWallet &aWalletSecond); + + static DapWallet fromVariant(const QVariant& aWallet); + +signals: + void nameChanged(const QString& asName); + void balanceChanged(const double& adBalance); + void iconChanged(const QString &asIcon); + void addressChanged(const QString& asAddress); + void networkAdded(const QString& asNetwork); + void networksChanged(const QStringList& asNetworks); + void tokensChanged(const QList<QObject*> asTokens); + void tokenAdded(const DapWalletToken& asNetwork); + +public slots: + QString getName() const; + void setName(const QString &asName); + double getBalance() const; + void setBalance(const double& adBalance); + QString getIcon() const; + void setIcon(const QString &sIcon); + void addNetwork(const QString& asNetwork); + QStringList getNetworks() const; + Q_INVOKABLE void setAddress(const QString& asNetwork); + QString getAddress() const; + void addAddress(const QString &aiAddress, const QString& asNetwork); + Q_INVOKABLE QString findAddress(const QString &asNetwork) const; + QMap<QString, QString> getAddresses() const; + void addToken(DapWalletToken *asToken); + Q_INVOKABLE QList<DapWalletToken*> findTokens(const QString& asNetwork); + Q_INVOKABLE QList<QObject*> getTokens() const; +}; + +Q_DECLARE_METATYPE(DapWallet) + + +#endif // DAPWALLET_H diff --git a/libCellFrameDashboardCommon/DapWalletToken.cpp b/libCellFrameDashboardCommon/DapWalletToken.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49832e6856abbfd7368e1fc467c5134d227970c3 --- /dev/null +++ b/libCellFrameDashboardCommon/DapWalletToken.cpp @@ -0,0 +1,115 @@ +#include "DapWalletToken.h" + +DapWalletToken::DapWalletToken(const QString &asName, QObject *parent) + : QObject(parent), m_sName(asName) +{ + +} + +DapWalletToken::DapWalletToken(const DapWalletToken &aToken) + : QObject(aToken.parent()), m_sName(aToken.m_sName), m_dBalance(aToken.m_dBalance), + m_iEmission(aToken.m_iEmission), m_sNetwork(aToken.m_sNetwork) +{ + +} + +DapWalletToken &DapWalletToken::operator=(const DapWalletToken &aToken) +{ + m_sName = aToken.m_sName; + m_dBalance = aToken.m_dBalance; + m_iEmission = aToken.m_iEmission; + m_sNetwork = aToken.m_sNetwork; + return (*this); +} + +bool DapWalletToken::operator==(const DapWalletToken &aToken) const +{ + return m_sName == aToken.m_sName + && m_dBalance == aToken.m_dBalance + && m_iEmission == aToken.m_iEmission + && m_sNetwork == aToken.m_sNetwork; +} + +QString DapWalletToken::getName() const +{ + return m_sName; +} + +void DapWalletToken::setName(const QString &sName) +{ + m_sName = sName; + + emit nameChanged(m_sName); +} + +double DapWalletToken::getBalance() const +{ + return m_dBalance; +} + +void DapWalletToken::setBalance(double dBalance) +{ + m_dBalance = dBalance; + + emit balanceChanged(m_dBalance); +} + +quint64 DapWalletToken::getEmission() const +{ + return m_iEmission; +} + +void DapWalletToken::setEmission(const quint64 &iEmission) +{ + m_iEmission = iEmission; + + emit emissionChanged(m_iEmission); +} + +QString DapWalletToken::getNetwork() const +{ + return m_sNetwork; +} + +void DapWalletToken::setNetwork(const QString &sNetwork) +{ + m_sNetwork = sNetwork; + + emit networkChanged(m_sNetwork); +} + +QString DapWalletToken::getIcon() const +{ + return m_sIcon; +} + +void DapWalletToken::setIcon(const QString &sIcon) +{ + m_sIcon = sIcon; + + emit iconChanged(m_sIcon); +} + +QDataStream& operator << (QDataStream& aOut, const DapWalletToken& aToken) +{ + QString emission; + emission.setNum(aToken.m_iEmission); + aOut << aToken.m_sName + << aToken.m_dBalance + << aToken.m_iEmission + << aToken.m_sNetwork; + return aOut; +} + +QDataStream& operator >> (QDataStream& aOut, DapWalletToken& aToken) +{ + aOut >> aToken.m_sName; + aOut.setFloatingPointPrecision(QDataStream::DoublePrecision); + aOut >> aToken.m_dBalance; + aOut.setFloatingPointPrecision(QDataStream::SinglePrecision); + aOut >> aToken.m_iEmission + >> aToken.m_sNetwork; + return aOut; +} + + diff --git a/libCellFrameDashboardCommon/DapWalletToken.h b/libCellFrameDashboardCommon/DapWalletToken.h new file mode 100644 index 0000000000000000000000000000000000000000..5de45c4f30422415184db6f5d4c373205c62bd54 --- /dev/null +++ b/libCellFrameDashboardCommon/DapWalletToken.h @@ -0,0 +1,61 @@ +#ifndef DAPWALLETTOKEN_H +#define DAPWALLETTOKEN_H + +#include <QObject> +#include <QString> +#include <QDataStream> + +class DapWalletToken : public QObject +{ + Q_OBJECT + + /// Token name. + QString m_sName; + /// Token balance. + double m_dBalance {0.0}; + /// Token emission. + quint64 m_iEmission {0}; + /// Network. + QString m_sNetwork; + /// Icon path. + QString m_sIcon; + +public: + explicit DapWalletToken(const QString& asName = QString(), QObject *parent = nullptr); + DapWalletToken(const DapWalletToken& aToken); + DapWalletToken& operator=(const DapWalletToken& aToken); + bool operator==(const DapWalletToken& aToken) const; + + Q_PROPERTY(QString Name MEMBER m_sName READ getName WRITE setName NOTIFY nameChanged) + Q_PROPERTY(double Balance MEMBER m_dBalance READ getBalance WRITE setBalance NOTIFY balanceChanged) + Q_PROPERTY(quint64 Emission MEMBER m_iEmission READ getEmission WRITE setEmission NOTIFY emissionChanged) + Q_PROPERTY(QString Network MEMBER m_sNetwork READ getNetwork WRITE setNetwork NOTIFY networkChanged) + Q_PROPERTY(QString Icon MEMBER m_sIcon READ getIcon WRITE setIcon NOTIFY iconChanged) + + + friend QDataStream& operator << (QDataStream& aOut, const DapWalletToken& aToken); + friend QDataStream& operator >> (QDataStream& aOut, DapWalletToken& aToken); + +signals: + void nameChanged(const QString & asName); + void balanceChanged(const double & adBalance); + void emissionChanged(const qint64& aiEmission); + void networkChanged(const QString &asNetwork); + void iconChanged(const QString &asIcon); + +public slots: + QString getName() const; + void setName(const QString &sName); + double getBalance() const; + void setBalance(double dBalance); + quint64 getEmission() const; + void setEmission(const quint64 &iEmission); + QString getNetwork() const; + void setNetwork(const QString &sNetwork); + QString getIcon() const; + void setIcon(const QString &sIcon); +}; + +Q_DECLARE_METATYPE(DapWalletToken) + +#endif // DAPWALLETTOKEN_H diff --git a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp index ce4185bd718c52bad0b0088c16a20e0609945ab2..ad310790a8605a7d228d1be2e5c1b0fafe69e804 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp @@ -221,8 +221,11 @@ QVariant DapAbstractCommand::respondToClient(const QVariant &arg1, const QVarian /// Reply from service. /// @details Performed on the service side. /// @return Service reply. -void DapAbstractCommand::replyFromService() +QVariant DapAbstractCommand::replyFromService() { DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit serviceResponded(reply->response().toJsonValue().toVariant()); + + return reply->response().toJsonValue().toVariant(); } diff --git a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h index aabd1cccc8f887212d7e3d44a780dde1aa6de23f..d0a46e9061e84015199c01441c7c03044508f4cb 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h +++ b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h @@ -24,8 +24,6 @@ class DapAbstractCommand : public DapCommand protected: /// Parent. QObject * m_parent {nullptr}; - -public: /// Overloaded constructor. /// @param asServiceName Service name. /// @param parent Parent. @@ -131,7 +129,7 @@ public slots: /// Reply from service. /// @details Performed on the service side. /// @return Service reply. - virtual void replyFromService(); + virtual QVariant replyFromService(); }; #endif // DAPABSTRACTCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp index 8fd108a6a01759319459309cf900845fcbd45561..514c596b9d7a9194cc0feae19c536b6fc3378bf0 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.cpp @@ -2,37 +2,16 @@ /// Overloaded constructor. /// @param asServiceName Service name. -/// @param apSocket Client connection socket with service. /// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. DapAddWalletCommand::DapAddWalletCommand(const QString &asServicename, QObject *parent) : DapAbstractCommand(asServicename, parent) { } -/// Send a response to the service. -/// @param arg1...arg10 Parameters. -/// @return Reply to service. -QVariant DapAddWalletCommand::respondToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, - const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, - const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, - const QVariant &arg10) -{ - Q_UNUSED(arg1) - Q_UNUSED(arg2) - Q_UNUSED(arg3) - Q_UNUSED(arg4) - Q_UNUSED(arg5) - Q_UNUSED(arg6) - Q_UNUSED(arg7) - Q_UNUSED(arg8) - Q_UNUSED(arg9) - Q_UNUSED(arg10) - - return QVariant(); -} - /// Send a response to the client. +/// @details Performed on the service side. /// @param arg1...arg10 Parameters. /// @return Reply to client. QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, @@ -40,10 +19,6 @@ QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVaria const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) { - Q_UNUSED(arg1) - Q_UNUSED(arg2) - Q_UNUSED(arg3) - Q_UNUSED(arg4) Q_UNUSED(arg5) Q_UNUSED(arg6) Q_UNUSED(arg7) @@ -51,14 +26,21 @@ QVariant DapAddWalletCommand::respondToClient(const QVariant &arg1, const QVaria Q_UNUSED(arg9) Q_UNUSED(arg10) - QByteArray result; QProcess process; - process.start(QString("%1 wallet new -w %2").arg(CLI_PATH).arg(arg1.toString())); + QJsonArray result; + process.start(QString("%1 wallet new -w %2 -sign %3 -net %4 -restore %5").arg(CLI_PATH).arg(arg1.toString()).arg(arg2.toString()).arg(arg3.toString()).arg(arg4.toString())); process.waitForFinished(-1); - result = process.readAll(); - QStringList res = QString::fromLatin1(result).split(" "); - QStringList list; - list.append(arg1.toString()); - list.append(res.at(res.size()-1).trimmed()); - return result.isEmpty() ? QStringList() : list; + QString res = QString::fromLatin1(process.readAll()); + if(res.contains("already exists")) + { + result.append(QJsonValue(false)); + result.append(QJsonValue("Wallet already exists")); + } + else + { + result.append(QJsonValue(true)); + result.append(QJsonValue(arg1.toString())); + result.append(QJsonValue("Wallet successfully created")); + } + return result.toVariantList(); } diff --git a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h index f7892ca9ee9d83a6825e328d78b0a2347205dad5..ea649f5d6e4d8aad1301583cf88a175b715305c5 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h +++ b/libCellFrameDashboardCommon/Handlers/DapAddWalletCommand.h @@ -2,7 +2,7 @@ ** ** This file is part of the libCellFrameDashboardClient library. ** -** The class implements the "Add wallet" command interface. +** The class implements the functionality of creating a new wallet. ** ****************************************************************************/ @@ -19,20 +19,13 @@ class DapAddWalletCommand : public DapAbstractCommand public: /// Overloaded constructor. /// @param asServiceName Service name. - /// @param apSocket Client connection socket with service. /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. explicit DapAddWalletCommand(const QString &asServicename, QObject *parent = nullptr); public slots: - /// Send a response to the service. - /// @param arg1...arg10 Parameters. - /// @return Reply to service. - QVariant respondToService(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), - const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), - const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), - const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), - const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()); /// Send a response to the client. + /// @details Performed on the service side. /// @param arg1...arg10 Parameters. /// @return Reply to client. QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), diff --git a/libCellFrameDashboardCommon/Handlers/DapCreateTransactionCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapCreateTransactionCommand.cpp index 88aacc40180f6301ad3cde51461b80f67c632a1e..9468e573313f0b4e2179121e2cc09cc053591df4 100644 --- a/libCellFrameDashboardCommon/Handlers/DapCreateTransactionCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapCreateTransactionCommand.cpp @@ -28,7 +28,7 @@ QVariant DapCreateTransactionCommand::respondToClient(const QVariant &arg1, cons Q_UNUSED(arg10) QProcess processCreate; - processCreate.start(QString("%1 tx_create -net %2 -chain %3 -from_wallet %3 -to_addr %4 -token %5 -value %6") + processCreate.start(QString("%1 tx_create -net %2 -chain %3 -from_wallet %4 -to_addr %5 -token %6 -value %7") .arg(m_sCliPath) .arg(arg1.toString()) .arg(arg2.toString()) diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a7e5b027b8aeee71320cdb455ca775e6c5a5cba --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.cpp @@ -0,0 +1,42 @@ +#include "DapGetListNetworksCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +/// @param asCliPath The path to cli nodes. +DapGetListNetworksCommand::DapGetListNetworksCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) + : DapAbstractCommand(asServicename, parent), m_sCliPath(asCliPath) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetListNetworksCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList networkList; + QProcess process; + process.start(QString("%1 net list").arg(m_sCliPath)); + process.waitForFinished(-1); + QString result = QString::fromLatin1(process.readAll()); + if(!(result.isEmpty() || result.isNull() || result.contains('\''))) + { + QStringList str = result.remove(" ").remove("\n").remove("\r").split(":").at(1).split(","); + return str; + } + return QString(); +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..fb16b4985d7396178ff63716dce2f84500204cce --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.h @@ -0,0 +1,33 @@ +#ifndef DAPGETLISTNETWORKSCOMMAND_H +#define DAPGETLISTNETWORKSCOMMAND_H + +#include <QProcess> + +#include "DapAbstractCommand.h" + +class DapGetListNetworksCommand : public DapAbstractCommand +{ + /// The path to cli nodes. + QString m_sCliPath; + +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + /// @param asCliPath The path to cli nodes. + DapGetListNetworksCommand(const QString &asServicename, QObject *parent = nullptr, const QString &asCliPath = QString()); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETLISTNETWORKSCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..089ff09bc879829f9401920b6ae45ce5fec836d8 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp @@ -0,0 +1,188 @@ +#include "DapGetListWalletsCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +/// @param asCliPath The path to cli nodes. +DapGetListWalletsCommand::DapGetListWalletsCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) + : DapAbstractCommand(asServicename, parent), m_sCliPath(asCliPath) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, + const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + +// DapWallet wallet; +// wallet.setName("VASY"); +// wallet.setBalance(25.5); +// wallet.setIcon("/fsghdhjghjufkigl"); +// wallet.addNetwork("Kelvin-testnet"); +// wallet.addNetwork("Private"); +// wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Kelvin-testnet"); +// wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Private"); + +// DapWalletToken token1("KLV", &wallet); +// token1.setBalance(5.5); +// token1.setNetwork("Kelvin-testnet"); +// token1.setEmission(464645646546); +// DapWalletToken token2("CELL", &wallet); +// token2.setBalance(100); +// token2.setNetwork("Private"); +// token2.setEmission(121212121); +// wallet.addToken(&token1); +// wallet.addToken(&token2); + +// QByteArray datas; +// QDataStream out(&datas, QIODevice::WriteOnly); +// out << wallet; + +// qDebug() << "balance after:\t" << wallet.getBalance(); +// qDebug() << "icon after:\t" << wallet.getIcon(); +// qDebug() << "networks after:\t" << wallet.getNetworks(); +// qDebug() << "m_aAddresses after:\t" << wallet.getAddresses(); +// qDebug() << "m_aTokens after:\t" << wallet.getTokens(); + + +// DapWallet wallet2; +// QByteArray d (datas); +// QDataStream in(&d, QIODevice::ReadOnly); +// in >> wallet2; + +// qDebug() << endl; +// qDebug() << "name before:\t" << wallet2.getName(); +// qDebug() << "balance before:\t" << wallet2.getBalance(); +// qDebug() << "icon before:\t" << wallet2.getIcon(); +// qDebug() << "networks before:\t" << wallet2.getNetworks(); +// qDebug() << "m_aAddresses before:\t" << wallet2.getAddresses(); +// // qDebug() << "m_aTokens before:\t" << wallet2.m_aTokens; + +// foreach (auto w, wallet2.getTokens()) { +// qDebug() << static_cast<DapWalletToken*>(w)->getName() << endl; +// qDebug() << static_cast<DapWalletToken*>(w)->getBalance() << endl; +// qDebug() << static_cast<DapWalletToken*>(w)->getEmission() << endl; +// qDebug() << static_cast<DapWalletToken*>(w)->getNetwork() << endl; + +// } + + +// QJsonValue str = QJsonValue::fromVariant(datas.toHex()); + + + +// QByteArray b = QByteArray::fromHex(str.toVariant().toByteArray()); +// std::string s = datas.toStdString(); +// QString str = QString::fromStdString(s); + +// DapWallet w; +// QByteArray d; +// QDataStream in(&datas, QIODevice::ReadOnly); +// in>>w; + + QList<DapWallet> wallets; + + QStringList list; + QProcess processN; + processN.start(QString("%1 net list").arg(m_sCliPath)); + processN.waitForFinished(-1); + QString result = QString::fromLatin1(processN.readAll()); + result.remove(' '); + if(!(result.isEmpty() || result.isNull() || result.contains('\''))) + { + list = result.remove("\n").remove("\r").split(":").at(1).split(","); + } + + QProcess process; + process.start(QString("%1 wallet list").arg(m_sCliPath)); + process.waitForFinished(-1); + QString res = QString::fromLatin1(process.readAll()); + QRegularExpression rx("wallet:\\s(.+)\\s", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator itr = rx.globalMatch(res); + while (itr.hasNext()) + { + QRegularExpressionMatch match = itr.next(); + QString walletName = match.captured(1); + DapWallet wallet; + wallet.setName(walletName); + auto begin = list.begin(); + auto end = list.end(); + for(; begin != end; ++begin) + { + + wallet.addNetwork(*begin); + + QProcess process_token; + process_token.start(QString("%1 wallet info -w %2 -net %3") + .arg(m_sCliPath) + .arg(walletName) + .arg(*begin)); + + process_token.waitForFinished(-1); + QByteArray result_tokens = process_token.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + DapWalletToken *token {nullptr}; + while((pos = regex.indexIn(result_tokens, pos)) != -1) + { + + if(!regex.cap(2).isEmpty()) + { + wallet.addAddress(regex.cap(2), *begin); + } + else + { + token = new DapWalletToken(); + token->setName(regex.cap(6).trimmed()); + token->setBalance(regex.cap(4).toDouble()); + QString str = regex.cap(5); + token->setEmission(regex.cap(5).toULongLong()); + token->setNetwork(*begin); + wallet.addToken(token); + } + + pos += regex.matchedLength(); + } + + } + wallets.append(wallet); + } + + QByteArray datas; + QDataStream out(&datas, QIODevice::WriteOnly); + out << wallets; + + return QJsonValue::fromVariant(datas.toHex()); +} + + +/// Reply from service. +/// @details Performed on the service side. +/// @return Service reply. +QVariant DapGetListWalletsCommand::replyFromService() +{ + QObject * s = sender(); + DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + + emit serviceResponded(reply->response().toJsonValue().toVariant().toByteArray()); + + return reply->response().toJsonValue().toVariant(); +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..202f38eff5819c46b84cbada60a5ce02a58bf8a9 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.h @@ -0,0 +1,41 @@ +#ifndef DAPGETLISTWALLETSCOMMAND_H +#define DAPGETLISTWALLETSCOMMAND_H + +#include <QProcess> +#include <QRegExp> +#include <QRegularExpression> +#include <QByteArray> +#include <QDataStream> +#include <QBuffer> +#include <QTextCodec> + +#include "DapWallet.h" +#include "DapAbstractCommand.h" + +class DapGetListWalletsCommand : public DapAbstractCommand +{ + /// The path to cli nodes. + QString m_sCliPath; + +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + /// @param asCliPath The path to cli nodes. + DapGetListWalletsCommand(const QString &asServicename, QObject *parent = nullptr, const QString &asCliPath = QString()); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; + QVariant replyFromService() override; +}; + +#endif // DAPGETLISTWALLETSCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc42b0be9a084eda789e2ceacef1dae432c33c5d --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.cpp @@ -0,0 +1,68 @@ +#include "DapGetWalletAddressesCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +DapGetWalletAddressesCommand::DapGetWalletAddressesCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send request to service. +/// @details Performed on the client side. +/// @param arg1...arg10 Parameters. +void DapGetWalletAddressesCommand::requestToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, + const QVariant &arg6, const QVariant &arg7, + const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + + DapAbstractCommand::requestToService(arg1, arg2.toStringList(), arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletAddressesCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList walletAddress; + QStringList networkList = arg2.toStringList(); + if(!networkList.isEmpty()) + { + for(int i{0}; i < networkList.count(); ++i) + { + QProcess process; + process.start(QString("%1 wallet info -w %2 -net %3").arg(CLI_PATH).arg(arg1.toString()).arg(networkList[i])); + process.waitForFinished(-1); + QByteArray result = process.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + while((pos = regex.indexIn(result, pos)) != -1) + { + if(!regex.cap(2).isEmpty()) + { + walletAddress.append(networkList[i]); + walletAddress.append(regex.cap(2)); + } + pos += regex.matchedLength(); + } + } + } + + return walletAddress; +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..adb8541f0be4b76ad7bdeef41de8f7a51fa55607 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.h @@ -0,0 +1,38 @@ +#ifndef DAPGETWALLETADDRESSESCOMMAND_H +#define DAPGETWALLETADDRESSESCOMMAND_H + +#include <QProcess> + +#include "DapAbstractCommand.h" + +class DapGetWalletAddressesCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + DapGetWalletAddressesCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send request to service. + /// @details Performed on the client side. + /// @param arg1...arg10 Parameters. + Q_INVOKABLE virtual void requestToService(const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()) override; + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETWALLETADDRESSESCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletHistoryCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetWalletHistoryCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ae61be3cb49fb745e1ada98bbae695894d1913c7 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletHistoryCommand.cpp @@ -0,0 +1,55 @@ +#include "DapGetWalletHistoryCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +/// @param asCliPath The path to cli nodes. +DapGetWalletHistoryCommand::DapGetWalletHistoryCommand(const QString &asServicename, QObject *parent, const QString &asCliPath) + : DapAbstractCommand(asServicename, parent), m_sCliPath(asCliPath) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletHistoryCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QList<QVariant> data; + QProcess process; + process.start(QString("%1 tx_history -net %2 -chain gdb -addr %3").arg(m_sCliPath).arg(arg1.toString()).arg(arg2.toString())); + process.waitForFinished(-1); + QByteArray result = process.readAll(); + if(!result.isEmpty()) + { + QRegularExpression regular("((\\w{3}\\s+){2}\\d{1,2}\\s+(\\d{1,2}:*){3}\\s+\\d{4})\\s+(\\w+)\\s+(\\d+)\\s(\\w+)\\s+\\w+\\s+([\\w\\d]+)", QRegularExpression::MultilineOption); + QRegularExpressionMatchIterator matchItr = regular.globalMatch(result); + while (matchItr.hasNext()) + { + if(data.count() >= 100) break; + QRegularExpressionMatch match = matchItr.next(); + QStringList dataItem = QStringList() + << match.captured(1) + << match.captured(4) + << match.captured(5) + << match.captured(6) + << match.captured(7); + data << dataItem; + } + } + + return data; +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletHistoryCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetWalletHistoryCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..d192e96bb1711eaeb279479a616c91e41ce76a31 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletHistoryCommand.h @@ -0,0 +1,36 @@ +#ifndef DAPGETWALLETHISTORYCOMMAND_H +#define DAPGETWALLETHISTORYCOMMAND_H + +#include <QProcess> +#include <QRegExp> +#include <QRegularExpression> + +#include "DapWallet.h" +#include "DapAbstractCommand.h" + +class DapGetWalletHistoryCommand : public DapAbstractCommand +{ + /// The path to cli nodes. + QString m_sCliPath; + +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + /// @param asCliPath The path to cli nodes. + DapGetWalletHistoryCommand(const QString &asServicename, QObject *parent = nullptr, const QString &asCliPath = QString()); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETWALLETHISTORYCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..276ce00443d300e8b39d6cf662efab5761a39be7 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.cpp @@ -0,0 +1,53 @@ +#include "DapGetWalletTokenInfoCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +DapGetWalletTokenInfoCommand::DapGetWalletTokenInfoCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletTokenInfoCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList token; + if(!(arg1.toString().isEmpty() || arg1.toString().isNull() + || arg2.toString().isEmpty() || arg2.toString().isNull())) + { + QProcess process; + process.start(QString("%1 wallet info -w %2 -net %3").arg(CLI_PATH).arg(arg1.toString()).arg(arg2.toString())); + process.waitForFinished(-1); + QByteArray result = process.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + while((pos = regex.indexIn(result, pos)) != -1) + { + if(regex.cap(2).isEmpty()) + { + token.append(regex.cap(6)); + token.append(regex.cap(4)); + token.append(regex.cap(5)); + } + pos += regex.matchedLength(); + } + } + + return token; +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..2ceaf209e90e25d93924d28e09ac1157dfc08059 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.h @@ -0,0 +1,30 @@ +#ifndef DAPGETWALLETTOKENINFOCOMMAND_H +#define DAPGETWALLETTOKENINFOCOMMAND_H + +#include <QProcess> +#include <QRegExp> + +#include "DapAbstractCommand.h" + +class DapGetWalletTokenInfoCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + DapGetWalletTokenInfoCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETWALLETTOKENINFOCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp index e4ffd9a3c644e602ad9d038fd5f1d8923fb9bc41..bbd3e08859fb0cd0fb0afcb8496307bfe896a190 100644 --- a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp @@ -125,8 +125,11 @@ void DapUpdateLogsCommand::dapGetLog() /// Reply from service. /// @details Performed on the service side. /// @return Service reply. -void DapUpdateLogsCommand::replyFromService() +QVariant DapUpdateLogsCommand::replyFromService() { DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit serviceResponded(reply->response().toJsonValue()); + + return reply->response().toJsonValue(); } diff --git a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h index 37d93fa8ea35c7796f5e6b378d0d37569e993951..8cd0223db0d85127329da7ee8276deebb1b41e82 100644 --- a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h +++ b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h @@ -63,7 +63,7 @@ public slots: /// Reply from service. /// @details Performed on the service side. /// @return Service reply. - virtual void replyFromService(); + virtual QVariant replyFromService(); }; #endif // DAPUPDATELOGSCOMMAND_H diff --git a/libCellFrameDashboardCommon/Models/DapWalletModel.cpp b/libCellFrameDashboardCommon/Models/DapWalletModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b794f8f0ff592c076a3103ca8012f573c9a1683e --- /dev/null +++ b/libCellFrameDashboardCommon/Models/DapWalletModel.cpp @@ -0,0 +1,129 @@ +#include "DapWalletModel.h" + +DapWalletModel::DapWalletModel(QObject *parent) + : QAbstractListModel(parent) +{ + +} + +DapWalletModel &DapWalletModel::getInstance() +{ + static DapWalletModel instance; + return instance; +} + +int DapWalletModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return m_aWallets.count(); +} + +QVariant DapWalletModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + switch (role) + { + case NameDisplayRole: return m_aWallets[index.row()].getName(); + case BalanceDisplayRole: return m_aWallets[index.row()].getBalance(); + case AddressDisplayRole: return m_aWallets[index.row()].getAddress(); + case IconDisplayRole: return m_aWallets[index.row()].getIcon(); + case NetworksDisplayRole: return m_aWallets[index.row()].getNetworks(); + case TokensDisplayRole: + return QVariant::fromValue<QList<QObject*>>(getTokens(index.row())); + case WalletsDisplayRole: return getWalletList(); + default: break; + } + + return QVariant(); +} + +QList<QObject*> DapWalletModel::getTokens(const int aIndex) const +{ + QList<QObject*> tokens; + auto cbegin = m_aWallets[aIndex].getTokens().cbegin(); + auto cend = m_aWallets[aIndex].getTokens().cend(); + for(; cbegin != cend; ++ cbegin) + tokens.append(*cbegin); + + return tokens; +} + +QStringList DapWalletModel::getWalletList() const +{ + QStringList walletList; + foreach (auto wallet, m_aWallets) + { + walletList.append(wallet.getName()); + } + return walletList; +} + +void DapWalletModel::appendWallet(const DapWallet &aWallet) +{ + m_aWallets.append(aWallet); + + emit walletListChanged(getWalletList()); + + int lastIndex = m_aWallets.count() - 1; + beginInsertRows(QModelIndex(), lastIndex, lastIndex); + endInsertRows(); +} + +void DapWalletModel::appendToken(const QString &asWalletAddress, DapWalletToken* aToken) +{ + auto wallet = std::find_if(m_aWallets.begin(), m_aWallets.end(), [=] (const DapWallet& aWallet) + { + return aWallet.getAddresses().values().contains(asWalletAddress); + }); + + return wallet->addToken(aToken); +} + +void DapWalletModel::removeWallet(const QString &asWalletAddress) +{ + int removeIndex = -1; + auto wallet = std::find_if(m_aWallets.cbegin(), m_aWallets.cend(), [=] (const DapWallet& aWallet) + { + return aWallet.getAddresses().values().contains(asWalletAddress); + }); + removeIndex = m_aWallets.indexOf(*wallet); + m_aWallets.removeAt(removeIndex); + + emit walletListChanged(getWalletList()); + + if(removeIndex == -1) + return; + beginRemoveRows(QModelIndex(), removeIndex, removeIndex); + endRemoveRows(); +} + +void DapWalletModel::removeWallet(const int aWalletIndex) +{ + if(aWalletIndex >= m_aWallets.count() || m_aWallets.count() < aWalletIndex) + return; + beginRemoveRows(QModelIndex(), aWalletIndex, aWalletIndex); + m_aWallets.removeAt(aWalletIndex); + + emit walletListChanged(getWalletList()); + + endRemoveRows(); +} + +QHash<int, QByteArray> DapWalletModel::roleNames() const +{ + static const QHash<int, QByteArray> roles + { + { NameDisplayRole, "name" }, + { BalanceDisplayRole, "balance" }, + { AddressDisplayRole, "address" }, + { IconDisplayRole, "iconPath" }, + { NetworksDisplayRole, "networks" }, + { TokensDisplayRole, "tokens" }, + { WalletsDisplayRole, "walletList" } + }; + + return roles; +} diff --git a/libCellFrameDashboardCommon/Models/DapWalletModel.h b/libCellFrameDashboardCommon/Models/DapWalletModel.h new file mode 100644 index 0000000000000000000000000000000000000000..5819271bb2aca1f2abd8fa7760be84f64248ae79 --- /dev/null +++ b/libCellFrameDashboardCommon/Models/DapWalletModel.h @@ -0,0 +1,57 @@ +#ifndef DAPWALLETMODEL_H +#define DAPWALLETMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <algorithm> +#include <QList> + +#include "DapWallet.h" + +class DapWalletModel : public QAbstractListModel +{ + Q_OBJECT + + QList<DapWallet> m_aWallets; + + explicit DapWalletModel(QObject *parent = nullptr); + +public: + Q_PROPERTY(QStringList WalletList READ getWalletList NOTIFY walletListChanged) + + enum DapWalletRole + { + NameDisplayRole = Qt::UserRole, + AddressDisplayRole, + BalanceDisplayRole, + IconDisplayRole, + NetworksDisplayRole, + TokensDisplayRole, + WalletsDisplayRole + }; + Q_ENUM(DapWalletRole) + + static DapWalletModel& getInstance(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + QHash<int, QByteArray> roleNames() const override; + + QList<QObject*> getTokens(const int aIndex) const; + + QStringList getWalletList() const; + +signals: + void walletListChanged(const QStringList& aWalletList); + +public slots: + + Q_INVOKABLE void appendWallet(const DapWallet& aWallet); + Q_INVOKABLE void appendToken(const QString& asWalletAddress, DapWalletToken* aToken); + Q_INVOKABLE void removeWallet(const QString& asWalletAddress); + Q_INVOKABLE void removeWallet(const int aWalletIndex); +}; + +#endif // DAPWALLETMODEL_H diff --git a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri index f51321a817dd39fed5ac745e946d9b5c0ee21bfb..e4d854e52c902fc6315944a5f6caf1804f60f196 100755 --- a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri +++ b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri @@ -18,16 +18,23 @@ SOURCES +=\ $$PWD/DapHistoryType.cpp \ $$PWD/DapSettings.cpp \ $$PWD/DapLogMessage.cpp \ - $$PWD/DapChainWallet.cpp \ $$PWD/DapSystemTrayIcon.cpp \ + $$PWD/DapWallet.cpp \ + $$PWD/DapWalletToken.cpp \ $$PWD/Handlers/DapAbstractCommand.cpp \ $$PWD/Handlers/DapActivateClientCommand.cpp \ - $$PWD/Handlers/DapCreateTransactionCommand.cpp \ + $$PWD/Handlers/DapGetListNetworksCommand.cpp \ + $$PWD/Handlers/DapGetListWalletsCommand.cpp \ $$PWD/Handlers/DapExportLogCommand.cpp \ + $$PWD/Handlers/DapGetWalletAddressesCommand.cpp \ + $$PWD/Handlers/DapGetWalletHistoryCommand.cpp \ + $$PWD/Handlers/DapGetWalletTokenInfoCommand.cpp \ + $$PWD/Handlers/DapCreateTransactionCommand.cpp \ $$PWD/Handlers/DapMempoolProcessCommand.cpp \ $$PWD/Handlers/DapQuitApplicationCommand.cpp \ $$PWD/Handlers/DapAddWalletCommand.cpp \ - $$PWD/Handlers/DapUpdateLogsCommand.cpp + $$PWD/Handlers/DapUpdateLogsCommand.cpp \ + $$PWD/Models/DapWalletModel.cpp HEADERS +=\ $$PWD/DapChainConvertor.h \ @@ -35,14 +42,21 @@ HEADERS +=\ $$PWD/DapHistoryType.h \ $$PWD/DapSettings.h \ $$PWD/DapLogMessage.h \ - $$PWD/DapChainWallet.h \ $$PWD/DapNodeType.h \ $$PWD/DapSystemTrayIcon.h \ + $$PWD/DapWallet.h \ + $$PWD/DapWalletToken.h \ $$PWD/Handlers/DapAbstractCommand.h \ $$PWD/Handlers/DapActivateClientCommand.h \ - $$PWD/Handlers/DapCreateTransactionCommand.h \ + $$PWD/Handlers/DapGetListNetworksCommand.h \ + $$PWD/Handlers/DapGetListWalletsCommand.h \ $$PWD/Handlers/DapExportLogCommand.h \ + $$PWD/Handlers/DapGetWalletAddressesCommand.h \ + $$PWD/Handlers/DapGetWalletHistoryCommand.h \ + $$PWD/Handlers/DapGetWalletTokenInfoCommand.h \ + $$PWD/Handlers/DapCreateTransactionCommand.h \ $$PWD/Handlers/DapMempoolProcessCommand.h \ $$PWD/Handlers/DapQuitApplicationCommand.h \ $$PWD/Handlers/DapAddWalletCommand.h \ - $$PWD/Handlers/DapUpdateLogsCommand.h + $$PWD/Handlers/DapUpdateLogsCommand.h \ + $$PWD/Models/DapWalletModel.h diff --git a/libdap-qt-ui-qml b/libdap-qt-ui-qml index 5b93902e0b1197f5e1fffbb0881091341322b541..103c3d107cf730c8158368d20e339647cc568659 160000 --- a/libdap-qt-ui-qml +++ b/libdap-qt-ui-qml @@ -1 +1 @@ -Subproject commit 5b93902e0b1197f5e1fffbb0881091341322b541 +Subproject commit 103c3d107cf730c8158368d20e339647cc568659