Browse Source

kivy: set_paid for paid invoices

283
ThomasV 9 years ago
parent
commit
41f6fec2ac
  1. 10
      gui/kivy/main.kv
  2. 20
      gui/kivy/main_window.py
  3. 8
      gui/kivy/uix/screens.py
  4. 6
      gui/kivy/uix/ui_screens/send.kv
  5. 4
      gui/qt/main_window.py
  6. 9
      lib/paymentrequest.py

10
gui/kivy/main.kv

@ -177,20 +177,18 @@
<SendReceiveBlueBottom@GridLayout> <SendReceiveBlueBottom@GridLayout>
item_height: dp(42)
foreground_color: .843, .914, .972, 1
cols: 1
padding: '12dp', 0
canvas.before: canvas.before:
Color: Color:
#rgba: .238, .585, .878, 1
rgba: 0.192, .498, 0.745, 1 rgba: 0.192, .498, 0.745, 1
BorderImage: BorderImage:
source: 'atlas://gui/kivy/theming/light/card_bottom' source: 'atlas://gui/kivy/theming/light/card_bottom'
size: self.size size: self.size
pos: self.pos pos: self.pos
item_height: dp(42)
foreground_color: .843, .914, .972, 1
cols: 1
padding: '12dp', 0
<CardSeparator@Widget> <CardSeparator@Widget>

20
gui/kivy/main_window.py

@ -4,6 +4,7 @@ import time
import datetime import datetime
import traceback import traceback
from decimal import Decimal from decimal import Decimal
import threading
import electrum import electrum
from electrum import WalletStorage, Wallet from electrum import WalletStorage, Wallet
@ -682,7 +683,6 @@ class ElectrumWindow(App):
d.open() d.open()
def sign_tx(self, *args): def sign_tx(self, *args):
import threading
threading.Thread(target=self._sign_tx, args=args).start() threading.Thread(target=self._sign_tx, args=args).start()
def _sign_tx(self, tx, password, on_success, on_failure): def _sign_tx(self, tx, password, on_success, on_failure):
@ -693,13 +693,23 @@ class ElectrumWindow(App):
return return
Clock.schedule_once(lambda dt: on_success(tx)) 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(): if self.network and self.network.is_connected():
self.show_info(_('Sending')) self.show_info(_('Sending'))
ok, txid = self.wallet.sendtx(tx) threading.Thread(target=self._broadcast_thread, args=(tx, on_complete)).start()
self.show_info(txid)
else: else:
self.show_info(_('Cannot broadcast transaction') + '\n' + _('Not connected')) self.show_info(_('Cannot broadcast transaction') + ':\n' + _('Not connected'))
def description_dialog(self, screen): def description_dialog(self, screen):
from uix.dialogs.label_dialog import LabelDialog from uix.dialogs.label_dialog import LabelDialog

8
gui/kivy/uix/screens.py

@ -235,6 +235,12 @@ class SendScreen(CScreen):
self.app.invoices.add(pr) self.app.invoices.add(pr)
self.app.update_tab('invoices') self.app.update_tab('invoices')
self.app.show_info(_("Invoice saved")) 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): def do_paste(self):
contents = unicode(self.app._clipboard.paste()) contents = unicode(self.app._clipboard.paste())
@ -287,7 +293,7 @@ class SendScreen(CScreen):
def send_tx(self, tx, password): def send_tx(self, tx, password):
def on_success(tx): def on_success(tx):
if tx.is_complete(): if tx.is_complete():
self.app.broadcast(tx) self.app.broadcast(tx, self.payment_request)
else: else:
self.app.tx_dialog(tx) self.app.tx_dialog(tx)
def on_failure(error): def on_failure(error):

6
gui/kivy/uix/ui_screens/send.kv

@ -35,7 +35,7 @@ SendScreen:
disabled: True disabled: True
shorten: True shorten: True
CardSeparator: CardSeparator:
opacity: message_selection.opacity opacity: int(not root.is_pr)
color: blue_bottom.foreground_color color: blue_bottom.foreground_color
BoxLayout: BoxLayout:
size_hint: 1, None size_hint: 1, None
@ -53,7 +53,7 @@ SendScreen:
disabled: root.is_pr disabled: root.is_pr
on_release: Clock.schedule_once(lambda dt: app.amount_dialog(s, True)) on_release: Clock.schedule_once(lambda dt: app.amount_dialog(s, True))
CardSeparator: CardSeparator:
opacity: message_selection.opacity opacity: int(not root.is_pr)
color: blue_bottom.foreground_color color: blue_bottom.foreground_color
BoxLayout: BoxLayout:
id: message_selection id: message_selection
@ -67,7 +67,7 @@ SendScreen:
pos_hint: {'center_y': .5} pos_hint: {'center_y': .5}
BlueButton: BlueButton:
id: description 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 disabled: root.is_pr
on_release: Clock.schedule_once(lambda dt: app.description_dialog(s)) on_release: Clock.schedule_once(lambda dt: app.description_dialog(s))
BoxLayout: BoxLayout:

4
gui/qt/main_window.py

@ -1322,8 +1322,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
status, msg = self.wallet.sendtx(tx) status, msg = self.wallet.sendtx(tx)
if not status: if not status:
return False, msg return False, msg
key = pr.get_id() pr.set_paid(tx.hash())
self.invoices.set_paid(key, tx.hash()) self.invoices.save()
self.payment_request = None self.payment_request = None
refund_address = self.wallet.addresses()[0] refund_address = self.wallet.addresses()[0]
ack_status, ack_msg = pr.send_ack(str(tx), refund_address) ack_status, ack_msg = pr.send_ack(str(tx), refund_address)

9
lib/paymentrequest.py

@ -102,7 +102,8 @@ class PaymentRequest:
self.payment_url = self.details.payment_url self.payment_url = self.details.payment_url
def is_pr(self): 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): def verify(self, contacts):
if not self.raw: if not self.raw:
@ -258,6 +259,8 @@ class PaymentRequest:
print "PaymentACK message received: %s" % paymntack.memo print "PaymentACK message received: %s" % paymntack.memo
return True, paymntack.memo return True, paymntack.memo
def set_paid(self, tx_hash):
self.tx = tx_hash
def make_unsigned_request(req): def make_unsigned_request(req):
@ -469,10 +472,6 @@ class InvoiceStore(object):
def get(self, k): def get(self, k):
return self.invoices.get(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): def sorted_list(self):
# sort # sort
return self.invoices.values() return self.invoices.values()

Loading…
Cancel
Save