Skip to content
Snippets Groups Projects
Commit ec7d3d99 authored by vladislav.cholak's avatar vladislav.cholak
Browse files

Added possibility to make transactions and fixed some UI elems

parent 7ba7b1a2
No related branches found
No related tags found
No related merge requests found
Showing
with 207 additions and 144 deletions
...@@ -252,6 +252,7 @@ DapRpcMessage DapRpcService::dispatch(const DapRpcMessage &aRequest) ...@@ -252,6 +252,7 @@ DapRpcMessage DapRpcService::dispatch(const DapRpcMessage &aRequest)
} }
const QByteArray &method(methodName(aRequest)); const QByteArray &method(methodName(aRequest));
qDebug() << method;
if (!m_invokableMethodHash.contains(method)) { if (!m_invokableMethodHash.contains(method)) {
return aRequest.createErrorResponse(DapErrorCode::MethodNotFound, "invalid method called"); return aRequest.createErrorResponse(DapErrorCode::MethodNotFound, "invalid method called");
} }
......
...@@ -75,6 +75,7 @@ void DapCommandController::processSendToken() ...@@ -75,6 +75,7 @@ void DapCommandController::processSendToken()
qWarning() << "Invalid response received"; qWarning() << "Invalid response received";
return; return;
} }
qInfo() << reply->response();
emit sigCommandResult(reply->response().result()); emit sigCommandResult(reply->response().result());
auto answer = reply->response().result().toVariant().toString(); auto answer = reply->response().result().toVariant().toString();
emit onTokenSended(answer); emit onTokenSended(answer);
...@@ -115,9 +116,7 @@ void DapCommandController::processGetWalletInfo() ...@@ -115,9 +116,7 @@ void DapCommandController::processGetWalletInfo()
} }
else else
{ {
QString s; balance.append(temp[x]);
s.setNum(x*10);
balance.append(temp[x] + s);
qDebug() << "BALANCE " << temp[x]; qDebug() << "BALANCE " << temp[x];
} }
} }
...@@ -156,7 +155,7 @@ void DapCommandController::addWallet(const QString &asWalletName) ...@@ -156,7 +155,7 @@ void DapCommandController::addWallet(const QString &asWalletName)
connect(reply, SIGNAL(finished()), this, SLOT(processAddWallet())); connect(reply, SIGNAL(finished()), this, SLOT(processAddWallet()));
} }
void DapCommandController::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const double &aAmount) void DapCommandController::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const QString &aAmount)
{ {
qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount);
DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.sendToken", asSendWallet, asAddressReceiver, asToken, aAmount); DapRpcServiceReply *reply = m_DAPRpcSocket->invokeRemoteMethod("RPCServer.sendToken", asSendWallet, asAddressReceiver, asToken, aAmount);
......
...@@ -71,7 +71,7 @@ public slots: ...@@ -71,7 +71,7 @@ public slots:
void getNodeLogs(int aiTimeStamp, int aiRowCount); void getNodeLogs(int aiTimeStamp, int aiRowCount);
void addWallet(const QString& asWalletName); void addWallet(const QString& asWalletName);
void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const double& aAmount); void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount);
void getWallets(); void getWallets();
......
...@@ -120,10 +120,10 @@ void DapServiceController::addWallet(const QString &asWalletName) ...@@ -120,10 +120,10 @@ void DapServiceController::addWallet(const QString &asWalletName)
m_pDapCommandController->addWallet(asWalletName); m_pDapCommandController->addWallet(asWalletName);
} }
void DapServiceController::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const double &aAmount) void DapServiceController::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const QString &aAmount)
{ {
qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount);
m_pDapCommandController->sendToken(asSendWallet, asAddressReceiver, asToken, aAmount); m_pDapCommandController->sendToken(asSendWallet.trimmed(), asAddressReceiver.trimmed(), asToken.trimmed(), aAmount);
} }
void DapServiceController::getWalletInfo(const QString &asWalletName) void DapServiceController::getWalletInfo(const QString &asWalletName)
......
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
void setLogModel(const DapLogModel &dapLogModel); void setLogModel(const DapLogModel &dapLogModel);
Q_INVOKABLE void addWallet(const QString& asWalletName); Q_INVOKABLE void addWallet(const QString& asWalletName);
Q_INVOKABLE void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const double& aAmount); Q_INVOKABLE void sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount);
void getWalletInfo(const QString& asWalletName); void getWalletInfo(const QString& asWalletName);
......
...@@ -11,140 +11,170 @@ Dialog { ...@@ -11,140 +11,170 @@ Dialog {
title: qsTr("Send token...") title: qsTr("Send token...")
width: parent.width/1.5 width: parent.width/1.5
height: 200 height: 280
x: parent.width / 2 - width / 2 x: parent.width / 2 - width / 2
y: parent.height / 2 - height / 2 y: parent.height / 2 - height / 2
function show() { function show() {
dialogSendToken.open(); dialogSendToken.open();
} }
contentItem: contentItem:
Rectangle Rectangle
{ {
anchors.fill: parent anchors.fill: parent
// TextField // TextField
// { // {
// background: Rectangle { // background: Rectangle {
// radius: 2 // radius: 2
// border.color: "gray" // border.color: "gray"
// border.width: 1 // border.width: 1
// } // }
// id: textFieldNameWallet // id: textFieldNameWallet
// selectByMouse: true // selectByMouse: true
// height: 35 // height: 35
// anchors.bottom: buttonOk.top // anchors.bottom: buttonOk.top
// anchors.bottomMargin: 20 // anchors.bottomMargin: 20
// anchors.right: parent.right // anchors.right: parent.right
// anchors.rightMargin: 10 // anchors.rightMargin: 10
// anchors.left: parent.left // anchors.left: parent.left
// anchors.leftMargin: 10 // anchors.leftMargin: 10
// font.pixelSize: 20 // font.pixelSize: 20
// clip: true // clip: true
// } // }
ComboBox { ComboBox {
id: comboBoxAddressWallet id: comboBoxToken
anchors.bottom: spinBoxAmount.top anchors { bottom: comboBoxAddressWallet.top; bottomMargin: 20; right: parent.right; rightMargin: 10;
anchors.bottomMargin: 20 left: parent.left; leftMargin: 10 }
anchors.right: parent.right model: listViewTokens.model
anchors.rightMargin: 10 delegate: ItemDelegate {
anchors.left: parent.left width: comboBoxToken.width
anchors.leftMargin: 10 contentItem: Text {
editable: true text: modelData
textRole: "text" font: comboBoxToken.font
onAccepted: { elide: Text.ElideRight
if (find(currentText) === -1) { verticalAlignment: Text.AlignVCenter
model.append({text: editText}) }
// currentIndex = find(editText) highlighted: comboBoxToken.highlightedIndex !== index
// fnameField.insert(currentIndex) }
}
}
ComboBox {
id: comboBoxAddressWallet
anchors.bottom: textFieldAmount.top
anchors.bottomMargin: 20
anchors.right: parent.right
anchors.rightMargin: 10
anchors.left: parent.left
anchors.leftMargin: 10
editable: true
textRole: "text"
onAccepted: {
if (find(currentText) === -1) {
model.append({text: editText})
// currentIndex = find(editText)
// fnameField.insert(currentIndex)
} }
} }
}
TextField {
property real realValue: parseFloat(textFieldAmount.text.replace(',', '.')) * 1e12;
id: textFieldAmount
anchors.bottom: buttonOk.top
anchors.bottomMargin: 20
anchors.right: parent.right
anchors.rightMargin: 10
placeholderText: "Amount (Ex. 2,9103)"
validator: DoubleValidator{}
}
Button
{
id: buttonCancel
text: qsTr("Cancel")
anchors.right: buttonOk.left
anchors.rightMargin: 10
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
contentItem: Text {
text: buttonCancel.text
font: buttonCancel.font
opacity: enabled ? 1.0 : 0.3
color: buttonCancel.down ? "#353841" : "white"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
SpinBox { background: Rectangle {
id: spinBoxAmount implicitWidth: 100
anchors.bottom: buttonOk.top implicitHeight: 30
anchors.bottomMargin: 20 opacity: enabled ? 1 : 0.3
anchors.right: parent.right color: buttonCancel.down ? "white" : "#353841"
anchors.rightMargin: 10 radius: 4
editable: true
} }
Button onClicked:
{ {
id: buttonCancel close()
text: qsTr("Cancel") }
anchors.right: buttonOk.left }
anchors.rightMargin: 10
anchors.bottom: parent.bottom
anchors.bottomMargin: 10
contentItem: Text { Button
text: buttonCancel.text {
font: buttonCancel.font id: buttonOk
opacity: enabled ? 1.0 : 0.3 text: "OK"
color: buttonCancel.down ? "#353841" : "white" anchors.right: parent.right
horizontalAlignment: Text.AlignHCenter anchors.rightMargin: 10
verticalAlignment: Text.AlignVCenter anchors.bottom: parent.bottom
elide: Text.ElideRight anchors.bottomMargin: 10
} contentItem: Text {
text: buttonOk.text
background: Rectangle { font: buttonOk.font
implicitWidth: 100 opacity: enabled ? 1.0 : 0.3
implicitHeight: 30 color: buttonOk.down ? "#353841" : "white"
opacity: enabled ? 1 : 0.3 horizontalAlignment: Text.AlignHCenter
color: buttonCancel.down ? "white" : "#353841" verticalAlignment: Text.AlignVCenter
radius: 4 elide: Text.ElideRight
} }
onClicked: background: Rectangle {
{ implicitWidth: 100
textFieldNameWallet.clear() implicitHeight: 30
close() opacity: enabled ? 1 : 0.3
} color: buttonOk.down ? "white" : "#353841"
radius: 4
} }
Button onClicked:
{ {
id: buttonOk let wallet = listViewWallet.model.get(listViewWallet.currentIndex).name;
text: "OK" let token = comboBoxToken.currentText;
anchors.right: parent.right let amount = textFieldAmount.realValue.toString();
anchors.rightMargin: 10 let receiver = comboBoxAddressWallet.editText;
anchors.bottom: parent.bottom
anchors.bottomMargin: 10 if (wallet && token && amount && receiver) {
contentItem: Text { console.log("Send " + token + "(" + amount + ") to address " + receiver + " from wallet " + wallet );
text: buttonOk.text dapServiceController.sendToken(wallet, receiver, token, amount);
font: buttonOk.font } else {
opacity: enabled ? 1.0 : 0.3 console.log("There's error!");
color: buttonOk.down ? "#353841" : "white" console.log(amount);
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 100
implicitHeight: 30
opacity: enabled ? 1 : 0.3
color: buttonOk.down ? "white" : "#353841"
radius: 4
}
onClicked:
{
// dapServiceController.addWallet(textFieldNameWallet.text)
console.log(comboBoxAddressWallet.displayText)
close()
} }
close()
} }
} }
}
} }
#include "DapUiQmlWidgetChainTransactions.h"
DapUiQmlWidgetChainTransactions::DapUiQmlWidgetChainTransactions(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image)
{
}
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
#include "DapUiQmlWidget.h" #include "DapUiQmlWidget.h"
class DapUiQmlWidgetChainTransctions : public DapUiQmlWidget class DapUiQmlWidgetChainTransactions : public DapUiQmlWidget
{ {
public: public:
explicit DapUiQmlWidgetChainTransctions(const QString &name, const QString &URLpage, const QString &image); explicit DapUiQmlWidgetChainTransactions(const QString &name, const QString &URLpage, const QString &image);
}; };
#endif // DAPUIQMLWIDGETCHAINTRANSCTIONS_H #endif // DAPUIQMLWIDGETCHAINTRANSCTIONS_H
#include "DapUiQmlWidgetChainTransctions.h"
DapUiQmlWidgetChainTransctions::DapUiQmlWidgetChainTransctions(const QString &name, const QString &URLpage, const QString &image) : DapUiQmlWidget(name, URLpage, image)
{
}
...@@ -27,15 +27,14 @@ DapUiQmlWidgetChainWalletForm { ...@@ -27,15 +27,14 @@ DapUiQmlWidgetChainWalletForm {
listViewWallet.onCurrentItemChanged: listViewWallet.onCurrentItemChanged:
{ {
listViewTokens.model = listViewWallet.model.get(listViewWallet.currentIndex).tokens listViewTokens.model = listViewWallet.model.get(listViewWallet.currentIndex).tokens
// console.log("Заголовок " + listViewWallet.model.get(listViewWallet.currentIndex).address) updateBalanceText();
console.log(listViewWallet.currentIndex) addressWallet.text = listViewWallet.model.get(listViewWallet.currentIndex).address
} }
listViewTokens.onCurrentItemChanged: listViewTokens.onCurrentItemChanged:
{ {
textBalance.text = listViewWallet.model.get(listViewWallet.currentIndex).balance[listViewTokens.currentIndex] updateBalanceText();
console.log(textBalance.text);
} }
buttonSaveWallet.onClicked: { buttonSaveWallet.onClicked: {
...@@ -45,5 +44,11 @@ DapUiQmlWidgetChainWalletForm { ...@@ -45,5 +44,11 @@ DapUiQmlWidgetChainWalletForm {
dialogSendToken.show() dialogSendToken.show()
} }
function updateBalanceText() {
let value = listViewTokens.currentIndex > -1 ? listViewWallet.model.get(listViewWallet.currentIndex).balance[listViewTokens.currentIndex] : "";
if (value)
textBalance.text = value.replace(/[^\d.-]/g, '');
else
textBalance.text = '';
}
} }
...@@ -12,11 +12,11 @@ Page { ...@@ -12,11 +12,11 @@ Page {
property alias listViewWallet: listViewWallet property alias listViewWallet: listViewWallet
property alias buttonSaveWallet: buttonSaveWallet property alias buttonSaveWallet: buttonSaveWallet
property alias dialogAddWallet: dialogAddWallet property alias dialogAddWallet: dialogAddWallet
property alias buttonSendToken: buttonSendToken
property alias dialogSendToken: dialogSendToken property alias dialogSendToken: dialogSendToken
property alias addressWallet: addressWallet property alias addressWallet: addressWallet
property alias listViewTokens: listViewTokens
property alias textBalance: textBalance property alias textBalance: textBalance
property alias listViewTokens: listViewTokens
property alias buttonSendToken: buttonSendToken
Rectangle Rectangle
{ {
...@@ -74,24 +74,29 @@ Page { ...@@ -74,24 +74,29 @@ Page {
TextEdit { TextEdit {
id: addressWallet id: addressWallet
font.pixelSize: 16 font.pixelSize: 11
wrapMode: Text.Wrap wrapMode: Text.Wrap
selectByMouse: true selectByMouse: true
color: "black" color: "black"
selectionColor: "#008080"
clip: true
anchors.top: parent.top anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.left: parent.left
readOnly: true
} }
ListView { ListView {
id: listViewTokens id: listViewTokens
orientation: ListView.Horizontal orientation: ListView.Vertical
anchors.top: addressWallet.bottom anchors.top: addressWallet.bottom
anchors.left: parent.left anchors.left: parent.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
width: parent.width*2/3 width: parent.width*2/3
flickableDirection: Flickable.VerticalFlick
delegate: Item { delegate: Item {
width: 200; height: 50 width: 200; height: 50
Text { id: nameField; text: modelData } Text { id: nameField; text: modelData; color: listViewTokens.currentIndex === index ? 'green' : 'black'; }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: listViewTokens.currentIndex = index onClicked: listViewTokens.currentIndex = index
...@@ -104,12 +109,15 @@ Page { ...@@ -104,12 +109,15 @@ Page {
Text Text
{ {
id: textBalance id: textBalance
wrapMode: Text.NoWrap
textFormat: Text.PlainText
clip: false
anchors.top: addressWallet.bottom anchors.top: addressWallet.bottom
anchors.left: listViewTokens.right anchors.left: listViewTokens.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
font.pixelSize: 70 font.pixelSize: 30
font.bold: true font.bold: true
} }
} }
......
...@@ -38,11 +38,11 @@ ICON = icon.ico ...@@ -38,11 +38,11 @@ ICON = icon.ico
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \ SOURCES += \
DapUiQmlWidgetChainTransactions.cpp \
main.cpp \ main.cpp \
DapUiQmlWidgetChainBallance.cpp \ DapUiQmlWidgetChainBallance.cpp \
DapUiQmlWidgetChainBlockExplorer.cpp \ DapUiQmlWidgetChainBlockExplorer.cpp \
DapUiQmlWidgetChainNodeLogs.cpp \ DapUiQmlWidgetChainNodeLogs.cpp \
DapUiQmlWidgetChainTransctions.cpp \
DapUiQmlWidgetChainOperations.cpp \ DapUiQmlWidgetChainOperations.cpp \
DapUiQmlWidgetModel.cpp \ DapUiQmlWidgetModel.cpp \
DapUiQmlWidget.cpp \ DapUiQmlWidget.cpp \
...@@ -72,9 +72,9 @@ HEADERS += \ ...@@ -72,9 +72,9 @@ HEADERS += \
DapUiQmlWidgetChainBallance.h \ DapUiQmlWidgetChainBallance.h \
DapUiQmlWidgetChainBlockExplorer.h \ DapUiQmlWidgetChainBlockExplorer.h \
DapUiQmlWidgetChainNodeLogs.h \ DapUiQmlWidgetChainNodeLogs.h \
DapUiQmlWidgetChainTransctions.h \
DapUiQmlScreenDashboard.h \ DapUiQmlScreenDashboard.h \
DapUiQmlWidgetChainOperations.h \ DapUiQmlWidgetChainOperations.h \
DapUiQmlWidgetChainTransactions.h \
DapUiQmlWidgetModel.h \ DapUiQmlWidgetModel.h \
DapUiQmlWidget.h \ DapUiQmlWidget.h \
DapScreenDialog.h \ DapScreenDialog.h \
......
...@@ -59,6 +59,12 @@ QStringList DapChainDashboardService::getWalletInfo(const QString &asWalletName) ...@@ -59,6 +59,12 @@ QStringList DapChainDashboardService::getWalletInfo(const QString &asWalletName)
return m_pDapChainWalletHandler->getWalletInfo(asWalletName); return m_pDapChainWalletHandler->getWalletInfo(asWalletName);
} }
QString DapChainDashboardService::sendToken(const QString &asWalletName, const QString &asReceiverAddr, const QString &asToken, const QString &asAmount)
{
qInfo() << QString("sendToken(%1;%2;%3;%4)").arg(asWalletName).arg(asReceiverAddr).arg(asToken).arg(asAmount);
return m_pDapChainWalletHandler->sendToken(asWalletName, asReceiverAddr, asToken, asAmount);
}
/// Activate the main client window by double-clicking the application icon in the system tray. /// Activate the main client window by double-clicking the application icon in the system tray.
/// @param reason Type of action on the icon in the system tray. /// @param reason Type of action on the icon in the system tray.
......
...@@ -73,6 +73,8 @@ public slots: ...@@ -73,6 +73,8 @@ public slots:
QMap<QString, QVariant> getWallets(); QMap<QString, QVariant> getWallets();
QStringList getWalletInfo(const QString &asWalletName); QStringList getWalletInfo(const QString &asWalletName);
QString sendToken(const QString &asWalletName, const QString &asReceiverAddr, const QString &asToken, const QString &asAmount);
}; };
......
...@@ -78,10 +78,10 @@ QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet) ...@@ -78,10 +78,10 @@ QStringList DapChainWalletHandler::getWalletInfo(const QString &asNameWallet)
return list; return list;
} }
QString DapChainWalletHandler::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const double &aAmount) QString DapChainWalletHandler::sendToken(const QString &asSendWallet, const QString &asAddressReceiver, const QString &asToken, const QString &aAmount)
{ {
QString answer; QString answer;
qInfo() << QString("sendToken(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount); qInfo() << QString("sendTokenTest(%1, %2, %3, %4)").arg(asSendWallet).arg(asAddressReceiver).arg(asToken).arg(aAmount);
QProcess processCreate; QProcess processCreate;
processCreate.start(QString("%1 tx_create -net private -chain gdb -from_wallet %2 -to_addr %3 -token %4 -value %5") processCreate.start(QString("%1 tx_create -net private -chain gdb -from_wallet %2 -to_addr %3 -token %4 -value %5")
.arg("/opt/kelvin-node/bin/kelvin-node-cli") .arg("/opt/kelvin-node/bin/kelvin-node-cli")
......
...@@ -22,7 +22,7 @@ public slots: ...@@ -22,7 +22,7 @@ public slots:
QStringList createWallet(const QString& asNameWallet); QStringList createWallet(const QString& asNameWallet);
QMap<QString, QVariant> getWallets(); QMap<QString, QVariant> getWallets();
QStringList getWalletInfo(const QString& asNameWallet); QStringList getWalletInfo(const QString& asNameWallet);
QString sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const double& aAmount); QString sendToken(const QString &asSendWallet, const QString& asAddressReceiver, const QString& asToken, const QString& aAmount);
}; };
#endif // DAPCHAINWALLETHANDLER_H #endif // DAPCHAINWALLETHANDLER_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment