New port numbers
[electrum-nvc.git] / gui / android.py
index c91539d..51af1d7 100644 (file)
@@ -22,9 +22,9 @@
 from __future__ import absolute_import
 import android
 
-from electrum import SimpleConfig, Wallet, WalletStorage, format_satoshis, mnemonic_encode, mnemonic_decode
-from electrum.bitcoin import is_valid
-from electrum import util
+from electrum_nvc import SimpleConfig, Wallet, WalletStorage, format_satoshis, mnemonic_encode, mnemonic_decode
+from electrum_nvc.bitcoin import is_valid
+from electrum_nvc import util
 from decimal import Decimal
 import datetime, re
 
@@ -44,10 +44,12 @@ def modal_input(title, msg, value = None, etype=None):
     droid.dialogShow()
     response = droid.dialogGetResponse()
     result = response.result
+    droid.dialogDismiss()
+
     if result is None:
         print "modal input: result is none"
-        return False
-    droid.dialogDismiss()
+        return modal_input(title, msg, value, etype)
+
     if result.get('which') == 'positive':
         return result.get('value')
 
@@ -58,10 +60,12 @@ def modal_question(q, msg, pos_text = 'OK', neg_text = 'Cancel'):
     droid.dialogShow()
     response = droid.dialogGetResponse()
     result = response.result
+    droid.dialogDismiss()
+
     if result is None:
         print "modal question: result is none"
-        return False
-    droid.dialogDismiss()
+        return modal_question(q,msg, pos_text, neg_text)
+
     return result.get('which') == 'positive'
 
 def edit_label(addr):
@@ -162,7 +166,7 @@ def make_layout(s, scrollable = False):
 
         <TextView
           android:id="@+id/textElectrum"
-          android:text="Electrum"
+          android:text="Electrum-NVC"
           android:textSize="7pt"
           android:textColor="#ff4444ff"
           android:gravity="left"
@@ -341,7 +345,7 @@ def get_history_values(n):
                 time_str = str( dt.time() )
             else:
                 time_str = str( dt.date() )
-        except:
+        except Exception:
             time_str = 'pending'
 
         conf_str = 'v' if conf else 'o'
@@ -454,7 +458,7 @@ def pay_to(recipient, amount, fee, label):
 
     try:
         tx = wallet.mktx( [(recipient, amount)], password, fee)
-    except BaseException, e:
+    except Exception as e:
         modal_dialog('error', e.message)
         droid.dialogDismiss()
         return
@@ -483,8 +487,8 @@ def make_new_contact():
     if r:
         data = r['extras']['SCAN_RESULT']
         if data:
-            if re.match('^bitcoin:', data):
-                address, _, _, _, _, _, _ = util.parse_url(data)
+            if re.match('^novacoin:', data):
+                address, _, _, _, _ = util.parse_URI(data)
             elif is_valid(data):
                 address = data
             else:
@@ -591,12 +595,12 @@ def payto_loop():
                 amount = droid.fullQueryDetail('amount').result.get('text')
 
                 if not is_valid(recipient):
-                    modal_dialog('Error','Invalid Bitcoin address')
+                    modal_dialog('Error','Invalid Novacoin address')
                     continue
 
                 try:
-                    amount = int( 100000000 * Decimal(amount) )
-                except:
+                    amount = int( 1000000 * Decimal(amount) )
+                except Exception:
                     modal_dialog('Error','Invalid amount')
                     continue
 
@@ -614,8 +618,8 @@ def payto_loop():
                 if r:
                     data = r['extras']['SCAN_RESULT']
                     if data:
-                        if re.match('^bitcoin:', data):
-                            payto, amount, label, _, _, _, _ = util.parse_url(data)
+                        if re.match('^novacoin:', data):
+                            payto, amount, label, _, _ = util.parse_URI(data)
                             droid.fullSetProperty("recipient", "text",payto)
                             droid.fullSetProperty("amount", "text", amount)
                             droid.fullSetProperty("label", "text", label)
@@ -713,8 +717,8 @@ def show_seed():
         password = None
     
     try:
