From 6b4666d63211591521d36c9a61414f79f3204967 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Thu, 15 Sep 2022 21:54:15 +0200 Subject: [PATCH] ui: Add error and info templates and display debug mode. --- basicswap/http_server.py | 47 ++++++++++++++++++--------------- basicswap/templates/error.html | 12 +++++++++ basicswap/templates/header.html | 7 +++++ basicswap/templates/info.html | 12 +++++++++ 4 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 basicswap/templates/error.html create mode 100644 basicswap/templates/info.html diff --git a/basicswap/http_server.py b/basicswap/http_server.py index ea73800..de6445a 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -107,29 +107,7 @@ def listExplorerActions(swap_client): return actions -def html_content_start(title, h2=None, refresh=None): - content = '\n' \ - + '' \ - + ('' if not refresh else ''.format(refresh)) \ - + '' + title + '\n' \ - + '' - if h2 is not None: - content += '

' + h2 + '

' - return content - - class HttpHandler(BaseHTTPRequestHandler): - def page_info(self, info_str): - content = html_content_start('BasicSwap Info') \ - + '

Info: ' + info_str + '

' \ - + '

home

' - return bytes(content, 'UTF-8') - - def page_error(self, error_str): - content = html_content_start('BasicSwap Error') \ - + '

Error: ' + error_str + '

' \ - + '

home

' - return bytes(content, 'UTF-8') def checkForm(self, post_string, name, messages): if post_string == '': @@ -146,6 +124,10 @@ class HttpHandler(BaseHTTPRequestHandler): swap_client = self.server.swap_client if swap_client.ws_server: args_dict['ws_url'] = swap_client.ws_server.url + if swap_client.debug: + args_dict['debug_mode'] = True + if swap_client.debug_ui: + args_dict['debug_ui_mode'] = True return bytes(template.render( title=self.server.title, h2=self.server.title, @@ -153,6 +135,27 @@ class HttpHandler(BaseHTTPRequestHandler): **args_dict, ), 'UTF-8') + def render_simple_template(self, template, args_dict): + swap_client = self.server.swap_client + return bytes(template.render( + title=self.server.title, + **args_dict, + ), 'UTF-8') + + def page_info(self, info_str): + template = env.get_template('info.html') + return self.render_simple_template(template, { + 'title_str': 'BasicSwap Info', + 'message_str': error_str, + }) + + def page_error(self, error_str): + template = env.get_template('error.html') + return self.render_simple_template(template, { + 'title_str': 'BasicSwap Error', + 'message_str': error_str, + }) + def page_explorers(self, url_split, post_string): swap_client = self.server.swap_client diff --git a/basicswap/templates/error.html b/basicswap/templates/error.html new file mode 100644 index 0000000..626dc0b --- /dev/null +++ b/basicswap/templates/error.html @@ -0,0 +1,12 @@ + + + + +{{ title }} + + +

{{ title_str }}

+

Error: {{ message_str }}

+

home

+ + diff --git a/basicswap/templates/header.html b/basicswap/templates/header.html index f9bd560..bf54b8d 100644 --- a/basicswap/templates/header.html +++ b/basicswap/templates/header.html @@ -13,6 +13,13 @@

{{ h2 }}

{% endif %} +{% if debug_mode == true %} +

Debug mode: Active

+{% endif %} +{% if debug_ui_mode == true %} +

Debug UI mode: Active

+{% endif %} + {% if ws_url %}