Add Coinbase exchange rate option
[electrum-nvc.git] / plugins / pointofsale.py
index 8bf1cdf..27f4ccd 100644 (file)
@@ -1,6 +1,7 @@
 import re
 import platform
 from decimal import Decimal
+from urllib import quote
 
 from PyQt4.QtGui import *
 from PyQt4.QtCore import *
@@ -65,7 +66,10 @@ class QR_Window(QWidget):
         amount_text = ''
         if amount:
             if currency:
-                self.amount = Decimal(amount) / self.exchanger.exchange(1, currency) if currency else amount
+                try:
+                    self.amount = Decimal(amount) / self.exchanger.exchange(1, currency) if currency else amount
+                except Exception:
+                    self.amount = None
             else:
                 self.amount = Decimal(amount)
             self.amount = self.amount.quantize(Decimal('1.0000'))
@@ -73,6 +77,9 @@ class QR_Window(QWidget):
             if currency:
                 amount_text += "<span style='font-size: 18pt'>%s %s</span><br/>" % (amount, currency)
             amount_text += "<span style='font-size: 21pt'>%s</span> <span style='font-size: 16pt'>BTC</span> " % str(self.amount) 
+        else:
+            self.amount = None
+            
         self.amount_label.setText(amount_text)
 
         self.label = label
@@ -83,9 +90,11 @@ class QR_Window(QWidget):
         if self.amount is not None:
             msg += '?amount=%s'%(str( self.amount))
             if self.label is not None:
-                msg += '&label=%s'%(self.label)
+                encoded_label = quote(self.label)
+                msg += '&label=%s'%(encoded_label)
         elif self.label is not None:
-            msg += '?label=%s'%(self.label)
+            encoded_label = quote(self.label)
+            msg += '?label=%s'%(encoded_label)
             
         self.qrw.set_addr( msg )
 
@@ -245,7 +254,7 @@ class Plugin(BasePlugin):
         item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
 
     
-    def receive_menu(self, menu):
+    def receive_menu(self, menu, addr):
         menu.addAction(_("Request amount"), self.edit_amount)
         menu.addAction(_("Show Invoice"), lambda: self.toggle_QR_window(True))