Skip to content

Commit

Permalink
DigitalNote GUI Wallet improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xdn-project committed May 12, 2016
1 parent 38914e1 commit d2d28be
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CryptoNoteWallet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set(CN_PROJECT_NAME "digitalnotewallet")
set(CN_CURRENCY_DISPLAY_NAME "DigitalNote")
set(CN_CURRENCY_TICKER "XDN")
set(CN_VERSION 1.0.6-beta)
set(CN_VERSION 1.0.7-beta)
2 changes: 1 addition & 1 deletion cryptonote
28 changes: 24 additions & 4 deletions src/NodeAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class InProcessNodeInitializer : public QObject {
Q_EMIT nodeInitCompletedSignal();
QCoreApplication::processEvents();
});
} catch (std::runtime_error& err) {
} catch (std::exception& err) {
Q_EMIT nodeInitFailedSignal(CryptoNote::error::INTERNAL_WALLET_ERROR);
QCoreApplication::processEvents();
return;
Expand Down Expand Up @@ -133,14 +133,26 @@ bool NodeAdapter::init() {
initTimer.setInterval(3000);
initTimer.setSingleShot(true);
initTimer.start();
bool initCompleted = false;
m_node->init([this](std::error_code _err) {
Q_UNUSED(_err);
});
Q_UNUSED(_err);
});
QEventLoop waitLoop;
connect(&initTimer, &QTimer::timeout, &waitLoop, &QEventLoop::quit);
connect(this, &NodeAdapter::peerCountUpdatedSignal, [&initCompleted]() {
initCompleted = true;
});
connect(this, &NodeAdapter::localBlockchainUpdatedSignal, [&initCompleted]() {
initCompleted = true;
});
connect(this, &NodeAdapter::peerCountUpdatedSignal, &waitLoop, &QEventLoop::quit);
connect(this, &NodeAdapter::localBlockchainUpdatedSignal, &waitLoop, &QEventLoop::quit);

waitLoop.exec();
if (initTimer.isActive() && !initCompleted) {
return false;
}

