]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
TxInfoDialog: show inputs on outgoing transactions
authortobtoht <thotbot@protonmail.com>
Tue, 6 Jul 2021 13:31:08 +0000 (15:31 +0200)
committertobtoht <thotbot@protonmail.com>
Tue, 6 Jul 2021 13:31:08 +0000 (15:31 +0200)
src/dialog/TxInfoDialog.cpp
src/dialog/TxInfoDialog.h
src/dialog/TxInfoDialog.ui

index 8abcea4f0ea91e0264ca3b15fd4f4d18eb219b43..dc549893460e8a51c5b7647f790f62566d376052 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "appcontext.h"
 #include "config.h"
+#include "libwalletqt/Coins.h"
+#include "libwalletqt/CoinsInfo.h"
 #include "libwalletqt/TransactionHistory.h"
 #include "libwalletqt/Transfer.h"
 #include "libwalletqt/WalletManager.h"
@@ -42,31 +44,52 @@ TxInfoDialog::TxInfoDialog(QSharedPointer<AppContext> ctx, TransactionInfo *txIn
         ui->btn_rebroadcastTx->hide();
     }
 
-    QTextCursor cursor = ui->destinations->textCursor();
-    for (const auto& transfer : txInfo->transfers()) {
-        auto address = transfer->address();
-        auto amount = WalletManager::displayAmount(transfer->amount());
-        auto index = m_ctx->wallet->subaddressIndex(address);
-        cursor.insertText(address, Utils::addressTextFormat(index, transfer->amount()));
-        cursor.insertText(QString(" %1").arg(amount), QTextCharFormat());
-        cursor.insertBlock();
+    if (txInfo->direction() == TransactionInfo::Direction_Out) {
+        // TODO: this will not properly represent coinjoin-like transactions.
+        QVector<CoinsInfo*> coins = m_ctx->wallet->coins()->coins_from_txid(m_txid);
+        QTextCursor c_i = ui->inputs->textCursor();
+        QString inputs_str;
+        for (const auto &coin : coins) {
+            inputs_str += QString("%1 %2\n").arg(coin->pubKey(), coin->displayAmount());
+        }
+        ui->inputs->setText(inputs_str);
+        ui->label_inputs->setText(QString("Inputs (%1)").arg(QString::number(coins.size())));
+        this->adjustHeight(ui->inputs, coins.size());
+    } else {
+        ui->frameInputs->hide();
     }
 
-    if (txInfo->transfers().size() == 0) {
-        ui->frameDestinations->hide();
+    QTextCursor cursor = ui->outputs->textCursor();
+
+    auto transfers = txInfo->transfers();
+    if (!transfers.isEmpty()) {
+        for (const auto& transfer : transfers) {
+            auto address = transfer->address();
+            auto amount = WalletManager::displayAmount(transfer->amount());
+            auto index = m_ctx->wallet->subaddressIndex(address);
+            cursor.insertText(address, Utils::addressTextFormat(index, transfer->amount()));
+            cursor.insertText(QString(" %1").arg(amount), QTextCharFormat());
+            cursor.insertBlock();
+        }
+        ui->label_outputs->setText(QString("Destinations (%2)").arg(QString::number(transfers.size())));
+        this->adjustHeight(ui->outputs, transfers.size());
+    } else {
+        ui->frameOutputs->hide();
     }
 
+    this->adjustSize();
+}
+
+void TxInfoDialog::adjustHeight(QTextEdit *textEdit, qreal docHeight) {
     QCoreApplication::processEvents();
 
-    qreal lineHeight = QFontMetrics(ui->destinations->document()->defaultFont()).height();
-    qreal docHeight = txInfo->transfers().size();
+    qreal lineHeight = QFontMetrics(ui->outputs->document()->defaultFont()).height();
+
     int h = int(docHeight * (lineHeight + 2) + 11);
     h = qMin(qMax(h, 100), 600);
-    ui->destinations->setMinimumHeight(h);
-    ui->destinations->setMaximumHeight(h);
-    ui->destinations->verticalScrollBar()->hide();
-
-    this->adjustSize();
+    textEdit->setMinimumHeight(h);
+    textEdit->setMaximumHeight(h);
+    textEdit->verticalScrollBar()->hide();
 }
 
 void TxInfoDialog::setData(TransactionInfo *tx) {
index a1ad1b92635922be91faf64a0e4371de820ef528..0041471aa6ebec2d5c08e70bd8e85b7f3222e60e 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <QDialog>
 #include <QTextCharFormat>
+#include <QTextEdit>
 #include <QtSvg/QSvgWidget>
 
 #include "appcontext.h"
@@ -31,6 +32,7 @@ private:
     void createTxProof();
     void setData(TransactionInfo *tx);
     void updateData();
+    void adjustHeight(QTextEdit *textEdit, qreal docHeight);
 
     QScopedPointer<Ui::TxInfoDialog> ui;
     QSharedPointer<AppContext> m_ctx;
index 66e9c0cc829a69fd137e0e50d7f0bbacaa38c7c2..02b18c82a0e97c927942ed10a5dbb117cea3f15b 100644 (file)
     </spacer>
    </item>
    <item>
-    <widget class="QFrame" name="frameDestinations">
+    <widget class="QFrame" name="frameInputs">
+     <property name="frameShape">
+      <enum>QFrame::NoFrame</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Raised</enum>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <property name="topMargin">
+       <number>0</number>
+      </property>
+      <property name="rightMargin">
+       <number>0</number>
+      </property>
+      <property name="bottomMargin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="QLabel" name="label_inputs">
+        <property name="text">
+         <string>Inputs:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QTextEdit" name="inputs">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QFrame" name="frameOutputs">
      <property name="frameShape">
       <enum>QFrame::NoFrame</enum>
      </property>
        <number>0</number>
       </property>
       <item>
-       <widget class="QLabel" name="label_destinations">
+       <widget class="QLabel" name="label_outputs">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
           <horstretch>0</horstretch>
        </widget>
       </item>
       <item>
-       <widget class="QTextEdit" name="destinations">
+       <widget class="QTextEdit" name="outputs">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
           <horstretch>0</horstretch>