serinko 4 anni fa
parent
commit
76d604131c
2 ha cambiato i file con 42 aggiunte e 12 eliminazioni
  1. 20 4
      texts_cli.py
  2. 22 8
      whallets_cli.py

+ 20 - 4
texts_cli.py

@@ -118,14 +118,14 @@ def _enter_new_info(y):
     msg = f"\nPlease write a correct {y}:\n\n"
     return msg
 
-def _save_wallet_confirm(**new_wallet):
+def _save_wallet_confirm(addresses, **new_wallet):
     """print wallet and ask user if to save it"""
     network = new_wallet["Network"]
     username = new_wallet["username"]
     twtr = new_wallet["twitter address"]
     ens = new_wallet["ENS"]
     info = new_wallet["info/note"]
-    address = new_wallet["address"]
+    addr = list(addresses)
 
     line_0 = ("****","This wallet will be saved to your dictionary:")
     line = ("-----","----------------------------------------------")
@@ -134,7 +134,8 @@ def _save_wallet_confirm(**new_wallet):
     line_3 = (f"Twitter:",f"{twtr}")
     line_4 = (f"ENS:",f"{ens}")
     line_5 = (f"Info:", f"{info}")
-    line_6 = (f"Address:", f"{address}")
+
+
     table = [
         line_0,
         line,
@@ -143,10 +144,25 @@ def _save_wallet_confirm(**new_wallet):
         line_3,
         line_4,
         line_5,
-        line_6
         ]
+
+    for i, address in enumerate(addr):
+        line = (f"Address_{i}:", f"{address}")
+        table.append(line)
     return table
 
+def _confirm_entry():
+    """Asks user to confirm the wallet saving or repeat"""
+    msg_0 = \
+        "\nDo you want to save the wallet to the database?"\
+        "\n1 - YES\n2 - NO"
+    msg_1 = "\nThe wallet was saved to your database."
+    msg_2 = \
+        "\nDo you want to add another wallet?"\
+        "\n1 - YES\n2 - NO"
+
+    return msg_0, msg_1, msg_2
+
 
 # def _display_wallets(chain, user):
 #     """Text template for table of wallet display function"""

+ 22 - 8
whallets_cli.py

@@ -63,11 +63,27 @@ def _new_choice():
 
 def add_wallet():
     """A function to add wallet to the wallets_dict.json"""
-    new_wallet = get_inputs()
+    new_wallet, addresses = get_inputs()
 
-    print(tabulate(tc._save_wallet_confirm(**new_wallet)))
+    print(tabulate(tc._save_wallet_confirm(addresses, **new_wallet)))
+    confirm_entry()
 
 
+def confirm_entry():
+    x = input(tc._confirm_entry()[0])
+    if x == '1':
+        save_wallet()
+    x = input(tc._confirm_entry()[2])
+    if x == '1':
+        add_wallet()
+
+
+
+
+def save_wallet():
+    """Saves the wallet into the database/dictionary and informs the user"""
+    # SAVE THE WALLET FUNCTION!!!
+    print(tc._confirm_entry()[1])
 
 
 
@@ -79,16 +95,15 @@ def get_inputs():
     """Get infor to add a new wallet"""
     ntw_i = _check_network()
     network = tc._return_network(ntw_i)
+    addresses = []
     new_wallet = {
             "username":" ",
             "twitter address":" ",
             "ENS":" ",
             "info/note":" ",
-            "address": []
+            "address": addresses
     }
 
-    addresses = []
-
     for item, value in new_wallet.items():
         x = input(tc._prompt_new_info(item))
         new_item = check_wallet_item(ntw_i,x)
@@ -99,12 +114,11 @@ def get_inputs():
                 new_item = input(tc._ask_more_wallets()[1])
                 addresses.append(new_item)
                 y = input(tc._ask_more_wallets()[0])
-            new_wallet[item] = addresses
         new_wallet[item] = new_item
 
     new_wallet["Network"] = network
 
-    return new_wallet
+    return new_wallet, addresses
 
 def _check_network():
     """Check if the existing network"""
@@ -160,7 +174,7 @@ def _correct_item(x,z):
                 new_item = x
         break
     return new_item
-    
+