-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.py
200 lines (160 loc) · 5.47 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from config import *
import network
def change_address(config: dict):
clear_screen()
print(fgYELLOW + "Enter new address: " + fgWHITE)
new_address = inpt(fgYELLOW + "Address: " + fgWHITE)
# Check if address exists
type = "getAccount&account="+new_address
response = network.request(type, config)
if response.get("errorCode") != None:
print(fgRED + "Error: Account Address " + fgYELLOW + new_address + fgRED + " does not exist!" + fgWHITE)
inpt("Press any enter to continue...")
return
config["address"] = new_address
save_config(config)
print(fgGREEN + "Address changed!" + fgWHITE)
save_config(config)
inpt("Press any enter to continue...")
return config
def change_fee(config: dict):
clear_screen()
print(fgYELLOW + "\n\nExample: 0.00735 is 735000 in NQT. [0.00735×(10^8 )]" + fgWHITE)
new_fee = inpt(fgYELLOW + "Fee (in NQT): " + fgWHITE)
config["fee"] = int(new_fee)
save_config(config)
print(fgGREEN + "Fee changed!" + fgWHITE)
save_config(config)
inpt("Press any enter to continue...")
return config
def change_deadline(config: dict):
clear_screen()
print(fgYELLOW + "Enter new deadline (minutes): " + fgWHITE)
new_deadline = inpt(fgYELLOW + "Deadline: " + fgWHITE)
config["deadline"] = int(new_deadline)
save_config(config)
print(fgGREEN + "Deadline changed!" + fgWHITE)
save_config(config)
inpt("Press any enter to continue...")
return config
def clear_transactions(config: dict):
config["transactions"] = {}
save_config(config)
print(fgGREEN + "Transactions cleared!" + fgWHITE)
inpt("Press any enter to continue...")
return config
def edit_favorites(config: dict):
clear_screen()
print(fgYELLOW + "Edit Favorites")
print("[1] Add New Favorite")
print("[2] Remove Favorite")
print("[3] Clear Favorites")
print("[4] Back")
print(fgWHITE)
commands = {
"1": add_favorite,
"2": remove_favorite,
"3": clear_favorites,
"4": None
}
while True:
user_input = getch(fgYELLOW + "" + fgWHITE)
if user_input in commands.keys():
config = commands[user_input](config)
break
save_config(config)
inpt("Press any enter to continue...")
return config
def add_favorite(config: dict):
clear_screen()
address = inpt(fgYELLOW + "Address: " + fgWHITE)
name = inpt(fgYELLOW + "Name: " + fgWHITE)
config["favorites"][address] = name
save_config(config)
print(fgGREEN + "Favorite added!" + fgWHITE)
inpt("Press any enter to continue...")
return config
def remove_favorite(config: dict):
clear_screen()
print(fgYELLOW + "Remove Favorite")
# Input the address/name they want to remove
# If the address or name exists, remove it from the config["favorites"]
print(fgYELLOW + "Enter the address/name of the favorite to remove. " + fgWHITE)
user_input = inpt(fgYELLOW + "Address/Name: " + fgWHITE)
if user_input in config["favorites"].keys():
del config["favorites"][user_input]
print(fgGREEN + "Favorite removed!" + fgWHITE)
elif user_input in config["favorites"].values():
for key, value in config["favorites"].items():
if value == user_input:
del config["favorites"][key]
print(fgGREEN + "Favorite removed!" + fgWHITE)
break
else:
print(fgRED + "Favorite does not exist!" + fgWHITE)
save_config(config)
inpt("Press any enter to continue...")
return config
def clear_favorites(config: dict):
config["favorites"] = {}
save_config(config)
print(fgGREEN + "Favorites cleared!" + fgWHITE)
inpt("Press any enter to continue...")
return config
def change_host_or_port(config: dict):
while True:
clear_screen()
# Change host or port
print(fgYELLOW + "Change Host or Port" + fgWHITE)
print("[1] Change Host")
print("[2] Change Port")
print("[3] Back")
num = getch(fgYELLOW + ">" + fgWHITE)
if num == "1":
config["host"] = inpt(fgYELLOW + "Host: " + fgWHITE)
print(fgGREEN + "Host changed!" + fgWHITE)
elif num == "2":
config["port"] = inpt(fgYELLOW + "Port: " + fgWHITE)
print(fgGREEN + "Port changed!" + fgWHITE)
elif num == "3":
return config
else:
print(fgRED + "Invalid input!" + fgWHITE)
inpt("Press enter to continue...")
continue
return config
def settings(config: dict):
"""
Settings
1. Change Address
2. Change default fee
3. Change default deadline
4. Clear Transactions
5. Edit Favorites
6. Change Host/Port
7. Quit
"""
commands = {
"1": change_address,
"2": change_fee,
"3": change_deadline,
"4": clear_transactions,
"5": edit_favorites,
"6": change_host_or_port
}
while True:
clear_screen()
print(fgYELLOW + "Settings" + fgWHITE)
print("1. Change Address")
print("2. Change default fee")
print("3. Change default deadline")
print("4. Clear Transactions")
print("5. Edit Favorites")
print("6. Change Host/Port")
print("7. Quit")
user_input = getch(fgYELLOW + "> " + fgWHITE)
if user_input in commands.keys():
commands[user_input](config)
elif user_input == "7":
break
pass