-        seed = wallet.decode_seed(password)
-    except:
+        seed = wallet.get_seed(password)
+    except Exception:
         modal_dialog('error','incorrect password')
         return
 
@@ -729,8 +733,8 @@ def change_password_dialog():
         password = None
 
     try:
-        seed = wallet.decode_seed(password)
-    except:
+        wallet.get_seed(password)
+    except Exception:
         modal_dialog('error','incorrect password')
         return
 
@@ -744,7 +748,7 @@ def change_password_dialog():
             modal_dialog('error','passwords do not match')
             return
 
-    wallet.update_password(seed, password, new_password)
+    wallet.update_password(password, new_password)
     if new_password:
         modal_dialog('Password updated','your wallet is encrypted')
     else:
@@ -756,12 +760,12 @@ def settings_loop():
 
 
     def set_listview():
-        server, port, p = network.default_server.split(':')
-        fee = str( Decimal( wallet.fee)/100000000 )
+        host, port, p = network.default_server.split(':')
+        fee = str( Decimal( wallet.fee)/1000000 )
         is_encrypted = 'yes' if wallet.use_encryption else 'no'
         protocol = protocol_name(p)
         droid.fullShow(settings_layout)
-        droid.fullSetList("myListView",['Server: ' + server, 'Protocol: '+ protocol, 'Port: '+port, 'Transaction fee: '+fee, 'Password: '+is_encrypted, 'Seed'])
+        droid.fullSetList("myListView",['Server: ' + host, 'Protocol: '+ protocol, 'Port: '+port, 'Transaction fee: '+fee, 'Password: '+is_encrypted, 'Seed'])
 
     set_listview()
 
@@ -803,11 +807,11 @@ def settings_loop():
                     network_changed = True
 
             elif pos == "3": #fee
-                fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ', str( Decimal( wallet.fee)/100000000 ), "numberDecimal")
+                fee = modal_input('Transaction fee', 'The fee will be this amount multiplied by the number of inputs in your transaction. ', str( Decimal( wallet.fee)/1000000 ), "numberDecimal")
                 if fee:
                     try:
-                        fee = int( 100000000 * Decimal(fee) )
-                    except:
+                        fee = int( 1000000 * Decimal(fee) )
+                    except Exception:
                         modal_dialog('error','invalid fee value')
                     wallet.set_fee(fee)
                     set_listview()
@@ -824,7 +828,7 @@ def settings_loop():
                 auto_connect = False
                 try:
                     network.set_parameters(host, port, protocol, proxy, auto_connect)
-                except:
+                except Exception:
                     modal_dialog('error','invalid server')
                 set_listview()
 
@@ -899,8 +903,7 @@ class ElectrumGui:
             if action == 'create':
                 wallet.init_seed(None)
                 self.show_seed()
-                wallet.save_seed()
-                wallet.create_accounts()
+                wallet.save_seed(None)
                 wallet.synchronize()  # generate first addresses offline
                 
             elif action == 'restore':
@@ -908,7 +911,7 @@ class ElectrumGui:
                 if not seed:
                     exit()
                 wallet.init_seed(str(seed))
-                wallet.save_seed()
+                wallet.save_seed(None)
             else:
                 exit()
 
@@ -918,7 +921,7 @@ class ElectrumGui:
                 if not self.restore_wallet():
                     exit()
 
-            self.password_dialog(wallet)
+            self.password_dialog()
 
         else:
             wallet = Wallet(storage)
@@ -983,7 +986,7 @@ class ElectrumGui:
             m = modal_input('Mnemonic','please enter your code')
             try:
                 seed = mnemonic_decode(m.split(' '))
-            except:
+            except Exception:
                 modal_dialog('error: could not decode this seed')
                 return
 
@@ -993,9 +996,6 @@ class ElectrumGui:
     def network_dialog(self):
         return True
 
-    def verify_seed(self):
-        wallet.save_seed()
-        return True
         
     def show_seed(self):
         modal_dialog('Your seed is:', wallet.seed)