diff --git a/src/cutecoin/core/transfer.py b/src/cutecoin/core/transfer.py index 1c99a8cf9f303dc0c0b34e422be1715aeeec5ef1..a8e13467f94c658537fe4a5f5700d8c98d7801ad 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 00489d2149754c742543e2c292306c9f0c700401..e0ad577f161fe34bde0a91d8c32c7c772545756a 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 444348ef20de2a246e21aac444a29451ba5a250f..909ced559f80562d0e9d84c6372a4ff5e9b87e82 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 bf8028331990f3657ce45869d949713b4e266e63..f651ed2211966ca14c4f486c4dd61ce2f4f691b6 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 779870852e0e0cb1425da4f44f3580ef7f44f0b1..aaea42e836829f1c82cc36f3806a2e4c081a519e 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)