Continue development of new transaction page
This commit is contained in:
1 parent
aa865e008d
commit
1e95d2b605
7 files changed
+36
-33
No files matched your search
Binary file not shown.
@@ -66,11 +66,6 @@ def display_account_info(account_id):
|
|||||||
label_value = customtkinter.CTkLabel(info_frame, text=value, font=("Helvetica", 14))
|
label_value = customtkinter.CTkLabel(info_frame, text=value, font=("Helvetica", 14))
|
||||||
label_key.grid(row=0, column=i*2, sticky='w', padx=10)
|
label_key.grid(row=0, column=i*2, sticky='w', padx=10)
|
||||||
label_value.grid(row=0, column=i*2+1, sticky='w', padx=10)
|
label_value.grid(row=0, column=i*2+1, sticky='w', padx=10)
|
||||||
notes = get_account(account_id).get('data', {}).get('notes', '')
|
|
||||||
|
|
||||||
print(f"Account: {account}") # Debugging
|
|
||||||
print(f"Account: {notes}") # Debugging
|
|
||||||
|
|
||||||
notes_text.configure(text=account.get('notes', ''))
|
notes_text.configure(text=account.get('notes', ''))
|
||||||
|
|
||||||
def on_transaction_double_click(event):
|
def on_transaction_double_click(event):
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ def get_transactions(account_id):
|
|||||||
|
|
||||||
def get_account(account_id):
|
def get_account(account_id):
|
||||||
"""Retrieves the account details for the given account_id."""
|
"""Retrieves the account details for the given account_id."""
|
||||||
print(f"Getting account details for account_id: {account_id}")
|
|
||||||
try:
|
try:
|
||||||
with open('application\\session_data.json', 'r') as f:
|
with open('application\\session_data.json', 'r') as f:
|
||||||
session_data = json.load(f)
|
session_data = json.load(f)
|
||||||
|
|||||||
@@ -24,54 +24,63 @@ else:
|
|||||||
|
|
||||||
def submit_transaction():
|
def submit_transaction():
|
||||||
"""Submit a new transaction to the server."""
|
"""Submit a new transaction to the server."""
|
||||||
global account_id, recipient_id
|
|
||||||
account_id = account_combobox.get()
|
account_id = account_combobox.get()
|
||||||
recipient_id = recipient_text.get()
|
recipient_id = recipient_text.get("1.0", "end-1c")
|
||||||
amount = amount_text.get() if amount_text.get() != "" else None
|
amount = amount_text.get("1.0", "end-1c")
|
||||||
description = description_text.get() if description_text.get() != "" else None
|
description = description_text.get("1.0", "end-1c")
|
||||||
if not description or not amount or not recipient_id or not account_id:
|
|
||||||
|
if not amount or not recipient_id or not account_id:
|
||||||
messagebox.showerror("Error", "Please fill in all fields.")
|
messagebox.showerror("Error", "Please fill in all fields.")
|
||||||
return
|
return
|
||||||
account_verification = verify_accounts(account_id, recipient_id)
|
|
||||||
|
# Convert amount to float
|
||||||
|
try:
|
||||||
|
amount = float(amount)
|
||||||
|
except ValueError:
|
||||||
|
messagebox.showerror("Error", "Invalid amount entered.")
|
||||||
|
return
|
||||||
|
|
||||||
|
account_verification = verify_accounts()
|
||||||
if account_verification is False:
|
if account_verification is False:
|
||||||
messagebox.showerror("Error", "Could not verify account IDs.")
|
messagebox.showerror("Error", "Could not verify account IDs.")
|
||||||
return
|
return
|
||||||
|
|
||||||
response = new_transaction(account_id, description, amount, recipient_id)
|
response = new_transaction(account_id, description, amount, recipient_id)
|
||||||
if response is None or "data" not in response:
|
if response is None or "data" not in response:
|
||||||
messagebox.showerror("Error", "Could not submit transaction.")
|
messagebox.showerror("Error", "Could not submit transaction.")
|
||||||
return
|
return
|
||||||
|
|
||||||
transaction_id = response["data"]
|
transaction_id = response["data"]
|
||||||
otp = generate_otp(account_id, transaction_id)
|
otp = generate_otp(account_id, transaction_id)
|
||||||
if otp is None or "data" not in otp:
|
if otp is None or "data" not in otp:
|
||||||
messagebox.showerror("Error", "Could not generate OTP.")
|
messagebox.showerror("Error", "Could not generate OTP.")
|
||||||
return
|
return
|
||||||
|
|
||||||
messagebox.showinfo("Success", f"Transaction submitted successfully. OTP: {otp['data']}")
|
messagebox.showinfo("Success", f"Transaction submitted successfully. OTP: {otp['data']}")
|
||||||
|
|
||||||
def verify_accounts():
|
def verify_accounts():
|
||||||
"""Verify that the account IDs are valid."""
|
"""Verify that the account IDs are valid."""
|
||||||
try:
|
try:
|
||||||
|
account_id = account_combobox.get()
|
||||||
|
recipient_id = recipient_text.get("1.0", "end-1c")
|
||||||
account = get_account(account_id)
|
account = get_account(account_id)
|
||||||
recipient_account = get_account(recipient_id)
|
recipient_id = get_account(recipient_id)
|
||||||
print(account)
|
|
||||||
print(recipient_account)
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
messagebox.showerror("Error", f"Failed to get account details: {e}")
|
messagebox.showerror("Error", f"Failed to get account details: {e}")
|
||||||
return False
|
return False
|
||||||
|
if account is None or recipient_id is None or "data" not in account or "data" not in recipient_id:
|
||||||
if account is None or recipient_account is None or "data" not in account or "data" not in recipient_account:
|
|
||||||
messagebox.showerror("Error", "Server did not return the expected response.")
|
messagebox.showerror("Error", "Server did not return the expected response.")
|
||||||
return False
|
return False
|
||||||
if "account_id" not in account["data"]:
|
if "account_id" not in account["data"]:
|
||||||
messagebox.showerror("Error", "Account ID not found.")
|
messagebox.showerror("Error", "Account ID not found.")
|
||||||
return False
|
return False
|
||||||
if "account_id" not in recipient_account["data"]:
|
if "account_id" not in recipient_id["data"]:
|
||||||
messagebox.showerror("Error", "Recipient Account ID not found.")
|
messagebox.showerror("Error", "Recipient Account ID not found.")
|
||||||
return False
|
return False
|
||||||
#check balance
|
amount = amount_text.get("1.0", "end-1c")
|
||||||
if account["data"]["balance"] < float(amount_text.get("1.0", "end-1c")):
|
if account["data"]["balance"] < amount: # Check the client has the required balance
|
||||||
messagebox.showerror("Error", "Insufficient funds.")
|
messagebox.showerror("Error", "Insufficient funds.")
|
||||||
return False
|
return False
|
||||||
submit_button.configure(state=tk.NORMAL) # Enable the submit button if the accounts are valid
|
|
||||||
messagebox.showinfo("Success", "Accounts verified successfully.")
|
messagebox.showinfo("Success", "Accounts verified successfully.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -107,22 +116,23 @@ welcome_label.pack(pady=20)
|
|||||||
close_button = customtkinter.CTkButton(root, text="Cancel and Close", command=root.destroy)
|
close_button = customtkinter.CTkButton(root, text="Cancel and Close", command=root.destroy)
|
||||||
close_button.pack(side="top", anchor="e", padx=10, pady=10)
|
close_button.pack(side="top", anchor="e", padx=10, pady=10)
|
||||||
|
|
||||||
# Create the account ID label and combobox
|
# Create a frame for the account ID combobox
|
||||||
account_label = customtkinter.CTkLabel(root, text="Account ID:", font=("Helvetica", 14))
|
account_label = customtkinter.CTkLabel(root, text="From Account ID:", font=("Helvetica", 14))
|
||||||
account_label.pack(pady=5)
|
account_label.pack(pady=5)
|
||||||
account_combobox = ttk.Combobox(root, height=1, width=250)
|
account_frame = ttk.Frame(root, width=200, height=25)
|
||||||
account_combobox.pack(pady=5)
|
account_frame.pack_propagate(0) # Don't shrink
|
||||||
|
account_frame.pack(pady=5)
|
||||||
|
|
||||||
|
# Create the account ID combobox inside the frame
|
||||||
|
account_combobox = ttk.Combobox(account_frame, height=1)
|
||||||
|
account_combobox.pack(fill='both', expand=True)
|
||||||
|
|
||||||
# Create the recipient ID label and text box
|
# Create the recipient ID label and text box
|
||||||
recipient_label = customtkinter.CTkLabel(root, text="Recipient ID:", font=("Helvetica", 14))
|
recipient_label = customtkinter.CTkLabel(root, text="To Recipient ID:", font=("Helvetica", 14))
|
||||||
recipient_label.pack(pady=5)
|
recipient_label.pack(pady=5)
|
||||||
recipient_text = customtkinter.CTkTextbox(root, height=2, width=250)
|
recipient_text = customtkinter.CTkTextbox(root, height=2, width=250)
|
||||||
recipient_text.pack(pady=5)
|
recipient_text.pack(pady=5)
|
||||||
|
|
||||||
# Create the verify buttons
|
|
||||||
verify_button = customtkinter.CTkButton(root, text="Verify Accounts", command=verify_accounts)
|
|
||||||
verify_button.pack(pady=10)
|
|
||||||
|
|
||||||
# Create the transaction description label and text box
|
# Create the transaction description label and text box
|
||||||
description_label = customtkinter.CTkLabel(root, text="Description:", font=("Helvetica", 14))
|
description_label = customtkinter.CTkLabel(root, text="Description:", font=("Helvetica", 14))
|
||||||
description_label.pack(pady=5)
|
description_label.pack(pady=5)
|
||||||
@@ -146,7 +156,7 @@ otp_text = customtkinter.CTkTextbox(root, height=2, width=250)
|
|||||||
otp_text.pack(pady=5)
|
otp_text.pack(pady=5)
|
||||||
|
|
||||||
# Create the submit button
|
# Create the submit button
|
||||||
submit_button = customtkinter.CTkButton(root, text="Submit", command=submit_transaction, state=tk.DISABLED)
|
submit_button = customtkinter.CTkButton(root, text="Submit", command=submit_transaction)
|
||||||
submit_button.pack(pady=5)
|
submit_button.pack(pady=5)
|
||||||
|
|
||||||
# Populate accounts combobox with the given client_id
|
# Populate accounts combobox with the given client_id
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"session_cookie": {"session": "zEUX5N4IojE58Mg8yfVC0XiNC-IcnHaZcBJRMRH9J94"}, "client_id": "9755c18f"}
|
{"session_cookie": {"session": "0vm2PELvoXxLiOtpdLDR6M4-WHJq5xq5BX92b46UTkM"}, "client_id": "9755c18f"}
|
||||||
@@ -261,7 +261,6 @@ def get_account(account_id:str):
|
|||||||
account = session.query(Account).filter_by(account_id=account_id).one_or_none()
|
account = session.query(Account).filter_by(account_id=account_id).one_or_none()
|
||||||
for account in session.query(Account).all():
|
for account in session.query(Account).all():
|
||||||
if account.account_id == account_id:
|
if account.account_id == account_id:
|
||||||
print(account.to_dict())
|
|
||||||
return format_response(True, "", account.to_dict()), 200
|
return format_response(True, "", account.to_dict()), 200
|
||||||
return format_response(False, "Account not found."), 404
|
return format_response(False, "Account not found."), 404
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user