Browse Source

Reworked notification flow and combined multiple transactions into one notification

283
Maran 12 years ago
parent
commit
06bfb60308
  1. 22
      gui/gui_classic.py
  2. 2
      lib/interface.py
  3. 6
      lib/wallet.py

22
gui/gui_classic.py

@ -314,6 +314,9 @@ class ElectrumWindow(QMainWindow):
# set initial message # set initial message
self.console.showMessage(self.wallet.interface.banner) self.console.showMessage(self.wallet.interface.banner)
# Once GUI has been initialized check if we want to announce something since the callback has been called before the GUI was initialized
self.notify_transactions()
# plugins that need to change the GUI do it here # plugins that need to change the GUI do it here
self.run_hook('init_gui') self.run_hook('init_gui')
@ -421,9 +424,24 @@ class ElectrumWindow(QMainWindow):
self.update_wallet() self.update_wallet()
def notify_transactions(self): def notify_transactions(self):
for tx in self.wallet.interface.pending_transactions: print_error("Notifying GUI")
if len(self.wallet.interface.pending_transactions_for_notifications) > 0:
# Combine the transactions if there are more then three
tx_amount = len(self.wallet.interface.pending_transactions_for_notifications)
if(tx_amount >= 3):
total_amount = 0
for tx in self.wallet.interface.pending_transactions_for_notifications:
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx)
if(v > 0):
total_amount += v
self.notify("%s new transactions received. Total amount received in the new transactions %s BTC" % (tx_amount, self.format_amount(total_amount)))
self.wallet.interface.pending_transactions_for_notifications = []
else:
for tx in self.wallet.interface.pending_transactions_for_notifications:
if tx: if tx:
self.wallet.interface.pending_transactions.remove(tx) self.wallet.interface.pending_transactions_for_notifications.remove(tx)
is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx) is_relevant, is_mine, v, fee = self.wallet.get_tx_value(tx)
if(v > 0): if(v > 0):
self.notify("New transaction received. %s BTC" % (self.format_amount(v))) self.notify("New transaction received. %s BTC" % (self.format_amount(v)))

2
lib/interface.py

@ -90,7 +90,7 @@ class Interface(threading.Thread):
self.unanswered_requests = {} self.unanswered_requests = {}
#banner #banner
self.banner = '' self.banner = ''
self.pending_transactions = [] self.pending_transactions_for_notifications= []
def queue_json_response(self, c): def queue_json_response(self, c):

6
lib/wallet.py

@ -682,8 +682,7 @@ class Wallet:
with self.transaction_lock: with self.transaction_lock:
self.transactions[tx_hash] = tx self.transactions[tx_hash] = tx
self.interface.pending_transactions.append(tx) self.interface.pending_transactions_for_notifications.append(tx)
self.interface.trigger_callback("new_transaction")
self.save_transactions() self.save_transactions()
if self.verifier and tx_height>0: if self.verifier and tx_height>0:
@ -1192,6 +1191,7 @@ class WalletSynchronizer(threading.Thread):
if self.was_updated and not requested_tx: if self.was_updated and not requested_tx:
self.interface.trigger_callback('updated') self.interface.trigger_callback('updated')
self.was_updated = False self.interface.trigger_callback("new_transaction") # Updated gets called too many times from other places as well; if we use that signal we get the notification three times
self.was_updated = False

Loading…
Cancel
Save