serinko 4 лет назад
Родитель
Сommit
20e8e29580
2 измененных файлов с 36 добавлено и 17 удалено
  1. 15 10
      texts_cli.py
  2. 21 7
      whallets_cli.py

+ 15 - 10
texts_cli.py

@@ -1,7 +1,7 @@
 """A module with all the display info for whallets-cli."""
 from tabulate import tabulate
 
-# import whallets_cli as cli
+import whallets_cli as cli
 
 def _welcome_message():
     """welcoming message to the cli"""
@@ -89,13 +89,18 @@ def _prompt_ens():
     msg = "\nEnter user's ENS:\n"
     return msg
 
-def _check_wallet_result(chain, name, addr, twtr, ens):
-    """Messages informing about existing wallet"""
-    ix = cli.check_wallet(chain, name, addr, twtr, ens)
-    if ix < 4:
-        items = ['name','address','twitter','ens']
-        item = items[ix]
-        msg = f"This {item} is already saved in the databse."
-    else:
-        msg = "New wallet was saved."
+
+def _display_wallet_check_result(y):
+    """displays answer based on added data"""
+    msg_0 = \
+        f"{x.title()} already exists in your wallet dictionary."\
+        f"\nDo you want to continue?\n1 - YES\n2 - NO (change the item)"\
+        f"{_menu_choice()}"
+    msg_1 = \
+        f"The new wallet will be saved with already existing info:\n"
+    return msg_0, msg_1
+
+def _enter_new_info(y):
+    """Asks user for a correct information"""
+    msg = f"\nPlease write a correct {y}:\n\n"
     return msg

+ 21 - 7
whallets_cli.py

@@ -61,9 +61,23 @@ def _new_choice():
 
 def add_wallet():
     """A function to add wallet to the wallets_dict.json"""
-    chain, name, addr, inf, twtr, ens = _get_inputs()
-    msg = tc._check_wallet_result(chain, name, addr, twtr, ens)
-    print(msg)
+    ntw_i, name, addr, inf, twtr, ens = _get_inputs()
+    x = check_wallet(ntw_i, name, addr, twtr, ens)
+    if x[0] != 4:
+        y = x[1]
+        new_item = _correct_item(y)
+
+
+def _correct_item(y):
+    """Allows user to rewrite an exisitng item in the wallet"""
+    z = (input(tc._display_wallet_check_result(y)[0]))
+    if z =='1':
+        print(tc._display_wallet_check_result(y)[1])
+        return y
+
+    elif z == '2':
+        new_item = input(tc._enter_new_info(y))
+        return new_item
 
 def remove_wallet():
     """Removes wallet from the wallet dictionary"""
@@ -105,13 +119,13 @@ def check_wallet(ntw_i,name, addr, twtr, ens):
         twitter = value['twitter']
         ens_saved = value['ens']
         if user == name:
-            x = 0
+            x = [0,'name']
         elif addr in wallets.values():
-            x = 1
+            x = [1, 'address']
         elif twtr == twitter:
-            x = 2
+            x = [2, 'twitter']
         elif ens == ens_saved:
-            x = 3
+            x = [3, 'ENS']
         else:
             x = 4
         return x