Repository navigation
Expand file tree
/
Copy pathcrypto_wallet.py
More file actions
2786 lines (2208 loc) · 125 KB
/
Copy pathcrypto_wallet.py
File metadata and controls
2786 lines (2208 loc) · 125 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Low Cap Charter Wallet - Professional Cryptocurrency Wallet
Enhanced with USD value display, improved blockchain connectivity, and MULTI-SEED PHRASE SUPPORT
"""
import sys
import os
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
import threading
import json
import time
from pathlib import Path
from typing import Optional, Dict, Any
from decimal import Decimal
# Import our improved modules
from wallet_core import WalletCore
from transaction_manager import ImprovedTransactionManager, GasSettings
from security_manager import SecurityManager
from storage_manager import StorageManager
from ui_components import ModernUI
from qr_generator import QRGenerator
from price_fetcher import PriceFetcher
# Import the improved network manager
try:
from network_manager import ImprovedNetworkManager
except ImportError:
# Fallback to original if improved version not available
from network_manager import NetworkManager as ImprovedNetworkManager
class ImprovedCryptoWallet:
def __init__(self):
self.root = tk.Tk()
self.root.title("Low Cap Charter Wallet")
self.root.geometry("1200x800")
self.root.configure(bg="#1a1a1a")
# Initialize improved managers
self.wallet_core = WalletCore()
self.network_manager = ImprovedNetworkManager()
self.transaction_manager = ImprovedTransactionManager()
self.security_manager = SecurityManager()
self.storage_manager = StorageManager()
self.qr_generator = QRGenerator()
self.ui = ModernUI(self.root)
self.price_fetcher = PriceFetcher()
# Current state
self.current_account = None
self.current_network = None
self.current_wallet_id = None
self.accounts = []
self.is_locked = True
# UI variables
self.address_var = tk.StringVar()
self.balance_refresh_active = False
self.auto_refresh_enabled = True
self.last_balance_check = 0
self.balance_cache = {}
# Initialize UI and load data
self.setup_ui()
self.load_wallet_data()
self.start_background_tasks()
def setup_ui(self):
"""Setup the main user interface"""
# Create main frame
main_frame = ttk.Frame(self.root, style="Dark.TFrame")
main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Top bar with wallet info and network selector
self.create_top_bar(main_frame)
# Main content area with tabs
self.create_main_content(main_frame)
# Bottom status bar
self.create_status_bar(main_frame)
# Setup styles
self.ui.setup_styles()
def create_top_bar(self, parent):
"""Create enhanced top navigation bar"""
# Clear existing top bar
for widget in parent.winfo_children():
if isinstance(widget, ttk.Frame) and widget.winfo_children():
first_child = widget.winfo_children()[0]
if isinstance(first_child, ttk.Label) and "Crypto Wallet" in first_child.cget("text"):
widget.destroy()
break
top_frame = ttk.Frame(parent, style="Dark.TFrame")
top_frame.pack(fill=tk.X, pady=(0, 10))
# Logo and title
title_frame = ttk.Frame(top_frame, style="Dark.TFrame")
title_frame.pack(side=tk.LEFT, fill=tk.Y)
title_label = ttk.Label(title_frame, text="🚀 Low Cap Charter Wallet",
font=("Arial", 16, "bold"), style="Title.TLabel")
title_label.pack(side=tk.LEFT, padx=(0, 20))
# Connection status indicator
status_frame = ttk.Frame(title_frame, style="Dark.TFrame")
status_frame.pack(side=tk.LEFT, padx=(0, 20))
self.connection_indicator = tk.Label(status_frame, text="🔴", font=("Arial", 12))
self.connection_indicator.pack(side=tk.LEFT)
self.connection_status_label = ttk.Label(status_frame, text="Disconnected",
style="Light.TLabel", font=("Arial", 10))
self.connection_status_label.pack(side=tk.LEFT, padx=(5, 0))
# Network selector
network_frame = ttk.Frame(top_frame, style="Dark.TFrame")
network_frame.pack(side=tk.RIGHT, fill=tk.Y)
ttk.Label(network_frame, text="Network:", style="Light.TLabel").pack(side=tk.LEFT, padx=(0, 5))
self.network_var = tk.StringVar()
self.network_combo = ttk.Combobox(network_frame, textvariable=self.network_var,
values=list(self.network_manager.get_networks().keys()),
state="readonly", width=20)
self.network_combo.pack(side=tk.LEFT, padx=(0, 10))
self.network_combo.bind("<<ComboboxSelected>>", self.on_network_change)
self.network_combo.set("Ethereum Mainnet")
# Wallet controls
controls_frame = ttk.Frame(network_frame, style="Dark.TFrame")
controls_frame.pack(side=tk.RIGHT)
if self.is_locked:
unlock_btn = self.ui.create_button(controls_frame, "🔓 Unlock Wallet",
self.unlock_wallet, "primary")
unlock_btn.pack(side=tk.LEFT, padx=2)
else:
lock_btn = self.ui.create_button(controls_frame, "🔒 Lock Wallet",
self.lock_wallet, "secondary")
lock_btn.pack(side=tk.LEFT, padx=2)
# Auto-refresh toggle
self.auto_refresh_var = tk.BooleanVar(value=True)
auto_refresh_check = ttk.Checkbutton(controls_frame, text="Auto Refresh",
variable=self.auto_refresh_var,
command=self.toggle_auto_refresh)
auto_refresh_check.pack(side=tk.LEFT, padx=5)
def create_main_content(self, parent):
"""Create main content area with tabs"""
# Create notebook for tabs
self.notebook = ttk.Notebook(parent, style="Dark.TNotebook")
self.notebook.pack(fill=tk.BOTH, expand=True)
# Wallet tab
self.wallet_tab = ttk.Frame(self.notebook, style="Dark.TFrame")
self.notebook.add(self.wallet_tab, text="💰 Wallet")
self.create_enhanced_wallet_tab()
# Send tab
self.send_tab = ttk.Frame(self.notebook, style="Dark.TFrame")
self.notebook.add(self.send_tab, text="📤 Send")
self.create_enhanced_send_tab()
# Receive tab
self.receive_tab = ttk.Frame(self.notebook, style="Dark.TFrame")
self.notebook.add(self.receive_tab, text="📥 Receive")
self.create_enhanced_receive_tab()
# Accounts tab - NEW: Now with multi-wallet support
self.accounts_tab = ttk.Frame(self.notebook, style="Dark.TFrame")
self.notebook.add(self.accounts_tab, text="👤 Accounts")
self.create_accounts_tab()
# Settings tab
self.settings_tab = ttk.Frame(self.notebook, style="Dark.TFrame")
self.notebook.add(self.settings_tab, text="⚙️ Settings")
self.create_settings_tab()
def create_enhanced_wallet_tab(self):
"""Create enhanced wallet overview tab with real balance"""
# Balance display with detailed info
balance_frame = ttk.LabelFrame(self.wallet_tab, text="Portfolio Overview",
style="Dark.TLabelframe")
balance_frame.pack(fill=tk.X, padx=10, pady=10)
# Main balance display
balance_info_frame = ttk.Frame(balance_frame, style="Dark.TFrame")
balance_info_frame.pack(fill=tk.X, padx=10, pady=10)
self.balance_label = ttk.Label(balance_info_frame, text="0.00 ETH",
font=("Arial", 24, "bold"), style="Balance.TLabel")
self.balance_label.pack(side=tk.LEFT)
# Balance controls
balance_controls = ttk.Frame(balance_info_frame, style="Dark.TFrame")
balance_controls.pack(side=tk.RIGHT)
refresh_btn = self.ui.create_icon_button(balance_controls, "🔄",
self.manual_refresh_balance,
"Refresh Balance")
refresh_btn.pack(side=tk.RIGHT, padx=(10, 0))
# Additional balance info
balance_details_frame = ttk.Frame(balance_frame, style="Dark.TFrame")
balance_details_frame.pack(fill=tk.X, padx=10, pady=(0, 10))
self.usd_balance_label = ttk.Label(balance_details_frame, text="$0.00 USD",
font=("Arial", 14), style="Light.TLabel")
self.usd_balance_label.pack(side=tk.LEFT)
self.balance_status_label = ttk.Label(balance_details_frame, text="",
font=("Arial", 10), style="Light.TLabel")
self.balance_status_label.pack(side=tk.RIGHT)
# Quick actions with improved layout
actions_frame = ttk.LabelFrame(self.wallet_tab, text="Quick Actions",
style="Dark.TLabelframe")
actions_frame.pack(fill=tk.X, padx=10, pady=10)
actions_inner = ttk.Frame(actions_frame, style="Dark.TFrame")
actions_inner.pack(fill=tk.X, padx=10, pady=10)
send_btn = self.ui.create_button(actions_inner, "📤 Send Funds",
lambda: self.notebook.select(1), "primary")
send_btn.pack(side=tk.LEFT, padx=5)
receive_btn = self.ui.create_button(actions_inner, "📥 Receive Funds",
lambda: self.notebook.select(2), "secondary")
receive_btn.pack(side=tk.LEFT, padx=5)
history_btn = self.ui.create_button(actions_inner, "📊 View History",
self.view_transaction_history, "accent")
history_btn.pack(side=tk.LEFT, padx=5)
test_btn = self.ui.create_button(actions_inner, "🧪 Test Connection",
self.test_network_connection, "secondary")
test_btn.pack(side=tk.LEFT, padx=5)
# Transaction history with enhanced display
history_frame = ttk.LabelFrame(self.wallet_tab, text="Recent Transactions",
style="Dark.TLabelframe")
history_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Transaction controls
tx_controls_frame = ttk.Frame(history_frame, style="Dark.TFrame")
tx_controls_frame.pack(fill=tk.X, padx=10, pady=(10, 5))
refresh_tx_btn = self.ui.create_button(tx_controls_frame, "🔄 Refresh Transactions",
self.refresh_transaction_history, "secondary")
refresh_tx_btn.pack(side=tk.LEFT, padx=5)
# Treeview for transactions
tx_tree_frame = ttk.Frame(history_frame, style="Dark.TFrame")
tx_tree_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=(0, 10))
columns = ("Date", "Type", "Amount", "Address", "Status", "Hash")
self.tx_tree = ttk.Treeview(tx_tree_frame, columns=columns, show="headings",
height=8, style="Dark.Treeview")
# Configure columns
column_widths = {"Date": 120, "Type": 80, "Amount": 120, "Address": 150, "Status": 80, "Hash": 100}
for col in columns:
self.tx_tree.heading(col, text=col)
self.tx_tree.column(col, width=column_widths.get(col, 100))
scrollbar = ttk.Scrollbar(tx_tree_frame, orient=tk.VERTICAL, command=self.tx_tree.yview)
self.tx_tree.configure(yscrollcommand=scrollbar.set)
self.tx_tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Bind double-click to view transaction details
self.tx_tree.bind("<Double-1>", self.view_transaction_details)
def create_enhanced_send_tab(self):
"""Create enhanced send transaction tab"""
# Send form with improved validation
form_frame = ttk.LabelFrame(self.send_tab, text="Send Transaction",
style="Dark.TLabelframe")
form_frame.pack(fill=tk.X, padx=20, pady=20)
# To address with validation
ttk.Label(form_frame, text="To Address:", style="Light.TLabel").grid(row=0, column=0,
sticky=tk.W, padx=10, pady=5)
to_frame = ttk.Frame(form_frame, style="Dark.TFrame")
to_frame.grid(row=0, column=1, padx=10, pady=5, sticky=tk.EW)
self.to_address_var = tk.StringVar()
self.to_address_var.trace('w', self.validate_address)
to_entry = ttk.Entry(to_frame, textvariable=self.to_address_var, width=45)
to_entry.pack(side=tk.LEFT, fill=tk.X, expand=True)
self.address_status_label = ttk.Label(to_frame, text="", style="Light.TLabel")
self.address_status_label.pack(side=tk.RIGHT, padx=(10, 0))
# Amount with balance check
ttk.Label(form_frame, text="Amount:", style="Light.TLabel").grid(row=1, column=0,
sticky=tk.W, padx=10, pady=5)
amount_frame = ttk.Frame(form_frame, style="Dark.TFrame")
amount_frame.grid(row=1, column=1, padx=10, pady=5, sticky=tk.EW)
self.amount_var = tk.StringVar()
self.amount_var.trace('w', self.validate_amount)
amount_entry = ttk.Entry(amount_frame, textvariable=self.amount_var, width=20)
amount_entry.pack(side=tk.LEFT)
self.currency_var = tk.StringVar()
currency_combo = ttk.Combobox(amount_frame, textvariable=self.currency_var,
values=["ETH"], state="readonly", width=10)
currency_combo.pack(side=tk.LEFT, padx=(10, 0))
currency_combo.set("ETH")
max_btn = self.ui.create_button(amount_frame, "MAX", self.set_max_amount, "secondary")
max_btn.pack(side=tk.LEFT, padx=(10, 0))
self.amount_status_label = ttk.Label(amount_frame, text="", style="Light.TLabel")
self.amount_status_label.pack(side=tk.LEFT, padx=(10, 0))
# Gas settings with real-time estimation
gas_frame = ttk.LabelFrame(form_frame, text="Gas Settings", style="Dark.TLabelframe")
gas_frame.grid(row=2, column=0, columnspan=2, sticky=tk.EW, padx=10, pady=10)
gas_inner = ttk.Frame(gas_frame, style="Dark.TFrame")
gas_inner.pack(fill=tk.X, padx=10, pady=10)
# Gas price selection
ttk.Label(gas_inner, text="Gas Speed:", style="Light.TLabel").grid(row=0, column=0,
sticky=tk.W, padx=5, pady=2)
self.gas_speed_var = tk.StringVar(value="standard")
gas_speed_combo = ttk.Combobox(gas_inner, textvariable=self.gas_speed_var,
values=["slow", "standard", "fast"], state="readonly", width=15)
gas_speed_combo.grid(row=0, column=1, padx=5, pady=2)
gas_speed_combo.bind("<<ComboboxSelected>>", self.update_gas_estimate)
# Gas limit
ttk.Label(gas_inner, text="Gas Limit:", style="Light.TLabel").grid(row=0, column=2,
sticky=tk.W, padx=5, pady=2)
self.gas_limit_var = tk.StringVar(value="21000")
ttk.Entry(gas_inner, textvariable=self.gas_limit_var, width=15).grid(row=0, column=3,
padx=5, pady=2)
# Gas price display
self.gas_info_label = ttk.Label(gas_inner, text="Estimating...", style="Light.TLabel")
self.gas_info_label.grid(row=1, column=0, columnspan=4, pady=5)
form_frame.columnconfigure(1, weight=1)
# Transaction preview and send
button_frame = ttk.Frame(self.send_tab, style="Dark.TFrame")
button_frame.pack(fill=tk.X, padx=20, pady=10)
estimate_btn = self.ui.create_button(button_frame, "💰 Estimate Gas",
self.estimate_transaction_gas, "secondary")
estimate_btn.pack(side=tk.LEFT, padx=5)
preview_btn = self.ui.create_button(button_frame, "🔍 Preview Transaction",
self.preview_send_transaction, "secondary")
preview_btn.pack(side=tk.LEFT, padx=5)
self.send_btn = self.ui.create_button(button_frame, "📤 Send Transaction",
self.send_transaction_confirmed, "primary")
self.send_btn.pack(side=tk.LEFT, padx=5)
self.send_btn.configure(state="disabled")
# Transaction preview area
self.preview_frame = ttk.LabelFrame(self.send_tab, text="Transaction Preview",
style="Dark.TLabelframe")
self.preview_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=10)
self.preview_text = tk.Text(self.preview_frame, height=8, width=80,
bg=self.ui.colors['bg_secondary'],
fg=self.ui.colors['text_primary'],
font=self.ui.fonts['mono'], relief='flat', borderwidth=10)
self.preview_text.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
def create_enhanced_receive_tab(self):
"""Create enhanced receive tab with improved QR code"""
# Account selection for multi-account wallets
account_frame = ttk.LabelFrame(self.receive_tab, text="Select Account",
style="Dark.TLabelframe")
account_frame.pack(fill=tk.X, padx=20, pady=20)
account_inner = ttk.Frame(account_frame, style="Dark.TFrame")
account_inner.pack(fill=tk.X, padx=10, pady=10)
ttk.Label(account_inner, text="Account:", style="Light.TLabel").pack(side=tk.LEFT)
self.receive_account_var = tk.StringVar()
self.receive_account_combo = ttk.Combobox(account_inner, textvariable=self.receive_account_var,
state="readonly", width=50)
self.receive_account_combo.pack(side=tk.LEFT, padx=(10, 0), fill=tk.X, expand=True)
self.receive_account_combo.bind("<<ComboboxSelected>>", self.update_receive_address)
# Address display with enhanced info
addr_frame = ttk.LabelFrame(self.receive_tab, text="Receive Address",
style="Dark.TLabelframe")
addr_frame.pack(fill=tk.X, padx=20, pady=20)
addr_inner = ttk.Frame(addr_frame, style="Dark.TFrame")
addr_inner.pack(fill=tk.X, padx=10, pady=10)
# Address display
self.receive_address_label = ttk.Label(addr_inner, text="No account selected",
font=("Courier", 11), style="Address.TLabel",
wraplength=500)
self.receive_address_label.pack(pady=(0, 10))
# Address controls
addr_controls = ttk.Frame(addr_inner, style="Dark.TFrame")
addr_controls.pack(fill=tk.X)
copy_btn = self.ui.create_button(addr_controls, "📋 Copy Address",
self.copy_receive_address, "primary")
copy_btn.pack(side=tk.LEFT, padx=5)
show_explorer_btn = self.ui.create_button(addr_controls, "🔍 View on Explorer",
self.view_address_on_explorer, "secondary")
show_explorer_btn.pack(side=tk.LEFT, padx=5)
share_btn = self.ui.create_button(addr_controls, "📤 Share QR Code",
self.share_qr_code, "accent")
share_btn.pack(side=tk.LEFT, padx=5)
# Network warning
self.network_warning_label = ttk.Label(addr_inner,
text="⚠️ Make sure sender uses the same network",
style="Light.TLabel", font=("Arial", 10))
self.network_warning_label.pack(pady=(10, 0))
# QR Code display with options
qr_frame = ttk.LabelFrame(self.receive_tab, text="QR Code",
style="Dark.TLabelframe")
qr_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
qr_controls = ttk.Frame(qr_frame, style="Dark.TFrame")
qr_controls.pack(fill=tk.X, padx=10, pady=10)
qr_btn = self.ui.create_button(qr_controls, "🔄 Generate QR Code",
self.generate_receive_qr_code, "primary")
qr_btn.pack(side=tk.LEFT, padx=5)
save_qr_btn = self.ui.create_button(qr_controls, "💾 Save QR Code",
self.save_qr_code, "secondary")
save_qr_btn.pack(side=tk.LEFT, padx=5)
self.qr_label = ttk.Label(qr_frame, text="Select an account and click 'Generate QR Code'",
style="Light.TLabel")
self.qr_label.pack(expand=True, pady=20)
def create_accounts_tab(self):
"""Create enhanced accounts management tab with MULTI-WALLET SUPPORT"""
# Create notebook for wallet management
self.accounts_notebook = ttk.Notebook(self.accounts_tab, style="Dark.TNotebook")
self.accounts_notebook.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)
# Wallets tab (seed phrase management) - NEW FEATURE
self.wallets_tab = ttk.Frame(self.accounts_notebook, style="Dark.TFrame")
self.accounts_notebook.add(self.wallets_tab, text="🏦 Wallets")
self.create_wallets_management_tab()
# Accounts tab (individual accounts)
self.individual_accounts_tab = ttk.Frame(self.accounts_notebook, style="Dark.TFrame")
self.accounts_notebook.add(self.individual_accounts_tab, text="👤 Accounts")
self.create_individual_accounts_tab()
def create_wallets_management_tab(self):
"""Create wallet (seed phrase) management tab - NEW FEATURE"""
# Wallet list with better display
wallet_list_frame = ttk.LabelFrame(self.wallets_tab, text="Seed Phrase Wallets",
style="Dark.TLabelframe")
wallet_list_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Wallet controls
wallet_controls_frame = ttk.Frame(wallet_list_frame, style="Dark.TFrame")
wallet_controls_frame.pack(fill=tk.X, padx=10, pady=10)
create_wallet_btn = self.ui.create_button(wallet_controls_frame, "🆕 Create New Seed Phrase Wallet",
self.create_new_seed_phrase_wallet, "primary")
create_wallet_btn.pack(side=tk.LEFT, padx=5)
import_wallet_btn = self.ui.create_button(wallet_controls_frame, "📥 Import Seed Phrase Wallet",
self.import_seed_phrase_wallet, "secondary")
import_wallet_btn.pack(side=tk.LEFT, padx=5)
switch_wallet_btn = self.ui.create_button(wallet_controls_frame, "🔄 Switch Active Wallet",
self.switch_seed_phrase_wallet, "accent")
switch_wallet_btn.pack(side=tk.LEFT, padx=5)
# Wallet treeview
wallet_tree_frame = ttk.Frame(wallet_list_frame, style="Dark.TFrame")
wallet_tree_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=(0, 10))
wallet_columns = ("Name", "Created", "Accounts", "Total Balance", "Status")
self.wallet_tree = ttk.Treeview(wallet_tree_frame, columns=wallet_columns, show="headings",
height=8, style="Dark.Treeview")
# Configure wallet columns
wallet_column_widths = {"Name": 200, "Created": 120, "Accounts": 80, "Total Balance": 150, "Status": 100}
for col in wallet_columns:
self.wallet_tree.heading(col, text=col)
self.wallet_tree.column(col, width=wallet_column_widths.get(col, 100))
wallet_scrollbar = ttk.Scrollbar(wallet_tree_frame, orient=tk.VERTICAL, command=self.wallet_tree.yview)
self.wallet_tree.configure(yscrollcommand=wallet_scrollbar.set)
self.wallet_tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
wallet_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Bind wallet selection event
self.wallet_tree.bind("<<TreeviewSelect>>", self.on_wallet_select)
# Wallet security actions
wallet_security_frame = ttk.Frame(wallet_list_frame, style="Dark.TFrame")
wallet_security_frame.pack(fill=tk.X, padx=10, pady=10)
view_seed_btn = self.ui.create_button(wallet_security_frame, "👁️ View Seed Phrase",
self.view_current_seed_phrase, "accent")
view_seed_btn.pack(side=tk.LEFT, padx=5)
export_wallet_btn = self.ui.create_button(wallet_security_frame, "📤 Export Wallet",
self.export_current_wallet, "secondary")
export_wallet_btn.pack(side=tk.LEFT, padx=5)
def create_individual_accounts_tab(self):
"""Create individual accounts management tab"""
# Account list with better display
list_frame = ttk.LabelFrame(self.individual_accounts_tab, text="Accounts Overview",
style="Dark.TLabelframe")
list_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Account controls
controls_frame = ttk.Frame(list_frame, style="Dark.TFrame")
controls_frame.pack(fill=tk.X, padx=10, pady=10)
create_btn = self.ui.create_button(controls_frame, "➕ Create Account",
self.create_new_account, "primary")
create_btn.pack(side=tk.LEFT, padx=5)
import_btn = self.ui.create_button(controls_frame, "📥 Import Account",
self.import_account, "secondary")
import_btn.pack(side=tk.LEFT, padx=5)
refresh_accounts_btn = self.ui.create_button(controls_frame, "🔄 Refresh Balances",
self.refresh_all_account_balances, "secondary")
refresh_accounts_btn.pack(side=tk.LEFT, padx=5)
# Account treeview with enhanced columns
tree_frame = ttk.Frame(list_frame, style="Dark.TFrame")
tree_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=(0, 10))
acc_columns = ("Name", "Address", "Balance", "Wallet", "Status")
self.acc_tree = ttk.Treeview(tree_frame, columns=acc_columns, show="headings",
height=10, style="Dark.Treeview")
# Configure account columns
acc_column_widths = {"Name": 120, "Address": 200, "Balance": 120, "Wallet": 150, "Status": 80}
for col in acc_columns:
self.acc_tree.heading(col, text=col)
self.acc_tree.column(col, width=acc_column_widths.get(col, 100))
acc_scrollbar = ttk.Scrollbar(tree_frame, orient=tk.VERTICAL, command=self.acc_tree.yview)
self.acc_tree.configure(yscrollcommand=acc_scrollbar.set)
self.acc_tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
acc_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# Account actions
acc_actions_frame = ttk.Frame(self.individual_accounts_tab, style="Dark.TFrame")
acc_actions_frame.pack(fill=tk.X, padx=10, pady=10)
switch_btn = self.ui.create_button(acc_actions_frame, "🔄 Switch Account",
self.switch_active_account, "primary")
switch_btn.pack(side=tk.LEFT, padx=5)
export_btn = self.ui.create_button(acc_actions_frame, "📤 Export Account",
self.export_account, "accent")
export_btn.pack(side=tk.LEFT, padx=5)
view_private_key_btn = self.ui.create_button(acc_actions_frame, "🔑 View Private Key",
self.view_account_private_key, "secondary")
view_private_key_btn.pack(side=tk.LEFT, padx=5)
# Bind selection event
self.acc_tree.bind("<<TreeviewSelect>>", self.on_account_select)
def create_settings_tab(self):
"""Create enhanced settings tab"""
# Network settings with testing
network_frame = ttk.LabelFrame(self.settings_tab, text="Network Settings",
style="Dark.TLabelframe")
network_frame.pack(fill=tk.X, padx=20, pady=20)
network_inner = ttk.Frame(network_frame, style="Dark.TFrame")
network_inner.pack(fill=tk.X, padx=10, pady=10)
test_networks_btn = self.ui.create_button(network_inner, "🧪 Test All Networks",
self.test_all_networks, "primary")
test_networks_btn.pack(side=tk.LEFT, padx=5)
add_network_btn = self.ui.create_button(network_inner, "🌐 Add Custom Network",
self.add_custom_network, "secondary")
add_network_btn.pack(side=tk.LEFT, padx=5)
optimize_btn = self.ui.create_button(network_inner, "⚡ Optimize RPCs",
self.optimize_network_rpcs, "accent")
optimize_btn.pack(side=tk.LEFT, padx=5)
# Security settings
security_frame = ttk.LabelFrame(self.settings_tab, text="Security Settings",
style="Dark.TLabelframe")
security_frame.pack(fill=tk.X, padx=20, pady=20)
security_inner = ttk.Frame(security_frame, style="Dark.TFrame")
security_inner.pack(fill=tk.X, padx=10, pady=10)
change_pw_btn = self.ui.create_button(security_inner, "🔑 Change Password",
self.change_password, "primary")
change_pw_btn.pack(side=tk.LEFT, padx=5)
backup_btn = self.ui.create_button(security_inner, "💾 Backup Wallet",
self.backup_wallet, "secondary")
backup_btn.pack(side=tk.LEFT, padx=5)
# Application settings
app_frame = ttk.LabelFrame(self.settings_tab, text="Application Settings",
style="Dark.TLabelframe")
app_frame.pack(fill=tk.X, padx=20, pady=20)
app_inner = ttk.Frame(app_frame, style="Dark.TFrame")
app_inner.pack(fill=tk.X, padx=10, pady=10)
# Auto-refresh settings
ttk.Label(app_inner, text="Auto-refresh interval (seconds):", style="Light.TLabel").pack(anchor=tk.W)
self.refresh_interval_var = tk.StringVar(value="30")
refresh_interval_entry = ttk.Entry(app_inner, textvariable=self.refresh_interval_var, width=10)
refresh_interval_entry.pack(anchor=tk.W, pady=5)
apply_settings_btn = self.ui.create_button(app_inner, "✅ Apply Settings",
self.apply_settings, "primary")
apply_settings_btn.pack(anchor=tk.W, pady=10)
def create_status_bar(self, parent):
"""Create enhanced bottom status bar"""
status_frame = ttk.Frame(parent, style="Dark.TFrame")
status_frame.pack(fill=tk.X, side=tk.BOTTOM)
self.status_label = ttk.Label(status_frame, text="Ready", style="Light.TLabel")
self.status_label.pack(side=tk.LEFT, padx=5)
# Last update time
self.last_update_label = ttk.Label(status_frame, text="", style="Light.TLabel")
self.last_update_label.pack(side=tk.LEFT, padx=20)
# Network connection status
self.connection_label = ttk.Label(status_frame, text="🔴 Disconnected",
style="Light.TLabel")
self.connection_label.pack(side=tk.RIGHT, padx=5)
# =============================================================================
# NEW MULTI-SEED PHRASE WALLET MANAGEMENT METHODS
# =============================================================================
def create_new_seed_phrase_wallet(self):
"""Create a new seed phrase wallet (completely separate wallet)"""
dialog = self.ui.create_modal_dialog("Create New Seed Phrase Wallet", 500, 400)
# Wallet name input
name_group = self.ui.create_input_group(dialog, "Wallet Name:",
"Enter wallet name", "text", 40)
name_group["frame"].pack(fill=tk.X, padx=20, pady=10)
# Password input
password_group = self.ui.create_input_group(dialog, "Wallet Password:",
"Enter password for this wallet", "password", 40)
password_group["frame"].pack(fill=tk.X, padx=20, pady=10)
confirm_group = self.ui.create_input_group(dialog, "Confirm Password:",
"Re-enter password", "password", 40)
confirm_group["frame"].pack(fill=tk.X, padx=20, pady=10)
# Buttons
btn_frame = ttk.Frame(dialog, style="Dark.TFrame")
btn_frame.pack(fill=tk.X, padx=20, pady=20)
generate_btn = self.ui.create_button(btn_frame, "🎲 Generate New Wallet",
lambda: self.generate_new_seed_phrase_wallet(dialog, name_group, password_group, confirm_group),
"primary")
generate_btn.pack(side=tk.LEFT, padx=5)
cancel_btn = self.ui.create_button(btn_frame, "❌ Cancel",
lambda: dialog.destroy(), "secondary")
cancel_btn.pack(side=tk.RIGHT, padx=5)
def generate_new_seed_phrase_wallet(self, dialog, name_group, password_group, confirm_group):
"""Generate and create new seed phrase wallet"""
wallet_name = name_group["input"].get()
password = password_group["input"].get()
confirm = confirm_group["input"].get()
if not wallet_name:
messagebox.showerror("Error", "Please enter a wallet name!")
return
if password != confirm:
messagebox.showerror("Error", "Passwords do not match!")
return
if len(password) < 8:
messagebox.showerror("Error", "Password must be at least 8 characters!")
return
try:
# Generate new mnemonic
mnemonic = self.wallet_core.generate_mnemonic()
# Create wallet in storage
wallet_id = self.storage_manager.create_wallet(wallet_name, password, mnemonic)
if wallet_id:
dialog.destroy()
self.show_new_seed_phrase_dialog(mnemonic, wallet_id, wallet_name)
else:
messagebox.showerror("Error", "Failed to create wallet!")
except Exception as e:
messagebox.showerror("Error", f"Failed to create wallet: {str(e)}")
def show_new_seed_phrase_dialog(self, mnemonic, wallet_id, wallet_name):
"""Show seed phrase for new wallet"""
dialog = self.ui.create_modal_dialog("New Seed Phrase Wallet Created", 700, 550)
# Success message
success_text = f"✅ New wallet '{wallet_name}' created successfully!\n\n⚠️ CRITICAL: Save your seed phrase securely!"
success_label = ttk.Label(dialog, text=success_text, style="Light.TLabel",
wraplength=650, justify='center')
success_label.pack(pady=20, padx=20)
# Seed phrase display
seed_frame = ttk.LabelFrame(dialog, text="Your New Seed Phrase", style="Dark.TLabelframe")
seed_frame.pack(fill=tk.X, padx=20, pady=20)
seed_text = tk.Text(seed_frame, height=4, width=60, wrap=tk.WORD,
bg=self.ui.colors['bg_secondary'],
fg=self.ui.colors['text_primary'],
font=self.ui.fonts['mono'], relief='flat', borderwidth=10)
seed_text.pack(padx=10, pady=10)
seed_text.insert('1.0', mnemonic)
seed_text.config(state='disabled')
# Important notes
notes_text = """📝 Important Notes:
• This seed phrase is completely separate from your other wallets
• Write it down and store it in a secure location
• Anyone with this phrase can access this wallet
• You can switch between wallets using the wallet management tab"""
notes_label = ttk.Label(dialog, text=notes_text, style="Light.TLabel",
wraplength=650, justify='left')
notes_label.pack(pady=10, padx=20)
# Buttons
btn_frame = ttk.Frame(dialog, style="Dark.TFrame")
btn_frame.pack(pady=20)
copy_btn = self.ui.create_button(btn_frame, "📋 Copy to Clipboard",
lambda: self.copy_to_clipboard(mnemonic), "secondary")
copy_btn.pack(side=tk.LEFT, padx=10)
continue_btn = self.ui.create_button(btn_frame, "✅ I've Saved It - Continue",
lambda: self.complete_new_wallet_setup(dialog, wallet_id), "primary")
continue_btn.pack(side=tk.LEFT, padx=10)
def complete_new_wallet_setup(self, dialog, wallet_id):
"""Complete new wallet setup"""
try:
dialog.destroy()
# Refresh wallet list
self.refresh_wallet_list()
# Show success message
success_msg = f"Wallet created successfully!\n\nTo use this wallet:\n"
success_msg += f"1. Go to the Wallets tab in Accounts\n"
success_msg += f"2. Select the new wallet and click 'Switch Active Wallet'\n"
success_msg += f"3. Enter the password you set for this wallet"
messagebox.showinfo("Success", success_msg)
# Switch to accounts tab to show the new wallet
self.notebook.select(3) # Accounts tab
except Exception as e:
dialog.destroy()
messagebox.showerror("Error", f"Failed to complete setup: {str(e)}")
def import_seed_phrase_wallet(self):
"""Import an existing seed phrase as a new wallet"""
dialog = self.ui.create_modal_dialog("Import Seed Phrase Wallet", 600, 500)
# Wallet name input
name_group = self.ui.create_input_group(dialog, "Wallet Name:",
"Enter name for this wallet", "text", 40)
name_group["frame"].pack(fill=tk.X, padx=20, pady=10)
# Seed phrase input
seed_group = self.ui.create_input_group(dialog, "Seed Phrase:",
"Enter your 12 or 24 word seed phrase", "textarea", 50)
seed_group["frame"].pack(fill=tk.X, padx=20, pady=10)
# Password input
password_group = self.ui.create_input_group(dialog, "Set Password:",
"Enter password for this wallet", "password", 40)
password_group["frame"].pack(fill=tk.X, padx=20, pady=10)
# Buttons
btn_frame = ttk.Frame(dialog, style="Dark.TFrame")
btn_frame.pack(fill=tk.X, padx=20, pady=20)
import_btn = self.ui.create_button(btn_frame, "📥 Import Wallet",
lambda: self.perform_seed_phrase_import(dialog, name_group, seed_group, password_group),
"primary")
import_btn.pack(side=tk.LEFT, padx=5)
cancel_btn = self.ui.create_button(btn_frame, "❌ Cancel",
lambda: dialog.destroy(), "secondary")
cancel_btn.pack(side=tk.RIGHT, padx=5)
def perform_seed_phrase_import(self, dialog, name_group, seed_group, password_group):
"""Perform the seed phrase wallet import"""
wallet_name = name_group["input"].get()
seed_phrase = seed_group["input"].get('1.0', tk.END).strip()
password = password_group["input"].get()
if not wallet_name:
messagebox.showerror("Error", "Please enter a wallet name!")
return
if not seed_phrase:
messagebox.showerror("Error", "Please enter a seed phrase!")
return
if len(password) < 8:
messagebox.showerror("Error", "Password must be at least 8 characters!")
return
try:
# Validate seed phrase
if not self.wallet_core.validate_mnemonic(seed_phrase):
messagebox.showerror("Error", "Invalid seed phrase!")
return
# Create wallet
wallet_id = self.storage_manager.create_wallet(wallet_name, password, seed_phrase)
if wallet_id:
dialog.destroy()
self.refresh_wallet_list()
success_msg = f"Wallet '{wallet_name}' imported successfully!\n\n"
success_msg += f"To use this wallet, go to the Wallets tab and switch to it."
messagebox.showinfo("Success", success_msg)
# Switch to accounts tab
self.notebook.select(3) # Accounts tab
else:
messagebox.showerror("Error", "Failed to import wallet!")
except Exception as e:
messagebox.showerror("Error", f"Failed to import wallet: {str(e)}")
def switch_seed_phrase_wallet(self):
"""Switch to a different seed phrase wallet"""
wallets = self.storage_manager.get_wallets()
if not wallets:
messagebox.showwarning("Warning", "No wallets available!")
return
dialog = self.ui.create_modal_dialog("Switch Seed Phrase Wallet", 500, 300)
# Wallet selection
ttk.Label(dialog, text="Select wallet to switch to:", style="Light.TLabel").pack(pady=10)
wallet_var = tk.StringVar()
wallet_combo = ttk.Combobox(dialog, textvariable=wallet_var,
values=[f"{w['name']} (Created: {time.strftime('%Y-%m-%d', time.localtime(w['created_at']))})" for w in wallets],
state="readonly", width=50)
wallet_combo.pack(pady=10, padx=20)
wallet_combo.set(wallets[0]["name"] if wallets else "")
# Password input
password_group = self.ui.create_input_group(dialog, "Password:",
"Enter wallet password", "password", 30)
password_group["frame"].pack(pady=10, padx=20)
# Buttons
btn_frame = ttk.Frame(dialog, style="Dark.TFrame")
btn_frame.pack(pady=20)
switch_btn = self.ui.create_button(btn_frame, "🔄 Switch Wallet",
lambda: self.perform_wallet_switch(dialog, wallet_var, password_group, wallets),
"primary")
switch_btn.pack(side=tk.LEFT, padx=10)
cancel_btn = self.ui.create_button(btn_frame, "❌ Cancel",
lambda: dialog.destroy(), "secondary")
cancel_btn.pack(side=tk.LEFT, padx=10)
def perform_wallet_switch(self, dialog, wallet_var, password_group, wallets):
"""Perform the wallet switch operation"""
selected_wallet_display = wallet_var.get()
password = password_group["input"].get()
if not selected_wallet_display or not password:
messagebox.showerror("Error", "Please select wallet and enter password!")
return
# Find the wallet by matching the display name
wallet_name = selected_wallet_display.split(" (Created:")[0]
wallet = next((w for w in wallets if w["name"] == wallet_name), None)
if not wallet:
messagebox.showerror("Error", "Wallet not found!")
return
try:
# Lock current wallet
if not self.is_locked:
self.storage_manager.lock_wallet()
# Try to unlock the selected wallet
if self.storage_manager.unlock_wallet(wallet["wallet_id"], password):
# Load accounts for this wallet
accounts = self.storage_manager.get_accounts(wallet["wallet_id"])
self.accounts = accounts
self.current_account = accounts[0] if accounts else None
self.current_wallet_id = wallet["wallet_id"]
self.is_locked = False
dialog.destroy()
# Update UI
self.update_account_ui()
self.create_top_bar(self.root.winfo_children()[0]) # Refresh top bar
self.manual_refresh_balance()
self.refresh_wallet_list()
# Update status
self.update_status(f"Switched to wallet: {wallet['name']}")
success_msg = f"Successfully switched to wallet '{wallet['name']}'!\n\n"
if accounts:
success_msg += f"Loaded {len(accounts)} account(s)."
else:
success_msg += "No accounts found. You may need to create accounts for this wallet."
messagebox.showinfo("Success", success_msg)
# Initialize network connection
self.on_network_change()
else:
messagebox.showerror("Error", "Incorrect password!")
except Exception as e:
messagebox.showerror("Error", f"Failed to switch wallet: {str(e)}")
def refresh_wallet_list(self):
"""Refresh the wallet list in the UI"""
if not hasattr(self, 'wallet_tree'):
return
# Clear existing items
for item in self.wallet_tree.get_children():
self.wallet_tree.delete(item)
# Get all wallets
wallets = self.storage_manager.get_wallets()
for wallet in wallets:
# Get account count for this wallet
try:
accounts = self.storage_manager.get_accounts(wallet["wallet_id"])
account_count = len(accounts)
except:
account_count = 0
# Format created date
created_date = time.strftime('%Y-%m-%d', time.localtime(wallet["created_at"]))