]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
MainWindow: improve tx history export error handling
authortobtoht <tob@featherwallet.org>
Sun, 16 Feb 2025 10:49:20 +0000 (11:49 +0100)
committertobtoht <tob@featherwallet.org>
Sun, 16 Feb 2025 10:52:59 +0000 (11:52 +0100)
src/MainWindow.cpp
src/libwalletqt/TransactionHistory.cpp

index 4a54c72929c384465aa163b6aaa5d89fdbc0919e..48a7237e93e933b66d815e9c0ed49786b5c477a0 100644 (file)
@@ -1711,13 +1711,26 @@ void MainWindow::onTxPoolBacklog(const QVector<quint64> &backlog, quint64 origin
 }
 
 void MainWindow::onExportHistoryCSV() {
-    QString fn = QFileDialog::getSaveFileName(this, "Save CSV file", QDir::homePath(), "CSV (*.csv)");
-    if (fn.isEmpty())
+    QString filePath = QFileDialog::getSaveFileName(this, "Save CSV file", QDir::homePath(), "CSV (*.csv)");
+    if (filePath.isEmpty())
         return;
-    if (!fn.endsWith(".csv"))
-        fn += ".csv";
-    m_wallet->history()->writeCSV(fn);
-    Utils::showInfo(this, "CSV export", QString("Transaction history exported to %1").arg(fn));
+    if (!filePath.endsWith(".csv"))
+        filePath += ".csv";
+    QFileInfo fileInfo(filePath);
+    QDir dir = fileInfo.absoluteDir();
+
+    if (!dir.exists()) {
+        Utils::showError(this, "Unable to export transaction history", QString("Path does not exist: %1").arg(dir.absolutePath()));
+        return;
+    }
+
+    bool success = m_wallet->history()->writeCSV(filePath);
+    if (!success) {
+        Utils::showError(this, "Unable to export transaction history", QString("No permission to write to: %1").arg(filePath));
+        return;
+    }
+
+    Utils::showInfo(this, "CSV export", QString("Transaction history exported to %1").arg(filePath));
 }
 
 void MainWindow::onImportHistoryDescriptionsCSV() {
index 7102f3ee56ad4670e9fcb6f871882ce16378789f..3df32850b2192cbee281a380603996703482a3c3 100644 (file)
@@ -400,9 +400,6 @@ bool TransactionHistory::writeCSV(const QString &path) {
         data += line;
     }
 
-    if (data.isEmpty())
-        return false;
-
     data = QString("blockHeight,timestamp,date,accountIndex,direction,balanceDelta,amount,fee,txid,description,paymentId,fiatAmount,fiatCurrency%1").arg(data);
     return Utils::fileWrite(path, data);
 }