Skip to content

Commit ba8fca3

Browse files
committed
refactor: Send SMP failure request on Window close
1 parent 97df7f1 commit ba8fca3

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

ui/contact_list.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ def show_contacts(self):
261261
def new_contact(self, contact_id):
262262
with self.user_data_lock:
263263
contact_name = contact_id if not self.user_data["contacts"][contact_id]["nickname"] else self.user_data["contacts"][contact_id]["nickname"]
264-
contact_is_verified = self.user_data["contacts"][contact_id]["lt_sign_key_smp"]["verified"]
265264

266265
button = tk.Button(
267266
self.contact_frame,
@@ -283,8 +282,6 @@ def new_contact(self, contact_id):
283282

284283
# If no nickname is set
285284
if (contact_name == contact_id):
286-
# We only allow setting nicknames after SMP verification succeeds
287-
if contact_is_verified:
288285
context_menu.add_command(
289286
label="Set nickname",
290287
command=lambda: self.change_contact_nickname(contact_id)
@@ -306,6 +303,14 @@ def new_contact(self, contact_id):
306303
button.bind("<Button-2>", lambda event: context_menu.tk_popup(event.x_root, event.y_root)) # MacOS
307304

308305
def change_contact_nickname(self, contact_id):
306+
with self.user_data_lock:
307+
contact_is_verified = self.user_data["contacts"][contact_id]["lt_sign_key_smp"]["verified"]
308+
309+
# We only allow setting nicknames after SMP verification succeeds
310+
if not contact_is_verified:
311+
messagebox.showwarning("Pending Verification", "You can only assign a nickname once SMP verification is complete")
312+
return
313+
309314
ContactNicknamePrompt(self, contact_id)
310315

311316
def remove_contact_nickname(self, contact_id):

ui/smp_question_window.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import tkinter as tk
22
from tkinter import messagebox
3-
# from ui.utils import *
4-
from logic.smp import smp_step_4_answer_provided
3+
from ui.utils import (
4+
enhanced_entry
5+
)
6+
from logic.smp import (
7+
smp_step_4_answer_provided,
8+
smp_failure_notify_contact
9+
)
510

611
class SMPQuestionWindow(tk.Toplevel):
712
def __init__(self, master, contact_id, question):
813
super().__init__(master)
914
self.contact_id = contact_id
15+
16+
self.protocol("WM_DELETE_WINDOW", self.on_close)
17+
1018

1119
self.title("Answer Verification Question")
12-
self.geometry("400x250")
20+
self.geometry("400x200")
1321
self.configure(bg="black")
1422

1523
# Question label
@@ -24,14 +32,12 @@ def __init__(self, master, contact_id, question):
2432
justify="left"
2533
).pack(pady=(10, 10))
2634

27-
# Answer input
2835
tk.Label(self, text="Answer:", fg="white", bg="black", anchor="w").pack(fill="x", padx=20)
2936
self.answer_entry = tk.Entry(self, width=50)
3037
self.answer_entry.pack(padx=20, pady=(0, 10))
3138

32-
# enhanced_entry(self.answer_entry, placeholder="I.e. Central Park")
39+
enhanced_entry(self.answer_entry, placeholder="I.e. Central Park")
3340

34-
# Send button
3541
tk.Button(
3642
self,
3743
text="Send Verification Request",
@@ -45,6 +51,10 @@ def __init__(self, master, contact_id, question):
4551
self.transient(master)
4652
self.grab_set()
4753

54+
def on_close(self):
55+
smp_failure_notify_contact(self.master.user_data, self.master.user_data_lock, self.contact_id, self.master.ui_queue)
56+
self.destroy()
57+
4858
def submit(self):
4959
answer = self.answer_entry.get().strip().lower()
5060
if not answer:

0 commit comments

Comments
 (0)