ui: Add error and info templates and display debug mode.
This commit is contained in:
		
							parent
							
								
									afba673085
								
							
						
					
					
						commit
						6b4666d632
					
				@ -107,29 +107,7 @@ def listExplorerActions(swap_client):
 | 
				
			|||||||
    return actions
 | 
					    return actions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def html_content_start(title, h2=None, refresh=None):
 | 
					 | 
				
			||||||
    content = '<!DOCTYPE html><html lang="en">\n<head>' \
 | 
					 | 
				
			||||||
        + '<meta charset="UTF-8">' \
 | 
					 | 
				
			||||||
        + ('' if not refresh else '<meta http-equiv="refresh" content="{}">'.format(refresh)) \
 | 
					 | 
				
			||||||
        + '<title>' + title + '</title></head>\n' \
 | 
					 | 
				
			||||||
        + '<body>'
 | 
					 | 
				
			||||||
    if h2 is not None:
 | 
					 | 
				
			||||||
        content += '<h2>' + h2 + '</h2>'
 | 
					 | 
				
			||||||
    return content
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class HttpHandler(BaseHTTPRequestHandler):
 | 
					class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			||||||
    def page_info(self, info_str):
 | 
					 | 
				
			||||||
        content = html_content_start('BasicSwap Info') \
 | 
					 | 
				
			||||||
            + '<p>Info: ' + info_str + '</p>' \
 | 
					 | 
				
			||||||
            + '<p><a href=\'/\'>home</a></p></body></html>'
 | 
					 | 
				
			||||||
        return bytes(content, 'UTF-8')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def page_error(self, error_str):
 | 
					 | 
				
			||||||
        content = html_content_start('BasicSwap Error') \
 | 
					 | 
				
			||||||
            + '<p>Error: ' + error_str + '</p>' \
 | 
					 | 
				
			||||||
            + '<p><a href=\'/\'>home</a></p></body></html>'
 | 
					 | 
				
			||||||
        return bytes(content, 'UTF-8')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def checkForm(self, post_string, name, messages):
 | 
					    def checkForm(self, post_string, name, messages):
 | 
				
			||||||
        if post_string == '':
 | 
					        if post_string == '':
 | 
				
			||||||
@ -146,6 +124,10 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
        swap_client = self.server.swap_client
 | 
					        swap_client = self.server.swap_client
 | 
				
			||||||
        if swap_client.ws_server:
 | 
					        if swap_client.ws_server:
 | 
				
			||||||
            args_dict['ws_url'] = swap_client.ws_server.url
 | 
					            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(
 | 
					        return bytes(template.render(
 | 
				
			||||||
            title=self.server.title,
 | 
					            title=self.server.title,
 | 
				
			||||||
            h2=self.server.title,
 | 
					            h2=self.server.title,
 | 
				
			||||||
@ -153,6 +135,27 @@ class HttpHandler(BaseHTTPRequestHandler):
 | 
				
			|||||||
            **args_dict,
 | 
					            **args_dict,
 | 
				
			||||||
        ), 'UTF-8')
 | 
					        ), '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):
 | 
					    def page_explorers(self, url_split, post_string):
 | 
				
			||||||
        swap_client = self.server.swap_client
 | 
					        swap_client = self.server.swap_client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								basicswap/templates/error.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								basicswap/templates/error.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html><html lang="en"><head>
 | 
				
			||||||
 | 
					<meta charset="UTF-8">
 | 
				
			||||||
 | 
					<link type="text/css" media="all" href="/static/css/simple/style.css" rel="stylesheet">
 | 
				
			||||||
 | 
					<link rel=icon sizes="32x32" type="image/png" href="/static/images/favicon-32.png">
 | 
				
			||||||
 | 
					<title>{{ title }}</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					<h2>{{ title_str }}</h2>
 | 
				
			||||||
 | 
					<p>Error: {{ message_str }}</p>
 | 
				
			||||||
 | 
					<p><a href=\'/\'>home</a></p>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
@ -13,6 +13,13 @@
 | 
				
			|||||||
<h2>{{ h2 }}</h2>
 | 
					<h2>{{ h2 }}</h2>
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{% if debug_mode == true %}
 | 
				
			||||||
 | 
					<p>Debug mode: Active</p>
 | 
				
			||||||
 | 
					{% endif %}
 | 
				
			||||||
 | 
					{% if debug_ui_mode == true %}
 | 
				
			||||||
 | 
					<p>Debug UI mode: Active</p>
 | 
				
			||||||
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if ws_url %}
 | 
					{% if ws_url %}
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
    var ws = new WebSocket("{{ ws_url }}"),
 | 
					    var ws = new WebSocket("{{ ws_url }}"),
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										12
									
								
								basicswap/templates/info.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								basicswap/templates/info.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html><html lang="en"><head>
 | 
				
			||||||
 | 
					<meta charset="UTF-8">
 | 
				
			||||||
 | 
					<link type="text/css" media="all" href="/static/css/simple/style.css" rel="stylesheet">
 | 
				
			||||||
 | 
					<link rel=icon sizes="32x32" type="image/png" href="/static/images/favicon-32.png">
 | 
				
			||||||
 | 
					<title>{{ title }}</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					<h2>{{ title_str }}</h2>
 | 
				
			||||||
 | 
					<p>Info: {{ message_str }}</p>
 | 
				
			||||||
 | 
					<p><a href=\'/\'>home</a></p>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user