Skip to content

Commit

Permalink
Update: Error report dialog box
Browse files Browse the repository at this point in the history
  • Loading branch information
rahilmansuri1 committed Jan 24, 2025
1 parent d23ad66 commit 0c86df9
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 367 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/iris-wallet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ jobs:
TOKEN_URI: ${{ secrets.TOKEN_URI }}
AUTH_PROVIDER_CERT_URL: ${{ secrets.AUTH_PROVIDER_CERT_URL }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
SMTP_EMAIL_ID: ${{ secrets.SMTP_EMAIL_ID }}
SMTP_EMAIL_TOKEN: ${{ secrets.SMTP_EMAIL_TOKEN }}
SUPPORT_EMAIL: ${{ secrets.SUPPORT_EMAIL }}
SMTP_HOST: ${{ secrets.SMTP_HOST }}
SMTP_PORT: ${{ secrets.SMTP_PORT }}
run: |
cd src/utils
python generate_config.py
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ client_config = {
'client_secret': 'your_client_secret',
},
}

# Config for the error report email server
report_email_server_config = {
'smtp_email_id': 'smtp_server_email_id',
'smtp_email_token': 'smtp_server_email_token',
'support_email': 'support_email_id',
'smtp_host': 'smtp.gmail.com',
'smtp_port': '587'
}
```

#### 8.2 Create Google Drive Credentials
Expand Down Expand Up @@ -139,9 +130,6 @@ report_email_server_config = {
6. **Update Your Configuration:**
- Save the modified JSON file and add it to your `config.py` file.

#### 8.3 Create Email Server Configuration
Search for **App Passwords** in your Gmail account to create an app password for email access.

### 9. Start the Application
You can now start the Iris Wallet application using:
```bash
Expand Down
Binary file modified src/translations/en_IN.qm
Binary file not shown.
24 changes: 24 additions & 0 deletions src/translations/en_IN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1510,5 +1510,29 @@ If you understand the above remarks and wish to proceed, press the button below
<source>set_minimum_confirmation_desc</source>
<translation>Set a minimum confirmation for RGB operation</translation>
</message>
<message>
<source>github_issue_label</source>
<translation>GitHub Issue</translation>
</message>
<message>
<source>email_us_at</source>
<translation>Email us at:</translation>
</message>
<message>
<source>do_not_expect_reply</source>
<translation>Note: do not expect a reply.</translation>
</message>
<message>
<source>thank_you_for_your_support</source>
<translation>Thank you for your support!</translation>
</message>
<message>
<source>open_an_issue</source>
<translation>Open an issue on GitHub (preferred):</translation>
</message>
<message>
<source>please_help_us</source>
<translation>Please help us improve by sharing the logs. You can report the issue in one of the following ways:</translation>
</message>
</context>
</TS>
112 changes: 0 additions & 112 deletions src/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
import base64
import binascii
import os
import platform
import shutil
import smtplib
import time
import zipfile
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from io import BytesIO

import pydenticon
Expand All @@ -42,7 +35,6 @@
from PySide6.QtWidgets import QPlainTextEdit
from PySide6.QtWidgets import QWidget

from config import report_email_server_config
from src.data.repository.setting_repository import SettingRepository
from src.data.service.helpers.main_asset_page_helper import get_offline_asset_ticker
from src.model.enums.enums_model import AssetType
Expand All @@ -61,9 +53,7 @@
from src.utils.constant import SLOW_TRANSACTION_FEE_BLOCKS
from src.utils.custom_exception import CommonException
from src.utils.error_message import ERROR_SAVE_LOGS
from src.utils.error_message import ERROR_SEND_REPORT_EMAIL
from src.utils.error_message import ERROR_SOMETHING_WENT_WRONG
from src.utils.error_message import ERROR_TITLE
from src.utils.info_message import INFO_COPY_MESSAGE
from src.utils.info_message import INFO_LOG_SAVE_DESCRIPTION
from src.utils.ln_node_manage import LnNodeServerManager
Expand Down Expand Up @@ -472,108 +462,6 @@ def close_button_navigation(parent, back_page_navigation=None):
parent.view_model.page_navigation.settings_page()


def generate_error_report_email(url, title):
"""Collect system info, format it, and generate the email body."""
# Collect system information
network = SettingRepository.get_wallet_network()
system_info = {
'URL': url,
'OS': platform.system(),
'OS Version': platform.version(),
'Wallet Version': __version__,
'Wallet Network': network.value,
'Architecture': platform.machine(),
'Processor': platform.processor(),
}

# Format system information for the email report
system_info_formatted = (
f"System Information Report:\n"
f"-------------------------\n"
f"URL: {system_info['URL']}\n"
f"Operating System: {system_info['OS']}\n"
f"OS Version: {system_info['OS Version']}\n"
f"Wallet Version: {system_info['Wallet Version']}\n"
f"Wallet Network: {system_info['Wallet Network']}\n"
f"Architecture: {system_info['Architecture']}\n"
f"Processor: {system_info['Processor']}\n"
)

# Generate the email body
email_body = (
f"{title}\n"
f"{'=' * len(title)}\n\n"
f"{system_info_formatted}\n"
f"Attached logs can be found in the provided ZIP file for further details."
)

return email_body


def send_crash_report_async(email_to, subject, body, zip_file_path):
"""
Asynchronously sends a crash report email with a ZIP attachment.
- Initializes a thread pool to run the email sending task asynchronously.
"""

