From f7a86436fa3266f8391dec6a4d5ad21bb3acb1d4 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Thu, 5 Feb 2015 21:22:12 +0100 Subject: [PATCH] Added the ability to send back a failed transaction or cancel it --- src/cutecoin/core/transfer.py | 3 ++ src/cutecoin/core/wallet.py | 4 +-- src/cutecoin/gui/currency_tab.py | 58 +++++++++++++++++++++----------- src/cutecoin/gui/mainwindow.py | 12 +++---- src/cutecoin/models/txhistory.py | 1 - 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/cutecoin/core/transfer.py b/src/cutecoin/core/transfer.py index 1c99a8cf..a8e13467 100644 --- a/src/cutecoin/core/transfer.py +++ b/src/cutecoin/core/transfer.py @@ -76,6 +76,9 @@ class Transfer(object): if block > self.metadata['block'] + 15: self.state = Transfer.REFUSED + def drop(self): + self.state = Transfer.DROPPED + class Received(Transfer): def __init__(self, txdoc, metadata): diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 00489d21..e0ad577f 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -40,7 +40,7 @@ class Cache(): def jsonify(self): data_transfer = [] - for s in self._transfers: + for s in self.transfers: data_transfer.append(s.jsonify()) data_sources = [] @@ -54,7 +54,7 @@ class Cache(): @property def transfers(self): - return self._transfers + return [t for t in self._transfers if t.state != Transfer.DROPPED] def refresh(self, community): current_block = 0 diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 444348ef..909ced55 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -9,11 +9,14 @@ import time import requests from ucoinpy.api import bma -from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, QMessageBox -from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal, QDateTime +from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication, \ + QMessageBox, QDialog +from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, \ + QThread, pyqtSignal, QDateTime from PyQt5.QtGui import QIcon from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from .community_tab import CommunityTabWidget +from .transfer import TransferMoneyDialog from ..models.txhistory import HistoryTableModel, TxFilterProxyModel from ..models.wallets import WalletsListModel from ..models.wallet import WalletListModel @@ -94,18 +97,16 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tabs_account.setEnabled(True) self.refresh_wallets() blockchain_init = QDateTime() - blockchain_init.setTime_t(self.community.get_block(1).mediantime) - - blockchain_lastblock = QDateTime() - blockchain_lastblock.setTime_t(self.community.get_block().mediantime) + blockchain_init.setTime_t(self.community.get_block(1).time) self.date_from.setMinimumDateTime(blockchain_init) self.date_from.setDateTime(blockchain_init) - self.date_from.setMaximumDateTime(blockchain_lastblock) + self.date_from.setMaximumDateTime(QDateTime().currentDateTime()) self.date_to.setMinimumDateTime(blockchain_init) - self.date_to.setDateTime(blockchain_lastblock) - self.date_to.setMaximumDateTime(blockchain_lastblock) + tomorrow_datetime = QDateTime().currentDateTime().addDays(1) + self.date_to.setDateTime(tomorrow_datetime) + self.date_to.setMaximumDateTime(tomorrow_datetime) ts_from = self.date_from.dateTime().toTime_t() ts_to = self.date_to.dateTime().toTime_t() @@ -211,17 +212,18 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): person_index = model.sourceModel().index(source_index.row(), pubkey_col) person = model.sourceModel().data(person_index, Qt.DisplayRole) - - payment_col = model.sourceModel().columns.index('Payment') - payment_index = model.sourceModel().index(source_index.row(), - payment_col) - payment_data = model.sourceModel().data(payment_index, Qt.DisplayRole) + transfer = model.sourceModel().transfers[source_index.row()] if state_data == Transfer.REFUSED: send_back = QAction("Send again", self) send_back.triggered.connect(self.send_again) - send_back.setData((payment_data, person)) + send_back.setData(transfer) menu.addAction(send_back) + cancel = QAction("Cancel", self) + cancel.triggered.connect(self.cancel_transfer) + cancel.setData(transfer) + menu.addAction(cancel) + copy_pubkey = QAction("Copy pubkey to clipboard", self) copy_pubkey.triggered.connect(self.copy_pubkey_to_clipboard) copy_pubkey.setData(person) @@ -244,10 +246,28 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): clipboard.setText(data) def send_again(self): - data = self.sender().data() - payment = data[0] - person = data[1] - #TODO: Send back the transaction and change its state + transfer = self.sender().data() + dialog = TransferMoneyDialog(self.app.current_account, + self.password_asker) + dialog.accepted.connect(self.refresh_wallets) + dialog.edit_pubkey.setText(transfer.metadata['receiver']) + dialog.combo_community.setCurrentText(self.community.name()) + dialog.spinbox_amount.setValue(transfer.metadata['amount']) + dialog.radio_pubkey.setChecked(True) + result = dialog.exec_() + if result == QDialog.Accepted: + transfer.drop() + self.table_history.model().invalidate() + + def cancel_transfer(self): + reply = QMessageBox.warning(self, "Warning", + """Are you sure ? +This money transfer will be removed and not sent.""", +QMessageBox.Ok | QMessageBox.Cancel) + if reply == QMessageBox.Ok: + transfer = self.sender().data() + transfer.drop() + self.table_history.model().invalidate() def wallet_changed(self): self.app.save(self.app.current_account) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index bf802833..f651ed22 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -5,7 +5,7 @@ Created on 1 févr. 2014 ''' from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog, QProgressBar, \ - QMessageBox, QLabel, QComboBox + QMessageBox, QLabel, QComboBox, QDialog from PyQt5.QtCore import QSignalMapper, QModelIndex, QObject, QThread, \ pyqtSlot, pyqtSignal, QDate, QDateTime, QTimer from PyQt5.QtGui import QIcon @@ -138,13 +138,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): dialog = TransferMoneyDialog(self.app.current_account, self.password_asker) dialog.accepted.connect(self.refresh_wallets) - dialog.exec_() - currency_tab = self.currencies_tabwidget.currentWidget() - '''currency_tab.table_history.model().sourceModel().dataChanged.emit( - QModelIndex(), - QModelIndex(), ()) - ''' - currency_tab.table_history.model().invalidate() + if dialog.exec_() == QDialog.Accepted: + currency_tab = self.currencies_tabwidget.currentWidget() + currency_tab.table_history.model().invalidate() def open_certification_dialog(self): dialog = CertificationDialog(self.app.current_account, diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index 77987085..aaea42e8 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -32,7 +32,6 @@ class TxFilterProxyModel(QSortFilterProxyModel): def filterAcceptsRow(self, sourceRow, sourceParent): def in_period(date_ts): return (date_ts in range(self.ts_from, self.ts_to)) - date_col = self.sourceModel().columns.index('Date') source_index = self.sourceModel().index(sourceRow, date_col) date = self.sourceModel().data(source_index, Qt.DisplayRole) -- GitLab