commit 41f6fec2acb19435eb8f87af96c391d2489b6c66
parent cdbc564fb3da70207256604999365a10415ebb04
Author: ThomasV <thomasv@electrum.org>
Date: Fri, 19 Feb 2016 13:53:01 +0100
kivy: set_paid for paid invoices
Diffstat:
6 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/gui/kivy/main.kv b/gui/kivy/main.kv
@@ -177,20 +177,18 @@
<SendReceiveBlueBottom@GridLayout>
+ item_height: dp(42)
+ foreground_color: .843, .914, .972, 1
+ cols: 1
+ padding: '12dp', 0
canvas.before:
Color:
- #rgba: .238, .585, .878, 1
rgba: 0.192, .498, 0.745, 1
BorderImage:
source: 'atlas://gui/kivy/theming/light/card_bottom'
size: self.size
pos: self.pos
- item_height: dp(42)
- foreground_color: .843, .914, .972, 1
- cols: 1
- padding: '12dp', 0
-
<CardSeparator@Widget>
diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py
@@ -4,6 +4,7 @@ import time
import datetime
import traceback
from decimal import Decimal
+import threading
import electrum
from electrum import WalletStorage, Wallet
@@ -682,7 +683,6 @@ class ElectrumWindow(App):
d.open()
def sign_tx(self, *args):
- import threading
threading.Thread(target=self._sign_tx, args=args).start()
def _sign_tx(self, tx, password, on_success, on_failure):
@@ -693,13 +693,23 @@ class ElectrumWindow(App):
return
Clock.schedule_once(lambda dt: on_success(tx))
- def broadcast(self, tx):
+ def _broadcast_thread(self, tx, on_complete):
+ ok, txid = self.wallet.sendtx(tx)
+ Clock.schedule_once(lambda dt: on_complete(ok, txid))
+
+ def broadcast(self, tx, pr=None):
+ def on_complete(ok, txid):
+ self.show_info(txid)
+ if ok and pr:
+ pr.set_paid(tx.hash())
+ self.invoices.save()
+ self.update_tab('invoices')
+
if self.network and self.network.is_connected():
self.show_info(_('Sending'))
- ok, txid = self.wallet.sendtx(tx)
- self.show_info(txid)
+ threading.Thread(target=self._broadcast_thread, args=(tx, on_complete)).start()
else:
- self.show_info(_('Cannot broadcast transaction') + '\n' + _('Not connected'))
+ self.show_info(_('Cannot broadcast transaction') + ':\n' + _('Not connected'))
def description_dialog(self, screen):
from uix.dialogs.label_dialog import LabelDialog
diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py
@@ -235,6 +235,12 @@ class SendScreen(CScreen):
self.app.invoices.add(pr)
self.app.update_tab('invoices')
self.app.show_info(_("Invoice saved"))
+ if pr.is_pr():
+ self.screen.is_pr = True
+ self.payment_request = pr
+ else:
+ self.screen.is_pr = False
+ self.payment_request = None
def do_paste(self):
contents = unicode(self.app._clipboard.paste())
@@ -287,7 +293,7 @@ class SendScreen(CScreen):
def send_tx(self, tx, password):
def on_success(tx):
if tx.is_complete():
- self.app.broadcast(tx)
+ self.app.broadcast(tx, self.payment_request)
else:
self.app.tx_dialog(tx)
def on_failure(error):
diff --git a/gui/kivy/uix/ui_screens/send.kv b/gui/kivy/uix/ui_screens/send.kv
@@ -35,7 +35,7 @@ SendScreen:
disabled: True
shorten: True
CardSeparator:
- opacity: message_selection.opacity
+ opacity: int(not root.is_pr)
color: blue_bottom.foreground_color
BoxLayout:
size_hint: 1, None
@@ -53,7 +53,7 @@ SendScreen:
disabled: root.is_pr
on_release: Clock.schedule_once(lambda dt: app.amount_dialog(s, True))
CardSeparator:
- opacity: message_selection.opacity
+ opacity: int(not root.is_pr)
color: blue_bottom.foreground_color
BoxLayout:
id: message_selection
@@ -67,7 +67,7 @@ SendScreen:
pos_hint: {'center_y': .5}
BlueButton:
id: description
- text: s.message if s.message else _('Description')
+ text: s.message if s.message else (_('No Description') if root.is_pr else _('Description'))
disabled: root.is_pr
on_release: Clock.schedule_once(lambda dt: app.description_dialog(s))
BoxLayout:
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -1322,8 +1322,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
status, msg = self.wallet.sendtx(tx)
if not status:
return False, msg
- key = pr.get_id()
- self.invoices.set_paid(key, tx.hash())
+ pr.set_paid(tx.hash())
+ self.invoices.save()
self.payment_request = None
refund_address = self.wallet.addresses()[0]
ack_status, ack_msg = pr.send_ack(str(tx), refund_address)
diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py
@@ -102,7 +102,8 @@ class PaymentRequest:
self.payment_url = self.details.payment_url
def is_pr(self):
- return self.get_outputs() != [(TYPE_ADDRESS, self.get_requestor(), self.get_amount())]
+ return self.get_amount() != 0
+ #return self.get_outputs() != [(TYPE_ADDRESS, self.get_requestor(), self.get_amount())]
def verify(self, contacts):
if not self.raw:
@@ -258,6 +259,8 @@ class PaymentRequest:
print "PaymentACK message received: %s" % paymntack.memo
return True, paymntack.memo
+ def set_paid(self, tx_hash):
+ self.tx = tx_hash
def make_unsigned_request(req):
@@ -469,10 +472,6 @@ class InvoiceStore(object):
def get(self, k):
return self.invoices.get(k)
- def set_paid(self, key, tx_hash):
- self.invoices[key].tx = tx_hash
- self.save()
-
def sorted_list(self):
# sort
return self.invoices.values()