if (initTimer.isActive()) {
initTimer.stop();
Q_EMIT nodeInitCompletedSignal();
Expand Down Expand Up @@ -189,9 +201,17 @@ bool NodeAdapter::initInProcessNode() {
CryptoNote::NetNodeConfig netNodeConfig = makeNetNodeConfig();
Q_EMIT initNodeSignal(&m_node, &CurrencyAdapter::instance().getCurrency(), this, &LoggerAdapter::instance().getLoggerManager(), coreConfig, netNodeConfig);
QEventLoop waitLoop;
bool initCompleted = false;
connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitCompletedSignal, [&initCompleted]() {
initCompleted = true;
});
connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitFailedSignal, [&initCompleted]() {
initCompleted = false;
});
connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitCompletedSignal, &waitLoop, &QEventLoop::quit);
connect(m_nodeInitializer, &InProcessNodeInitializer::nodeInitFailedSignal, &waitLoop, &QEventLoop::exit);
if (waitLoop.exec() != 0) {

if (waitLoop.exec() != 0 || !initCompleted) {
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/AddressBookFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void AddressBookFrame::addClicked() {
if (!CurrencyAdapter::instance().validateAddress(address)) {
QCoreApplication::postEvent(&MainWindow::instance(), new ShowMessageEvent(tr("Invalid address"), QtCriticalMsg));
return;
} else if (label.trimmed().isEmpty()) {
QCoreApplication::postEvent(&MainWindow::instance(), new ShowMessageEvent(tr("Empty label"), QtCriticalMsg));
return;
}

AddressBookModel::instance().addAddress(label, address);
Expand Down
1 change: 1 addition & 0 deletions src/gui/DepositsFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ DepositsFrame::DepositsFrame(QWidget* _parent) : QFrame(_parent), m_ui(new Ui::D
m_ui->m_tickerLabel1->setText(CurrencyAdapter::instance().getCurrencyTicker().toUpper());
m_ui->m_tickerLabel2->setText(CurrencyAdapter::instance().getCurrencyTicker().toUpper());
m_ui->m_tickerLabel3->setText(CurrencyAdapter::instance().getCurrencyTicker().toUpper());
m_ui->m_feeLabel->setText(tr("%1 %2").arg(CurrencyAdapter::instance().formatAmount(CurrencyAdapter::instance().getMinimumFee())).arg(CurrencyAdapter::instance().getCurrencyTicker().toUpper()));

connect(&WalletAdapter::instance(), &WalletAdapter::walletActualDepositBalanceUpdatedSignal,
this, &DepositsFrame::actualDepositBalanceUpdated, Qt::QueuedConnection);
Expand Down
7 changes: 7 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ void MainWindow::connectToSignals() {
connect(&WalletAdapter::instance(), &WalletAdapter::walletTransactionCreatedSignal, this, [this]() {
QApplication::alert(this);
});

connect(&WalletAdapter::instance(), &WalletAdapter::walletSendTransactionCompletedSignal, this, [this](CryptoNote::TransactionId _transactionId, int _error, const QString& _errorString) {
if (_error == 0) {
m_ui->m_transactionsAction->setChecked(true);
}
});

connect(&NodeAdapter::instance(), &NodeAdapter::peerCountUpdatedSignal, this, &MainWindow::peerCountUpdated, Qt::QueuedConnection);
connect(m_ui->m_exitAction, &QAction::triggered, qApp, &QApplication::quit);
connect(m_ui->m_messagesFrame, &MessagesFrame::replyToSignal, this, &MainWindow::replyTo);
Expand Down
29 changes: 29 additions & 0 deletions src/gui/SendFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace WalletGui {

Q_DECL_CONSTEXPR int DEFAULT_MIXIN = 2;
Q_DECL_CONSTEXPR quint64 COMMENT_CHAR_PRICE = 1000000;

SendFrame::SendFrame(QWidget* _parent) : QFrame(_parent), m_ui(new Ui::SendFrame) {
m_ui->setupUi(this);
Expand Down Expand Up @@ -58,11 +59,14 @@ void SendFrame::addRecipientClicked() {
m_transfers[0]->disableRemoveButton(false);
}

connect(newTransfer, &TransferFrame::commentEditedSignal, this, &SendFrame::updateFee);
connect(newTransfer, &TransferFrame::destroyed, [this](QObject* _obj) {
m_transfers.removeOne(static_cast<TransferFrame*>(_obj));
if (m_transfers.size() == 1) {
m_transfers[0]->disableRemoveButton(true);
}

updateFee();
});
}

Expand Down Expand Up @@ -111,6 +115,12 @@ void SendFrame::sendClicked() {
}

if (WalletAdapter::instance().isOpen()) {
QByteArray paymentIdString = m_ui->m_paymentIdEdit->text().toUtf8();
if (!isValidPaymentId(paymentIdString)) {
QCoreApplication::postEvent(&MainWindow::instance(), new ShowMessageEvent(tr("Invalid payment ID"), QtCriticalMsg));
return;
}

WalletAdapter::instance().sendTransaction(walletTransfers, fee, m_ui->m_paymentIdEdit->text(), m_ui->m_mixinSlider->value(),
walletMessages);
}
Expand All @@ -132,5 +142,24 @@ void SendFrame::sendTransactionCompleted(CryptoNote::TransactionId _id, bool _er
void SendFrame::walletActualBalanceUpdated(quint64 _balance) {
m_ui->m_balanceLabel->setText(CurrencyAdapter::instance().formatAmount(_balance));
}

void SendFrame::updateFee() {
quint64 commentsFee = 0;
Q_FOREACH (const auto& transfer, m_transfers) {
commentsFee += transfer->getComment().length() * COMMENT_CHAR_PRICE;
}

m_ui->m_feeSpin->setMinimum( CurrencyAdapter::instance().formatAmount(commentsFee + CurrencyAdapter::instance().getMinimumFee()).toDouble());
m_ui->m_feeSpin->setValue(m_ui->m_feeSpin->minimum());
}

bool SendFrame::isValidPaymentId(const QByteArray& _paymentIdString) {
if (_paymentIdString.isEmpty()) {
return true;
}

QByteArray paymentId = QByteArray::fromHex(_paymentIdString);
return (paymentId.size() == sizeof(Crypto::Hash)) && (_paymentIdString.toUpper() == paymentId.toHex().toUpper());
}

}
2 changes: 2 additions & 0 deletions src/gui/SendFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class SendFrame : public QFrame {

void sendTransactionCompleted(CryptoNote::TransactionId _transactionId, bool _error, const QString& _errorText);
void walletActualBalanceUpdated(quint64 _balance);
void updateFee();
static bool isValidPaymentId(const QByteArray& _paymentIdString);

Q_SLOT void addRecipientClicked();
Q_SLOT void clearAllClicked();
Expand Down
18 changes: 16 additions & 2 deletions src/gui/SendMessageFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
namespace WalletGui {

Q_DECL_CONSTEXPR quint64 MESSAGE_AMOUNT = 100000;
Q_DECL_CONSTEXPR quint64 MINIMAL_MESSAGE_FEE = 100000000;
Q_DECL_CONSTEXPR quint64 MESSAGE_CHAR_PRICE = 1000000;
Q_DECL_CONSTEXPR quint64 MINIMAL_MESSAGE_FEE = MESSAGE_CHAR_PRICE;
Q_DECL_CONSTEXPR int DEFAULT_MESSAGE_MIXIN = 2;
Q_DECL_CONSTEXPR quint32 MESSAGE_ADDRESS_INPUT_INTERVAL = 1500;

Expand All @@ -29,6 +30,7 @@ SendMessageFrame::SendMessageFrame(QWidget* _parent) : QFrame(_parent), m_ui(new
m_ui->setupUi(this);
m_ui->m_mixinSlider->setValue(DEFAULT_MESSAGE_MIXIN);
m_ui->m_feeSpin->setMinimum(CurrencyAdapter::instance().formatAmount(MESSAGE_AMOUNT + MINIMAL_MESSAGE_FEE).toDouble());
m_ui->m_feeSpin->setValue(m_ui->m_feeSpin->minimum());
connect(&WalletAdapter::instance(), &WalletAdapter::walletSendMessageCompletedSignal, this, &SendMessageFrame::sendMessageCompleted,
Qt::QueuedConnection);
connect(m_aliasProvider, &AliasProvider::aliasFoundSignal, this, &SendMessageFrame::onAliasFound);
Expand Down Expand Up @@ -70,7 +72,7 @@ void SendMessageFrame::sendMessageCompleted(CryptoNote::TransactionId _transacti

void SendMessageFrame::reset() {
m_ui->m_mixinSlider->setValue(DEFAULT_MESSAGE_MIXIN);
m_ui->m_feeSpin->setValue(m_ui->m_feeSpin->minimum());
m_ui->m_feeSpin->setValue(MESSAGE_AMOUNT + MINIMAL_MESSAGE_FEE);
m_ui->m_addressEdit->clear();
m_ui->m_messageTextEdit->clear();
}
Expand Down Expand Up @@ -101,6 +103,18 @@ void SendMessageFrame::addressEdited(const QString& _text) {
m_addressInputTimer = startTimer(MESSAGE_ADDRESS_INPUT_INTERVAL);
}

void SendMessageFrame::messageTextChanged() {
QString messageText = m_ui->m_messageTextEdit->toPlainText();
quint32 messageSize = messageText.length() ;
if (messageSize > 0) {
--messageSize;
}

m_ui->m_feeSpin->setMinimum(CurrencyAdapter::instance().formatAmount(MESSAGE_AMOUNT + MINIMAL_MESSAGE_FEE +
messageSize * MESSAGE_CHAR_PRICE).toDouble());
m_ui->m_feeSpin->setValue(m_ui->m_feeSpin->minimum());
}

void SendMessageFrame::mixinValueChanged(int _value) {
m_ui->m_mixinEdit->setText(QString::number(_value));
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/SendMessageFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SendMessageFrame : public QFrame {

Q_SLOT void addressBookClicked();
Q_SLOT void addressEdited(const QString& _text);
Q_SLOT void messageTextChanged();
Q_SLOT void mixinValueChanged(int _value);
Q_SLOT void pasteClicked();
Q_SLOT void sendClicked();
Expand Down
4 changes: 4 additions & 0 deletions src/gui/TransferFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void TransferFrame::addressEdited(const QString& _text) {
m_addressInputTimer = startTimer(TRANSACTION_ADDRESS_INPUT_INTERVAL);
}

void TransferFrame::commentEdited(const QString& _text) {
Q_EMIT commentEditedSignal();
}

void TransferFrame::pasteClicked() {
m_ui->m_addressEdit->setText(QApplication::clipboard()->text());
}
Expand Down
4 changes: 4 additions & 0 deletions src/gui/TransferFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class TransferFrame : public QFrame {
void onAliasFound(const QString& _name, const QString& _address);
Q_SLOT void addressBookClicked();
Q_SLOT void addressEdited(const QString& _text);
Q_SLOT void commentEdited(const QString& _text);
Q_SLOT void pasteClicked();

Q_SIGNALS:
void commentEditedSignal();
};

}
14 changes: 14 additions & 0 deletions src/gui/ui/depositsframe.ui
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="m_feeTextLabel">
<property name="text">
<string>Deposit fee:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="m_feeLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
25 changes: 21 additions & 4 deletions src/gui/ui/sendmessageframe.ui
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.Helvetica Neue DeskInterface'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'.SF NS Text'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'.Helvetica Neue DeskInterface';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -198,7 +198,7 @@ p, li { white-space: pre-wrap; }
<number>8</number>
</property>
<property name="minimum">
<double>1.001000000000000</double>
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000.000000000000000</double>
Expand All @@ -207,7 +207,7 @@ p, li { white-space: pre-wrap; }
<double>0.010000000000000</double>
</property>
<property name="value">
<double>1.001000000000000</double>
<double>0.000000000000000</double>
</property>
</widget>
</item>
Expand Down Expand Up @@ -334,12 +334,29 @@ p, li { white-space: pre-wrap; }
</hint>
</hints>
</connection>
<connection>
<sender>m_messageTextEdit</sender>
<signal>textChanged()</signal>
<receiver>SendMessageFrame</receiver>
<slot>messageTextChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>386</x>
<y>227</y>
</hint>
<hint type="destinationlabel">
<x>386</x>
<y>287</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addressBookClicked()</slot>
<slot>pasteClicked()</slot>
<slot>sendClicked()</slot>
<slot>mixinValueChanged(int)</slot>
<slot>addressEdited(QString)</slot>
<slot>messageTextChanged()</slot>
</slots>
</ui>
19 changes: 18 additions & 1 deletion src/gui/ui/transferframe.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>885</width>
<height>134</height>
<height>136</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -213,10 +213,27 @@
</hint>
</hints>
</connection>
<connection>
<sender>m_transactionCommentEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>TransferFrame</receiver>
<slot>commentEdited(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>499</x>
<y>118</y>
</hint>
<hint type="destinationlabel">
<x>442</x>
<y>67</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addressBookClicked()</slot>
<slot>pasteClicked()</slot>
<slot>addressEdited(QString)</slot>
<slot>commentEdited(QString)</slot>
</slots>
</ui>
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) {
splash->show();
}

splash->showMessage(QObject::tr("Loading blockchain..."), Qt::AlignLeft | Qt::AlignBottom, Qt::white);
splash->showMessage(QObject::tr("Loading blockchain..."), Qt::AlignLeft | Qt::AlignBottom, Qt::black);
app.processEvents();
qRegisterMetaType<CryptoNote::TransactionId>("CryptoNote::TransactionId");
qRegisterMetaType<quintptr>("quintptr");
Expand Down

0 comments on commit d2d28be

Please sign in to comment.