def send_crash_report(email_to, subject, body, zip_file_path):
"""
- Retrieves the email server configuration (email ID and token).
- Creates a multipart email message with the subject, sender, and recipient.
- Attaches the email body and the ZIP file (if it exists).
- Connects to the SMTP server using TLS, authenticates with the email ID and token, and sends the email.
- Handles any exceptions that occur during the email sending process by showing an error toast message.
"""
email_id = report_email_server_config['smtp_email_id']
email_token = report_email_server_config['smtp_email_token']

# Create a multipart message
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = email_id
msg['To'] = email_to

# Attach the body text
msg.attach(MIMEText(body))

# Attach the ZIP file
if zip_file_path and os.path.exists(zip_file_path):
with open(zip_file_path, 'rb') as attachment:
part = MIMEBase('application', 'octet-stream')
part.set_payload(attachment.read())

# Encode the attachment
encoders.encode_base64(part)

# Add headers
part.add_header(
'Content-Disposition',
f'attachment; filename="{os.path.basename(zip_file_path)}"',
)

# Attach the part to the message
msg.attach(part)

try:
# Connect to the SMTP server
smtp_host = report_email_server_config.get(
'smtp_host', 'smtp.gmail.com',
)
smtp_port = report_email_server_config.get('smtp_port', 587)
with smtplib.SMTP(smtp_host, smtp_port) as server:
server.starttls()
server.login(email_id, email_token)
server.sendmail(email_id, [email_to], msg.as_string())
except CommonException as e:
ToastManager.error(
parent=None, title=ERROR_TITLE,
description=ERROR_SEND_REPORT_EMAIL.format(e),
)

executor = ThreadPoolExecutor(max_workers=1)
executor.submit(send_crash_report, email_to, subject, body, zip_file_path)


def find_files_with_name(path, keyword):
"""This method finds a file using the provided name."""
found_files = []
Expand Down
4 changes: 4 additions & 0 deletions src/utils/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@

# Syncing chain info label timer in milliseconds
SYNCING_CHAIN_LABEL_TIMER = 5000

# Email and github issue url for error report
CONTACT_EMAIL = '[email protected]'
GITHUB_ISSUE_LINK = 'https://github.com/RGB-Tools/iris-wallet-desktop/issues/new?template=Blank+issue'
1 change: 0 additions & 1 deletion src/utils/error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
ERROR_ENDPOINT_NOT_ALLOW_TO_CACHE_CHECK_CACHE_LIST = 'Provide endpoint {} not allow to cache please check cache list in endpoints.py file'
ERROR_CREATE_UTXO_FEE_RATE_ISSUE = 'Unexpected error'
ERROR_MESSAGE_TO_CHANGE_FEE_RATE = 'Please change default fee rate from setting page'
ERROR_SEND_REPORT_EMAIL = 'Failed to send email: {}'
ERROR_OPERATION_CANCELLED = 'Operation cancelled'
ERROR_NEW_CONNECTION_ERROR = 'Failed to connect to the server.because of network connection.'
ERROR_MAX_RETRY_EXITS = 'Max retries exceeded. while checking internet connection.'
Expand Down
13 changes: 0 additions & 13 deletions src/utils/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ def get_env_var(key, default=None):
'AUTH_PROVIDER_CERT_URL', 'https://www.googleapis.com/oauth2/v1/certs',
)
client_secret = get_env_var('CLIENT_SECRET')
smtp_email_id = get_env_var('SMTP_EMAIL_ID')
smtp_email_token = get_env_var('SMTP_EMAIL_TOKEN')
support_email = get_env_var('SUPPORT_EMAIL')
smtp_host = get_env_var('SMTP_HOST', 'smtp.gmail.com')
smtp_port = get_env_var('SMTP_PORT', '587')

# Create the content of config.py
config_content = f"""
Expand All @@ -57,14 +52,6 @@ def get_env_var(key, default=None):
'client_secret': '{client_secret}',
}},
}}
report_email_server_config = {{
'smtp_email_id': '{smtp_email_id}',
'smtp_email_token': '{smtp_email_token}',
'support_email': '{support_email}',
'smtp_host': '{smtp_host}',
'smtp_port': '{smtp_port}'
}}
"""

# Write the content to config.py
Expand Down
2 changes: 1 addition & 1 deletion src/utils/handle_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def handle_exceptions(exc):
)

if exc.response.status_code == 500:
PageNavigationEventManager.get_instance().error_report_signal.emit(exc.response.url)
PageNavigationEventManager.get_instance().error_report_signal.emit()
raw_exc = exc.response.json()
raise CommonException(error_message, raw_exc) from exc

Expand Down
4 changes: 2 additions & 2 deletions src/utils/page_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def sidebar(self):
"""This method return the sidebar objects."""
return self._ui.sidebar

def error_report_dialog_box(self, url):
def error_report_dialog_box(self):
"""This method display the error report dialog box"""
error_report_dialog = ErrorReportDialog(url=url)
error_report_dialog = ErrorReportDialog()
error_report_dialog.exec()
3 changes: 2 additions & 1 deletion src/utils/page_navigation_events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable = too-few-public-methods
"""Make page navigation global"""
from __future__ import annotations

Expand Down Expand Up @@ -45,7 +46,7 @@ class PageNavigationEventManager(QObject):
about_page_signal = Signal()
faucets_page_signal = Signal()
help_page_signal = Signal()
error_report_signal = Signal(str)
error_report_signal = Signal()

def __init__(self):
super().__init__()
Expand Down
Loading

0 comments on commit 0c86df9

Please sign in to comment.